Skip to content

Commit 34a6ead

Browse files
committed
Added file share support to Enable-Protection
1 parent 891bc6b commit 34a6ead

File tree

29 files changed

+1200
-649
lines changed

29 files changed

+1200
-649
lines changed

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Helpers/Conversions/ConversionHelpers.cs

Lines changed: 112 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,115 @@ public static List<BackupEngineBase> GetBackupEngineModelList(
127127

128128
#region policy
129129

130+
/// <summary>
131+
/// Helper function to convert ps backup policy model for AzureVM from service response.
132+
/// </summary>
133+
public static PolicyBase GetPolicyModelForAzureIaaSVM(ServiceClientModel.ProtectionPolicyResource serviceClientResponse,
134+
PolicyBase policyModel)
135+
{
136+
if (((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).RetentionPolicy.GetType() !=
137+
typeof(ServiceClientModel.LongTermRetentionPolicy))
138+
{
139+
Logger.Instance.WriteDebug("Unknown RetentionPolicy object received: " +
140+
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).RetentionPolicy.GetType());
141+
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
142+
return null;
143+
}
144+
145+
if (((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).SchedulePolicy.GetType() !=
146+
typeof(ServiceClientModel.SimpleSchedulePolicy))
147+
{
148+
Logger.Instance.WriteDebug("Unknown SchedulePolicy object received: " +
149+
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).SchedulePolicy.GetType());
150+
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
151+
return null;
152+
}
153+
154+
policyModel = new AzureVmPolicy();
155+
AzureVmPolicy iaasPolicyModel = policyModel as AzureVmPolicy;
156+
iaasPolicyModel.WorkloadType = WorkloadType.AzureVM;
157+
iaasPolicyModel.BackupManagementType = BackupManagementType.AzureVM;
158+
iaasPolicyModel.RetentionPolicy = PolicyHelpers.GetPSLongTermRetentionPolicy((ServiceClientModel.LongTermRetentionPolicy)
159+
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).RetentionPolicy,
160+
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).TimeZone);
161+
iaasPolicyModel.SchedulePolicy = PolicyHelpers.GetPSSimpleSchedulePolicy((ServiceClientModel.SimpleSchedulePolicy)
162+
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).SchedulePolicy,
163+
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).TimeZone);
164+
return policyModel;
165+
}
166+
167+
/// <summary>
168+
/// Helper function to convert ps backup policy model for AzureSql from service response.
169+
/// </summary>
170+
public static PolicyBase GetPolicyModelForAzureSql(ServiceClientModel.ProtectionPolicyResource serviceClientResponse,
171+
PolicyBase policyModel)
172+
{
173+
ServiceClientModel.AzureSqlProtectionPolicy azureSqlPolicy =
174+
(ServiceClientModel.AzureSqlProtectionPolicy)serviceClientResponse.Properties;
175+
176+
if (azureSqlPolicy.RetentionPolicy.GetType() !=
177+
typeof(ServiceClientModel.SimpleRetentionPolicy))
178+
{
179+
Logger.Instance.WriteDebug("Unknown RetentionPolicy object received: " +
180+
azureSqlPolicy.RetentionPolicy.GetType());
181+
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
182+
return null;
183+
}
184+
185+
policyModel = new AzureSqlPolicy();
186+
AzureSqlPolicy sqlPolicyModel = policyModel as AzureSqlPolicy;
187+
sqlPolicyModel.WorkloadType = WorkloadType.AzureSQLDatabase;
188+
sqlPolicyModel.BackupManagementType = BackupManagementType.AzureSQL;
189+
190+
ServiceClientModel.SimpleRetentionPolicy azureSqlRetentionPolicy =
191+
(ServiceClientModel.SimpleRetentionPolicy)azureSqlPolicy.RetentionPolicy;
192+
sqlPolicyModel.RetentionPolicy =
193+
PolicyHelpers.GetPSSimpleRetentionPolicy(azureSqlRetentionPolicy, null);
194+
return policyModel;
195+
}
196+
197+
/// <summary>
198+
/// Helper function to convert ps backup policy model for Azure FileShare from service response.
199+
/// </summary>
200+
public static PolicyBase GetPolicyModelForAzureFileShare(ServiceClientModel.ProtectionPolicyResource serviceClientResponse,
201+
PolicyBase policyModel)
202+
{
203+
ServiceClientModel.AzureFileShareProtectionPolicy azureFileSharePolicy =
204+
(ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties;
205+
206+
if (azureFileSharePolicy.RetentionPolicy.GetType() !=
207+
typeof(ServiceClientModel.LongTermRetentionPolicy))
208+
{
209+
Logger.Instance.WriteDebug("Unknown RetentionPolicy object received: " +
210+
azureFileSharePolicy.RetentionPolicy.GetType());
211+
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
212+
return null;
213+
}
214+
215+
if (azureFileSharePolicy.SchedulePolicy.GetType() !=
216+
typeof(ServiceClientModel.SimpleSchedulePolicy))
217+
{
218+
Logger.Instance.WriteDebug("Unknown SchedulePolicy object received: " +
219+
azureFileSharePolicy.SchedulePolicy.GetType());
220+
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
221+
return null;
222+
}
223+
224+
225+
policyModel = new AzureFileSharePolicy();
226+
AzureFileSharePolicy fileSharePolicyModel = policyModel as AzureFileSharePolicy;
227+
fileSharePolicyModel.WorkloadType = WorkloadType.AzureFiles;
228+
fileSharePolicyModel.BackupManagementType = BackupManagementType.AzureStorage;
229+
fileSharePolicyModel.RetentionPolicy =
230+
PolicyHelpers.GetPSLongTermRetentionPolicy((ServiceClientModel.LongTermRetentionPolicy)((ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties).RetentionPolicy,
231+
((ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties).TimeZone);
232+
fileSharePolicyModel.SchedulePolicy =
233+
PolicyHelpers.GetPSSimpleSchedulePolicy((ServiceClientModel.SimpleSchedulePolicy)
234+
((ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties).SchedulePolicy,
235+
((ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties).TimeZone);
236+
return policyModel;
237+
}
238+
130239
/// <summary>
131240
/// Helper function to convert ps backup policy model from service response.
132241
/// </summary>
@@ -142,84 +251,17 @@ public static PolicyBase GetPolicyModel(ServiceClientModel.ProtectionPolicyResou
142251

143252
if (serviceClientResponse.Properties.GetType() == typeof(ServiceClientModel.AzureIaaSVMProtectionPolicy))
144253
{
145-
if (((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).RetentionPolicy.GetType() !=
146-
typeof(ServiceClientModel.LongTermRetentionPolicy))
147-
{
148-
Logger.Instance.WriteDebug("Unknown RetentionPolicy object received: " +
149-
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).RetentionPolicy.GetType());
150-
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
151-
return null;
152-
}
153-
154-
if (((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).SchedulePolicy.GetType() !=
155-
typeof(ServiceClientModel.SimpleSchedulePolicy))
156-
{
157-
Logger.Instance.WriteDebug("Unknown SchedulePolicy object received: " +
158-
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).SchedulePolicy.GetType());
159-
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
160-
return null;
161-
}
162-
163-
policyModel = new AzureVmPolicy();
164-
AzureVmPolicy iaasPolicyModel = policyModel as AzureVmPolicy;
165-
iaasPolicyModel.WorkloadType = WorkloadType.AzureVM;
166-
iaasPolicyModel.BackupManagementType = BackupManagementType.AzureVM;
167-
iaasPolicyModel.RetentionPolicy = PolicyHelpers.GetPSLongTermRetentionPolicy((ServiceClientModel.LongTermRetentionPolicy)
168-
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).RetentionPolicy,
169-
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).TimeZone);
170-
iaasPolicyModel.SchedulePolicy = PolicyHelpers.GetPSSimpleSchedulePolicy((ServiceClientModel.SimpleSchedulePolicy)
171-
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).SchedulePolicy,
172-
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).TimeZone);
254+
policyModel = GetPolicyModelForAzureIaaSVM(serviceClientResponse, policyModel);
173255
}
174256
else if (serviceClientResponse.Properties.GetType() ==
175257
typeof(ServiceClientModel.AzureSqlProtectionPolicy))
176258
{
177-
ServiceClientModel.AzureSqlProtectionPolicy azureSqlPolicy =
178-
(ServiceClientModel.AzureSqlProtectionPolicy)serviceClientResponse.Properties;
179-
180-
if (azureSqlPolicy.RetentionPolicy.GetType() !=
181-
typeof(ServiceClientModel.SimpleRetentionPolicy))
182-
{
183-
Logger.Instance.WriteDebug("Unknown RetentionPolicy object received: " +
184-
azureSqlPolicy.RetentionPolicy.GetType());
185-
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
186-
return null;
187-
}
188-
189-
policyModel = new AzureSqlPolicy();
190-
AzureSqlPolicy sqlPolicyModel = policyModel as AzureSqlPolicy;
191-
sqlPolicyModel.WorkloadType = WorkloadType.AzureSQLDatabase;
192-
sqlPolicyModel.BackupManagementType = BackupManagementType.AzureSQL;
193-
194-
ServiceClientModel.SimpleRetentionPolicy azureSqlRetentionPolicy =
195-
(ServiceClientModel.SimpleRetentionPolicy)azureSqlPolicy.RetentionPolicy;
196-
sqlPolicyModel.RetentionPolicy =
197-
PolicyHelpers.GetPSSimpleRetentionPolicy(azureSqlRetentionPolicy, null);
259+
policyModel = GetPolicyModelForAzureSql(serviceClientResponse, policyModel);
198260
}
199261
else if (serviceClientResponse.Properties.GetType() ==
200262
typeof(ServiceClientModel.AzureFileShareProtectionPolicy))
201263
{
202-
ServiceClientModel.AzureFileShareProtectionPolicy azureFileSharePolicy =
203-
(ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties;
204-
205-
if (azureFileSharePolicy.RetentionPolicy.GetType() !=
206-
typeof(ServiceClientModel.LongTermRetentionPolicy))
207-
{
208-
Logger.Instance.WriteDebug("Unknown RetentionPolicy object received: " +
209-
azureFileSharePolicy.RetentionPolicy.GetType());
210-
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
211-
return null;
212-
}
213-
214-
policyModel = new AzureFileSharePolicy();
215-
AzureFileSharePolicy fileSharePolicyModel = policyModel as AzureFileSharePolicy;
216-
fileSharePolicyModel.WorkloadType = WorkloadType.AzureFiles;
217-
fileSharePolicyModel.BackupManagementType = BackupManagementType.AzureStorage;
218-
219-
ServiceClientModel.LongTermRetentionPolicy azureFileShareRetentionPolicy =
220-
(ServiceClientModel.LongTermRetentionPolicy)azureFileSharePolicy.RetentionPolicy;
221-
fileSharePolicyModel.RetentionPolicy =
222-
PolicyHelpers.GetPSLongTermRetentionPolicy(azureFileShareRetentionPolicy, null);
264+
policyModel = GetPolicyModelForAzureFileShare(serviceClientResponse, policyModel);
223265
}
224266
else
225267
{

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Helpers/TrackingHelpers.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,34 @@ public static RestAzureNS.AzureOperationResponse GetOperationResult(
110110
return opStatusResponse;
111111
}
112112

113+
/// <summary>
114+
/// Block to track the operation to completion.
115+
/// Waits till the HTTP status code of the operation becomes something other than Accepted.
116+
/// </summary>
117+
/// <param name="response">Response of the operation returned by the service.</param>
118+
/// <param name="getOpStatus">Delegate method to fetch the operation status of the operation.</param>
119+
/// <returns>Result of the operation once it completes.</returns>
120+
public static RestAzureNS.AzureOperationResponse<T> GetOperationResult<T>(
121+
RestAzureNS.AzureOperationResponse<T> response,
122+
Func<string, RestAzureNS.AzureOperationResponse<T>> getOpStatus)
123+
where T: ServiceClientModel.ProtectionContainerResource
124+
{
125+
var operationId = response.Response.Headers.GetOperationResultId();
126+
127+
var opStatusResponse = getOpStatus(operationId);
128+
129+
while (opStatusResponse.Response.StatusCode == SystemNet.HttpStatusCode.Accepted)
130+
{
131+
TestMockSupport.Delay(_defaultSleepForOperationTracking * 1000);
132+
133+
opStatusResponse = getOpStatus(operationId);
134+
}
135+
136+
opStatusResponse = getOpStatus(operationId);
137+
138+
return opStatusResponse;
139+
}
140+
113141
/// <summary>
114142
/// Retries request to URL for specified no. of tries in case of failure
115143
/// </summary>

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/AzureFileShareModels/AzureFileShareItem.cs

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,14 @@
1818
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
1919
{
2020
/// <summary>
21-
/// Azure File Share Item Class
21+
/// Azure files Item Class
2222
/// </summary>
23-
public class AzureFileShareItem : ItemBase
23+
public class AzureFileShareItem : AzureItem
2424
{
2525
/// <summary>
26-
/// Protection Status of the item
26+
/// Container id of item
2727
/// </summary>
28-
public ItemProtectionStatus ProtectionStatus { get; set; }
29-
30-
/// <summary>
31-
/// Protection State of the item
32-
/// </summary>
33-
public ItemProtectionState ProtectionState { get; set; }
34-
35-
/// <summary>
36-
/// Last Backup Status for the item
37-
/// </summary>
38-
public string LastBackupStatus { get; set; }
39-
40-
/// <summary>
41-
/// Last Backup Time for the item
42-
/// </summary>
43-
public DateTime? LastBackupTime { get; set; }
44-
45-
/// <summary>
46-
/// Protection Policy Name for the Item
47-
/// </summary>
48-
public string ProtectionPolicyName { get; set; }
49-
50-
/// <summary>
51-
/// ExtendedInfo for the Item
52-
/// </summary
53-
public AzureFileShareItemExtendedInfo ExtendedInfo { get; set; }
28+
public string ParentContainerFabricId { get; set; }
5429

5530
/// <summary>
5631
/// Constructor. Takes the service client object representing the protected item
@@ -62,12 +37,11 @@ public class AzureFileShareItem : ItemBase
6237
/// <param name="policyName">Name of the protection policy associated with this protected item</param>
6338
public AzureFileShareItem(ProtectedItemResource protectedItemResource,
6439
string containerName, ContainerType containerType, string policyName)
65-
: base(protectedItemResource, containerName, containerType)
40+
: base(protectedItemResource, containerName, containerType, policyName)
6641
{
6742
AzureFileshareProtectedItem protectedItem = (AzureFileshareProtectedItem)protectedItemResource.Properties;
6843
LastBackupStatus = protectedItem.LastBackupStatus;
6944
LastBackupTime = protectedItem.LastBackupTime;
70-
ProtectionPolicyName = policyName;
7145
ProtectionState =
7246
EnumUtils.GetEnum<ItemProtectionState>(protectedItem.ProtectionState.ToString());
7347
ProtectionStatus = EnumUtils.GetEnum<ItemProtectionStatus>(protectedItem.ProtectionStatus);
@@ -77,21 +51,6 @@ public AzureFileShareItem(ProtectedItemResource protectedItemResource,
7751
/// <summary>
7852
/// Azure File Share Item ExtendedInfo Class
7953
/// </summary>
80-
public class AzureFileShareItemExtendedInfo : ItemExtendedInfoBase
81-
{
82-
/// <summary>
83-
/// Oldest Recovery Point for the Item
84-
/// </summary
85-
public DateTime? OldestRecoveryPoint { get; set; }
86-
87-
/// <summary>
88-
/// Recovery Points Count for the Item
89-
/// </summary
90-
public int RecoveryPointCount { get; set; }
91-
92-
/// <summary>
93-
/// PolicyState for the Item
94-
/// </summary
95-
public string PolicyState { get; set; }
96-
}
54+
public class AzureFileShareItemExtendedInfo : AzureItemExtendedInfo
55+
{ }
9756
}

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/AzureFileShareModels/AzureFileSharePolicy.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,8 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
1717
/// <summary>
1818
/// Azure FileShare specific backup policy class.
1919
/// </summary>
20-
public class AzureFileSharePolicy : PolicyBase
20+
public class AzureFileSharePolicy : AzurePolicy
2121
{
22-
/// <summary>
23-
/// Object defining the retention behavior of this policy.
24-
/// </summary>
25-
public RetentionPolicyBase RetentionPolicy { get; set; }
26-
27-
public override void Validate()
28-
{
29-
base.Validate();
30-
RetentionPolicy.Validate();
31-
}
22+
3223
}
3324
}

0 commit comments

Comments
 (0)