Skip to content

Commit 278dab3

Browse files
committed
policy exception messages changes to point to Resources.resx file
1 parent 6146387 commit 278dab3

File tree

11 files changed

+320
-98
lines changed

11 files changed

+320
-98
lines changed

src/ResourceManager/RecoveryServices.Backup/Cmdlets/ProtectionPolicy/GetAzureRmRecoveryServicesPolicy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public override void ExecuteCmdlet()
6969
HydraAdapter);
7070
if (policy == null)
7171
{
72-
throw new ArgumentException(string.Format(Resources.PolicyNotFound, Name));
72+
throw new ArgumentException(string.Format(Resources.PolicyNotFoundException, Name));
7373
}
7474
policyList.Add(ConversionHelpers.GetPolicyModel(policy.Item));
7575
}

src/ResourceManager/RecoveryServices.Backup/Cmdlets/ProtectionPolicy/NewAzureRmRecoveryServicesPolicy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public override void ExecuteCmdlet()
6464
// Validate if policy already exists
6565
if (PolicyCmdletHelpers.GetProtectionPolicyByName(Name, HydraAdapter) != null)
6666
{
67-
throw new ArgumentException(string.Format(Resources.PolicyAlreadyExist, Name));
67+
throw new ArgumentException(string.Format(Resources.PolicyAlreadyExistException, Name));
6868
}
6969

7070
PsBackupProviderManager providerManager = new PsBackupProviderManager(new Dictionary<System.Enum, object>()

src/ResourceManager/RecoveryServices.Backup/Cmdlets/ProtectionPolicy/SetAzureRmRecoveryServicesPolicy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public override void ExecuteCmdlet()
5858
Policy.Name, HydraAdapter);
5959
if (servicePolicy == null)
6060
{
61-
throw new ArgumentException(string.Format(Resources.PolicyNotFound, Policy.Name));
61+
throw new ArgumentException(string.Format(Resources.PolicyNotFoundException, Policy.Name));
6262
}
6363

