Beispiel #1
0
        public BackUpOperationStatusResponse WaitForOperationCompletionUsingStatusLink(
            string statusUrlLink,
            Func <string, BackUpOperationStatusResponse> serviceClientMethod)
        {
            // using this directly because it doesn't matter which function we use.
            // return type is same and currently we are using it in only two places.
            // protected item and policy.
            BackUpOperationStatusResponse response = serviceClientMethod(statusUrlLink);

            while (
                response != null &&
                response.OperationStatus != null &&
                response.OperationStatus.Status == OperationStatusValues.InProgress.ToString())
            {
                WriteDebug("Tracking operation completion using status link: " + statusUrlLink);
                TestMockSupport.Delay(_defaultSleepForOperationTracking * 1000);
                response = serviceClientMethod(statusUrlLink);
            }

            return(response);
        }
Beispiel #2
0
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

                WriteDebug(string.Format("Input params - Policy: {0}" +
                                         "RetentionPolicy:{1}, SchedulePolicy:{2}",
                                         Policy == null ? "NULL" : Policy.ToString(),
                                         RetentionPolicy == null ? "NULL" : RetentionPolicy.ToString(),
                                         SchedulePolicy == null ? "NULL" : SchedulePolicy.ToString()));

                // Validate policy name
                PolicyCmdletHelpers.ValidateProtectionPolicyName(Policy.Name);

                // Validate if policy already exists
                ProtectionPolicyResponse servicePolicy = PolicyCmdletHelpers.GetProtectionPolicyByName(
                    Policy.Name, ServiceClientAdapter);
                if (servicePolicy == null)
                {
                    throw new ArgumentException(string.Format(Resources.PolicyNotFoundException,
                                                              Policy.Name));
                }

                PsBackupProviderManager providerManager = new PsBackupProviderManager(
                    new Dictionary <System.Enum, object>()
                {
                    { PolicyParams.ProtectionPolicy, Policy },
                    { PolicyParams.RetentionPolicy, RetentionPolicy },
                    { PolicyParams.SchedulePolicy, SchedulePolicy },
                }, ServiceClientAdapter);

                IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(
                    Policy.WorkloadType,
                    Policy.BackupManagementType);
                ProtectionPolicyResponse policyResponse = psBackupProvider.ModifyPolicy();
                WriteDebug("ModifyPolicy http response from service: " +
                           policyResponse.StatusCode.ToString());

                if (policyResponse.StatusCode == System.Net.HttpStatusCode.Accepted)
                {
                    WriteDebug("Tracking operation status URL for completion: " +
                               policyResponse.AzureAsyncOperation);

                    // Track OperationStatus URL for operation completion
                    BackUpOperationStatusResponse operationResponse =
                        TrackingHelpers.WaitForOperationCompletionUsingStatusLink(
                            policyResponse.AzureAsyncOperation,
                            ServiceClientAdapter.GetProtectionPolicyOperationStatusByURL);

                    WriteDebug("Final operation status: " + operationResponse.OperationStatus.Status);

                    if (operationResponse.OperationStatus.Properties != null &&
                        ((OperationStatusJobsExtendedInfo)operationResponse.OperationStatus.Properties).JobIds != null)
                    {
                        // get list of jobIds and return jobResponses
                        WriteObject(GetJobObject(
                                        ((OperationStatusJobsExtendedInfo)operationResponse.OperationStatus.Properties).JobIds));
                    }

                    if (operationResponse.OperationStatus.Status == OperationStatusValues.Failed.ToString())
                    {
                        // if operation failed, then trace error and throw exception
                        if (operationResponse.OperationStatus.OperationStatusError != null)
                        {
                            WriteDebug(string.Format(
                                           "OperationStatus Error: {0} " +
                                           "OperationStatus Code: {1}",
                                           operationResponse.OperationStatus.OperationStatusError.Message,
                                           operationResponse.OperationStatus.OperationStatusError.Code));
                        }
                    }
                }
                else
                {
                    // ServiceClient will return OK if NO datasources are associated with this policy
                    WriteDebug("No datasources are associated with Policy, http response code: " +
                               policyResponse.StatusCode.ToString());
                }
            });
        }