Skip to content

Commit 7ca71b0

Browse files
committed
Addressed review comments
changed base class for AzureFileSharePolicy rebase changes renaming azurefileshareextended info rebase changes
1 parent b06f08b commit 7ca71b0

File tree

7 files changed

+185
-105
lines changed

7 files changed

+185
-105
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.Models/AzureFileShareModels/AzureFileShareItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ public AzureFileShareItem(ProtectedItemResource protectedItemResource,
5151
/// <summary>
5252
/// Azure File Share Item ExtendedInfo Class
5353
/// </summary>
54-
public class AzureFileShareExtendedInfo : AzureItemExtendedInfo
54+
public class AzureFileShareItemExtendedInfo : AzureItemExtendedInfo
5555
{ }
5656
}

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
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
16+
{
17+
/// <summary>
18+
/// Azure Workload specific backup policy class.
19+
/// </summary>
20+
public class AzurePolicy : PolicyBase
21+
{
22+
/// <summary>
23+
/// Object defining the schedule associated with this policy.
24+
/// </summary>
25+
public SchedulePolicyBase SchedulePolicy { get; set; }
26+
27+
/// <summary>
28+
/// Object defining the retention behavior of this policy.
29+
/// </summary>
30+
public RetentionPolicyBase RetentionPolicy { get; set; }
31+
32+
public override void Validate()
33+
{
34+
base.Validate();
35+
36+
SchedulePolicy.Validate();
37+
RetentionPolicy.Validate();
38+
}
39+
}
40+
41+
}

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/AzureVmModels/AzureVmPolicy.cs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,9 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
1717
/// <summary>
1818
/// Azure VM specific backup policy class.
1919
/// </summary>
20-
public class AzureVmPolicy : PolicyBase
20+
public class AzureVmPolicy : AzurePolicy
2121
{
22-
/// <summary>
23-
/// Object defining the schedule associated with this policy.
24-
/// </summary>
25-
public SchedulePolicyBase SchedulePolicy { get; set; }
2622

27-
/// <summary>
28-
/// Object defining the retention behavior of this policy.
29-
/// </summary>
30-
public RetentionPolicyBase RetentionPolicy { get; set; }
31-
32-
public override void Validate()
33-
{
34-
base.Validate();
35-
36-
SchedulePolicy.Validate();
37-
RetentionPolicy.Validate();
38-
}
3923
}
4024

4125
}

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/Commands.RecoveryServices.Backup.Models.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
<Compile Include="AzureFileShareModels\AzureFileShareItem.cs" />
5353
<Compile Include="AzureModels\AzureContainer.cs" />
5454
<Compile Include="AzureModels\AzureItem.cs" />
55+
<Compile Include="AzureModels\AzurePolicy.cs" />
5556
<Compile Include="AzureSqlModels\AzureSqlContainer.cs" />
5657
<Compile Include="AzureSqlModels\AzureSqlItem.cs" />
5758
<Compile Include="AzureSqlModels\AzureSqlPolicy.cs" />

0 commit comments

Comments
 (0)