コード例 #1
0
        private List <PSSchedulerJob> GetSchedulerJobs(string cloudService, string jobCollection)
        {
            List <PSSchedulerJob>   lstJobs   = new List <PSSchedulerJob>();
            CloudServiceGetResponse csDetails = csmClient.CloudServices.Get(cloudService);

            foreach (CloudServiceGetResponse.Resource csRes in csDetails.Resources)
            {
                if (csRes.ResourceProviderNamespace.Equals(Constants.SchedulerRPNameProvider, StringComparison.OrdinalIgnoreCase) && csRes.Name.Equals(jobCollection, StringComparison.OrdinalIgnoreCase))
                {
                    SchedulerClient schedClient = new SchedulerClient(csmClient.Credentials, cloudService, jobCollection);
                    JobListResponse jobs        = schedClient.Jobs.List(new JobListParameters
                    {
                        Skip = 0,
                    });
                    foreach (Job job in jobs)
                    {
                        lstJobs.Add(new PSSchedulerJob
                        {
                            JobName           = job.Id,
                            Lastrun           = job.Status == null ? null : job.Status.LastExecutionTime,
                            Nextrun           = job.Status == null ? null : job.Status.NextExecutionTime,
                            Status            = job.State.ToString(),
                            StartTime         = job.StartTime,
                            Recurrence        = job.Recurrence == null ? "" : job.Recurrence.Interval.ToString() + " per " + job.Recurrence.Frequency.ToString(),
                            Failures          = job.Status == null ? default(int?) : job.Status.FailureCount,
                            Faults            = job.Status == null ? default(int?) : job.Status.FaultedCount,
                            Executions        = job.Status == null ? default(int?) : job.Status.ExecutionCount,
                            EndSchedule       = GetEndTime(job),
                            JobCollectionName = jobCollection
                        });
                    }
                }
            }
            return(lstJobs);
        }
コード例 #2
0
        private CloudServiceResource GetCacheService(string cloudServiceName, string cacheServiceName)
        {
            CloudServiceGetResponse response      = client.CloudServices.Get(cloudServiceName);
            CloudServiceResource    cacheResource = response.Resources.FirstOrDefault((r) =>
            {
                return(IsCachingResource(r.Type) && r.Name.Equals(cacheServiceName, StringComparison.OrdinalIgnoreCase));
            });

            return(cacheResource);
        }
コード例 #3
0
 private bool CloudServiceExists(string cloudServiceName)
 {
     try
     {
         CloudServiceGetResponse response = client.CloudServices.Get(cloudServiceName);
     }
     catch (CloudException ex)
     {
         if (ex.Response.StatusCode == System.Net.HttpStatusCode.NotFound)
         {
             return(false);
         }
         throw ex;
     }
     return(true);
 }
