From 529c7bb41226865b9cff0589ee7d6a8b16b53a60 Mon Sep 17 00:00:00 2001 From: ayfathim Date: Thu, 11 Apr 2019 21:01:06 +0530 Subject: [PATCH 1/6] adding remove disk api, introducing zone, network fields in enable protection --- ...AzureRM.RecoveryServices.SiteRecovery.psd1 | 2 + ...mands.RecoveryServices.SiteRecovery.csproj | 11 +- .../PSAsrReplicationProtectedItemsClient.cs | 28 ++++ .../Models/PSFabricDetails.cs | 11 +- .../Models/PSObjects.cs | 7 + ...veryServicesAsrReplicationProtectedItem.cs | 23 ++- ...ServicesAsrReplicationProtectedItemDisk.cs | 145 ++++++++++++++++++ .../packages.config | 9 +- 8 files changed, 224 insertions(+), 12 deletions(-) create mode 100644 src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemDisk.cs diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/AzureRM.RecoveryServices.SiteRecovery.psd1 b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/AzureRM.RecoveryServices.SiteRecovery.psd1 index fdd394a44d34..d5769687f685 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/AzureRM.RecoveryServices.SiteRecovery.psd1 +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/AzureRM.RecoveryServices.SiteRecovery.psd1 @@ -116,6 +116,7 @@ CmdletsToExport = 'Remove-AzureRmRecoveryServicesAsrProtectionContainerMapping', 'Remove-AzureRmRecoveryServicesAsrRecoveryPlan', 'Remove-AzureRmRecoveryServicesAsrReplicationProtectedItem', + 'Remove-AzureRmRecoveryServicesAsrReplicationProtectedItemDisk', 'Remove-AzureRmRecoveryServicesAsrServicesProvider', 'Remove-AzureRmRecoveryServicesAsrStorageClassificationMapping', 'Remove-AzureRmRecoveryServicesAsrvCenter', @@ -164,6 +165,7 @@ AliasesToExport = 'Add-ASRReplicationProtectedItemDisk', 'Edit-ASRRP', 'Edit-ASR 'Remove-ASRFabric', 'Remove-ASRNetworkMapping', 'Remove-ASRPolicy', 'Remove-ASRProtectionContainerMapping', 'Remove-ASRRP', 'Remove-ASRRecoveryPlan', 'Remove-ASRReplicationProtectedItem', + 'Remove-ASRReplicationProtectedItemDisk', 'Remove-ASRServicesProvider', 'Remove-ASRStorageClassificationMapping', 'Remove-ASRvCenter', 'Restart-ASRJob', 'Resume-ASRJob', 'Set-ASRAlertSetting', diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Commands.RecoveryServices.SiteRecovery.csproj b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Commands.RecoveryServices.SiteRecovery.csproj index cf0314e61c08..5a88f610ef69 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Commands.RecoveryServices.SiteRecovery.csproj +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Commands.RecoveryServices.SiteRecovery.csproj @@ -44,14 +44,14 @@ ..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.4.2.1-preview\lib\net452\Microsoft.Azure.Management.RecoveryServices.dll True - - ..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.SiteRecovery.1.3.0-preview\lib\net452\Microsoft.Azure.Management.RecoveryServices.SiteRecovery.dll + + ..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.SiteRecovery.2.0.0-preview\lib\net452\Microsoft.Azure.Management.RecoveryServices.SiteRecovery.dll - ..\..\..\packages\Microsoft.Rest.ClientRuntime.2.3.18\lib\net452\Microsoft.Rest.ClientRuntime.dll + ..\..\..\packages\Microsoft.Rest.ClientRuntime.2.3.19\lib\net452\Microsoft.Rest.ClientRuntime.dll - ..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.18\lib\net452\Microsoft.Rest.ClientRuntime.Azure.dll + ..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.19\lib\net452\Microsoft.Rest.ClientRuntime.Azure.dll ..\..\..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll @@ -118,6 +118,7 @@ + @@ -196,4 +197,4 @@ - + \ No newline at end of file diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Common/PSAsrReplicationProtectedItemsClient.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Common/PSAsrReplicationProtectedItemsClient.cs index bfb1da1b9dc9..06ea5545ad2e 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Common/PSAsrReplicationProtectedItemsClient.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Common/PSAsrReplicationProtectedItemsClient.cs @@ -108,6 +108,34 @@ public PSSiteRecoveryLongRunningOperation AddDisks( return result; } + /// + /// Remove disks from replicated protected item. + /// + /// Fabric Name + /// Protection Container ID + /// Virtual Machine ID or Replication group Id + /// Remove disks input. + /// Job response + public PSSiteRecoveryLongRunningOperation RemoveDisks( + string fabricName, + string protectionContainerName, + string replicationProtectedItemName, + RemoveDisksInput input) + { + var op = this.GetSiteRecoveryClient() + .ReplicationProtectedItems.BeginRemoveDisksWithHttpMessagesAsync( + fabricName, + protectionContainerName, + replicationProtectedItemName, + input, + this.GetRequestHeaders(true)) + .GetAwaiter() + .GetResult(); + + var result = SiteRecoveryAutoMapperProfile.Mapper.Map(op); + return result; + } + /// /// Retrieves Replicated Protected Item. /// diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/PSFabricDetails.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/PSFabricDetails.cs index e5440c200859..849d19374085 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/PSFabricDetails.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/PSFabricDetails.cs @@ -1183,6 +1183,7 @@ public ASRAzureToAzureSpecificRPIDetails(A2AReplicationDetails details) this.RecoveryAzureCloudService = details.RecoveryCloudService; this.RecoveryFabricLocation = details.RecoveryFabricLocation; this.RecoveryAvailabilitySet = details.RecoveryAvailabilitySet; + this.RecoveryAvailabilityZone = details.RecoveryAvailabilityZone; this.TestFailoverRecoveryFabricObjectId = details.TestFailoverRecoveryFabricObjectId; this.MonitoringJobType = details.MonitoringJobType; this.MonitoringPercentageCompletion = details.MonitoringPercentageCompletion; @@ -1214,7 +1215,7 @@ public ASRAzureToAzureSpecificRPIDetails(A2AReplicationDetails details) .ConvertAll(disk => new ASRAzureToAzureProtectedDiskDetails(disk))); } - if (details.UnprotectedDisks != null && details.UnprotectedDisks.Count > 0) + /* if (details.UnprotectedDisks != null && details.UnprotectedDisks.Count > 0) { this.A2AUnprotectedDiskDetails = new List(); foreach (var unprotectedDisk in details.UnprotectedDisks) @@ -1226,6 +1227,7 @@ public ASRAzureToAzureSpecificRPIDetails(A2AReplicationDetails details) }); } } + */ if (details.VmSyncedConfigDetails != null) { @@ -1281,6 +1283,11 @@ public ASRAzureToAzureSpecificRPIDetails(A2AReplicationDetails details) /// public string RecoveryAvailabilitySet { get; set; } + /// + /// Recovery availability zone. + /// + public string RecoveryAvailabilityZone { get; set; } + /// /// Synced configuration details of the virtual machine. /// @@ -1311,7 +1318,7 @@ public ASRAzureToAzureSpecificRPIDetails(A2AReplicationDetails details) /// /// Gets or sets A2A unprotected disk details. /// - public List A2AUnprotectedDiskDetails { get; set; } + //public List A2AUnprotectedDiskDetails { get; set; } /// /// Gets or sets the recovery fabric object Id. diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/PSObjects.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/PSObjects.cs index a940102e80b3..aa64da99cd2f 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/PSObjects.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/PSObjects.cs @@ -2261,6 +2261,7 @@ public ASRAzureToAzureProtectedDiskDetails(A2AProtectedDiskDetails disk) this.DiskName = disk.DiskName; this.DiskType = disk.DiskType; this.DiskState = disk.DiskState; + this.AllowedDiskLevelOperation = disk.AllowedDiskLevelOperation; this.Managed = false; } @@ -2280,6 +2281,7 @@ public ASRAzureToAzureProtectedDiskDetails(A2AProtectedManagedDiskDetails disk) this.DiskName = disk.DiskName; this.DiskType = disk.DiskType; this.DiskState = disk.DiskState; + this.AllowedDiskLevelOperation = disk.AllowedDiskLevelOperation; this.RecoveryReplicaDiskAccountType = disk.RecoveryReplicaDiskAccountType; this.RecoveryReplicaDiskId = disk.RecoveryReplicaDiskId; this.RecoveryResourceGroupId = disk.RecoveryResourceGroupId; @@ -2360,6 +2362,11 @@ public ASRAzureToAzureProtectedDiskDetails(A2AProtectedManagedDiskDetails disk) /// public string DiskState { get; set; } + /// + /// Gets or sets the Allowed Disk Level Operation. + /// + public IList AllowedDiskLevelOperation { get; set; } + /// /// Gets or sets recovery disk uri. /// diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/NewAzureRmRecoveryServicesAsrReplicationProtectedItem.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/NewAzureRmRecoveryServicesAsrReplicationProtectedItem.cs index c85ac8b08805..a835b7401685 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/NewAzureRmRecoveryServicesAsrReplicationProtectedItem.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/NewAzureRmRecoveryServicesAsrReplicationProtectedItem.cs @@ -216,6 +216,8 @@ public class NewAzureRmRecoveryServicesAsrReplicationProtectedItem : SiteRecover /// [Parameter(ParameterSetName = ASRParameterSets.VMwareToAzure)] [Parameter(ParameterSetName = ASRParameterSets.HyperVSiteToAzure)] + [Parameter(ParameterSetName = ASRParameterSets.AzureToAzure)] + [Parameter(ParameterSetName = ASRParameterSets.AzureToAzureWithoutDiskDetails)] [ValidateNotNullOrEmpty] public string RecoveryAzureNetworkId { get; set; } @@ -225,6 +227,8 @@ public class NewAzureRmRecoveryServicesAsrReplicationProtectedItem : SiteRecover /// [Parameter(ParameterSetName = ASRParameterSets.VMwareToAzure)] [Parameter(ParameterSetName = ASRParameterSets.HyperVSiteToAzure)] + [Parameter(ParameterSetName = ASRParameterSets.AzureToAzure)] + [Parameter(ParameterSetName = ASRParameterSets.AzureToAzureWithoutDiskDetails)] [ValidateNotNullOrEmpty] public string RecoveryAzureSubnetName { get; set; } @@ -261,6 +265,14 @@ public class NewAzureRmRecoveryServicesAsrReplicationProtectedItem : SiteRecover [ValidateNotNullOrEmpty] public string RecoveryAvailabilitySetId { get; set; } + /// + /// Gets or sets ID of the AvailabilityZone to recover the machine to in the event of a failover. + /// + [Parameter(ParameterSetName = ASRParameterSets.AzureToAzure)] + [Parameter(ParameterSetName = ASRParameterSets.AzureToAzureWithoutDiskDetails)] + [ValidateNotNullOrEmpty] + public string RecoveryAvailabilityZone { get; set; } + /// /// Gets or sets BootDiagnosticStorageAccountId. /// @@ -604,7 +616,10 @@ private void AzureToAzureReplication(EnableProtectionInput input) RecoveryResourceGroupId = this.RecoveryResourceGroupId, RecoveryCloudServiceId = this.RecoveryCloudServiceId, RecoveryAvailabilitySetId = this.RecoveryAvailabilitySetId, - RecoveryBootDiagStorageAccountId = this.RecoveryBootDiagStorageAccountId + RecoveryBootDiagStorageAccountId = this.RecoveryBootDiagStorageAccountId, + RecoveryAvailabilityZone = this.RecoveryAvailabilityZone, + RecoveryAzureNetworkId = this.RecoveryAzureNetworkId, + RecoverySubnetName = this.RecoveryAzureSubnetName }; if (!string.IsNullOrEmpty(this.RecoveryCloudServiceId)) @@ -612,6 +627,12 @@ private void AzureToAzureReplication(EnableProtectionInput input) providerSettings.RecoveryResourceGroupId = null; } + if (!string.IsNullOrEmpty(this.RecoveryAvailabilityZone) && + !string.IsNullOrEmpty(this.RecoveryAvailabilitySetId)) + { + throw new Exception("RecoveryAvailabilityZone and RecoveryAvailabilitySetId cannot be set together for a VM"); + } + if (this.AzureToAzureDiskReplicationConfiguration == null) { if (this.AzureVmId.ToLower().Contains(ARMResourceTypeConstants.Compute.ToLower())) diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemDisk.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemDisk.cs new file mode 100644 index 000000000000..d5d7ed648d82 --- /dev/null +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemDisk.cs @@ -0,0 +1,145 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System.Management.Automation; +using System.Collections.Generic; +using Microsoft.Azure.Management.RecoveryServices.SiteRecovery.Models; +using Job = Microsoft.Azure.Management.RecoveryServices.SiteRecovery.Models.Job; + +namespace Microsoft.Azure.Commands.RecoveryServices.SiteRecovery +{ + /// + /// Removes disks to replication protected item. + /// + [Cmdlet("Remove", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "RecoveryServicesAsrReplicationProtectedItemDisk", DefaultParameterSetName = ASRParameterSets.EnterpriseToEnterprise, SupportsShouldProcess = true)] + [Alias("Remove-ASRReplicationProtectedItemDisk")] + [OutputType(typeof(ASRJob))] + public class RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemDisk : SiteRecoveryCmdletBase + { + [ValidateNotNullOrEmpty] + [Parameter(Mandatory = true)] + public ASRReplicationProtectedItem ReplicationProtectedItem { get; set; } + + /// + /// Switch parameter specifying that the disk replication config created for managed disk. + /// + [Parameter( + ParameterSetName = ASRParameterSets.AzureToAzureManagedDisk, + Mandatory = true)] + public SwitchParameter ManagedDisk { get; set; } + + /// + /// Gets or sets the disk uri. + /// + [Parameter(ParameterSetName = ASRParameterSets.AzureToAzure, + Mandatory = true)] + [ValidateNotNullOrEmpty] + public string[] VhdUri { get; set; } + + /// + /// Gets or sets the disk Id. + /// + [Parameter(ParameterSetName = ASRParameterSets.AzureToAzureManagedDisk, + Mandatory = true)] + [ValidateNotNullOrEmpty] + public string[] DiskId { get; set; } + + [Parameter] + public SwitchParameter WaitForCompletion { get; set; } + + /// + /// ProcessRecord of the command. + /// + public override void ExecuteSiteRecoveryCmdlet() + { + base.ExecuteSiteRecoveryCmdlet(); + + // check for A2A protected item - if providerSpecificDetails is A2AReplicationDetails. + + var removeDisksProviderSpecificInput = new RemoveDisksProviderSpecificInput(); + var inputProperties = new RemoveDisksInputProperties + { + ProviderSpecificDetails = removeDisksProviderSpecificInput + }; + var input = new RemoveDisksInput { Properties = inputProperties }; + AzureToAzureReplication(input); + + this.response = this.RecoveryServicesClient.RemoveDisks( + Utilities.GetValueFromArmId( + this.ReplicationProtectedItem.ID, + ARMResourceTypeConstants.ReplicationFabrics), + Utilities.GetValueFromArmId( + this.ReplicationProtectedItem.ID, + ARMResourceTypeConstants.ReplicationProtectionContainers), + this.ReplicationProtectedItem.Name, + input); + + this.jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails( + PSRecoveryServicesClient.GetJobIdFromReponseLocation(this.response.Location)); + + this.WriteObject(new ASRJob(this.jobResponse)); + + if (this.WaitForCompletion.IsPresent) + { + this.WaitForJobCompletion(this.jobResponse.Name); + + this.jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails( + PSRecoveryServicesClient + .GetJobIdFromReponseLocation(this.response.Location)); + + this.WriteObject(new ASRJob(this.jobResponse)); + } + } + + /// + /// Helper method to fill in input details. + /// + private void AzureToAzureReplication(RemoveDisksInput input) + { + var providerSettings = new A2ARemoveDisksInput() + { + VmDisksUris = new List(), + VmManagedDisksIds = new List() + }; + + if (this.ManagedDisk.IsPresent) + { + providerSettings.VmManagedDisksIds = this.DiskId; + } + else + { + providerSettings.VmDisksUris = this.VhdUri; + } + + input.Properties.ProviderSpecificDetails = providerSettings; + } + + /// + /// Writes Job. + /// + /// Job object. + private void WriteJob( + Job job) + { + this.WriteObject(new ASRJob(job)); + } + + private Job jobResponse; + + /// + /// Job response. + /// + private PSSiteRecoveryLongRunningOperation response; + } +} diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/packages.config b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/packages.config index 83a4456eb24e..5495aa50cb10 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/packages.config +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/packages.config @@ -2,8 +2,9 @@ - - - + + + - + + \ No newline at end of file From 537ad528a4675eeea9f980b4634238ae02e7432c Mon Sep 17 00:00:00 2001 From: ayfathim Date: Wed, 17 Apr 2019 16:42:04 +0530 Subject: [PATCH 2/6] Updated with comments,Fix for reprotect bug#227197 --- ...AzureRM.RecoveryServices.SiteRecovery.psd1 | 2 +- .../PSAsrReplicationProtectedItemsClient.cs | 20 ++++++------- ...ServicesAsrReplicationProtectedItemDisk.cs | 29 +++++++------------ ...mRecoveryServicesAsrProtectionDirection.cs | 2 +- 4 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/AzureRM.RecoveryServices.SiteRecovery.psd1 b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/AzureRM.RecoveryServices.SiteRecovery.psd1 index d5769687f685..ea54bf4c6b74 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/AzureRM.RecoveryServices.SiteRecovery.psd1 +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/AzureRM.RecoveryServices.SiteRecovery.psd1 @@ -115,7 +115,7 @@ CmdletsToExport = 'Remove-AzureRmRecoveryServicesAsrProtectionContainer', 'Remove-AzureRmRecoveryServicesAsrProtectionContainerMapping', 'Remove-AzureRmRecoveryServicesAsrRecoveryPlan', - 'Remove-AzureRmRecoveryServicesAsrReplicationProtectedItem', + 'Remove-AzureRmRecoveryServicesAsrReplicationProtectedItem', 'Remove-AzureRmRecoveryServicesAsrReplicationProtectedItemDisk', 'Remove-AzureRmRecoveryServicesAsrServicesProvider', 'Remove-AzureRmRecoveryServicesAsrStorageClassificationMapping', diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Common/PSAsrReplicationProtectedItemsClient.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Common/PSAsrReplicationProtectedItemsClient.cs index 06ea5545ad2e..ea654cc2ad54 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Common/PSAsrReplicationProtectedItemsClient.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Common/PSAsrReplicationProtectedItemsClient.cs @@ -28,8 +28,8 @@ public partial class PSRecoveryServicesClient /// Removes Replicated Protected Item. /// /// Fabric Name - /// Protection Container ID - /// Virtual Machine ID or Replication group Id + /// Protection Container Name + /// Replication Protected Item Name /// Disable protection input. /// Job response public PSSiteRecoveryLongRunningOperation DisableProtection( @@ -56,8 +56,8 @@ public PSSiteRecoveryLongRunningOperation DisableProtection( /// Creates Replicated Protected Item. /// /// Fabric Name - /// Protection Container ID - /// Virtual Machine ID or Replication group Id + /// Protection Container Name + /// Replication Protected Item Name /// Enable protection input. /// Job response public PSSiteRecoveryLongRunningOperation EnableProtection( @@ -81,11 +81,11 @@ public PSSiteRecoveryLongRunningOperation EnableProtection( } /// - /// Add disks to replicated protected item. + /// Add disks to replication protected item. /// /// Fabric Name - /// Protection Container ID - /// Virtual Machine ID or Replication group Id + /// Protection Container Name + /// Replication Protected Item Name /// Add disks input. /// Job response public PSSiteRecoveryLongRunningOperation AddDisks( @@ -109,11 +109,11 @@ public PSSiteRecoveryLongRunningOperation AddDisks( } /// - /// Remove disks from replicated protected item. + /// Remove disks from replication protected item. /// /// Fabric Name - /// Protection Container ID - /// Virtual Machine ID or Replication group Id + /// Protection Container Name + /// Replication Protected Item Name /// Remove disks input. /// Job response public PSSiteRecoveryLongRunningOperation RemoveDisks( diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemDisk.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemDisk.cs index d5d7ed648d82..95417be8e960 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemDisk.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemDisk.cs @@ -32,15 +32,7 @@ public class RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemDisk : Site public ASRReplicationProtectedItem ReplicationProtectedItem { get; set; } /// - /// Switch parameter specifying that the disk replication config created for managed disk. - /// - [Parameter( - ParameterSetName = ASRParameterSets.AzureToAzureManagedDisk, - Mandatory = true)] - public SwitchParameter ManagedDisk { get; set; } - - /// - /// Gets or sets the disk uri. + /// Gets or sets the disk uri. /// [Parameter(ParameterSetName = ASRParameterSets.AzureToAzure, Mandatory = true)] @@ -48,7 +40,7 @@ public class RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemDisk : Site public string[] VhdUri { get; set; } /// - /// Gets or sets the disk Id. + /// Gets or sets the disk Id. /// [Parameter(ParameterSetName = ASRParameterSets.AzureToAzureManagedDisk, Mandatory = true)] @@ -73,7 +65,7 @@ public override void ExecuteSiteRecoveryCmdlet() ProviderSpecificDetails = removeDisksProviderSpecificInput }; var input = new RemoveDisksInput { Properties = inputProperties }; - AzureToAzureReplication(input); + FillRemoveDiskInputForAzureToAzureReplication(input); this.response = this.RecoveryServicesClient.RemoveDisks( Utilities.GetValueFromArmId( @@ -105,7 +97,7 @@ public override void ExecuteSiteRecoveryCmdlet() /// /// Helper method to fill in input details. /// - private void AzureToAzureReplication(RemoveDisksInput input) + private void FillRemoveDiskInputForAzureToAzureReplication(RemoveDisksInput input) { var providerSettings = new A2ARemoveDisksInput() { @@ -113,13 +105,14 @@ private void AzureToAzureReplication(RemoveDisksInput input) VmManagedDisksIds = new List() }; - if (this.ManagedDisk.IsPresent) - { - providerSettings.VmManagedDisksIds = this.DiskId; - } - else + switch (this.ParameterSetName) { - providerSettings.VmDisksUris = this.VhdUri; + case ASRParameterSets.AzureToAzure: + providerSettings.VmDisksUris = this.VhdUri; + break; + case ASRParameterSets.AzureToAzureManagedDisk: + providerSettings.VmManagedDisksIds = this.DiskId; + break; } input.Properties.ProviderSpecificDetails = providerSettings; diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/UpdateAzureRmRecoveryServicesAsrProtectionDirection.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/UpdateAzureRmRecoveryServicesAsrProtectionDirection.cs index d8fa1582934b..c2cad12dcea4 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/UpdateAzureRmRecoveryServicesAsrProtectionDirection.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/UpdateAzureRmRecoveryServicesAsrProtectionDirection.cs @@ -635,7 +635,7 @@ private void populateManagedDiskInputDetails( RecoveryResourceGroupId = disk.RecoveryResourceGroupId, RecoveryReplicaDiskAccountType = disk.RecoveryReplicaDiskAccountType, RecoveryTargetDiskAccountType = disk.RecoveryTargetDiskAccountType, - PrimaryStagingAzureStorageAccountId = this.LogStorageAccountId, + PrimaryStagingAzureStorageAccountId = disk.LogStorageAccountId, }); } } From db854ed6c9c3cbc49c70e18dace61e22cfed7360 Mon Sep 17 00:00:00 2001 From: ayfathim Date: Wed, 17 Apr 2019 16:59:45 +0530 Subject: [PATCH 3/6] correcting the indentaion --- .../AzureRM.RecoveryServices.SiteRecovery.psd1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/AzureRM.RecoveryServices.SiteRecovery.psd1 b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/AzureRM.RecoveryServices.SiteRecovery.psd1 index ea54bf4c6b74..dd69160bb1fa 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/AzureRM.RecoveryServices.SiteRecovery.psd1 +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/AzureRM.RecoveryServices.SiteRecovery.psd1 @@ -115,8 +115,8 @@ CmdletsToExport = 'Remove-AzureRmRecoveryServicesAsrProtectionContainer', 'Remove-AzureRmRecoveryServicesAsrProtectionContainerMapping', 'Remove-AzureRmRecoveryServicesAsrRecoveryPlan', - 'Remove-AzureRmRecoveryServicesAsrReplicationProtectedItem', - 'Remove-AzureRmRecoveryServicesAsrReplicationProtectedItemDisk', + 'Remove-AzureRmRecoveryServicesAsrReplicationProtectedItem', + 'Remove-AzureRmRecoveryServicesAsrReplicationProtectedItemDisk', 'Remove-AzureRmRecoveryServicesAsrServicesProvider', 'Remove-AzureRmRecoveryServicesAsrStorageClassificationMapping', 'Remove-AzureRmRecoveryServicesAsrvCenter', @@ -163,9 +163,9 @@ AliasesToExport = 'Add-ASRReplicationProtectedItemDisk', 'Edit-ASRRP', 'Edit-ASR 'New-ASRRecoveryPlan', 'New-ASRReplicationProtectedItem', 'New-ASRStorageClassificationMapping', 'New-ASRvCenter', 'Remove-ASRFabric', 'Remove-ASRNetworkMapping', 'Remove-ASRPolicy', - 'Remove-ASRProtectionContainerMapping', 'Remove-ASRRP', - 'Remove-ASRRecoveryPlan', 'Remove-ASRReplicationProtectedItem', - 'Remove-ASRReplicationProtectedItemDisk', + 'Remove-ASRProtectionContainerMapping', 'Remove-ASRRP', + 'Remove-ASRRecoveryPlan', 'Remove-ASRReplicationProtectedItem', + 'Remove-ASRReplicationProtectedItemDisk', 'Remove-ASRServicesProvider', 'Remove-ASRStorageClassificationMapping', 'Remove-ASRvCenter', 'Restart-ASRJob', 'Resume-ASRJob', 'Set-ASRAlertSetting', From 7982833bd4826a5fd3623a8f03db05e8a3971d60 Mon Sep 17 00:00:00 2001 From: ayfathim Date: Wed, 17 Apr 2019 17:37:50 +0530 Subject: [PATCH 4/6] correting the default parameter set name --- ...reRmRecoveryServicesAsrReplicationProtectedItemDisk.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemDisk.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemDisk.cs index 95417be8e960..abfcdfd652fd 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemDisk.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemDisk.cs @@ -22,7 +22,7 @@ namespace Microsoft.Azure.Commands.RecoveryServices.SiteRecovery /// /// Removes disks to replication protected item. /// - [Cmdlet("Remove", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "RecoveryServicesAsrReplicationProtectedItemDisk", DefaultParameterSetName = ASRParameterSets.EnterpriseToEnterprise, SupportsShouldProcess = true)] + [Cmdlet("Remove", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "RecoveryServicesAsrReplicationProtectedItemDisk", DefaultParameterSetName = ASRParameterSets.AzureToAzure, SupportsShouldProcess = true)] [Alias("Remove-ASRReplicationProtectedItemDisk")] [OutputType(typeof(ASRJob))] public class RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemDisk : SiteRecoveryCmdletBase @@ -34,16 +34,14 @@ public class RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemDisk : Site /// /// Gets or sets the disk uri. /// - [Parameter(ParameterSetName = ASRParameterSets.AzureToAzure, - Mandatory = true)] + [Parameter(ParameterSetName = ASRParameterSets.AzureToAzure, Mandatory = true)] [ValidateNotNullOrEmpty] public string[] VhdUri { get; set; } /// /// Gets or sets the disk Id. /// - [Parameter(ParameterSetName = ASRParameterSets.AzureToAzureManagedDisk, - Mandatory = true)] + [Parameter(ParameterSetName = ASRParameterSets.AzureToAzureManagedDisk, Mandatory = true)] [ValidateNotNullOrEmpty] public string[] DiskId { get; set; } From 5c282cb3198ee4d6cc5a0113a5686d07956f73bb Mon Sep 17 00:00:00 2001 From: ayfathim Date: Mon, 22 Apr 2019 00:32:46 +0530 Subject: [PATCH 5/6] updating to new nuget --- .../Commands.RecoveryServices.SiteRecovery.csproj | 2 +- .../Models/PSFabricDetails.cs | 5 ++--- .../Commands.RecoveryServices.SiteRecovery/packages.config | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Commands.RecoveryServices.SiteRecovery.csproj b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Commands.RecoveryServices.SiteRecovery.csproj index 5a88f610ef69..28ef46b16496 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Commands.RecoveryServices.SiteRecovery.csproj +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Commands.RecoveryServices.SiteRecovery.csproj @@ -45,7 +45,7 @@ True - ..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.SiteRecovery.2.0.0-preview\lib\net452\Microsoft.Azure.Management.RecoveryServices.SiteRecovery.dll + ..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.SiteRecovery.2.0.1-preview\lib\net452\Microsoft.Azure.Management.RecoveryServices.SiteRecovery.dll ..\..\..\packages\Microsoft.Rest.ClientRuntime.2.3.19\lib\net452\Microsoft.Rest.ClientRuntime.dll diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/PSFabricDetails.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/PSFabricDetails.cs index 849d19374085..b7969992ed17 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/PSFabricDetails.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/PSFabricDetails.cs @@ -1215,7 +1215,7 @@ public ASRAzureToAzureSpecificRPIDetails(A2AReplicationDetails details) .ConvertAll(disk => new ASRAzureToAzureProtectedDiskDetails(disk))); } - /* if (details.UnprotectedDisks != null && details.UnprotectedDisks.Count > 0) + if (details.UnprotectedDisks != null && details.UnprotectedDisks.Count > 0) { this.A2AUnprotectedDiskDetails = new List(); foreach (var unprotectedDisk in details.UnprotectedDisks) @@ -1227,7 +1227,6 @@ public ASRAzureToAzureSpecificRPIDetails(A2AReplicationDetails details) }); } } - */ if (details.VmSyncedConfigDetails != null) { @@ -1318,7 +1317,7 @@ public ASRAzureToAzureSpecificRPIDetails(A2AReplicationDetails details) /// /// Gets or sets A2A unprotected disk details. /// - //public List A2AUnprotectedDiskDetails { get; set; } + public List A2AUnprotectedDiskDetails { get; set; } /// /// Gets or sets the recovery fabric object Id. diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/packages.config b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/packages.config index 5495aa50cb10..7d7c692f1c24 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/packages.config +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/packages.config @@ -2,7 +2,7 @@ - + From 814cb41de3958115afecc566dd6488582d6b9f73 Mon Sep 17 00:00:00 2001 From: ayfathim Date: Fri, 10 May 2019 13:00:37 +0530 Subject: [PATCH 6/6] ResolveHealthError API and tests --- .../ScenarioTests/A2A/A2ATestsHelper.ps1 | 28 ++ .../ScenarioTests/A2A/AsrA2ATests.cs | 44 +++ .../ScenarioTests/A2A/AsrA2ATests.ps1 | 302 +++++++++++++++++- ...AzureRM.RecoveryServices.SiteRecovery.psd1 | 3 +- ...mands.RecoveryServices.SiteRecovery.csproj | 1 + .../PSAsrReplicationProtectedItemsClient.cs | 28 ++ .../Models/2016-08-10/ASRPSObjects.cs | 12 + ...sAsrReplicationProtectedItemHealthError.cs | 111 +++++++ 8 files changed, 519 insertions(+), 10 deletions(-) create mode 100644 src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemHealthError.cs diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery.Test/ScenarioTests/A2A/A2ATestsHelper.ps1 b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery.Test/ScenarioTests/A2A/A2ATestsHelper.ps1 index d34cd10bcd42..4cf969b920a4 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery.Test/ScenarioTests/A2A/A2ATestsHelper.ps1 +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery.Test/ScenarioTests/A2A/A2ATestsHelper.ps1 @@ -198,3 +198,31 @@ Function WaitForIRCompletion $IRjobs WaitForJobCompletion -JobId $IRjobs[0].Name -JobQueryWaitTimeInSeconds $JobQueryWaitTimeInSeconds -Message $("Finalize IR in Progress...") } + +Function WaitForAddDisksIRCompletion +{ + param( + [PSObject] $affectedObjectId, + [int] $JobQueryWaitTimeInSeconds = 10 + ) + $isProcessingLeft = $true + $IRjobs = $null + + Write-Host $("Add-Disk IR in Progress...") -ForegroundColor Yellow + do + { + $IRjobs = Get-AzureRmRecoveryServicesAsrJob -TargetObjectId $affectedObjectId | Sort-Object StartTime -Descending | select -First 2 | Where-Object{$_.JobType -eq "AddDisksIrCompletion"} + $isProcessingLeft = ($IRjobs -eq $null -or $IRjobs.Count -ne 1) + + if($isProcessingLeft) + { + Write-Host $("Adddisk IR in Progress...") -ForegroundColor Yellow + Write-Host $("Waiting for: " + $JobQueryWaitTimeInSeconds.ToString + " Seconds") -ForegroundColor Yellow + [Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait($JobQueryWaitTimeInSeconds * 1000) + } + }While($isProcessingLeft) + + Write-Host $("Finalize Add disk IR jobs:") -ForegroundColor Green + $IRjobs + WaitForJobCompletion -JobId $IRjobs[0].Name -JobQueryWaitTimeInSeconds $JobQueryWaitTimeInSeconds -Message $("Finalize IR in Progress...") +} diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery.Test/ScenarioTests/A2A/AsrA2ATests.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery.Test/ScenarioTests/A2A/AsrA2ATests.cs index 2fc9b966ea94..bac19156915a 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery.Test/ScenarioTests/A2A/AsrA2ATests.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery.Test/ScenarioTests/A2A/AsrA2ATests.cs @@ -76,5 +76,49 @@ public void A2ATestNewContainer() { this.RunPowerShellTest(_logger, Constants.NewModel, "Test-NewContainer"); } + +#if NETSTANDARD + [Fact(Skip = "Needs investigation, TestManagementClientHelper class wasn't initialized with the ResourceManagementClient client.")] +#else + [Fact] +#endif + [Trait(Category.AcceptanceType, Category.CheckIn)] + public void A2ANewReplicationProtectedItemDisk() + { + this.RunPowerShellTest(_logger, Constants.NewModel, "Test-NewReplicationProtectedItem"); + } + +#if NETSTANDARD + [Fact(Skip = "Needs investigation, TestManagementClientHelper class wasn't initialized with the ResourceManagementClient client.")] +#else + [Fact] +#endif + [Trait(Category.AcceptanceType, Category.CheckIn)] + public void A2AAddReplicationProtectedItemDisk() + { + this.RunPowerShellTest(_logger, Constants.NewModel, "Test-AddReplicationProtectedItemDisk"); + } + +#if NETSTANDARD + [Fact(Skip = "Needs investigation, TestManagementClientHelper class wasn't initialized with the ResourceManagementClient client.")] +#else + [Fact] +#endif + [Trait(Category.AcceptanceType, Category.CheckIn)] + public void A2ARemoveReplicationProtectedItemDisk() + { + this.RunPowerShellTest(_logger, Constants.NewModel, "Test-RemoveReplicationProtectedItemDisk"); + } + +#if NETSTANDARD + [Fact(Skip = "Needs investigation, TestManagementClientHelper class wasn't initialized with the ResourceManagementClient client.")] +#else + [Fact] +#endif + [Trait(Category.AcceptanceType, Category.CheckIn)] + public void A2ARemoveReplicationProtectedItemHealthError() + { + this.RunPowerShellTest(_logger, Constants.NewModel, "Test-ResolveHealthError"); + } } } diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery.Test/ScenarioTests/A2A/AsrA2ATests.ps1 b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery.Test/ScenarioTests/A2A/AsrA2ATests.ps1 index c0fe04fe010d..c63c6c7aba62 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery.Test/ScenarioTests/A2A/AsrA2ATests.ps1 +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery.Test/ScenarioTests/A2A/AsrA2ATests.ps1 @@ -90,11 +90,72 @@ function Test-NewAsrFabric { Assert-AreEqual $fab.FabricSpecificDetails.Location $primaryLocation } +<# +.SYNOPSIS + Test GetAsrFabric new parametersets +#> +function Test-NewContainer { + #variables + $seed = 33; + $primaryPolicyName = getPrimaryPolicy + $recoveryPolicyName = getRecoveryPolicy + + $primaryContainerMappingName = getPrimaryContainerMapping + $recoveryContainerMappingName = getRecoveryContainerMapping + $primaryContainerName = getPrimaryContainer + $recoveryContainerName = getRecoveryContainer + $vaultRgLocation = getVaultRgLocation + $vaultName = getVaultName + $vaultLocation = getVaultLocation + $vaultRg = getVaultRg + $primaryLocation = getPrimaryLocation + $recoveryLocation = getRecoveryLocation + $primaryFabricName = getPrimaryFabric + $recoveryFabricName = getRecoveryFabric + $RecoveryReplicaDiskAccountType = "Premium_LRS" + $RecoveryTargetDiskAccountType = "Premium_LRS" -function Test-NewContainer{ + New-AzureRmResourceGroup -name $vaultRg -location $vaultRgLocation -force + [Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait(20 * 1000) + # vault Creation + New-azureRmRecoveryServicesVault -ResourceGroupName $vaultRg -Name $vaultName -Location $vaultLocation + [Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait(20 * 1000) + $Vault = Get-AzureRMRecoveryServicesVault -ResourceGroupName $vaultRg -Name $vaultName + Set-ASRVaultContext -Vault $Vault + # fabric Creation + ### AzureToAzure New paramset + $fabJob= New-AzureRmRecoveryServicesAsrFabric -Azure -Name $primaryFabricName -Location $primaryLocation + WaitForJobCompletion -JobId $fabJob.Name + $fab = Get-AzureRmRecoveryServicesAsrFabric -Name $primaryFabricName + Assert-true { $fab.name -eq $primaryFabricName } + Assert-AreEqual $fab.FabricSpecificDetails.Location $primaryLocation - $seed = 33; - $primaryPolicyName = getPrimaryPolicy + #recovery fabric + $fabJob= New-AzureRmRecoveryServicesAsrFabric -Azure -Name $recoveryFabricName -Location $recoveryLocation + WaitForJobCompletion -JobId $fabJob.Name + $fab = Get-AzureRmRecoveryServicesAsrFabric -Name $recoveryFabricName + Assert-true { $fab.name -eq $recoveryFabricName } + Assert-AreEqual $fab.FabricSpecificDetails.Location $recoveryLocation + $pf = get-asrFabric -Name $primaryFabricName + $rf = get-asrFabric -Name $recoveryFabricName + + ### AzureToAzure (Default) + $job = New-AzureRmRecoveryServicesAsrProtectionContainer -Name $primaryContainerName -Fabric $pf + WaitForJobCompletion -JobId $Job.Name + $pc = Get-asrProtectionContainer -name $primaryContainerName -Fabric $pf + Assert-NotNull($pc) + Assert-AreEqual $pc.Name $primaryContainerName +} + +<# +.SYNOPSIS + Test-NewReplicationProtectedItem new parametersets +#> + +function Test-NewReplicationProtectedItem{ + #variables + $seed = 336; + $primaryPolicyName = getPrimaryPolicy $recoveryPolicyName = getRecoveryPolicy $primaryContainerMappingName = getPrimaryContainerMapping @@ -106,16 +167,27 @@ function Test-NewContainer{ $vaultName = getVaultName $vaultLocation = getVaultLocation $vaultRg = getVaultRg - $primaryLocation = getPrimaryLocation - $recoveryLocation = getRecoveryLocation + $primaryLocation = getRecoveryLocation + $recoveryLocation = getPrimaryLocation $primaryFabricName = getPrimaryFabric $recoveryFabricName = getRecoveryFabric $RecoveryReplicaDiskAccountType = "Premium_LRS" $RecoveryTargetDiskAccountType = "Premium_LRS" + $policyName = getPrimaryPolicy + $mappingName = getPrimaryContainerMapping + $primaryNetMapping = getPrimaryNetworkMapping + + $logStg = "/subscriptions/509099b2-9d2c-4636-b43e-bd5cafb6be69/resourcegroups/pstest1/providers/Microsoft.Storage/storageAccounts/cachestgpstest1" + $v2VmId ="/subscriptions/509099b2-9d2c-4636-b43e-bd5cafb6be69/resourceGroups/pstest1/providers/Microsoft.Compute/virtualMachines/linux-vm1" + $PrimaryAzureNetworkId ="/subscriptions/509099b2-9d2c-4636-b43e-bd5cafb6be69/resourceGroups/pstest1/providers/Microsoft.Network/virtualNetworks/pstest1-vnet" + $RecoveryAzureNetworkId ="/subscriptions/509099b2-9d2c-4636-b43e-bd5cafb6be69/resourceGroups/pstest1-asr/providers/Microsoft.Network/virtualNetworks/rec-pstests1" + $recRg = "/subscriptions/509099b2-9d2c-4636-b43e-bd5cafb6be69/resourceGroups/pstest1-asr" + $vmName ="linux-vm1" + $vhdid ="/subscriptions/509099b2-9d2c-4636-b43e-bd5cafb6be69/resourceGroups/pstest1/providers/Microsoft.Compute/disks/linux-vm1_OsDisk_1_3d376317b0d6463bb344da9fab7d56f3" New-AzureRmResourceGroup -name $vaultRg -location $vaultRgLocation -force [Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait(20 * 1000) - # vault Creation + # vault Creation New-azureRmRecoveryServicesVault -ResourceGroupName $vaultRg -Name $vaultName -Location $vaultLocation [Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait(20 * 1000) $Vault = Get-AzureRMRecoveryServicesVault -ResourceGroupName $vaultRg -Name $vaultName @@ -136,11 +208,223 @@ function Test-NewContainer{ $pf = get-asrFabric -Name $primaryFabricName $rf = get-asrFabric -Name $recoveryFabricName - ### AzureToAzure (Default) + ### AzureToAzure (Default) $job = New-AzureRmRecoveryServicesAsrProtectionContainer -Name $primaryContainerName -Fabric $pf WaitForJobCompletion -JobId $Job.Name $pc = Get-asrProtectionContainer -name $primaryContainerName -Fabric $pf - Assert-NotNull($pc) - Assert-AreEqual $pc.Name $primaryContainerName + $job = New-AzureRmRecoveryServicesAsrProtectionContainer -Name $recoveryContainerName -Fabric $rf + WaitForJobCompletion -JobId $Job.Name + $rc = Get-asrProtectionContainer -name $recoveryContainerName -Fabric $rf + #create policy + $job = New-AzureRmRecoveryServicesAsrPolicy -Name $policyName -RecoveryPointRetentionInHours 12 -AzureToAzure + WaitForJobCompletion -JobId $job.Name + $policy = Get-AzureRmRecoveryServicesAsrPolicy -Name $policyName + $job = New-AzureRmRecoveryServicesAsrProtectionContainerMapping -Name $mappingName -Policy $policy -PrimaryProtectionContainer $pc -RecoveryProtectionContainer $rc + WaitForJobCompletion -JobId $job.Name + $mapping = Get-AzureRmRecoveryServicesAsrProtectionContainerMapping -Name $mappingName -ProtectionContainer $pc + + #network mapping + $job = New-AzureRmRecoveryServicesAsrNetworkMapping -AzureToAzure -Name $primaryNetMapping -PrimaryFabric $pf -PrimaryAzureNetworkId $PrimaryAzureNetworkId -RecoveryFabric $rf -RecoveryAzureNetworkId $RecoveryAzureNetworkId + WaitForJobCompletion -JobId $job.Name + + $disk1= New-AzureRmRecoveryServicesAsrAzureToAzureDiskReplicationConfig -DiskId $vhdid -LogStorageAccountId $logStg -ManagedDisk -RecoveryReplicaDiskAccountType $RecoveryReplicaDiskAccountType -RecoveryResourceGroupId $recRg -RecoveryTargetDiskAccountType $RecoveryTargetDiskAccountType + $enableDRjob = New-AzureRmRecoveryServicesAsrReplicationProtectedItem -AzureToAzure -AzureVmId $v2VmId -Name $vmName -ProtectionContainerMapping $mapping -RecoveryResourceGroupId $recrg -AzureToAzureDiskReplicationConfiguration $disk1 + WaitForJobCompletion -JobId $enableDRjob.Name + WaitForIRCompletion -affectedObjectId $enableDRjob.TargetObjectId +} + +<# +.SYNOPSIS + Test AddReplicationProtectedItemDisk new parametersets +#> + +function Test-AddReplicationProtectedItemDisk{ + #variables + $seed = 336; + $vaultName = getVaultName + $vaultLocation = getVaultLocation + $vaultRg = getVaultRg + $primaryLocation = getPrimaryLocation + $recoveryLocation = getRecoveryLocation + $RecoveryReplicaDiskAccountType = "Premium_LRS" + $RecoveryTargetDiskAccountType = "Premium_LRS" + + $v2VmId ="/subscriptions/509099b2-9d2c-4636-b43e-bd5cafb6be69/resourceGroups/pstests/providers/Microsoft.Compute/virtualMachines/Vm1" + $vmName ="vm1" + $vmRg = "pstests" + $diskName = "A2ADisk0"+ $seed + + # vault + $Vault = Get-AzureRMRecoveryServicesVault -ResourceGroupName $vaultRg -Name $vaultName + Set-ASRVaultContext -Vault $Vault + # fabric + $pf = Get-ASRFabric | where-object {$_.FabricSpecificDetails.Location -eq $primaryLocation} + Assert-NotNull($pf) + $rf = Get-ASRFabric | where-object {$_.FabricSpecificDetails.Location -eq $recoveryLocation} + Assert-NotNull($rf) + + ### AzureToAzure (Default) + $pc = Get-asrProtectionContainer -name $primaryContainerName -Fabric $pf + $rc = Get-asrProtectionContainer -name $recoveryContainerName -Fabric $rf + Assert-NotNull($pc) + Assert-NotNull($rc) + + #add diskId + $pe = Get-AzureRmRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $pc -Name $vmName + Assert-NotNull($pe) + + #create disk and attach + $vm = get-azureRmVm -ResourceGroupName $vmRg -Name $vmName + $newDiskConfig = New-AzurermDiskConfig -Location $vm.Location -CreateOption Empty -DiskSizeGB 5 + $newDisk = New-AzurermDisk -ResourceGroupName $vm.ResourceGroupName -DiskName $diskName -Disk $newDiskConfig + $vm = Add-AzureRmVMDataDisk -VM $vm -Name $diskName -CreateOption Attach -ManagedDiskId $newDisk.Id -Lun 5 + Update-azureRmVm -ResourceGroupName $vmRg -VM $vm + + #wait for the add-disk health warning to appear + Write-Host $("Waiting for Add-Disk health warning...") -ForegroundColor Yellow + $HealthQueryWaitTimeInSeconds = 10 + do + { + $pe = Get-AzureRmRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $pc -Name $vmName + $healthError = $pe.ReplicationHealthErrors | where-object {$_.ErrorCode -eq 153039} + + if($healthError -eq $null) + { + Write-Host $("Waiting for Add-Disk health warning...") -ForegroundColor Yellow + Write-Host $("Waiting for: " + $HealthQueryWaitTimeInSeconds.ToString + " Seconds") -ForegroundColor Yellow + [Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait($HealthQueryWaitTimeInSeconds * 1000) + } + }While($healthError -eq $null) + + #add disks + $disk2= New-AzureRmRecoveryServicesAsrAzureToAzureDiskReplicationConfig -DiskId $newDisk.Id -LogStorageAccountId $pe.ProviderSpecificDetails.A2ADiskDetails[0].PrimaryStagingAzureStorageAccountId -ManagedDisk -RecoveryReplicaDiskAccountType $RecoveryReplicaDiskAccountType -RecoveryResourceGroupId $pe.ProviderSpecificDetails.A2ADiskDetails[0].RecoveryResourceGroupId -RecoveryTargetDiskAccountType $RecoveryTargetDiskAccountType + $addDRjob = Add-AzureRmRecoveryServicesAsrReplicationProtectedItemDisk -ReplicationProtectedItem $pe -AzureToAzureDiskReplicationConfiguration $disk2 + WaitForJobCompletion -JobId $addDRjob.Name + WaitForAddDisksIRCompletion -affectedObjectId $addDRjob.TargetObjectId + + $pe = Get-AzureRmRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $pc -Name $vmName + Assert-NotNull($pe) +} + +<# +.SYNOPSIS + Test AddReplicationProtectedItemDisk new parametersets +#> + +function Test-RemoveReplicationProtectedItemDisk{ + #variables + $seed = 336; + $vaultName = getVaultName + $vaultLocation = getVaultLocation + $vaultRg = getVaultRg + $primaryLocation = getPrimaryLocation + $recoveryLocation = getRecoveryLocation + $RecoveryReplicaDiskAccountType = "Premium_LRS" + $RecoveryTargetDiskAccountType = "Premium_LRS" + + $v2VmId ="/subscriptions/509099b2-9d2c-4636-b43e-bd5cafb6be69/resourceGroups/pstests/providers/Microsoft.Compute/virtualMachines/Vm1" + $vmName ="vm1" + $vmRg = "pstests" + $diskName = "A2ADisk0"+ $seed + + # vault + $Vault = Get-AzureRMRecoveryServicesVault -ResourceGroupName $vaultRg -Name $vaultName + Set-ASRVaultContext -Vault $Vault + # fabric + $pf = Get-ASRFabric | where-object {$_.FabricSpecificDetails.Location -eq $primaryLocation} + Assert-NotNull($pf) + $rf = Get-ASRFabric | where-object {$_.FabricSpecificDetails.Location -eq $recoveryLocation} + Assert-NotNull($rf) + + ### AzureToAzure (Default) + $pc = Get-asrProtectionContainer -name $primaryContainerName -Fabric $pf + $rc = Get-asrProtectionContainer -name $recoveryContainerName -Fabric $rf + Assert-NotNull($pc) + Assert-NotNull($rc) + + #add diskId + $pe = Get-AzureRmRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $pc -Name $vmName + Assert-NotNull($pe) + + #get disk to deattach + | $removeDisk = $pe.ProviderSpecificDetails.A2ADiskDetails | where-object {$_.AllowedDiskLevelOperation.Count -eq 1} + Assert-NotNull($removeDisk) + + $vm = get-azureRmVm -ResourceGroupName $vmRg -Name $vmName + $removeDiskId = $vm.StorageProfile.DataDisks | Where-Object {$_.ManagedDisk.Name -eq $removeDisk.DiskName} + + $removeDRjob = Remove-AzureRmRecoveryServicesAsrReplicationProtectedItemDisk -ReplicationProtectedItem $pe -DiskId $removeDiskId.ManagedDisk.Id + WaitForJobCompletion -JobId $removeDRjob.Name + + $pe = Get-AzureRmRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $pc -Name $vmName + Assert-NotNull($pe) +} + +<# +.SYNOPSIS + Test AddReplicationProtectedItemDisk new parametersets +#> + +function Test-ResolveHealthError{ + #variables + $seed = 336; + $vaultName = getVaultName + $vaultLocation = getVaultLocation + $vaultRg = getVaultRg + $primaryLocation = getPrimaryLocation + $recoveryLocation = getRecoveryLocation + $RecoveryReplicaDiskAccountType = "Premium_LRS" + $RecoveryTargetDiskAccountType = "Premium_LRS" + + $v2VmId ="/subscriptions/509099b2-9d2c-4636-b43e-bd5cafb6be69/resourceGroups/pstests/providers/Microsoft.Compute/virtualMachines/Vm1" + $vmName ="vm1" + $vmRg = "pstests" + $diskName = "A2ADisk0"+ $seed + + # vault + $Vault = Get-AzureRMRecoveryServicesVault -ResourceGroupName $vaultRg -Name $vaultName + Set-ASRVaultContext -Vault $Vault + # fabric + $pf = Get-ASRFabric | where-object {$_.FabricSpecificDetails.Location -eq $primaryLocation} + Assert-NotNull($pf) + $rf = Get-ASRFabric | where-object {$_.FabricSpecificDetails.Location -eq $recoveryLocation} + Assert-NotNull($rf) + + ### AzureToAzure (Default) + $pc = Get-asrProtectionContainer -name $primaryContainerName -Fabric $pf + $rc = Get-asrProtectionContainer -name $recoveryContainerName -Fabric $rf + Assert-NotNull($pc) + Assert-NotNull($rc) + + #add diskId + $pe = Get-AzureRmRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $pc -Name $vmName + Assert-NotNull($pe) + + #create disk and attach + $vm = get-azureRmVm -ResourceGroupName $vmRg -Name $vmName + $newDiskConfig = New-AzurermDiskConfig -Location $vm.Location -CreateOption Empty -DiskSizeGB 5 + $newDisk = New-AzurermDisk -ResourceGroupName $vm.ResourceGroupName -DiskName $diskName -Disk $newDiskConfig + $vm = Add-AzureRmVMDataDisk -VM $vm -Name $diskName -CreateOption Attach -ManagedDiskId $newDisk.Id -Lun 5 + Update-azureRmVm -ResourceGroupName $vmRg -VM $vm + + #wait for the add-disk health warning to appear + Write-Host $("Waiting for Add-Disk health warning...") -ForegroundColor Yellow + $HealthQueryWaitTimeInSeconds = 10 + do + { + $pe = Get-AzureRmRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $pc -Name $vmName + $healthError = $pe.ReplicationHealthErrors | where-object {$_.ErrorCode -eq 153039} + + if($healthError -eq $null) + { + Write-Host $("Waiting for Add-Disk health warning...") -ForegroundColor Yellow + Write-Host $("Waiting for: " + $HealthQueryWaitTimeInSeconds.ToString + " Seconds") -ForegroundColor Yellow + [Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait($HealthQueryWaitTimeInSeconds * 1000) + } + }While($healthError -eq $null) + + #resolve health error + $addDRjob = Remove-AzureRmRecoveryServicesAsrReplicationProtectedItemHealthError -ReplicationProtectedItem $pe -ErrorIds $healthError.ErrorId + WaitForJobCompletion -JobId $addDRjob.Name } diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/AzureRM.RecoveryServices.SiteRecovery.psd1 b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/AzureRM.RecoveryServices.SiteRecovery.psd1 index dd69160bb1fa..81e73abc7c1e 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/AzureRM.RecoveryServices.SiteRecovery.psd1 +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/AzureRM.RecoveryServices.SiteRecovery.psd1 @@ -117,6 +117,7 @@ CmdletsToExport = 'Remove-AzureRmRecoveryServicesAsrRecoveryPlan', 'Remove-AzureRmRecoveryServicesAsrReplicationProtectedItem', 'Remove-AzureRmRecoveryServicesAsrReplicationProtectedItemDisk', + 'RecoveryServicesAsrReplicationProtectedItemHealthError', 'Remove-AzureRmRecoveryServicesAsrServicesProvider', 'Remove-AzureRmRecoveryServicesAsrStorageClassificationMapping', 'Remove-AzureRmRecoveryServicesAsrvCenter', @@ -165,7 +166,7 @@ AliasesToExport = 'Add-ASRReplicationProtectedItemDisk', 'Edit-ASRRP', 'Edit-ASR 'Remove-ASRFabric', 'Remove-ASRNetworkMapping', 'Remove-ASRPolicy', 'Remove-ASRProtectionContainerMapping', 'Remove-ASRRP', 'Remove-ASRRecoveryPlan', 'Remove-ASRReplicationProtectedItem', - 'Remove-ASRReplicationProtectedItemDisk', + 'Remove-ASRReplicationProtectedItemDisk', 'Remove-ASRReplicationProtectedItemHealthError', 'Remove-ASRServicesProvider', 'Remove-ASRStorageClassificationMapping', 'Remove-ASRvCenter', 'Restart-ASRJob', 'Resume-ASRJob', 'Set-ASRAlertSetting', diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Commands.RecoveryServices.SiteRecovery.csproj b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Commands.RecoveryServices.SiteRecovery.csproj index 28ef46b16496..8a1177ef914c 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Commands.RecoveryServices.SiteRecovery.csproj +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Commands.RecoveryServices.SiteRecovery.csproj @@ -118,6 +118,7 @@ + diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Common/PSAsrReplicationProtectedItemsClient.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Common/PSAsrReplicationProtectedItemsClient.cs index ea654cc2ad54..274cc477d222 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Common/PSAsrReplicationProtectedItemsClient.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Common/PSAsrReplicationProtectedItemsClient.cs @@ -136,6 +136,34 @@ public PSSiteRecoveryLongRunningOperation RemoveDisks( return result; } + /// + /// Removes the Health error from replication protected item. + /// + /// Fabric Name + /// Protection Container Name + /// Replication Protected Item Name + /// Remove disks input. + /// Job response + public PSSiteRecoveryLongRunningOperation ResolveHealthError( + string fabricName, + string protectionContainerName, + string replicationProtectedItemName, + ResolveHealthInput input) + { + var op = this.GetSiteRecoveryClient() + .ReplicationProtectedItems.BeginResolveHealthErrorsWithHttpMessagesAsync( + fabricName, + protectionContainerName, + replicationProtectedItemName, + input, + this.GetRequestHeaders(true)) + .GetAwaiter() + .GetResult(); + + var result = SiteRecoveryAutoMapperProfile.Mapper.Map(op); + return result; + } + /// /// Retrieves Replicated Protected Item. /// diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/2016-08-10/ASRPSObjects.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/2016-08-10/ASRPSObjects.cs index 02d50e18fbd5..272e904e0b86 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/2016-08-10/ASRPSObjects.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/2016-08-10/ASRPSObjects.cs @@ -46,6 +46,8 @@ public ASRHealthError_2016_08_10(HealthError healthError) this.PossibleCauses = healthError.PossibleCauses; this.RecommendedAction = healthError.RecommendedAction; this.RecoveryProviderErrorMessage = healthError.RecoveryProviderErrorMessage; + this.ErrorId = healthError.ErrorId; + this.CustomerResolvability = healthError.CustomerResolvability; this.childError = new List(); if (healthError.InnerHealthErrors != null) { @@ -121,6 +123,16 @@ public ASRHealthError_2016_08_10(InnerHealthError healthError) /// public string ErrorMessage { get; set; } + /// + /// Id of error. + /// + public string ErrorId { get; set; } + + /// + /// CustomerResolvability of error. + /// + public string CustomerResolvability { get; set; } + /// /// Possible causes of error. /// diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemHealthError.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemHealthError.cs new file mode 100644 index 000000000000..a3efa9869089 --- /dev/null +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemHealthError.cs @@ -0,0 +1,111 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System.Management.Automation; +using System.Collections.Generic; +using Microsoft.Azure.Management.RecoveryServices.SiteRecovery.Models; +using Job = Microsoft.Azure.Management.RecoveryServices.SiteRecovery.Models.Job; + +namespace Microsoft.Azure.Commands.RecoveryServices.SiteRecovery +{ + /// + /// Removes health error for the replication protected item. + /// + [Cmdlet("Remove", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "RecoveryServicesAsrReplicationProtectedItemHealthError", DefaultParameterSetName = ASRParameterSets.AzureToAzure, SupportsShouldProcess = true)] + [Alias("Remove-ASRReplicationProtectedItemHealthError")] + [OutputType(typeof(ASRJob))] + public class RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemHealthError : SiteRecoveryCmdletBase + { + [ValidateNotNullOrEmpty] + [Parameter(Mandatory = true)] + public ASRReplicationProtectedItem ReplicationProtectedItem { get; set; } + + /// + /// Gets or sets the errro id. + /// + [Parameter(Mandatory = true)] + [ValidateNotNullOrEmpty] + public string[] ErrorIds { get; set; } + + [Parameter] + public SwitchParameter WaitForCompletion { get; set; } + + /// + /// ProcessRecord of the command. + /// + public override void ExecuteSiteRecoveryCmdlet() + { + base.ExecuteSiteRecoveryCmdlet(); + + var input = new ResolveHealthInput { Properties = new ResolveHealthInputProperties()}; + FillResolveHealthErrorInput(input); + + this.response = this.RecoveryServicesClient.ResolveHealthError( + Utilities.GetValueFromArmId( + this.ReplicationProtectedItem.ID, + ARMResourceTypeConstants.ReplicationFabrics), + Utilities.GetValueFromArmId( + this.ReplicationProtectedItem.ID, + ARMResourceTypeConstants.ReplicationProtectionContainers), + this.ReplicationProtectedItem.Name, + input); + + this.jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails( + PSRecoveryServicesClient.GetJobIdFromReponseLocation(this.response.Location)); + + this.WriteObject(new ASRJob(this.jobResponse)); + + if (this.WaitForCompletion.IsPresent) + { + this.WaitForJobCompletion(this.jobResponse.Name); + + this.jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails( + PSRecoveryServicesClient + .GetJobIdFromReponseLocation(this.response.Location)); + + this.WriteObject(new ASRJob(this.jobResponse)); + } + } + + /// + /// Helper method to fill in input details. + /// + private void FillResolveHealthErrorInput(ResolveHealthInput input) + { + input.Properties.HealthErrors = new List(); + + foreach (string errorId in ErrorIds) + { + input.Properties.HealthErrors.Add(new ResolveHealthError(errorId)); + } + } + + /// + /// Writes Job. + /// + /// Job object. + private void WriteJob( + Job job) + { + this.WriteObject(new ASRJob(job)); + } + + private Job jobResponse; + + /// + /// Job response. + /// + private PSSiteRecoveryLongRunningOperation response; + } +}