Skip to content

Commit 74ad567

Browse files
author
Samuel Anudeep
committed
Merge branch 'devSwagger' into samSwagger
2 parents 50e7d8b + c5b53ff commit 74ad567

23 files changed

+237
-259
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,9 @@ public static PolicyBase GetPolicyModel(ServiceClientModel.ProtectionPolicyResou
203203
/// Helper function to convert ps backup policy list model from service response.
204204
/// </summary>
205205
public static List<PolicyBase> GetPolicyModelList(
206-
ServiceClientModel.ProtectionPolicyListResponse serviceClientListResponse)
206+
List<ServiceClientModel.ProtectionPolicyResource> serviceClientListResponse)
207207
{
208-
if (serviceClientListResponse == null || serviceClientListResponse.ItemList == null ||
209-
serviceClientListResponse.ItemList.Value == null || serviceClientListResponse.ItemList.Value.Count == 0)
208+
if (serviceClientListResponse == null && serviceClientListResponse.Count == 0)
210209
{
211210
Logger.Instance.WriteDebug("Received empty list of policies from service");
212211
return null;
@@ -215,7 +214,7 @@ public static List<PolicyBase> GetPolicyModelList(
215214
List<PolicyBase> policyModels = new List<PolicyBase>();
216215
PolicyBase policyModel = null;
217216

218-
foreach (ServiceClientModel.ProtectionPolicyResource resource in serviceClientListResponse.ItemList.Value)
217+
foreach (ServiceClientModel.ProtectionPolicyResource resource in serviceClientListResponse)
219218
{
220219
policyModel = GetPolicyModel(resource);
221220
if (policyModel != null)

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
1919
using Microsoft.Rest;
2020
using Microsoft.Rest.Azure;
21-
using CmdletModel = Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
2221

2322
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers
2423
{
@@ -65,7 +64,7 @@ public static CmdletModel.JobBase GetPSJob(JobResource serviceClientJob)
6564
/// <summary>
6665
/// Helper function to convert ps backup job list model from service response.
6766
/// </summary>
68-
public static void AddServiceClientJobsToPSList(Microsoft.Rest.Azure.IPage<JobResource> serviceClientJobs, List<CmdletModel.JobBase> psJobs, ref int jobsCount)
67+
public static void AddServiceClientJobsToPSList(List<JobResource> serviceClientJobs, List<CmdletModel.JobBase> psJobs, ref int jobsCount)
6968
{
7069
if (serviceClientJobs != null )
7170
{
@@ -102,8 +101,17 @@ private static CmdletModel.AzureVmJob GetPSAzureVmJob(JobResource serviceClientJ
102101
}
103102

104103
response.JobId = GetLastIdFromFullId(serviceClientJob.Id);
105-
response.StartTime = (DateTime)vmJob.StartTime;
106-
response.EndTime = (DateTime)vmJob.EndTime;
104+
DateTime startTime = DateTime.MinValue;
105+
if (vmJob.StartTime.HasValue)
106+
{
107+
response.StartTime = (DateTime)vmJob.StartTime;
108+
}
109+
else
110+
{
111+
throw new ArgumentNullException("Job Start Time is null");
112+
}
113+
114+
response.EndTime = vmJob.EndTime;
107115
response.Duration = new TimeSpan(Convert.ToInt64(vmJob.Duration));
108116
response.Status = vmJob.Status;
109117
response.VmVersion = vmJob.VirtualMachineVersion;
@@ -191,12 +199,12 @@ public static string GetLastIdFromFullId(string fullId)
191199
/// <summary>
192200
/// Helper function to get job type from ps backup management type.
193201
/// </summary>
194-
public static string GetJobTypeForService(CmdletModel.BackupManagementType mgmtType)
202+
public static BackupManagementType GetJobTypeForService(CmdletModel.BackupManagementType mgmtType)
195203
{
196204
switch (mgmtType)
197205
{
198206
case CmdletModel.BackupManagementType.AzureVM:
199-
return BackupManagementType.AzureIaasVM.ToString();
207+
return BackupManagementType.AzureIaasVM;
200208
default:
201209
throw new Exception("Invalid BackupManagementType provided: " + mgmtType);
202210
}

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

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ public static SimpleRetentionPolicy GetPSSimpleRetentionPolicy(
8989
{
9090
simplePolicy.RetentionDurationType = EnumUtils.GetEnum<RetentionDurationType>(
9191
hydraRetPolicy.RetentionDuration.DurationType);
92-
simplePolicy.RetentionCount = hydraRetPolicy.RetentionDuration.Count;
92+
simplePolicy.RetentionCount = hydraRetPolicy.RetentionDuration.Count.HasValue ?
93+
(int)hydraRetPolicy.RetentionDuration.Count : default(int);
9394
}
9495

9596
simplePolicy.Validate();
@@ -107,19 +108,22 @@ private static int GetRetentionDurationInDays(ServiceClientModel.RetentionDurati
107108
switch (retentionDuration.DurationType)
108109
{
109110
case ServiceClientModel.RetentionDurationType.Days:
110-
daysCount = retentionDuration.Count;
111+
daysCount = GetIntegerFromNullableIntgerValue(retentionDuration.Count);
111112
break;
112113

113114
case ServiceClientModel.RetentionDurationType.Weeks:
114-
daysCount = retentionDuration.Count * PolicyConstants.NumOfDaysInWeek;
115+
daysCount = GetIntegerFromNullableIntgerValue(retentionDuration.Count)
116+
* PolicyConstants.NumOfDaysInWeek;
115117
break;
116118

117119
case ServiceClientModel.RetentionDurationType.Months:
118-
daysCount = retentionDuration.Count * PolicyConstants.NumOfDaysInMonth;
120+
daysCount = GetIntegerFromNullableIntgerValue(retentionDuration.Count)
121+
* PolicyConstants.NumOfDaysInMonth;
119122
break;
120123

121124
case ServiceClientModel.RetentionDurationType.Years:
122-
daysCount = retentionDuration.Count * PolicyConstants.NumOfDaysInYear;
125+
daysCount = GetIntegerFromNullableIntgerValue(retentionDuration.Count)
126+
* PolicyConstants.NumOfDaysInYear;
123127
break;
124128

125129
default:
@@ -137,19 +141,22 @@ private static int GetRetentionDurationInWeeks(ServiceClientModel.RetentionDurat
137141
switch (retentionDuration.DurationType)
138142
{
139143
case ServiceClientModel.RetentionDurationType.Days:
140-
weeksCount = retentionDuration.Count / PolicyConstants.NumOfDaysInWeek;
144+
weeksCount = GetIntegerFromNullableIntgerValue(retentionDuration.Count)
145+
/ PolicyConstants.NumOfDaysInWeek;
141146
break;
142147

143148
case ServiceClientModel.RetentionDurationType.Weeks:
144-
weeksCount = retentionDuration.Count;
149+
weeksCount = GetIntegerFromNullableIntgerValue(retentionDuration.Count);
145150
break;
146151

147152
case ServiceClientModel.RetentionDurationType.Months:
148-
weeksCount = retentionDuration.Count * PolicyConstants.NumOfWeeksInMonth;
153+
weeksCount = GetIntegerFromNullableIntgerValue(retentionDuration.Count)
154+
* PolicyConstants.NumOfWeeksInMonth;
149155
break;
150156

151157
case ServiceClientModel.RetentionDurationType.Years:
152-
weeksCount = retentionDuration.Count * PolicyConstants.NumOfWeeksInYear;
158+
weeksCount = GetIntegerFromNullableIntgerValue(retentionDuration.Count)
159+
* PolicyConstants.NumOfWeeksInYear;
153160
break;
154161

155162
default:
@@ -167,19 +174,22 @@ private static int GetRetentionDurationInMonths(ServiceClientModel.RetentionDura
167174
switch (retentionDuration.DurationType)
168175
{
169176
case ServiceClientModel.RetentionDurationType.Days:
170-
monthsCount = retentionDuration.Count / PolicyConstants.NumOfDaysInMonth;
177+
monthsCount = GetIntegerFromNullableIntgerValue(retentionDuration.Count)
178+
/ PolicyConstants.NumOfDaysInMonth;
171179
break;
172180

173181
case ServiceClientModel.RetentionDurationType.Weeks:
174-
monthsCount = retentionDuration.Count / PolicyConstants.NumOfWeeksInMonth;
182+
monthsCount = GetIntegerFromNullableIntgerValue(retentionDuration.Count)
183+
/ PolicyConstants.NumOfWeeksInMonth;
175184
break;
176185

177186
case ServiceClientModel.RetentionDurationType.Months:
178-
monthsCount = retentionDuration.Count;
187+
monthsCount = GetIntegerFromNullableIntgerValue(retentionDuration.Count);
179188
break;
180189

181190
case ServiceClientModel.RetentionDurationType.Years:
182-
monthsCount = retentionDuration.Count * PolicyConstants.NumOfMonthsInYear;
191+
monthsCount = GetIntegerFromNullableIntgerValue(retentionDuration.Count)
192+
* PolicyConstants.NumOfMonthsInYear;
183193
break;
184194

185195
default:
@@ -197,19 +207,22 @@ private static int GetRetentionDurationInYears(ServiceClientModel.RetentionDurat
197207
switch (retentionDuration.DurationType)
198208
{
199209
case ServiceClientModel.RetentionDurationType.Days:
200-
yearsCount = retentionDuration.Count / PolicyConstants.NumOfDaysInYear;
210+
yearsCount = GetIntegerFromNullableIntgerValue(retentionDuration.Count)
211+
/ PolicyConstants.NumOfDaysInYear;
201212
break;
202213

203214
case ServiceClientModel.RetentionDurationType.Weeks:
204-
yearsCount = retentionDuration.Count / PolicyConstants.NumOfWeeksInYear;
215+
yearsCount = GetIntegerFromNullableIntgerValue(retentionDuration.Count)
216+
/ PolicyConstants.NumOfWeeksInYear;
205217
break;
206218

207219
case ServiceClientModel.RetentionDurationType.Months:
208-
yearsCount = retentionDuration.Count / PolicyConstants.NumOfMonthsInYear;
220+
yearsCount = GetIntegerFromNullableIntgerValue(retentionDuration.Count)
221+
/ PolicyConstants.NumOfMonthsInYear;
209222
break;
210223

211224
case ServiceClientModel.RetentionDurationType.Years:
212-
yearsCount = retentionDuration.Count;
225+
yearsCount = GetIntegerFromNullableIntgerValue(retentionDuration.Count);
213226
break;
214227

215228
default:
@@ -308,8 +321,9 @@ private static DailyRetentionFormat GetPSLTRDailyRetentionFormat(
308321
{
309322
Day psDay = new Day()
310323
{
311-
Date = serviceClientDay.Date,
312-
IsLast = serviceClientDay.IsLast
324+
Date = GetIntegerFromNullableIntgerValue(serviceClientDay.Date),
325+
IsLast = serviceClientDay.IsLast.HasValue ?
326+
(bool)serviceClientDay.IsLast : default(bool)
313327
};
314328

315329
psFormat.DaysOfTheMonth.Add(psDay);
@@ -428,7 +442,8 @@ private static ServiceClientModel.DailyRetentionSchedule GetServiceClientLTRDail
428442
DurationType = ServiceClientModel.RetentionDurationType.Days
429443
};
430444

431-
serviceClientDaily.RetentionTimes = psDaily.RetentionTimes;
445+
serviceClientDaily.RetentionTimes = GetNullableDateTimeListFromDateTimeList
446+
(psDaily.RetentionTimes);
432447

433448
return serviceClientDaily;
434449
}
@@ -447,7 +462,8 @@ private static ServiceClientModel.WeeklyRetentionSchedule GetServiceClientLTRWee
447462
Count = psWeekly.DurationCountInWeeks,
448463
DurationType = ServiceClientModel.RetentionDurationType.Weeks
449464
};
450-
serviceClientWeekly.RetentionTimes = psWeekly.RetentionTimes;
465+
serviceClientWeekly.RetentionTimes = GetNullableDateTimeListFromDateTimeList(
466+
psWeekly.RetentionTimes);
451467
serviceClientWeekly.DaysOfTheWeek = HelperUtils.GetStringListFromEnumList<DayOfWeek>(psWeekly.DaysOfTheWeek);
452468

453469
return serviceClientWeekly;
@@ -467,7 +483,8 @@ private static ServiceClientModel.MonthlyRetentionSchedule GetServiceClientLTRMo
467483
Count = psMonthly.DurationCountInMonths,
468484
DurationType = ServiceClientModel.RetentionDurationType.Months
469485
};
470-
serviceClientMonthly.RetentionTimes = psMonthly.RetentionTimes;
486+
serviceClientMonthly.RetentionTimes = GetNullableDateTimeListFromDateTimeList(
487+
psMonthly.RetentionTimes);
471488

472489
serviceClientMonthly.RetentionScheduleFormatType = psMonthly.RetentionScheduleFormatType.ToString();
473490
if (psMonthly.RetentionScheduleFormatType == RetentionScheduleFormat.Daily)
@@ -496,7 +513,8 @@ private static ServiceClientModel.YearlyRetentionSchedule GetServiceClientLTRYea
496513
Count = psYearly.DurationCountInYears,
497514
DurationType = ServiceClientModel.RetentionDurationType.Years
498515
};
499-
serviceClientYearly.RetentionTimes = psYearly.RetentionTimes;
516+
serviceClientYearly.RetentionTimes = GetNullableDateTimeListFromDateTimeList(
517+
psYearly.RetentionTimes);
500518

501519
serviceClientYearly.RetentionScheduleFormatType = psYearly.RetentionScheduleFormatType.ToString();
502520
if (psYearly.RetentionScheduleFormatType == RetentionScheduleFormat.Daily)
@@ -565,5 +583,10 @@ private static ServiceClientModel.WeeklyRetentionFormat GetServiceClientLTRWeekl
565583
#endregion
566584

567585
#endregion
586+
587+
private static int GetIntegerFromNullableIntgerValue(int? value)
588+
{
589+
return (value.HasValue ? (int)value : default(int));
590+
}
568591
}
569592
}

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static SimpleSchedulePolicy GetPSSimpleSchedulePolicy(
6060
// <summary>
6161
/// Helper function to parse utc time from local time.
6262
/// </summary>
63-
public static List<DateTime> ParseDateTimesToUTC(IList<DateTime> localTimes)
63+
public static List<DateTime> ParseDateTimesToUTC(IList<DateTime?> localTimes)
6464
{
6565
if (localTimes == null || localTimes.Count == 0)
6666
{
@@ -72,6 +72,10 @@ public static List<DateTime> ParseDateTimesToUTC(IList<DateTime> localTimes)
7272

7373
foreach (DateTime localTime in localTimes)
7474
{
75+
if(localTime == null)
76+
{
77+
throw new ArgumentNullException("Policy date time object is null");
78+
}
7579
temp = localTime;
7680
if (localTime.Kind != DateTimeKind.Utc)
7781
{
@@ -105,6 +109,25 @@ public static ServiceClientModel.SimpleSchedulePolicy GetServiceClientSimpleSche
105109
return serviceClientPolicy;
106110
}
107111

112+
// <summary>
113+
/// Helper function to get nullable date time list from date time list.
114+
/// </summary>
115+
public static List<DateTime?> GetNullableDateTimeListFromDateTimeList(IList<DateTime> localTimes)
116+
{
117+
if (localTimes == null || localTimes.Count == 0)
118+
{
119+
return null;
120+
}
121+
122+
List<DateTime?> convertedTime = new List<DateTime?>();
123+
124+
foreach (DateTime localTime in localTimes)
125+
{
126+
convertedTime.Add((DateTime)localTime);
127+
}
128+
129+
return convertedTime;
130+
}
108131
#endregion
109132
}
110133
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,5 @@ public static List<T> GetPagedList<T>(Func<IPage<T>> listResources, Func<string,
296296

297297
return resources;
298298
}
299-
300299
}
301300
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@ public interface IPsBackupProvider
3232
{
3333
void Initialize(Dictionary<System.Enum, object> providerData, ServiceClientAdapter serviceClientAdapter);
3434

35-
BaseRecoveryServicesJobResponse EnableProtection();
35+
Microsoft.Rest.Azure.AzureOperationResponse EnableProtection();
3636

37-
BaseRecoveryServicesJobResponse DisableProtection();
37+
Microsoft.Rest.Azure.AzureOperationResponse DisableProtection();
3838

39-
BaseRecoveryServicesJobResponse TriggerBackup();
39+
Microsoft.Rest.Azure.AzureOperationResponse TriggerBackup();
4040

41-
BaseRecoveryServicesJobResponse TriggerRestore();
41+
Microsoft.Rest.Azure.AzureOperationResponse TriggerRestore();
4242

43-
ProtectedItemResponse GetProtectedItem();
43+
//ProtectedItemResponse GetProtectedItem();
44+
ProtectedItemResource GetProtectedItem();
4445

4546
CmdletModel.RecoveryPointBase GetRecoveryPointDetails();
4647

0 commit comments

Comments
 (0)