public override void ExecuteCmdlet() { if (ParameterSetName == JobFilterSet) { JobId = Job.JobId; } ExecutionBlock(() => { base.ExecuteCmdlet(); 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))); } }, ShouldProcess(JobId, "Stop")); }
public void TriggerInquiry(string vaultName, string vaultResourceGroupName, string containerName, string workloadType) { ODataQuery <BMSContainersInquiryQueryObject> queryParams = new ODataQuery <BMSContainersInquiryQueryObject>( q => q.WorkloadType == workloadType); string errorMessage = string.Empty; var inquiryResponse = ServiceClientAdapter.InquireContainer( containerName, queryParams, vaultName, vaultResourceGroupName); var operationStatus = TrackingHelpers.GetOperationResult( inquiryResponse, operationId => ServiceClientAdapter.GetContainerRefreshOrInquiryOperationResult( operationId, vaultName: vaultName, resourceGroupName: vaultResourceGroupName)); //Now wait for the operation to Complete if (inquiryResponse.Response.StatusCode != SystemNet.HttpStatusCode.NoContent) { errorMessage = string.Format(Resources.TriggerEnquiryFailureErrorCode, inquiryResponse.Response.StatusCode); Logger.Instance.WriteDebug(errorMessage); } }
public void RegisterContainer(string containerName, ProtectionContainerResource protectionContainerResource, string vaultName, string vaultResourceGroupName) { var registerResponse = ServiceClientAdapter.RegisterContainer( containerName, protectionContainerResource, vaultName, vaultResourceGroupName); var operationStatus = TrackingHelpers.GetOperationResult( registerResponse, operationId => ServiceClientAdapter.GetRegisterContainerOperationResult( operationId, containerName, vaultName: vaultName, resourceGroupName: vaultResourceGroupName)); //Now wait for the operation to Complete if (registerResponse.Response.StatusCode != SystemNet.HttpStatusCode.NoContent) { string errorMessage = string.Format(Resources.RegisterFailureErrorCode, registerResponse.Response.StatusCode); Logger.Instance.WriteDebug(errorMessage); } }
public void RefreshContainer(string vaultName = null, string vaultResourceGroupName = null, ODataQuery <BMSRefreshContainersQueryObject> queryParam = null) { var refreshContainerJobResponse = ServiceClientAdapter.RefreshContainers( vaultName: vaultName, resourceGroupName: vaultResourceGroupName, queryParam: queryParam); var operationStatus = TrackingHelpers.GetOperationResult( refreshContainerJobResponse, operationId => ServiceClientAdapter.GetContainerRefreshOrInquiryOperationResult( operationId, vaultName: vaultName, resourceGroupName: vaultResourceGroupName)); //Now wait for the operation to Complete if (refreshContainerJobResponse.Response.StatusCode != SystemNet.HttpStatusCode.NoContent) { string errorMessage = string.Format(Resources.DiscoveryFailureErrorCode, refreshContainerJobResponse.Response.StatusCode); Logger.Instance.WriteDebug(errorMessage); } }
/// <summary> /// This method triggers the Data Move operation on Target vault. /// </summary> /// <param name="vaultName"></param> /// <param name="resourceGroupName"></param> /// <param name="triggerMoveRequest"></param> public void TriggerDataMove(string vaultName, string resourceGroupName, TriggerDataMoveRequest triggerMoveRequest) { //trigger move var triggerMoveOperationResponse = ServiceClientAdapter.BmsAdapter.Client.BeginBMSTriggerDataMoveWithHttpMessagesAsync( vaultName, resourceGroupName, triggerMoveRequest).Result; // track trigger-move operation to success var operationStatus = TrackingHelpers.GetOperationStatusDataMove( triggerMoveOperationResponse, operationId => ServiceClientAdapter.GetDataMoveOperationStatus(operationId, vaultName, resourceGroupName)); Logger.Instance.WriteDebug("Trigger move operation: " + operationStatus.Body.Status); }
public override void ExecuteCmdlet() { ExecutionBlock(() => { base.ExecuteCmdlet(); ResourceIdentifier resourceIdentifier = new ResourceIdentifier(VaultId); string vaultName = resourceIdentifier.ResourceName; string vaultResourceGroupName = resourceIdentifier.ResourceGroupName; string workloadType = ConversionUtils.GetServiceClientWorkloadType(WorkloadType.ToString()); string backupManagementType = Container.BackupManagementType.ToString(); ODataQuery <BMSContainersInquiryQueryObject> queryParams = new ODataQuery <BMSContainersInquiryQueryObject>( q => q.WorkloadType == workloadType && q.BackupManagementType == backupManagementType); string errorMessage = string.Empty; var inquiryResponse = ServiceClientAdapter.InquireContainer( Container.Name, queryParams, vaultName, vaultResourceGroupName); var operationStatus = TrackingHelpers.GetOperationResult( inquiryResponse, operationId => ServiceClientAdapter.GetRegisterContainerOperationResult( operationId, Container.Name, vaultName: vaultName, resourceGroupName: vaultResourceGroupName)); if (inquiryResponse.Response.StatusCode == SystemNet.HttpStatusCode.OK) { Logger.Instance.WriteDebug(errorMessage); } //Now wait for the operation to Complete if (inquiryResponse.Response.StatusCode != SystemNet.HttpStatusCode.NoContent) { errorMessage = string.Format(Resources.TriggerEnquiryFailureErrorCode, inquiryResponse.Response.StatusCode); Logger.Instance.WriteDebug(errorMessage); } if (PassThru.IsPresent) { WriteObject(Container); } }, ShouldProcess(Container.Name, VerbsLifecycle.Invoke)); }
/// <summary> /// Based on the response from the service, handles the job created in the service appropriately. /// </summary> /// <param name="response">Response from service</param> /// <param name="operationName">Name of the operation</param> protected void HandleCreatedJob( AzureRestNS.AzureOperationResponse response, string operationName, string vaultName = null, string resourceGroupName = null) { WriteDebug(Resources.TrackingOperationStatusURLForCompletion + response.Response.Headers.GetAzureAsyncOperationHeader()); var operationStatus = TrackingHelpers.GetOperationStatus( response, operationId => ServiceClientAdapter.GetProtectedItemOperationStatus( operationId, vaultName: vaultName, resourceGroupName: resourceGroupName)); if (response != null && operationStatus != null) { WriteDebug(Resources.FinalOperationStatus + operationStatus.Status); if (operationStatus.Properties != null) { var jobExtendedInfo = (OperationStatusJobExtendedInfo)operationStatus.Properties; if (jobExtendedInfo.JobId != null) { var jobStatusResponse = (OperationStatusJobExtendedInfo)operationStatus.Properties; WriteObject(GetJobObject( jobStatusResponse.JobId, vaultName: vaultName, resourceGroupName: resourceGroupName)); } } if (operationStatus.Status == OperationStatusValues.Failed && operationStatus.Error != null) { var errorMessage = string.Format( Resources.OperationFailed, operationName, operationStatus.Error.Code, operationStatus.Error.Message); throw new Exception(errorMessage); } } }
private void RefreshContainer() { string errorMessage = string.Empty; var refreshContainerJobResponse = ServiceClientAdapter.RefreshContainers(); var operationStatus = TrackingHelpers.GetOperationResult( refreshContainerJobResponse, operationId => ServiceClientAdapter.GetRefreshContainerOperationResult(operationId)); //Now wait for the operation to Complete if (refreshContainerJobResponse.Response.StatusCode != SystemNet.HttpStatusCode.NoContent) { errorMessage = string.Format(Resources.DiscoveryFailureErrorCode, refreshContainerJobResponse.Response.StatusCode); Logger.Instance.WriteDebug(errorMessage); } }
/// <summary> /// This method prepares the source vault for Data Move operation. /// </summary> /// <param name="vaultName"></param> /// <param name="resourceGroupName"></param> /// <param name="prepareMoveRequest"></param> public string PrepareDataMove(string vaultName, string resourceGroupName, PrepareDataMoveRequest prepareMoveRequest) { // prepare move var prepareMoveOperationResponse = ServiceClientAdapter.BmsAdapter.Client.BeginBMSPrepareDataMoveWithHttpMessagesAsync( vaultName, resourceGroupName, prepareMoveRequest).Result; // track prepare-move operation to success var operationStatus = TrackingHelpers.GetOperationStatusDataMove( prepareMoveOperationResponse, operationId => ServiceClientAdapter.GetDataMoveOperationStatus(operationId, vaultName, resourceGroupName)); Logger.Instance.WriteDebug("Prepare move operation: " + operationStatus.Body.Status); // get the correlation Id and return it for trigger data move var operationResult = TrackingHelpers.GetCorrelationId( prepareMoveOperationResponse, operationId => ServiceClientAdapter.GetPrepareDataMoveOperationResult(operationId, vaultName, resourceGroupName)); Logger.Instance.WriteDebug("Prepare move - correlationId:" + operationResult.CorrelationId); return(operationResult.CorrelationId); }
/// <summary> /// Based on the response from the service, handles the job created in the service appropriately. /// </summary> /// <param name="itemResponse">Response from service</param> /// <param name="operationName">Name of the operation</param> protected void HandleCreatedJob(BaseRecoveryServicesJobResponse itemResponse, string operationName) { WriteDebug(Resources.TrackingOperationStatusURLForCompletion + itemResponse.AzureAsyncOperation); var response = TrackingHelpers.WaitForOperationCompletionUsingStatusLink( itemResponse.AzureAsyncOperation, ServiceClientAdapter.GetProtectedItemOperationStatusByURL); if (response != null && response.OperationStatus != null) { WriteDebug(Resources.FinalOperationStatus + response.OperationStatus.Status); if (response.OperationStatus.Properties != null) { var jobExtendedInfo = (OperationStatusJobExtendedInfo)response.OperationStatus.Properties; if (jobExtendedInfo.JobId != null) { var jobStatusResponse = (OperationStatusJobExtendedInfo)response.OperationStatus.Properties; WriteObject(GetJobObject(jobStatusResponse.JobId)); } } if (response.OperationStatus.Status == OperationStatusValues.Failed && response.OperationStatus.OperationStatusError != null) { var errorMessage = string.Format( Resources.OperationFailed, operationName, response.OperationStatus.OperationStatusError.Code, response.OperationStatus.OperationStatusError.Message); throw new Exception(errorMessage); } } }
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()); } }); }
public override void ExecuteCmdlet() { ExecutionBlock(() => { base.ExecuteCmdlet(); ResourceIdentifier resourceIdentifier = new ResourceIdentifier(VaultId); string vaultName = resourceIdentifier.ResourceName; string resourceGroupName = resourceIdentifier.ResourceGroupName; 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 ProtectionPolicyResource servicePolicy = PolicyCmdletHelpers.GetProtectionPolicyByName( Policy.Name, ServiceClientAdapter, vaultName: vaultName, resourceGroupName: resourceGroupName); if (servicePolicy == null) { throw new ArgumentException(string.Format(Resources.PolicyNotFoundException, Policy.Name)); } PsBackupProviderManager providerManager = new PsBackupProviderManager( new Dictionary <System.Enum, object>() { { VaultParams.VaultName, vaultName }, { VaultParams.ResourceGroupName, resourceGroupName }, { PolicyParams.ProtectionPolicy, Policy }, { PolicyParams.RetentionPolicy, RetentionPolicy }, { PolicyParams.SchedulePolicy, SchedulePolicy }, }, ServiceClientAdapter); IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance( Policy.WorkloadType, Policy.BackupManagementType); AzureOperationResponse <ProtectionPolicyResource> policyResponse = psBackupProvider.ModifyPolicy(); WriteDebug("ModifyPolicy http response from service: " + policyResponse.Response.StatusCode.ToString()); if (policyResponse.Response.StatusCode == System.Net.HttpStatusCode.Accepted) { // Track OperationStatus URL for operation completion string policyName = Policy.Name; ServiceClientModel.OperationStatus operationStatus = TrackingHelpers.GetOperationStatus( policyResponse, operationId => ServiceClientAdapter.GetProtectionPolicyOperationStatus( policyName, operationId, vaultName: vaultName, resourceGroupName: resourceGroupName)); WriteDebug("Final operation status: " + operationStatus.Status); if (operationStatus.Properties != null && ((OperationStatusJobsExtendedInfo)operationStatus.Properties) .JobIds != null) { // get list of jobIds and return jobResponses WriteObject(GetJobObject( ((OperationStatusJobsExtendedInfo)operationStatus.Properties).JobIds, vaultName: vaultName, resourceGroupName: resourceGroupName)); } if (operationStatus.Status == OperationStatusValues.Failed) { // if operation failed, then trace error and throw exception if (operationStatus.Error != null) { WriteDebug(string.Format( "OperationStatus Error: {0} " + "OperationStatus Code: {1}", operationStatus.Error.Message, operationStatus.Error.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.Response.StatusCode.ToString()); } }, ShouldProcess(Policy.Name, VerbsCommon.Set)); }
public override void ExecuteCmdlet() { ExecutionBlock(() => { base.ExecuteCmdlet(); ResourceIdentifier resourceIdentifier = new ResourceIdentifier(VaultId); string vaultName = resourceIdentifier.ResourceName; string resourceGroupName = resourceIdentifier.ResourceGroupName; if (!((Container.ContainerType == ContainerType.Windows && Container.BackupManagementType == BackupManagementType.MAB) || (Container.ContainerType == ContainerType.AzureSQL && Container.BackupManagementType == BackupManagementType.AzureSQL) || (Container.ContainerType == ContainerType.AzureStorage && Container.BackupManagementType == BackupManagementType.AzureStorage) || (Container.ContainerType == ContainerType.AzureVMAppContainer && Container.BackupManagementType == BackupManagementType.AzureWorkload))) { throw new ArgumentException(string.Format(Resources.UnsupportedContainerException, Container.ContainerType, Container.BackupManagementType)); } bool yesToAll = Force.IsPresent; bool noToAll = false; if (ShouldContinue(Resources.DeleteContainerRegistration, Resources.UnregisterContainer, ref yesToAll, ref noToAll)) { string containerName = Container.Name; if (Container.ContainerType == ContainerType.AzureSQL) { containerName = ContainerConstansts.SqlContainerNamePrefix + containerName; } if (Container.ContainerType == ContainerType.AzureVMAppContainer || Container.ContainerType == ContainerType.AzureStorage) { if (Container.ContainerType == ContainerType.AzureStorage) { containerName = "StorageContainer;" + containerName; } var unRegisterResponse = ServiceClientAdapter.UnregisterWorkloadContainers( containerName, vaultName: vaultName, resourceGroupName: resourceGroupName); var operationStatus = TrackingHelpers.GetOperationResult( unRegisterResponse, operationId => ServiceClientAdapter.GetContainerRefreshOrInquiryOperationResult( operationId, vaultName: vaultName, resourceGroupName: resourceGroupName)); //Now wait for the operation to Complete if (unRegisterResponse.Response.StatusCode != SystemNet.HttpStatusCode.NoContent) { string errorMessage = string.Format(Resources.UnRegisterFailureErrorCode, unRegisterResponse.Response.StatusCode); Logger.Instance.WriteDebug(errorMessage); } } else { ServiceClientAdapter.UnregisterContainers( containerName, vaultName: vaultName, resourceGroupName: resourceGroupName); } if (PassThru.IsPresent) { WriteObject(Container); } } }, ShouldProcess(Container.Name, VerbsLifecycle.Unregister)); }