6464
PsBackupProviderManager providerManager = new PsBackupProviderManager(new Dictionary<System.Enum, object>()

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
16-
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
1715
using System;
1816
using System.Collections.Generic;
1917
using System.Linq;
2018
using System.Text;
2119
using System.Threading.Tasks;
20+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
21+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
22+
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
2223

2324
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers
2425
{
@@ -62,7 +63,7 @@ public static AzureRmRecoveryServicesPolicyBase GetPolicyModel(ProtectionPolicyR
6263

6364
if(hydraResponse == null || hydraResponse.Properties == null)
6465
{
65-
throw new ArgumentException("Empty policy Hydra response");
66+
throw new ArgumentException(Resources.EmptyHydraResponseException);
6667
}
6768

6869
if (hydraResponse.Properties.GetType() == typeof(AzureIaaSVMProtectionPolicy))

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System.Collections.Generic;
2020
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
2121
using HydraModels = Microsoft.Azure.Management.RecoveryServices.Backup.Models;
22+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
2223

2324
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers
2425
{
@@ -61,6 +62,9 @@ public static AzureRmRecoveryServicesLongTermRetentionPolicy GetPSLongTermRetent
6162
ltrPolicy.YearlySchedule = GetPSLTRYearlySchedule(hydraRetPolicy.YearlySchedule);
6263
}
6364

65+
// safe side validate
66+
ltrPolicy.Validate();
67+
6468
return ltrPolicy;
6569
}
6670

@@ -97,8 +101,8 @@ private static int GetRetentionDurationInDays(HydraModels.RetentionDuration rete
97101
break;
98102

99103
default:
100-
throw new ArgumentException("Invalid DurationType:" +
101-
retentionDuration.DurationType.ToString());
104+
throw new ArgumentException(Resources.InvalidDurationTypeException,
105+
retentionDuration.DurationType.ToString());
102106
}
103107

104108
return daysCount;
@@ -127,8 +131,8 @@ private static int GetRetentionDurationInWeeks(HydraModels.RetentionDuration ret
127131
break;
128132

129133
default:
130-
throw new ArgumentException("Invalid DurationType:" +
131-
retentionDuration.DurationType.ToString());
134+
throw new ArgumentException(Resources.InvalidDurationTypeException,
135+
retentionDuration.DurationType.ToString());
132136
}
133137

134138
return weeksCount;
@@ -157,8 +161,8 @@ private static int GetRetentionDurationInMonths(HydraModels.RetentionDuration re
157161
break;
158162

159163
default:
160-
throw new ArgumentException("Invalid DurationType:" +
161-
retentionDuration.DurationType.ToString());
164+
throw new ArgumentException(Resources.InvalidDurationTypeException,
165+
retentionDuration.DurationType.ToString());
162166
}
163167

164168
return monthsCount;
@@ -187,8 +191,8 @@ private static int GetRetentionDurationInYears(HydraModels.RetentionDuration ret
187191
break;
188192

189193
default:
190-
throw new ArgumentException("Invalid DurationType:" +
191-
retentionDuration.DurationType.ToString());
194+
throw new ArgumentException(Resources.InvalidDurationTypeException,
195+
retentionDuration.DurationType.ToString());
192196
}
193197

194198
return yearsCount;

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

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,46 @@ public partial class PolicyHelpers
2727
#region HydraToPSObject conversions
2828

2929
public static AzureRmRecoveryServicesSimpleSchedulePolicy GetPSSimpleSchedulePolicyPolicy(
30-
SimpleSchedulePolicy hydraRetPolicy)
30+
SimpleSchedulePolicy hydraPolicy)
3131
{
32-
throw new NotImplementedException();
32+
if (hydraPolicy == null)
33+
{
34+
return null;
35+
}
36+
37+
AzureRmRecoveryServicesSimpleSchedulePolicy psPolicy = new AzureRmRecoveryServicesSimpleSchedulePolicy();
38+
39+
psPolicy.ScheduleRunDays = HelperUtils.GetEnumListFromStringList<DayOfWeek>(hydraPolicy.ScheduleRunDays);
40+
psPolicy.ScheduleRunFrequency = (ScheduleRunType)Enum.Parse(typeof(ScheduleRunType),
41+
hydraPolicy.ScheduleRunFrequency);
42+
psPolicy.ScheduleRunTimes = (List<DateTime>)hydraPolicy.ScheduleRunTimes;
43+
44+
// safe side validation
45+
psPolicy.Validate();
46+
47+
return psPolicy;
3348
}
3449

3550
#endregion
3651

3752
#region PStoHydraObject conversions
3853

3954
public static SimpleSchedulePolicy GetHydraSimpleSchedulePolicy(
40-
AzureRmRecoveryServicesSimpleSchedulePolicy psRetPolicy)
55+
AzureRmRecoveryServicesSimpleSchedulePolicy psPolicy)
4156
{
42-
throw new NotImplementedException();
57+
if (psPolicy == null)
58+
{
59+
return null;
60+
}
61+
62+
SimpleSchedulePolicy hydraPolicy = new SimpleSchedulePolicy();
63+
hydraPolicy.ScheduleRunFrequency = psPolicy.ScheduleRunFrequency.ToString();
64+
if (psPolicy.ScheduleRunFrequency == ScheduleRunType.Weekly)
65+
{
66+
hydraPolicy.ScheduleRunDays = HelperUtils.GetStringListFromEnumList<DayOfWeek>(psPolicy.ScheduleRunDays);
67+
}
68+
69+
return hydraPolicy;
4370
}
4471

4572
#endregion

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System.Collections.Generic;
2020
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
2121
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
22+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
2223

