Example #1
0
        public PolicyAgentDocumentForTenantWrapper(PolicyAgentDocumentForTenant doc)
        {
            doc.Validate("doc");

            this.Incarnation = doc.Incarnation;
            this.Jobs        = new List <ITenantJob>();
            this.JobSetsRequiringApproval = new List <List <string> >();
            this.RoleInstanceHealthInfos  = new List <RoleInstanceHealthInfo>();

            if (doc.JobInfo != null)
            {
                var tenantJobInfo = doc.JobInfo.Deserialize();
                this.JobDocumentIncarnation = tenantJobInfo.DocumentIncarnation;

                if (tenantJobInfo.Jobs != null)
                {
                    foreach (var job in tenantJobInfo.Jobs)
                    {
                        this.Jobs.Add(new TenantJobWrapper(job));
                    }
                }

                if (tenantJobInfo.SetOfJobListsForAnyOfApproval != null)
                {
                    foreach (var anyOneOfJobsToApprove in tenantJobInfo.SetOfJobListsForAnyOfApproval)
                    {
                        var jobset = new List <string>();

                        if (anyOneOfJobsToApprove.JobList != null)
                        {
                            foreach (var bondId in anyOneOfJobsToApprove.JobList)
                            {
                                var id = bondId.ToGuid().ToString();
                                jobset.Add(id);
                            }
                        }

                        JobSetsRequiringApproval.Add(jobset);
                    }
                }
            }

            if (doc.RoleInstanceHealthInfo != null)
            {
                var roleInstanceHealthInfo = doc.RoleInstanceHealthInfo.Deserialize();
                this.RoleInstanceHealthInfoIncarnation = roleInstanceHealthInfo.Incarnation;
                this.RoleInstanceHealthInfoTimestamp   = roleInstanceHealthInfo.Timestamp;

                if (roleInstanceHealthInfo.RoleInstanceHealth != null)
                {
                    this.RoleInstanceHealthInfos = roleInstanceHealthInfo.RoleInstanceHealth;
                }
            }
        }
        public void ToJsonTest()
        {
            var tji = new TenantJobInfo
            {
                DocumentIncarnation = 1
            };

            tji.Jobs.Add(
                new TenantJob
            {
                ContextStringGivenByTenant = "tojsontest",
                JobStatus = JobStatusEnum.Executing,
                JobStep   = new JobStepInfo
                {
                    AcknowledgementStatus          = AcknowledgementStatusEnum.WaitingForAcknowledgement,
                    ActionStatus                   = ImpactActionStatus.NotExecuted,
                    ImpactStep                     = ImpactStepEnum.ImpactStart,
                    DeadlineForResponse            = "-1",
                    CurrentlyImpactedRoleInstances = new List <RoleInstanceImpactedByJob>
                    {
                        new RoleInstanceImpactedByJob
                        {
                            PreviousServiceInstanceName = "A",
                            UpdatedServiceInstanceName  = "B",
                            RoleInstanceName            = "SF_IN_1",
                            UpdateDomain = 1,
                        }
                    },
                }
            });

            var doc = new PolicyAgentDocumentForTenant
            {
                Incarnation = "1",
                JobInfo     = new Bonded <TenantJobInfo>(tji),
            };

            // simple tests for now
            var json = doc.ToJson();

            Assert.IsNotNull(json);

            // from json is not necessary for bond types since PolicyAgentDocumentForTenant contains an IBonded<JobInfo> which
            // cannot be deserialized in a straight forward fashion.
        }