Skip to content

Commit deb03e8

Browse files
committed
Enable-Protection cmdlet Fixes
1 parent 8bc1f10 commit deb03e8

File tree

3 files changed

+16
-23
lines changed

3 files changed

+16
-23
lines changed

src/ResourceManager/RecoveryServices.Backup/Cmdlets/Item/EnableAzureRmRecoveryServicesProtection.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,12 @@ public override void ExecuteCmdlet()
7676
{ItemParams.ParameterSetName, this.ParameterSetName},
7777
}, HydraAdapter);
7878

79-
IPsBackupProvider psBackupProvider = (Item != null) ? providerManager.GetProviderInstance(WorkLoadType, Item.BackupManagementType)
79+
IPsBackupProvider psBackupProvider = (Item != null) ? providerManager.GetProviderInstance(Item.WorkloadType, Item.BackupManagementType)
8080
: providerManager.GetProviderInstance(WorkLoadType);
8181

8282
var jobResponse = psBackupProvider.EnableProtection();
8383

8484
// Track Response and display job details
85-
// -- TBD to move it to common helper and remove hard-coded vaules
8685

8786
var response = OperationStatusHelper.TrackOperationStatus(jobResponse, HydraAdapter);
8887

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.HydraAdapter/HydraAdapter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public partial class HydraAdapter
2727
const string AppSettingsSectionName = "appSettings";
2828
const string RecoveryServicesResourceNamespace = "Microsoft.RecoveryServices";
2929
const string ProviderNamespaceKey = "ProviderNamespace";
30-
const string AzureFabricName = "AzureIaasVM";
30+
const string AzureFabricName = "Azure";
3131

3232
ClientProxy<RecoveryServicesNS.RecoveryServicesBackupManagementClient, RecoveryServicesModelsNS.CustomRequestHeaders> BmsAdapter;
3333

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Providers/Providers/IaasVmPsBackupProvider.cs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public BaseRecoveryServicesJobResponse EnableProtection()
6464
AzureRmRecoveryServicesIaasVmItem item = (AzureRmRecoveryServicesIaasVmItem)
6565
ProviderData.ProviderParameters[ItemParams.Item];
6666
// do validations
67-
6867

6968
string containerUri = "";
7069
string protectedItemUri = "";
@@ -587,6 +586,7 @@ private void ValidateAzureVMContainerType(Microsoft.Azure.Commands.RecoveryServi
587586
type.ToString()));
588587
}
589588
}
589+
590590
private void ValidateAzureVMProtectionPolicy(AzureRmRecoveryServicesPolicyBase policy)
591591
{
592592
if (policy == null || policy.GetType() != typeof(AzureRmRecoveryServicesIaasVmPolicy))
@@ -625,10 +625,9 @@ private void ValidateAzureVMRetentionPolicy(AzureRmRecoveryServicesRetentionPoli
625625
policy.Validate();
626626
}
627627

628-
private void ValidateAzureVMEnableProtectionRequest(string vmName, string rgName, string serviceName,
628+
private void ValidateAzureVMEnableProtectionRequest(string vmName, string serviceName, string rgName,
629629
AzureRmRecoveryServicesPolicyBase policy)
630630
{
631-
ValidateAzureVMProtectionPolicy(policy);
632631
if(string.IsNullOrEmpty(vmName))
633632
{
634633
throw new ArgumentException(string.Format(Resources.InvalidAzureVMName));
@@ -642,8 +641,6 @@ private void ValidateAzureVMEnableProtectionRequest(string vmName, string rgName
642641
private void ValidateAzureVMModifyProtectionRequest(AzureRmRecoveryServicesItemBase itemBase,
643642
AzureRmRecoveryServicesPolicyBase policy)
644643
{
645-
ValidateAzureVMProtectionPolicy(policy);
646-
647644
if (itemBase == null || itemBase.GetType() != typeof(AzureRmRecoveryServicesIaasVmItem))
648645
{
649646
throw new ArgumentException(string.Format(Resources.InvalidProtectionPolicyException,
@@ -716,8 +713,10 @@ private bool IsDiscoveryNeeded(string vmName, string rgName, bool isComputeAzure
716713
vmVersion = (isComputeAzureVM) == true ? computeAzureVMVersion : classicComputeAzureVMVersion;
717714

718715
ProtectableObjectListQueryParameters queryParam = new ProtectableObjectListQueryParameters();
719-
queryParam.ProviderType = ProviderType.AzureIaasVM.ToString();
720-
queryParam.FriendlyName = vmName;
716+
// --- TBD To be added once bug is fixed in hydra and service
717+
//queryParam.ProviderType = ProviderType.AzureIaasVM.ToString();
718+
//queryParam.FriendlyName = vmName;
719+
721720
// No need to use skip or top token here as no pagination support of IaaSVM PO.
722721

723722
//First check if container is discovered or not
@@ -736,8 +735,9 @@ private bool IsDiscoveryNeeded(string vmName, string rgName, bool isComputeAzure
736735
{
737736
AzureIaaSVMProtectableItem iaaSVMProtectableItem = (AzureIaaSVMProtectableItem)protectableItem.Properties;
738737
if (iaaSVMProtectableItem != null &&
739-
iaaSVMProtectableItem.FriendlyName == vmName && iaaSVMProtectableItem.ResourceGroup == rgName
740-
&& iaaSVMProtectableItem.VirtualMachineVersion == vmVersion)
738+
string.Compare(iaaSVMProtectableItem.FriendlyName, vmName, true) == 0
739+
&& string.Compare(iaaSVMProtectableItem.ResourceGroup, rgName, true) == 0
740+
&& string.Compare(iaaSVMProtectableItem.VirtualMachineVersion, vmVersion, true) == 0)
741741
{
742742
protectableObject = iaaSVMProtectableItem;
743743
isDiscoveryNeed = false;
@@ -751,18 +751,12 @@ private bool IsDiscoveryNeeded(string vmName, string rgName, bool isComputeAzure
751751

752752
private void RefreshContainer()
753753
{
754-
bool isRetryNeeded = true;
755-
int retryCount = 1;
756-
bool isDiscoverySuccessful = true;
754+
bool isDiscoverySuccessful = false;
757755
string errorMessage = string.Empty;
758-
while (!isDiscoverySuccessful && retryCount <= 3)
759-
{
760-
var refreshContainerJobResponse = HydraAdapter.RefreshContainers();
756+
var refreshContainerJobResponse = HydraAdapter.RefreshContainers();
761757

762-
//Now wait for the operation to Complete
763-
isRetryNeeded = WaitForDiscoveryToComplete(refreshContainerJobResponse.Location, out isDiscoverySuccessful, out errorMessage);
764-
retryCount++;
765-
}
758+
//Now wait for the operation to Complete
759+
WaitForDiscoveryToComplete(refreshContainerJobResponse.Location, out isDiscoverySuccessful, out errorMessage);
766760

767761
if (!isDiscoverySuccessful)
768762
{
@@ -778,7 +772,7 @@ private bool WaitForDiscoveryToComplete(string locationUri, out bool isDiscovery
778772

779773
isDiscoverySuccessful = true;
780774
//If operation fails check if retry is needed or not
781-
if (status != HttpStatusCode.OK)
775+
if (status != HttpStatusCode.NoContent)
782776
{
783777
isDiscoverySuccessful = false;
784778
errorMessage = String.Format(Resources.DiscoveryFailureErrorMessage, status);

0 commit comments

Comments
 (0)