Skip to content

Commit f7fb9f2

Browse files
committed
Merge pull request #228 from MabOneSdk/pragrawa-dev1
Enable-Protection cmdlet Fixes
2 parents dfc902f + deb03e8 commit f7fb9f2

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 = "";
@@ -613,6 +612,7 @@ private void ValidateAzureVMContainerType(Microsoft.Azure.Commands.RecoveryServi
613612
type.ToString()));
614613
}
615614
}
615+
616616
private void ValidateAzureVMProtectionPolicy(AzureRmRecoveryServicesPolicyBase policy)
617617
{
618618
if (policy == null || policy.GetType() != typeof(AzureRmRecoveryServicesIaasVmPolicy))
@@ -651,10 +651,9 @@ private void ValidateAzureVMRetentionPolicy(AzureRmRecoveryServicesRetentionPoli
651651
policy.Validate();
652652
}
653653

654-
private void ValidateAzureVMEnableProtectionRequest(string vmName, string rgName, string serviceName,
654+
private void ValidateAzureVMEnableProtectionRequest(string vmName, string serviceName, string rgName,
655655
AzureRmRecoveryServicesPolicyBase policy)
656656
{
657-
ValidateAzureVMProtectionPolicy(policy);
658657
if(string.IsNullOrEmpty(vmName))
659658
{
660659
throw new ArgumentException(string.Format(Resources.InvalidAzureVMName));
@@ -668,8 +667,6 @@ private void ValidateAzureVMEnableProtectionRequest(string vmName, string rgName
668667
private void ValidateAzureVMModifyProtectionRequest(AzureRmRecoveryServicesItemBase itemBase,
669668
AzureRmRecoveryServicesPolicyBase policy)
670669
{
671-
ValidateAzureVMProtectionPolicy(policy);
672-
673670
if (itemBase == null || itemBase.GetType() != typeof(AzureRmRecoveryServicesIaasVmItem))
674671
{
675672
throw new ArgumentException(string.Format(Resources.InvalidProtectionPolicyException,
@@ -742,8 +739,10 @@ private bool IsDiscoveryNeeded(string vmName, string rgName, bool isComputeAzure
742739
vmVersion = (isComputeAzureVM) == true ? computeAzureVMVersion : classicComputeAzureVMVersion;
743740

744741
ProtectableObjectListQueryParameters queryParam = new ProtectableObjectListQueryParameters();
745-
queryParam.ProviderType = ProviderType.AzureIaasVM.ToString();
746-
queryParam.FriendlyName = vmName;
742+
// --- TBD To be added once bug is fixed in hydra and service
743+
//queryParam.ProviderType = ProviderType.AzureIaasVM.ToString();
744+
//queryParam.FriendlyName = vmName;
745+
747746
// No need to use skip or top token here as no pagination support of IaaSVM PO.
748747

749748
//First check if container is discovered or not
@@ -762,8 +761,9 @@ private bool IsDiscoveryNeeded(string vmName, string rgName, bool isComputeAzure
762761
{
763762
AzureIaaSVMProtectableItem iaaSVMProtectableItem = (AzureIaaSVMProtectableItem)protectableItem.Properties;
764763
if (iaaSVMProtectableItem != null &&
765-
iaaSVMProtectableItem.FriendlyName == vmName && iaaSVMProtectableItem.ResourceGroup == rgName
766-
&& iaaSVMProtectableItem.VirtualMachineVersion == vmVersion)
764+
string.Compare(iaaSVMProtectableItem.FriendlyName, vmName, true) == 0
765+
&& string.Compare(iaaSVMProtectableItem.ResourceGroup, rgName, true) == 0
766+
&& string.Compare(iaaSVMProtectableItem.VirtualMachineVersion, vmVersion, true) == 0)
767767
{
768768
protectableObject = iaaSVMProtectableItem;
769769
isDiscoveryNeed = false;
@@ -777,18 +777,12 @@ private bool IsDiscoveryNeeded(string vmName, string rgName, bool isComputeAzure
777777

778778
private void RefreshContainer()
779779
{
780-
bool isRetryNeeded = true;
781-
int retryCount = 1;
782-
bool isDiscoverySuccessful = true;
780+
bool isDiscoverySuccessful = false;
783781
string errorMessage = string.Empty;
784-
while (!isDiscoverySuccessful && retryCount <= 3)
785-
{
786-
var refreshContainerJobResponse = HydraAdapter.RefreshContainers();
782+
var refreshContainerJobResponse = HydraAdapter.RefreshContainers();
787783

788-
//Now wait for the operation to Complete
789-
isRetryNeeded = WaitForDiscoveryToComplete(refreshContainerJobResponse.Location, out isDiscoverySuccessful, out errorMessage);
790-
retryCount++;
791-
}
784+
//Now wait for the operation to Complete
785+
WaitForDiscoveryToComplete(refreshContainerJobResponse.Location, out isDiscoverySuccessful, out errorMessage);
792786

793787
if (!isDiscoverySuccessful)
794788
{
@@ -804,7 +798,7 @@ private bool WaitForDiscoveryToComplete(string locationUri, out bool isDiscovery
804798

805799
isDiscoverySuccessful = true;
806800
//If operation fails check if retry is needed or not
807-
if (status != HttpStatusCode.OK)
801+
if (status != HttpStatusCode.NoContent)
808802
{
809803
isDiscoverySuccessful = false;
810804
errorMessage = String.Format(Resources.DiscoveryFailureErrorMessage, status);

0 commit comments

Comments
 (0)