2324
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers
2425
{
@@ -32,16 +33,15 @@ public static void ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
3233
if(schPolicy.ScheduleRunFrequency == ScheduleRunType.Daily &&
3334
ltrPolicy.DailySchedule == null)
3435
{
35-
throw new ArgumentException("Daily Retention Schedule can't be null if Daily Backup Schedule is enabled ");
36+
throw new ArgumentException(Resources.DailyRetentionScheduleNullException);
3637
}
3738

3839
// for weekly schedule, daily retention policy should be NULL
3940
// AND weekly retention policy is required
4041
if (schPolicy.ScheduleRunFrequency == ScheduleRunType.Weekly &&
4142
(ltrPolicy.DailySchedule != null || ltrPolicy.WeeklySchedule == null))
4243
{
43-
throw new ArgumentException("If Weekly backup schedule is enabled, Daily retention schedule should be null &" +
44-
"Weekly retention schedule should not be null");
44+
throw new ArgumentException(Resources.WeeklyRetentionScheduleNullException);
4545
}
4646

4747
// validate daily retention schedule with schPolicy
@@ -58,8 +58,7 @@ public static void ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
5858
// count of daysOfWeek should match for weekly schedule
5959
if(ltrPolicy.WeeklySchedule.DaysOfTheWeek.Count != schPolicy.ScheduleRunDays.Count)
6060
{
61-
throw new ArgumentException(
62-
"DaysOfTheWeek in WeeklySchedule of retention policy must be same as ScheduleRunDays in SchedulePolicy");
61+
throw new ArgumentException(Resources.DaysofTheWeekInWeeklyRetentionException);
6362
}
6463

6564
// validate days of week
@@ -75,7 +74,7 @@ public static void ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
7574
if(schPolicy.ScheduleRunFrequency == ScheduleRunType.Weekly &&
7675
ltrPolicy.MonthlySchedule.RetentionScheduleFormatType == Cmdlets.Models.RetentionScheduleFormat.Daily)
7776
{
78-
throw new ArgumentException("DailyRetentionFormat cannot be chosen if Weekly BackupSchedule is selected");
77+
throw new ArgumentException(Resources.MonthlyYearlyInvalidDailyRetentionFormatTypeException);
7978
}
8079

8180
// for monthly and weeklyFormat, validate days of week
@@ -95,7 +94,7 @@ public static void ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
9594
if (schPolicy.ScheduleRunFrequency == ScheduleRunType.Weekly &&
9695
ltrPolicy.YearlySchedule.RetentionScheduleFormatType == Cmdlets.Models.RetentionScheduleFormat.Daily)
9796
{
98-
throw new ArgumentException("DailyRetentionFormat cannot be chosen if Weekly BackupSchedule is selected");
97+
throw new ArgumentException(Resources.MonthlyYearlyInvalidDailyRetentionFormatTypeException);
9998
}
10099

101100
// for yearly and weeklyFormat, validate days of week
@@ -111,18 +110,18 @@ public static void ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
111110

112111
private static void ValidateRetentionAndBackupTimes(List<DateTime> schPolicyTimes, List<DateTime> retPolicyTimes)
113112
{
114-
//Currently supported BackupTimes & retentionTimes is 1
113+
//Currently supported BackupTimes & retentionTimes is 1
115114
if (retPolicyTimes == null || retPolicyTimes.Count != 1)
116115
{
117-
throw new ArgumentException("Only one RetentionTime is Allowed in RententionSchedules");
116+
throw new ArgumentException(Resources.InvalidRetentionTimesInPolicyException);
118117
}
119118
if (schPolicyTimes == null || schPolicyTimes.Count != 1)
120119
{
121-
throw new ArgumentException("Only one BackupTime is Allowed in SchedulePolicy");
120+
throw new ArgumentException(Resources.InvalidBackupTimesInSchedulePolicyException);
122121
}
123122
if (schPolicyTimes[0] != retPolicyTimes[0])
124123
{
125-
throw new ArgumentException("RetentionTime in retention schedule should be same as backup time in SchedulePolicy");
124+
throw new ArgumentException(Resources.BackupAndRetentionTimesMismatch);
126125
}
127126
}
128127

@@ -132,8 +131,7 @@ private static void ValidateRetentionAndScheduleDaysOfWeek(List<DayOfWeek> schLi
132131
{
133132
if (!schList.Contains(day))
134133
{
135-
throw new ArgumentException(
136-
"DaysOfTheWeek in retention schedule should be subset of ScheduleRunDays of SchedulePolicy");
134+
throw new ArgumentException(Resources.MonthlyYearlyRetentionDaysOfWeekException);
137135
}
138136
}
139137
}

0 commit comments

Comments
 (0)