@@ -64,7 +64,7 @@ public BaseRecoveryServicesJobResponse EnableProtection()
64
64
AzureRmRecoveryServicesIaasVmItem item = ( AzureRmRecoveryServicesIaasVmItem )
65
65
ProviderData . ProviderParameters [ ItemParams . Item ] ;
66
66
// do validations
67
-
67
+
68
68
string containerUri = "" ;
69
69
string protectedItemUri = "" ;
70
70
bool isComputeAzureVM = false ;
@@ -78,22 +78,21 @@ public BaseRecoveryServicesJobResponse EnableProtection()
78
78
79
79
ValidateAzureVMEnableProtectionRequest ( azureVMName , azureVMCloudServiceName , azureVMResourceGroupName , policy ) ;
80
80
81
- AzureIaaSVMProtectableItem protectableObject = GetAzureVMProtectableObject ( azureVMName , azureVMRGName , isComputeAzureVM ) ;
81
+ ProtectableObjectResource protectableObjectResource = GetAzureVMProtectableObject ( azureVMName , azureVMRGName , isComputeAzureVM ) ;
82
82
83
- containerUri = protectableObject . ContainerUri ;
84
- protectedItemUri = protectableObject . ProtectableObjectUri ;
83
+ Dictionary < UriEnums , string > keyValueDict = HelperUtils . ParseUri ( protectableObjectResource . Id ) ;
84
+ containerUri = HelperUtils . GetContainerUri ( keyValueDict , item . Id ) ;
85
+ protectedItemUri = HelperUtils . GetProtectedItemUri ( keyValueDict , item . Id ) ;
85
86
}
86
87
else
87
88
{
88
89
ValidateAzureVMWorkloadType ( item . WorkloadType , policy . WorkloadType ) ;
89
90
ValidateAzureVMModifyProtectionRequest ( itemBase , policy ) ;
90
91
91
- isComputeAzureVM = IsComputeAzureVM ( item . VirtualMachineId ) ;
92
-
93
- string containerType = HydraHelpers . GetHydraContainerType ( item . ContainerType ) ;
94
- string vmType = HydraHelpers . GetHydraWorkloadType ( item . WorkloadType ) ;
95
- containerUri = string . Join ( separator , new string [ ] { containerType , item . ContainerName } ) ;
96
- protectedItemUri = string . Join ( separator , new string [ ] { vmType , item . Name } ) ;
92
+ isComputeAzureVM = IsComputeAzureVM ( item . VirtualMachineId ) ;
93
+ Dictionary < UriEnums , string > keyValueDict = HelperUtils . ParseUri ( item . Id ) ;
94
+ containerUri = HelperUtils . GetContainerUri ( keyValueDict , item . Id ) ;
95
+ protectedItemUri = HelperUtils . GetProtectedItemUri ( keyValueDict , item . Id ) ;
97
96
}
98
97
99
98
// construct Hydra protectedItem request
@@ -672,7 +671,6 @@ private void ValidateAzureVMRetentionPolicy(AzureRmRecoveryServicesRetentionPoli
672
671
private void ValidateAzureVMEnableProtectionRequest ( string vmName , string serviceName , string rgName ,
673
672
AzureRmRecoveryServicesPolicyBase policy )
674
673
{
675
- ValidateAzureVMProtectionPolicy ( policy ) ;
676
674
if ( string . IsNullOrEmpty ( vmName ) )
677
675
{
678
676
throw new ArgumentException ( string . Format ( Resources . InvalidAzureVMName ) ) ;
@@ -716,19 +714,19 @@ private bool IsComputeAzureVM(string virtualMachineId)
716
714
return isComputeAzureVM ;
717
715
}
718
716
719
- private AzureIaaSVMProtectableItem GetAzureVMProtectableObject ( string azureVMName , string azureVMRGName , bool isComputeAzureVM )
717
+ private ProtectableObjectResource GetAzureVMProtectableObject ( string azureVMName , string azureVMRGName , bool isComputeAzureVM )
720
718
{
721
719
//TriggerDiscovery if needed
722
720
723
721
bool isDiscoveryNeed = false ;
724
722
725
- AzureIaaSVMProtectableItem protectableObject = null ;
726
- isDiscoveryNeed = IsDiscoveryNeeded ( azureVMName , azureVMRGName , isComputeAzureVM , out protectableObject ) ;
723
+ ProtectableObjectResource protectableObjectResource = null ;
724
+ isDiscoveryNeed = IsDiscoveryNeeded ( azureVMName , azureVMRGName , isComputeAzureVM , out protectableObjectResource ) ;
727
725
if ( isDiscoveryNeed )
728
726
{
729
727
Logger . Instance . WriteDebug ( String . Format ( Resources . VMNotDiscovered , azureVMName ) ) ;
730
728
RefreshContainer ( ) ;
731
- isDiscoveryNeed = IsDiscoveryNeeded ( azureVMName , azureVMRGName , isComputeAzureVM , out protectableObject ) ;
729
+ isDiscoveryNeed = IsDiscoveryNeeded ( azureVMName , azureVMRGName , isComputeAzureVM , out protectableObjectResource ) ;
732
730
if ( isDiscoveryNeed == true )
733
731
{
734
732
// Container is not discovered. Throw exception
@@ -738,7 +736,7 @@ private AzureIaaSVMProtectableItem GetAzureVMProtectableObject(string azureVMNam
738
736
Logger . Instance . ThrowTerminatingError ( new ErrorRecord ( new Exception ( Resources . AzureVMNotFound ) , string . Empty , ErrorCategory . InvalidArgument , null ) ) ;
739
737
}
740
738
}
741
- if ( protectableObject == null )
739
+ if ( protectableObjectResource == null )
742
740
{
743
741
// Container is not discovered. Throw exception
744
742
string vmversion = ( isComputeAzureVM ) ? computeAzureVMVersion : classicComputeAzureVMVersion ;
@@ -747,15 +745,15 @@ private AzureIaaSVMProtectableItem GetAzureVMProtectableObject(string azureVMNam
747
745
Logger . Instance . ThrowTerminatingError ( new ErrorRecord ( new Exception ( Resources . AzureVMNotFound ) , string . Empty , ErrorCategory . InvalidArgument , null ) ) ;
748
746
}
749
747
750
- return protectableObject ;
748
+ return protectableObjectResource ;
751
749
752
750
}
753
751
754
752
private bool IsDiscoveryNeeded ( string vmName , string rgName , bool isComputeAzureVM ,
755
- out AzureIaaSVMProtectableItem protectableObject )
753
+ out ProtectableObjectResource protectableObjectResource )
756
754
{
757
755
bool isDiscoveryNeed = true ;
758
- protectableObject = null ;
756
+ protectableObjectResource = null ;
759
757
string vmVersion = string . Empty ;
760
758
vmVersion = ( isComputeAzureVM ) == true ? computeAzureVMVersion : classicComputeAzureVMVersion ;
761
759
@@ -786,7 +784,7 @@ private bool IsDiscoveryNeeded(string vmName, string rgName, bool isComputeAzure
786
784
&& string . Compare ( iaaSVMProtectableItem . ResourceGroup , rgName , true ) == 0
787
785
&& string . Compare ( iaaSVMProtectableItem . VirtualMachineVersion , vmVersion , true ) == 0 )
788
786
{
789
- protectableObject = iaaSVMProtectableItem ;
787
+ protectableObjectResource = protectableItem ;
790
788
isDiscoveryNeed = false ;
791
789
break ;
792
790
}
@@ -800,9 +798,9 @@ private void RefreshContainer()
800
798
{
801
799
bool isDiscoverySuccessful = false ;
802
800
string errorMessage = string . Empty ;
803
- var refreshContainerJobResponse = HydraAdapter . RefreshContainers ( ) ;
801
+ var refreshContainerJobResponse = HydraAdapter . RefreshContainers ( ) ;
804
802
805
- //Now wait for the operation to Complete
803
+ //Now wait for the operation to Complete
806
804
WaitForDiscoveryToComplete ( refreshContainerJobResponse . Location , out isDiscoverySuccessful , out errorMessage ) ;
807
805
808
806
if ( ! isDiscoverySuccessful )
0 commit comments