示例#1
0
        public void PolicyAgentDocSerDeTest()
        {
            var job  = TenantJobHelper.CreateNewTenantJob();
            var jobs = new List <ITenantJob> {
                job
            };
            var doc = TenantJobHelper.CreateNewPolicyAgentDocumentForTenant(jobs, 1);

            // Note: do not use ToJson() since it uses public settings for serialization which means
            // that the object cannot be deserialized.
            string json = JsonConvert.SerializeObject(doc, internalSerializationSettings);
            var    doc2 = json.FromJson <MockPolicyAgentDocumentForTenant>();

            Assert.AreEqual(doc.Incarnation, doc2.Incarnation);
            Assert.AreEqual(doc.JobDocumentIncarnation, doc2.JobDocumentIncarnation);
            Assert.AreEqual(doc.RoleInstanceHealthInfoIncarnation, doc2.RoleInstanceHealthInfoIncarnation);
            Assert.AreEqual(doc.RoleInstanceHealthInfoTimestamp, doc2.RoleInstanceHealthInfoTimestamp);
            Assert.AreEqual(doc.Jobs.Count, doc2.Jobs.Count);
            Assert.AreEqual(doc.RoleInstanceHealthInfos.Count, doc2.RoleInstanceHealthInfos.Count);

            for (int i = 0; i < doc.Jobs.Count; i++)
            {
                Assert.AreEqual(doc.Jobs[i].Id, doc2.Jobs[i].Id);
                Assert.AreEqual(doc.Jobs[i].ContextStringGivenByTenant, doc2.Jobs[i].ContextStringGivenByTenant);
                Assert.AreEqual(doc.Jobs[i].JobStatus, doc2.Jobs[i].JobStatus);
                Assert.IsTrue(doc.Jobs[i].RoleInstancesToBeImpacted.SequenceEqual(doc2.Jobs[i].RoleInstancesToBeImpacted));
            }

            string json3 = JsonConvert.SerializeObject(doc2, internalSerializationSettings);

            Assert.AreEqual(json, json3);
        }
示例#2
0
        protected override void Run(CancellationToken cancellationToken)
        {
            var tenantJob = TenantJobHelper.CreateNewTenantJob();

            PolicyAgentService.CreateTenantJob(tenantJob);

            RepairManager.CompletedEvent.WaitOne();
            CompletedEvent.Set();
        }
        protected override void Run(CancellationToken cancellationToken)
        {
            var tenantJob = TenantJobHelper.CreateNewTenantJob(ImpactActionEnum.PlatformUpdate); // Root HE

            // this kicks things off
            PolicyAgentService.CreateTenantJob(tenantJob);

            RepairManager.CompletedEvent.WaitOne();
            CompletedEvent.Set();
        }
        protected override void Run(CancellationToken cancellationToken)
        {
            var tenantJob = TenantJobHelper.CreateNewTenantJob(ImpactActionEnum.PlatformMaintenance);

            // this kicks things off
            PolicyAgentService.CreateTenantJob(tenantJob);

            ProcessCloser.ExitEvent.WaitOne();

            CompletedEvent.Set();
        }
示例#5
0
        protected override void Run(CancellationToken cancellationToken)
        {
            var tenantJob = TenantJobHelper.CreateNewTenantJob(ImpactActionEnum.PlatformMaintenance);

            // this kicks things off
            PolicyAgentService.CreateTenantJob(tenantJob);

            ProcessCloser.ExitEvent.WaitOne();

            var elapsed = DateTimeOffset.UtcNow - startTime;

            Assert.IsTrue(elapsed >= TimeSpan.FromSeconds(MaxRetryDurationInSeconds), "Verifying if max retry duration is exceeded");
            CompletedEvent.Set();
        }
            private void SendNewJobStep(PolicyAgentRequest request, uint ud, List <string> roleInstances)
            {
                foreach (JobStepResponse jobStepResponse in request.JobResponse.JobStepResponses)
                {
                    Guid guid = jobStepResponse.JobId.ToGuid();
                    var  id   = guid;

                    var tenantJob = (MockTenantJob)GetTenantJob(id);

                    tenantJob.JobStep = TenantJobHelper.CreateNewJobStepInfo(ud, roleInstances);

                    // update job after it does its job, so that IS gets it again when it polls for it.
                    UpdateTenantJob(tenantJob);
                }
            }
            private void SendNewJobStep(PolicyAgentRequest request)
            {
                foreach (JobStepResponse jobStepResponse in request.JobResponse.JobStepResponses)
                {
                    Guid guid = jobStepResponse.JobId.ToGuid();
                    var  id   = guid;

                    MockTenantJob tenantJob = (MockTenantJob)GetTenantJob(id);

                    tenantJob.JobStep = TenantJobHelper.CreateNewJobStepInfo(1, new List <string> {
                        "Role_IN_2", "Role_IN_3"
                    });

                    // update job after it does its job, so that IS gets it again when it polls for it.
                    UpdateTenantJob(tenantJob);
                }
            }
示例#8
0
            /// <summary>
            /// When IS makes a RepairRequest post to PolicyAgent, then we create a new tenant job in response
            /// </summary>
            public override async Task PostPolicyAgentRequestAsync(
                Guid activityId,
                PolicyAgentRequest request,
                CancellationToken cancellationToken)
            {
                if (request.RepairRequest != null && request.RepairRequest.RoleInstanceId != null)
                {
                    string id = request.RepairRequest.RoleInstanceId + "/" + request.RepairRequest.Action;

                    if (!repairRequests.Contains(id))
                    {
                        var tenantJob = TenantJobHelper.CreateNewTenantJob(
                            ImpactActionEnum.TenantMaintenance,
                            0,
                            new List <string> {
                            "Role_IN_1"
                        },
                            request.RepairRequest.ContextId);
                        CreateTenantJob(tenantJob);

                        repairRequests.Add(id);
                        return;
                    }
                }

                if (policyAgentStage == 0)
                {
                    SendImpactEnd(request);
                }
                else if (policyAgentStage == 1)
                {
                    SendCompletion(request, true);
                    CompletedEvent.Set();
                }

                policyAgentStage++;

                await Task.FromResult(0);
            }
示例#9
0
        public async Task BasicTest1Async()
        {
            var activityId = Guid.NewGuid();
            var job        = TenantJobHelper.CreateNewTenantJob();
            var jobs       = new List <ITenantJob> {
                job
            };

            var doc = TenantJobHelper.CreateNewPolicyAgentDocumentForTenant(jobs, 1);

            var coordinatorContext = new CoordinatorContext {
                Doc = doc
            };

            ActionHelper.CreateMappedWorkItems(jobs, new List <IRepairTask>(), coordinatorContext);

            await CreateReconciler().ReconcileAsync(activityId, coordinatorContext).ConfigureAwait(false);

            Assert.AreEqual(coordinatorContext.MappedTenantJobs[job.Id].Actions.Count, 1);
            var action = coordinatorContext.MappedTenantJobs[job.Id].Actions[0];

            Assert.IsTrue(action is CreateInPreparingAction, "Verifying if new repair task is being created");
        }
        public virtual Task <IPolicyAgentDocumentForTenant> GetDocumentAsync(Guid activityId, CancellationToken cancellationToken)
        {
            var doc = TenantJobHelper.CreateNewPolicyAgentDocumentForTenant(tenantJobs.Values.ToList(), jobDocIncarnation);

            return(Task.FromResult(doc));
        }