public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

                if (ParameterSetName == JobFilterSet)
                {
                    JobId = Job.JobId;
                }

                WriteDebug("Stopping job with ID: " + JobId);

                var cancelResponse = ServiceClientAdapter.CancelJob(JobId);

                var operationStatus = TrackingHelpers.GetOperationResult(
                    cancelResponse,
                    operationId => ServiceClientAdapter.GetCancelJobOperationResult(operationId));

                if (operationStatus.Response.StatusCode != HttpStatusCode.NoContent)
                {
                    throw new Exception(string.Format(Resources.JobCouldNotCancelJob,
                                                      cancelResponse.Response.StatusCode.ToString()));
                }
                else
                {
                    WriteObject(JobConversions.GetPSJob(ServiceClientAdapter.GetJob(JobId)));
                }
            });
        }
 /// <summary>
 /// Get the job PS model after fetching the job object from the service given the job ID.
 /// </summary>
 /// <param name="jobId">ID of the job to be fetched</param>
 /// <returns></returns>
 public CmdletModel.JobBase GetJobObject(string jobId, string vaultName = null, string resourceGroupName = null)
 {
     return(JobConversions.GetPSJob(ServiceClientAdapter.GetJob(
                                        jobId,
                                        vaultName: vaultName,
                                        resourceGroupName: resourceGroupName)));
 }
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

                if (ParameterSetName == JobFilterSet)
                {
                    JobId = Job.JobId;
                }

                WriteDebug("Fetching job with ID: " + JobId);

                var adapterResponse = ServiceClientAdapter.GetJob(JobId);
                WriteObject(JobConversions.GetPSJob(adapterResponse));
            });
        }