コード例 #4
0
        public PSJobDetail GetJobDetail(string jobCollection, string job, string cloudService)
        {
            CloudServiceGetResponse csDetails = csmClient.CloudServices.Get(cloudService);

            foreach (CloudServiceGetResponse.Resource csRes in csDetails.Resources)
            {
                if (csRes.ResourceProviderNamespace.Equals(Constants.SchedulerRPNameProvider, StringComparison.OrdinalIgnoreCase) && csRes.Name.Equals(jobCollection, StringComparison.OrdinalIgnoreCase))
                {
                    SchedulerClient schedClient = this.currentSubscription.CreateClient <SchedulerClient>(false, cloudService, jobCollection, csmClient.Credentials, schedulerManagementClient.BaseUri);

                    JobListResponse jobs = schedClient.Jobs.List(new JobListParameters
                    {
                        Skip = 0,
                    });
                    foreach (Job j in jobs)
                    {
                        if (j.Id.ToLower().Equals(job.ToLower()))
                        {
                            if (Enum.GetName(typeof(JobActionType), j.Action.Type).Contains("Http"))
                            {
                                return(new PSHttpJobDetail
                                {
                                    JobName = j.Id,
                                    JobCollectionName = jobCollection,
                                    CloudService = cloudService,
                                    ActionType = Enum.GetName(typeof(JobActionType), j.Action.Type),
                                    Uri = j.Action.Request.Uri,
                                    Method = j.Action.Request.Method,
                                    Body = j.Action.Request.Body,
                                    Headers = j.Action.Request.Headers,
                                    Status = j.State.ToString(),
                                    StartTime = j.StartTime,
                                    EndSchedule = GetEndTime(j),
                                    Recurrence = j.Recurrence == null ? string.Empty : j.Recurrence.Interval.ToString() + " per " + j.Recurrence.Frequency.ToString(),
                                    Failures = j.Status == null ? default(int?) : j.Status.FailureCount,
                                    Faults = j.Status == null ? default(int?) : j.Status.FaultedCount,
                                    Executions = j.Status == null ? default(int?) : j.Status.ExecutionCount,
                                    Lastrun = j.Status == null ? null : j.Status.LastExecutionTime,
                                    Nextrun = j.Status == null ? null : j.Status.NextExecutionTime
                                });
                            }
                            else
                            {
                                return(new PSStorageQueueJobDetail
                                {
                                    JobName = j.Id,
                                    JobCollectionName = jobCollection,
                                    CloudService = cloudService,
                                    ActionType = Enum.GetName(typeof(JobActionType), j.Action.Type),
                                    StorageAccountName = j.Action.QueueMessage.StorageAccountName,
                                    StorageQueueName = j.Action.QueueMessage.QueueName,
                                    SasToken = j.Action.QueueMessage.SasToken,
                                    QueueMessage = j.Action.QueueMessage.Message,
                                    Status = j.State.ToString(),
                                    EndSchedule = GetEndTime(j),
                                    StartTime = j.StartTime,
                                    Recurrence = j.Recurrence == null ? string.Empty : j.Recurrence.Interval.ToString() + " per " + j.Recurrence.Frequency.ToString(),
                                    Failures = j.Status == null ? default(int?) : j.Status.FailureCount,
                                    Faults = j.Status == null ? default(int?) : j.Status.FaultedCount,
                                    Executions = j.Status == null ? default(int?) : j.Status.ExecutionCount,
                                    Lastrun = j.Status == null ? null : j.Status.LastExecutionTime,
                                    Nextrun = j.Status == null ? null : j.Status.NextExecutionTime
                                });
                            }
                        }
                    }
                }
            }
            return(null);
        }
