Beispiel #1
0
        private JobModelProxy GetPublishedJobDetails(Guid jobId)
        {
            var result = SendRequest("jobs/" + jobId, HttpMethod.Get);

            if (result.Length == 0) // maybe return null instead?
                return null;

            dynamic jsonJob = JObject.Parse(result);

            var job = new Job();
            job.JobID = jobId;
            job.CreationTime = (DateTime)jsonJob.properties.creationTime;
            job.LastModifiedTime = (DateTime)jsonJob.properties.lastModifiedTime;
            job.JobStatus = jsonJob.properties.status;
            job.StartTime = jsonJob.properties.startTime != null ? (DateTime?)jsonJob.properties.startTime : null;
            job.EndTime = jsonJob.properties.endTime != null ? (DateTime?)jsonJob.properties.endTime : null;

            var jobModelProxy = new JobModelProxy(job, Context);

            foreach (var param in jsonJob.properties.parameters)
            {
                //jobModelProxy.Parameters.Add(param)
            }

            var output = SendRequest("jobs/" + jobId + "/streams", HttpMethod.Get);
            jobModelProxy = ParseJobStreams(jobModelProxy, output);

            if (jsonJob.properties.exception != null)
            {
                jobModelProxy.Result.Add(new JobOutput()
                {
                    JobID = jobId,
                    RunbookVersionID = Guid.Empty,
                    StreamTypeName = "Error",
                    StreamTime = DateTime.Now,
                    StreamText = jsonJob.properties.exception,
                    TenantID = Guid.Empty
                });
            }

            return jobModelProxy;
        }
Beispiel #2
0
        public IList<JobModelProxy> GetJobs(Guid runbookVersionId)
        {
            // Since Azure are so nice, not providing any IDs for our runbooks and instead
            // using the name to identify the runbooks (as contrary to SMA which uses GUIDs),
            // we need to query our backend context to retrieve the correct runbook based on
            // our genereated GUID
            var runbook = Context.Runbooks.FirstOrDefault(r => (r.Tag as RunbookModelProxy).PublishedRunbookVersionID == runbookVersionId);

            if (runbook == null) // no runbook found?
                return new List<JobModelProxy>();

            var jobs = new List<JobModelProxy>();
            var result = SendRequest("jobs", HttpMethod.Get);
            dynamic jsonJobs = JObject.Parse(result);

            if (jsonJobs.value != null)
            {
                foreach (var job in jsonJobs.value)
                {
                    if (job.properties.runbook.name != (runbook.Tag as RunbookModelProxy).RunbookName)
                        continue;

                    var azureJob = new Job();
                    azureJob.JobID = job.properties.jobId;
                    azureJob.JobStatus = job.properties.status;
                    azureJob.CreationTime = job.properties.creationTime;
                    azureJob.StartTime = job.properties.startTime;
                    azureJob.LastModifiedTime = job.properties.lastModifiedTime;
                    azureJob.EndTime = job.properties.endTime;

                    jobs.Add(new JobModelProxy(azureJob, Context));
                }
            }

            return jobs;
        }
Beispiel #3
0
        private JobModelProxy GetDraftJobDetails(RunbookModelProxy runbook)
        {
            var result = SendRequest("runbooks/" + runbook.RunbookName.ToUrlSafeString() + "/draft/testJob", HttpMethod.Get);

            if (result.Length < 1)
                return null;

            dynamic jsonJob = JObject.Parse(result);

            var job = new Job();
            job.JobID = Guid.NewGuid();
            job.CreationTime = (DateTime)jsonJob.creationTime;
            job.LastModifiedTime = (DateTime)jsonJob.lastModifiedTime;
            job.JobStatus = jsonJob.status;
            job.StartTime = jsonJob.startTime != null ? (DateTime?)jsonJob.startTime : null;
            job.EndTime = jsonJob.endTime != null ? (DateTime?)jsonJob.endTime : null;
            job.JobException = jsonJob.exception;

            var jobModelProxy = new JobModelProxy(job, Context);

            foreach (var param in jsonJob.parameters)
            {
                //jobModelProxy.Parameters.Add(param)
            }

            var output = string.Empty;

            try
            {
                output = SendRequest("runbooks/" + runbook.RunbookName.ToUrlSafeString() + "/draft/testJob/streams", HttpMethod.Get);
                jobModelProxy = ParseJobStreams(jobModelProxy, output);
            }
            catch (WebException)
            {
                // The job haven't been started yet, ignore this.
            }

            return jobModelProxy;
        }