Skip to content

Commit b332ee4

Browse files
committed
minor policy fixes and fixed merge conflicts
2 parents e69c113 + bc40a7d commit b332ee4

File tree

5 files changed

+43
-25
lines changed

5 files changed

+43
-25
lines changed

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Helpers/Validations/PolicyValidations.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,28 @@ public static void ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
3131
{
3232
// for daily schedule, daily retention policy is required
3333
if (schPolicy.ScheduleRunFrequency == ScheduleRunType.Daily &&
34-
ltrPolicy.DailySchedule == null)
34+
(ltrPolicy.DailySchedule == null || ltrPolicy.IsDailyScheduleEnabled == false))
3535
{
3636
throw new ArgumentException(Resources.DailyRetentionScheduleNullException);
3737
}
3838

3939
// for weekly schedule, daily retention policy should be NULL
4040
// AND weekly retention policy is required
4141
if (schPolicy.ScheduleRunFrequency == ScheduleRunType.Weekly &&
42-
(ltrPolicy.DailySchedule != null || ltrPolicy.WeeklySchedule == null))
42+
(ltrPolicy.IsDailyScheduleEnabled != false || ltrPolicy.WeeklySchedule == null ||
43+
(ltrPolicy.IsWeeklyScheduleEnabled == false)))
4344
{
4445
throw new ArgumentException(Resources.WeeklyRetentionScheduleNullException);
4546
}
4647

4748
// validate daily retention schedule with schPolicy
48-
if (ltrPolicy.DailySchedule != null)
49+
if (ltrPolicy.DailySchedule != null && ltrPolicy.IsDailyScheduleEnabled == true)
4950
{
5051
ValidateRetentionAndBackupTimes(schPolicy.ScheduleRunTimes, ltrPolicy.DailySchedule.RetentionTimes);
5152
}
5253

5354
// validate weekly retention schedule with schPolicy
54-
if (ltrPolicy.WeeklySchedule != null)
55+
if (ltrPolicy.WeeklySchedule != null && ltrPolicy.IsWeeklyScheduleEnabled == true)
5556
{
5657
ValidateRetentionAndBackupTimes(schPolicy.ScheduleRunTimes, ltrPolicy.WeeklySchedule.RetentionTimes);
5758

@@ -69,7 +70,7 @@ public static void ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
6970
}
7071