コード例 #5
0
        public List <PSJobHistory> GetJobHistory(string jobCollection, string job, string region, string jobStatus = "")
        {
            if (!this.AvailableRegions.Contains(region, StringComparer.OrdinalIgnoreCase))
            {
                throw new Exception(Resources.SchedulerInvalidLocation);
            }

            List <PSJobHistory> lstPSJobHistory = new List <PSJobHistory>();
            string cloudService = region.ToCloudServiceName();
            CloudServiceGetResponse csDetails = csmClient.CloudServices.Get(cloudService);

            foreach (CloudServiceGetResponse.Resource csRes in csDetails.Resources)
            {
                if (csRes.ResourceProviderNamespace.Equals(Constants.SchedulerRPNameProvider, StringComparison.InvariantCultureIgnoreCase) && csRes.Name.Equals(jobCollection, StringComparison.OrdinalIgnoreCase))
                {
                    SchedulerClient schedClient = this.currentSubscription.CreateClient <SchedulerClient>(false, cloudService, jobCollection.Trim(), csmClient.Credentials, schedulerManagementClient.BaseUri);

                    List <JobGetHistoryResponse.JobHistoryEntry> lstHistory = new List <JobGetHistoryResponse.JobHistoryEntry>();
                    int currentTop = 100;

                    if (string.IsNullOrEmpty(jobStatus))
                    {
                        JobGetHistoryResponse history = schedClient.Jobs.GetHistory(job.Trim(), new JobGetHistoryParameters {
                            Top = 100
                        });
                        lstHistory.AddRange(history.JobHistory);
                        while (history.JobHistory.Count > 99)
                        {
                            history = schedClient.Jobs.GetHistory(job.Trim(), new JobGetHistoryParameters {
                                Top = 100, Skip = currentTop
                            });
                            currentTop += 100;
                            lstHistory.AddRange(history.JobHistory);
                        }
                    }
                    else if (!string.IsNullOrEmpty(jobStatus))
                    {
                        JobHistoryStatus      status  = jobStatus.Equals("Completed") ? JobHistoryStatus.Completed : JobHistoryStatus.Failed;
                        JobGetHistoryResponse history = schedClient.Jobs.GetHistoryWithFilter(job.Trim(), new JobGetHistoryWithFilterParameters {
                            Top = 100, Status = status
                        });
                        lstHistory.AddRange(history.JobHistory);
                        while (history.JobHistory.Count > 99)
                        {
                            history = schedClient.Jobs.GetHistoryWithFilter(job.Trim(), new JobGetHistoryWithFilterParameters {
                                Top = 100, Skip = currentTop
                            });
                            currentTop += 100;
                            lstHistory.AddRange(history.JobHistory);
                        }
                    }
                    foreach (JobGetHistoryResponse.JobHistoryEntry entry in lstHistory)
                    {
                        PSJobHistory historyObj = new PSJobHistory();
                        historyObj.Status    = entry.Status.ToString();
                        historyObj.StartTime = entry.StartTime;
                        historyObj.EndTime   = entry.EndTime;
                        historyObj.JobName   = entry.Id;
                        historyObj.Details   = GetHistoryDetails(entry.Message);
                        historyObj.Retry     = entry.RetryCount;
                        historyObj.Occurence = entry.RepeatCount;
                        if (JobHistoryActionName.ErrorAction == entry.ActionName)
                        {
                            PSJobHistoryError errorObj = historyObj.ToJobHistoryError();
                            errorObj.ErrorAction = JobHistoryActionName.ErrorAction.ToString();
                            lstPSJobHistory.Add(errorObj);
                        }
                        else
                        {
                            lstPSJobHistory.Add(historyObj);
                        }
                    }
                }
            }
            return(lstPSJobHistory);
        }