Exemple #4
0
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName == JobFilterSet)
            {
                JobId = Job.JobId;
            }

            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(VaultId);
                string vaultName         = resourceIdentifier.ResourceName;
                string resourceGroupName = resourceIdentifier.ResourceGroupName;

                WriteDebug("Stopping job with ID: " + JobId);

                var cancelResponse = ServiceClientAdapter.CancelJob(
                    JobId,
                    vaultName: vaultName,
                    resourceGroupName: resourceGroupName);

                var operationStatus = TrackingHelpers.GetOperationResult(
                    cancelResponse,
                    operationId => ServiceClientAdapter.GetCancelJobOperationResult(
                        operationId,
                        vaultName: vaultName,
                        resourceGroupName: resourceGroupName));

                if (operationStatus.Response.StatusCode != HttpStatusCode.NoContent)
                {
                    throw new Exception(string.Format(Resources.JobCouldNotCancelJob,
                                                      cancelResponse.Response.StatusCode.ToString()));
                }
                else
                {
                    WriteObject(JobConversions.GetPSJob(ServiceClientAdapter.GetJob(
                                                            JobId,
                                                            vaultName: vaultName,
                                                            resourceGroupName: resourceGroupName)));
                }
            }, ShouldProcess(JobId, "Stop"));
        }
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(VaultId);
                string vaultName         = resourceIdentifier.ResourceName;
                string resourceGroupName = resourceIdentifier.ResourceGroupName;

                if (ParameterSetName == JobFilterSet)
                {
                    JobId = Job.JobId;
                }

                WriteDebug("Fetching job with ID: " + JobId);

                if (UseSecondaryRegion.IsPresent)
                {
                    CrrModel.CrrJobRequest jobRequest = new CrrModel.CrrJobRequest();
                    jobRequest.JobName    = JobId;
                    jobRequest.ResourceId = VaultId;

                    // check this GetVault for rainy day scenario
                    ARSVault vault         = ServiceClientAdapter.GetVault(resourceGroupName, vaultName);
                    string secondaryRegion = BackupUtils.regionMap[vault.Location];

                    CrrModel.JobResource jobDetailsCrr = ServiceClientAdapter.GetCRRJobDetails(secondaryRegion, jobRequest);
                    WriteObject(JobConversions.GetPSJobCrr(jobDetailsCrr));
                }
                else
                {
                    JobResource jobDetails = ServiceClientAdapter.GetJob(
                        JobId,
                        vaultName: vaultName,
                        resourceGroupName: resourceGroupName);

                    WriteObject(JobConversions.GetPSJob(jobDetails));
                }
            });
        }
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(VaultId);
                string vaultName         = resourceIdentifier.ResourceName;
                string resourceGroupName = resourceIdentifier.ResourceGroupName;

                if (ParameterSetName == JobFilterSet)
                {
                    JobId = Job.JobId;
                }

                WriteDebug("Fetching job with ID: " + JobId);

                var adapterResponse = ServiceClientAdapter.GetJob(
                    JobId,
                    vaultName: vaultName,
                    resourceGroupName: resourceGroupName);
                WriteObject(JobConversions.GetPSJob(adapterResponse));
            });
        }
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

                List <string> jobsToWaitOn = new List <string>();
                List <JobBase> finalJobs   = new List <JobBase>();

                object castedObj;
                if (GetCastedObjFromPSObj <JobBase>(Job, out castedObj))
                {
                    JobBase justJob = castedObj as JobBase;
                    jobsToWaitOn.Add(justJob.JobId);
                }
                else if (GetCastedObjFromPSObj <List <JobBase> >(Job, out castedObj))
                {
                    List <JobBase> jobsList = castedObj as List <JobBase>;
                    foreach (var job in jobsList)
                    {
                        jobsToWaitOn.Add(job.JobId);
                    }
                }
                else if (Job.GetType() == typeof(System.Object[]))
                {
                    System.Object[] castedJobsList = Job as System.Object[];
                    object castedJob;
                    foreach (var job in castedJobsList)
                    {
                        if (GetCastedObjFromPSObj <JobBase>(job, out castedJob))
                        {
                            jobsToWaitOn.Add((castedJob as JobBase).JobId);
                        }
                        else
                        {
                            throw new Exception(string.Format(Resources.JobWaitJobInvalidInput,
                                                              Job.GetType().FullName));
                        }
                    }
                }
                else
                {
                    // not a valid object. throw exception.
                    throw new Exception(string.Format(Resources.JobWaitJobInvalidInput,
                                                      Job.GetType().FullName));
                }

                // now wait until timeout happens or all jobs complete execution
                DateTime waitBeginning = DateTime.UtcNow;

                while (true)
                {
                    if (Timeout.HasValue)
                    {
                        if (DateTime.UtcNow.Subtract(waitBeginning) >=
                            TimeSpan.FromSeconds(Timeout.Value))
                        {
                            break;
                        }
                    }

                    bool hasUnfinishedJob = false;
                    finalJobs.Clear();
                    for (int i = 0; i < jobsToWaitOn.Count; i++)
                    {
                        string jobId   = jobsToWaitOn[i];
                        var updatedJob = JobConversions.GetPSJob(
                            ServiceClientAdapter.GetJob(jobId)
                            );

                        if (IsJobInProgress(updatedJob))
                        {
                            hasUnfinishedJob = true;
                        }
                        else
                        {
                            // removing finished job from list
                            jobsToWaitOn.RemoveAt(i);
                            i--;
                        }

                        finalJobs.Add(updatedJob);
                    }

                    if (!hasUnfinishedJob)
                    {
                        break;
                    }

                    // sleep for 30 seconds before checking again
                    TestMockSupport.Delay(30 * 1000);
                }

                WriteObject(finalJobs, enumerateCollection: true);
            });
        }
 /// <summary>
 /// Get the job PS model after fetching the job object from the service given the job ID.
 /// </summary>
 /// <param name="jobId">ID of the job to be fetched</param>
 /// <returns></returns>
 public CmdletModel.JobBase GetJobObject(string jobId)
 {
     return(JobConversions.GetPSJob(ServiceClientAdapter.GetJob(jobId)));
 }
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(VaultId);
                string vaultName         = resourceIdentifier.ResourceName;
                string resourceGroupName = resourceIdentifier.ResourceGroupName;

                List <string> jobsToWaitOn = new List <string>();
                List <JobBase> finalJobs   = new List <JobBase>();

                object castedObj;
                if (GetCastedObjFromPSObj <JobBase>(Job, out castedObj))
                {
                    JobBase justJob = castedObj as JobBase;
                    jobsToWaitOn.Add(justJob.JobId);
                }
                else if (GetCastedObjFromPSObj <List <JobBase> >(Job, out castedObj))
                {
                    List <JobBase> jobsList = castedObj as List <JobBase>;
                    foreach (var job in jobsList)
                    {
                        jobsToWaitOn.Add(job.JobId);
                    }
                }
                else if (Job.GetType() == typeof(object[]))
                {
                    object[] castedJobsList = Job as object[];
                    object castedJob;
                    foreach (var job in castedJobsList)
                    {
                        if (GetCastedObjFromPSObj <JobBase>(job, out castedJob))
                        {
                            jobsToWaitOn.Add((castedJob as JobBase).JobId);
                        }
                        else
                        {
                            throw new Exception(string.Format(Resources.JobWaitJobInvalidInput,
                                                              Job.GetType().FullName));
                        }
                    }
                }
                else
                {
                    // not a valid object. throw exception.
                    throw new Exception(string.Format(Resources.JobWaitJobInvalidInput,
                                                      Job.GetType().FullName));
                }

                // now wait until timeout happens or all jobs complete execution
                DateTime waitBeginning = DateTime.UtcNow;

                while (true)
                {
                    if (Timeout.HasValue)
                    {
                        if (DateTime.UtcNow.Subtract(waitBeginning) >=
                            TimeSpan.FromSeconds(Timeout.Value))
                        {
                            break;
                        }
                    }

                    bool hasUnfinishedJob = false;
                    finalJobs.Clear();
                    for (int i = 0; i < jobsToWaitOn.Count; i++)
                    {
                        string jobId   = jobsToWaitOn[i];
                        var updatedJob = JobConversions.GetPSJob(
                            ServiceClientAdapter.GetJob(
                                jobId,
                                vaultName: vaultName,
                                resourceGroupName: resourceGroupName));

                        if (IsJobInProgress(updatedJob))
                        {
                            hasUnfinishedJob = true;
                        }
                        else
                        {
                            // removing finished job from list
                            jobsToWaitOn.RemoveAt(i);
                            i--;
                        }

                        finalJobs.Add(updatedJob);
                    }

                    if (!hasUnfinishedJob)
                    {
                        break;
                    }

                    // sleep for 30 seconds before checking again
                    string testMode = Environment.GetEnvironmentVariable("AZURE_TEST_MODE");

                    if (!TestMockSupport.RunningMocked)
                    {
                        TestMockSupport.Delay(30 * 1000);
                    }
                    if (String.Compare(testMode, "Record", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        Thread.Sleep(30000);
                    }
                }

                WriteObject(finalJobs, enumerateCollection: true);
            });
        }