7172
// validate monthly retention schedule with schPolicy
72-
if (ltrPolicy.MonthlySchedule != null)
73+
if (ltrPolicy.MonthlySchedule != null && ltrPolicy.IsMonthlyScheduleEnabled == true)
7374
{
7475
ValidateRetentionAndBackupTimes(schPolicy.ScheduleRunTimes, ltrPolicy.MonthlySchedule.RetentionTimes);
7576

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/Properties/Resources.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/Properties/Resources.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@
205205
<value>RetentionTime in retention schedule should be same as backup time in SchedulePolicy</value>
206206
</data>
207207
<data name="DailyRetentionScheduleNullException" xml:space="preserve">
208-
<value>Daily Retention Schedule can't be null if Daily Backup Schedule is enabled</value>
208+
<value>Daily Retention Schedule can't be null (or) IsDailyScheduleEnabled should be 'true' if Daily Backup Schedule is enabled</value>
209209
</data>
210210
<data name="DailyScheduleEnabledButScheduleIsNullException" xml:space="preserve">
211211
<value>RetentionPolicy: IsDailyScheduleEnabled=true but DailySchedule is NULL</value>
@@ -229,7 +229,7 @@
229229
<value>RetentionDuration in Days/Weeks/Months/Years should be from 1 - 9999</value>
230230
</data>
231231
<data name="WeeklyRetentionScheduleNullException" xml:space="preserve">
232-
<value>If Weekly backup schedule is enabled, Daily retention schedule should be null and Weekly retention schedule should not be null</value>
232+
<value>If Weekly backup schedule is enabled, then IsDailyScheduleEnabled should be false and Weekly retention schedule should not be null, IsWeeklyScheduleEnabled should be true</value>
233233
</data>
234234
<data name="WeeklyScheduleEnabledButScheduleIsNullException" xml:space="preserve">
235235
<value>RetentionPolicy: IsWeeklyScheduleEnabled=true but WeeklySchedule is NULL</value>

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

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -264,25 +264,30 @@ public ProtectionPolicyResponse CreatePolicy()
264264
{
265265
string policyName = (string)ProviderData.ProviderParameters[PolicyParams.PolicyName];
266266
Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.WorkloadType workloadType =
267-
(Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.WorkloadType)ProviderData.ProviderParameters[PolicyParams.WorkloadType];
268-
AzureRmRecoveryServicesRetentionPolicyBase retentionPolicy = (AzureRmRecoveryServicesRetentionPolicyBase)
269-
ProviderData.ProviderParameters[PolicyParams.RetentionPolicy];
270-
AzureRmRecoveryServicesSchedulePolicyBase schedulePolicy = (AzureRmRecoveryServicesSchedulePolicyBase)
271-
ProviderData.ProviderParameters[PolicyParams.SchedulePolicy];
267+
(Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.WorkloadType)ProviderData.ProviderParameters[PolicyParams.WorkloadType];
268+
AzureRmRecoveryServicesRetentionPolicyBase retentionPolicy =
269+
ProviderData.ProviderParameters.ContainsKey(PolicyParams.RetentionPolicy) ?
270+
(AzureRmRecoveryServicesRetentionPolicyBase)ProviderData.ProviderParameters[PolicyParams.RetentionPolicy] :
271+
null;
272+
AzureRmRecoveryServicesSchedulePolicyBase schedulePolicy =
273+
ProviderData.ProviderParameters.ContainsKey(PolicyParams.SchedulePolicy) ?
274+
(AzureRmRecoveryServicesSchedulePolicyBase)ProviderData.ProviderParameters[PolicyParams.SchedulePolicy] :
275+
null;
272276

273277
// do validations
274278
ValidateAzureVMWorkloadType(workloadType);
275279
ValidateAzureVMSchedulePolicy(schedulePolicy);
276280
Logger.Instance.WriteDebug("Validation of Schedule policy is successful");
277281

278-
// update the retention times from backupSchedule to retentionPolicy after converting to UTC
279-
CopyScheduleTimeToRetentionTimes((AzureRmRecoveryServicesLongTermRetentionPolicy)retentionPolicy,
280-
(AzureRmRecoveryServicesSimpleSchedulePolicy)schedulePolicy);
281-
282282
// validate RetentionPolicy
283283
ValidateAzureVMRetentionPolicy(retentionPolicy);
284284
Logger.Instance.WriteDebug("Validation of Retention policy is successful");
285285

286+
// update the retention times from backupSchedule to retentionPolicy after converting to UTC
287+
CopyScheduleTimeToRetentionTimes((AzureRmRecoveryServicesLongTermRetentionPolicy)retentionPolicy,
288+
(AzureRmRecoveryServicesSimpleSchedulePolicy)schedulePolicy);
289+
Logger.Instance.WriteDebug("Copy of RetentionTime from with SchedulePolicy to RetentionPolicy is successful");
290+
286291
// Now validate both RetentionPolicy and SchedulePolicy together
287292
PolicyHelpers.ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
288293
(AzureRmRecoveryServicesLongTermRetentionPolicy)retentionPolicy,
@@ -311,15 +316,23 @@ public ProtectionPolicyResponse CreatePolicy()
311316

312317
public ProtectionPolicyResponse ModifyPolicy()
313318
{
314-
AzureRmRecoveryServicesRetentionPolicyBase retentionPolicy = (AzureRmRecoveryServicesRetentionPolicyBase)
315-
ProviderData.ProviderParameters[PolicyParams.RetentionPolicy];
316-
AzureRmRecoveryServicesSchedulePolicyBase schedulePolicy = (AzureRmRecoveryServicesSchedulePolicyBase)
317-
ProviderData.ProviderParameters[PolicyParams.SchedulePolicy];
318-
AzureRmRecoveryServicesPolicyBase policy = (AzureRmRecoveryServicesPolicyBase)
319-
ProviderData.ProviderParameters[PolicyParams.ProtectionPolicy];
319+
AzureRmRecoveryServicesRetentionPolicyBase retentionPolicy =
320+
ProviderData.ProviderParameters.ContainsKey(PolicyParams.RetentionPolicy) ?
321+
(AzureRmRecoveryServicesRetentionPolicyBase)ProviderData.ProviderParameters[PolicyParams.RetentionPolicy] :
322+
null;
323+
AzureRmRecoveryServicesSchedulePolicyBase schedulePolicy =
324+
ProviderData.ProviderParameters.ContainsKey(PolicyParams.SchedulePolicy) ?
325+
(AzureRmRecoveryServicesSchedulePolicyBase)ProviderData.ProviderParameters[PolicyParams.SchedulePolicy] :
326+
null;
327+
328+
AzureRmRecoveryServicesPolicyBase policy =
329+
ProviderData.ProviderParameters.ContainsKey(PolicyParams.ProtectionPolicy) ?
330+
(AzureRmRecoveryServicesPolicyBase)ProviderData.ProviderParameters[PolicyParams.ProtectionPolicy] :
331+
null;
320332

321333
// do validations
322334
ValidateAzureVMProtectionPolicy(policy);
335+
Logger.Instance.WriteDebug("Validation of Protection Policy is successful");
323336

324337
// RetentionPolicy and SchedulePolicy both should not be empty
325338
if (retentionPolicy == null && schedulePolicy == null)
@@ -332,22 +345,26 @@ public ProtectionPolicyResponse ModifyPolicy()
332345
{
333346
ValidateAzureVMSchedulePolicy(schedulePolicy);
334347
((AzureRmRecoveryServicesIaasVmPolicy)policy).SchedulePolicy = schedulePolicy;
348+
Logger.Instance.WriteDebug("Validation of Schedule policy is successful");
335349
}
336350
if (retentionPolicy != null)
337351
{
338352
ValidateAzureVMRetentionPolicy(retentionPolicy);
339353
((AzureRmRecoveryServicesIaasVmPolicy)policy).RetentionPolicy = retentionPolicy;
354+
Logger.Instance.WriteDebug("Validation of Retention policy is successful");
340355
}
341356

342357
// copy the backupSchedule time to retentionPolicy after converting to UTC
343358
CopyScheduleTimeToRetentionTimes(
344359
(AzureRmRecoveryServicesLongTermRetentionPolicy)((AzureRmRecoveryServicesIaasVmPolicy)policy).RetentionPolicy,
345360
(AzureRmRecoveryServicesSimpleSchedulePolicy)((AzureRmRecoveryServicesIaasVmPolicy)policy).SchedulePolicy);
361+
Logger.Instance.WriteDebug("Copy of RetentionTime from with SchedulePolicy to RetentionPolicy is successful");
346362

347363
// Now validate both RetentionPolicy and SchedulePolicy matches or not
348364
PolicyHelpers.ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
349365
(AzureRmRecoveryServicesLongTermRetentionPolicy)((AzureRmRecoveryServicesIaasVmPolicy)policy).RetentionPolicy,
350366
(AzureRmRecoveryServicesSimpleSchedulePolicy)((AzureRmRecoveryServicesIaasVmPolicy)policy).SchedulePolicy);
367+
Logger.Instance.WriteDebug("Validation of Retention policy with Schedule policy is successful");
351368

352369
// construct Hydra policy request
353370
ProtectionPolicyRequest hydraRequest = new ProtectionPolicyRequest()

src/ResourceManager/RecoveryServices.Backup/Microsoft.Azure.Commands.RecoveryServices.Backup.format.ps1xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
<PropertyName>BackupManagementType</PropertyName>
4343
</TableColumnItem>
4444
<TableColumnItem>
45-
<PropertyName>SchedulePolicy.ScheduleRunTimes</PropertyName>
45+
<ScriptBlock>$_.SchedulePolicy.ScheduleRunTimes</ScriptBlock>
4646
</TableColumnItem>
4747
<TableColumnItem>
48-
<PropertyName>SchedulePolicy.ScheduleRunDays</PropertyName>
48+
<ScriptBlock>$_.SchedulePolicy.ScheduleRunDays</ScriptBlock>
4949
</TableColumnItem>
5050
</TableColumnItems>
5151
</TableRowEntry>

0 commit comments

Comments
 (0)