コード例 #1
0
        private async Task <IJobBlockingPolicyManager> CreateAsync(IPropertyManagerWrapper propertyManager)
        {
            var versionedPropertyStore = await VersionedPropertyStore.CreateAsync(
                Guid.NewGuid(),
                TraceType,
                new Uri(Constants.StoreName),
                propertyManager,
                retryPolicyFactory).ConfigureAwait(false);

            IJobBlockingPolicyManager jobPolicyManager =
                await JobBlockingPolicyManager.CreateAsync(
                    TraceType, versionedPropertyStore).ConfigureAwait(false);

            return(jobPolicyManager);
        }
コード例 #2
0
        public async Task MigrationToNamespacePrefixTestAsync()
        {
            var mockVersionedPropertyStore = new MockVersionedPropertyStore();

            IJobBlockingPolicyManager jobPolicyManager = await JobBlockingPolicyManager.CreateAsync(
                TraceType, mockVersionedPropertyStore).ConfigureAwait(false);

            Assert.AreEqual(jobPolicyManager.Policy, JobBlockingPolicy.BlockNone);

            await jobPolicyManager.UpdatePolicyAsync(JobBlockingPolicy.BlockAllJobs).ConfigureAwait(false);

            Assert.AreEqual(jobPolicyManager.Policy, JobBlockingPolicy.BlockAllJobs);

            // IS is migrated to parallel mode with per-tenant jobblocking policy option
            var mockTenantSpecificVersionedPropertyStore = new MockVersionedPropertyStore();
            IJobBlockingPolicyManager jobPolicyManager2  = await JobBlockingPolicyManager.CreateAsync(
                TraceType, mockTenantSpecificVersionedPropertyStore, mockVersionedPropertyStore).ConfigureAwait(false);

            // the namespace properties should have the same policy as the existing old properties
            Assert.AreEqual(jobPolicyManager2.Policy, JobBlockingPolicy.BlockAllJobs);

            var activityId = Guid.NewGuid();
            var vkv        = await mockVersionedPropertyStore
                             .GetValueAsync(activityId, JobBlockingPolicyManager.PolicyPropertyName, JobBlockingPolicyManager.PolicyVersionName)
                             .ConfigureAwait(false);

            Assert.IsNotNull(vkv);

            var vkv2 = await mockTenantSpecificVersionedPropertyStore
                       .GetValueAsync(activityId, JobBlockingPolicyManager.PolicyPropertyName, JobBlockingPolicyManager.PolicyVersionName)
                       .ConfigureAwait(false);

            Assert.IsNotNull(vkv2);

            Assert.AreEqual(vkv.Value, vkv2.Value);
        }
        public IInfrastructureCoordinator Create()
        {
            var repairManager = new ServiceFabricRepairManagerFactory(env, activityLogger).Create();

            if (repairManager == null)
            {
                const string message = "Unable to create Repair Manager client; cannot continue further.";
                TraceType.WriteWarning(message);
                throw new ManagementException(message);
            }

            var policyAgentClient = new PolicyAgentClient(env, policyAgentServiceWrapper, activityLogger);

            var retryPolicyFactory = new LinearRetryPolicyFactory(
                env.DefaultTraceType,
                InfrastructureService.Constants.BackoffPeriodInMilliseconds,
                InfrastructureService.Constants.MaxRetryAttempts,
                AzureHelper.IsRetriableException);

            string tenantSpecificStoreName = "{0}/{1}".ToString(InfrastructureService.Constants.StoreName, configSection.Name);

            var tenantSpecificVersionedPropertyStore = VersionedPropertyStore.CreateAsync(
                Guid.NewGuid(),
                env.CreateTraceType("PropertyStore"),
                new Uri(tenantSpecificStoreName),
                new PropertyManagerWrapper(),
                retryPolicyFactory).GetAwaiter().GetResult();

            // if this exists, job blocking policy manager will migrate job blocking policy properties
            // from this one to the tenant-specific store.
            var versionedPropertyStore = VersionedPropertyStore.CreateAsync(
                Guid.NewGuid(),
                env.CreateTraceType("PropertyStoreOld"),
                new Uri(InfrastructureService.Constants.StoreName),
                new PropertyManagerWrapper(),
                retryPolicyFactory).GetAwaiter().GetResult();

            var jobBlockingPolicyManager = JobBlockingPolicyManager.CreateAsync(
                env.CreateTraceType("JobBlockingPolicyManager"),
                tenantSpecificVersionedPropertyStore,
                versionedPropertyStore).GetAwaiter().GetResult();

            var allowActionMap = new AllowActionMap();
            var coordinatorCommandProcessor = new CoordinatorCommandProcessor(
                env,
                policyAgentClient,
                jobBlockingPolicyManager,
                allowActionMap);
            var mappedPolicyFactory = new DefaultActionPolicyFactory(env, jobBlockingPolicyManager, allowActionMap);

            var coordinator =
                new AzureParallelInfrastructureCoordinator(
                    env,
                    tenantId,
                    policyAgentClient,
                    repairManager,
                    new ServiceFabricHealthClient(),
                    coordinatorCommandProcessor,
                    jobBlockingPolicyManager,
                    mappedPolicyFactory,
                    activityLogger,
                    partitionId,
                    replicaId);

            return(coordinator);
        }