コード例 #6
0
        public PSJobDetail GetJobDetail(string jobCollection, string job, string cloudService)
        {
            CloudServiceGetResponse csDetails = csmClient.CloudServices.Get(cloudService);

            foreach (CloudServiceGetResponse.Resource csRes in csDetails.Resources)
            {
                if (csRes.ResourceProviderNamespace.Equals(Constants.SchedulerRPNameProvider, StringComparison.OrdinalIgnoreCase) && csRes.Name.Equals(jobCollection, StringComparison.OrdinalIgnoreCase))
                {
                    SchedulerClient schedClient = AzureSession.Instance.ClientFactory.CreateCustomClient <SchedulerClient>(cloudService, jobCollection, csmClient.Credentials, schedulerManagementClient.BaseUri);

                    JobListResponse jobs = schedClient.Jobs.List(new JobListParameters
                    {
                        Skip = 0,
                    });
                    foreach (Job j in jobs)
                    {
                        if (j.Id.ToLower().Equals(job.ToLower()))
                        {
                            if (Enum.GetName(typeof(JobActionType), j.Action.Type).Contains("Http"))
                            {
                                PSHttpJobDetail jobDetail = new PSHttpJobDetail();
                                jobDetail.JobName           = j.Id;
                                jobDetail.JobCollectionName = jobCollection;
                                jobDetail.CloudService      = cloudService;
                                jobDetail.ActionType        = Enum.GetName(typeof(JobActionType), j.Action.Type);
                                jobDetail.Uri         = j.Action.Request.Uri;
                                jobDetail.Method      = j.Action.Request.Method;
                                jobDetail.Body        = j.Action.Request.Body;
                                jobDetail.Headers     = j.Action.Request.Headers;
                                jobDetail.Status      = j.State.ToString();
                                jobDetail.StartTime   = j.StartTime;
                                jobDetail.EndSchedule = GetEndTime(j);
                                jobDetail.Recurrence  = j.Recurrence == null ? string.Empty : j.Recurrence.Interval.ToString() + " (" + j.Recurrence.Frequency.ToString() + "s)";
                                if (j.Status != null)
                                {
                                    jobDetail.Failures   = j.Status.FailureCount;
                                    jobDetail.Faults     = j.Status.FaultedCount;
                                    jobDetail.Executions = j.Status.ExecutionCount;
                                    jobDetail.Lastrun    = j.Status.LastExecutionTime;
                                    jobDetail.Nextrun    = j.Status.NextExecutionTime;
                                }
                                if (j.Action.Request.Authentication != null)
                                {
                                    switch (j.Action.Request.Authentication.Type)
                                    {
                                    case HttpAuthenticationType.ClientCertificate:
                                        PSClientCertAuthenticationJobDetail ClientCertJobDetail = new PSClientCertAuthenticationJobDetail(jobDetail);
                                        ClientCertJobDetail.ClientCertExpiryDate  = ((j.Action.Request.Authentication) as ClientCertAuthentication).CertificateExpiration.ToString();
                                        ClientCertJobDetail.ClientCertSubjectName = ((j.Action.Request.Authentication) as ClientCertAuthentication).CertificateSubjectName;
                                        ClientCertJobDetail.ClientCertThumbprint  = ((j.Action.Request.Authentication) as ClientCertAuthentication).CertificateThumbprint;
                                        return(ClientCertJobDetail);

                                    case HttpAuthenticationType.ActiveDirectoryOAuth:
                                        PSAADOAuthenticationJobDetail AADOAuthJobDetail = new PSAADOAuthenticationJobDetail(jobDetail);
                                        AADOAuthJobDetail.Audience = ((j.Action.Request.Authentication) as AADOAuthAuthentication).Audience;
                                        AADOAuthJobDetail.ClientId = ((j.Action.Request.Authentication) as AADOAuthAuthentication).ClientId;
                                        AADOAuthJobDetail.Tenant   = ((j.Action.Request.Authentication) as AADOAuthAuthentication).Tenant;
                                        return(AADOAuthJobDetail);

                                    case HttpAuthenticationType.Basic:
                                        PSBasicAuthenticationJobDetail BasicAuthJobDetail = new PSBasicAuthenticationJobDetail(jobDetail);
                                        BasicAuthJobDetail.Username = ((j.Action.Request.Authentication) as BasicAuthentication).Username;
                                        return(BasicAuthJobDetail);
                                    }
                                }
                                return(jobDetail);
                            }
                            else
                            {
                                return(new PSStorageQueueJobDetail
                                {
                                    JobName = j.Id,
                                    JobCollectionName = jobCollection,
                                    CloudService = cloudService,
                                    ActionType = Enum.GetName(typeof(JobActionType), j.Action.Type),
                                    StorageAccountName = j.Action.QueueMessage.StorageAccountName,
                                    StorageQueueName = j.Action.QueueMessage.QueueName,
                                    SasToken = j.Action.QueueMessage.SasToken,
                                    QueueMessage = j.Action.QueueMessage.Message,
                                    Status = j.State.ToString(),
                                    EndSchedule = GetEndTime(j),
                                    StartTime = j.StartTime,
                                    Recurrence = j.Recurrence == null ? string.Empty : j.Recurrence.Interval.ToString() + " (" + j.Recurrence.Frequency.ToString() + "s)",
                                    Failures = j.Status == null ? default(int?) : j.Status.FailureCount,
                                    Faults = j.Status == null ? default(int?) : j.Status.FaultedCount,
                                    Executions = j.Status == null ? default(int?) : j.Status.ExecutionCount,
                                    Lastrun = j.Status == null ? null : j.Status.LastExecutionTime,
                                    Nextrun = j.Status == null ? null : j.Status.NextExecutionTime
                                });
                            }
                        }
                    }
                }
            }
            return(null);
        }