From 79c9469b505dd6f8a0eb3acfa11cb9c6e3756e2a Mon Sep 17 00:00:00 2001 From: dragonfly91 Date: Thu, 28 Apr 2016 02:06:25 +0530 Subject: [PATCH 1/3] Fix Get Job by Id bug --- .../GetAzureRmRecoveryServicesBackupJob.cs | 89 ++++++++++--------- 1 file changed, 49 insertions(+), 40 deletions(-) diff --git a/src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup/Cmdlets/Jobs/GetAzureRmRecoveryServicesBackupJob.cs b/src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup/Cmdlets/Jobs/GetAzureRmRecoveryServicesBackupJob.cs index 18072d3eeaeb..ac277eac5ccf 100644 --- a/src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup/Cmdlets/Jobs/GetAzureRmRecoveryServicesBackupJob.cs +++ b/src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup/Cmdlets/Jobs/GetAzureRmRecoveryServicesBackupJob.cs @@ -24,7 +24,7 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets /// /// Get list of jobs /// - [Cmdlet(VerbsCommon.Get, "AzureRmRecoveryServicesBackupJob"), + [Cmdlet(VerbsCommon.Get, "AzureRmRecoveryServicesBackupJob"), OutputType(typeof(JobBase), typeof(IList))] public class GetAzureRmRecoveryServicesBackupJob : RecoveryServicesBackupCmdletBase { @@ -112,7 +112,7 @@ public override void ExecuteCmdlet() List result = new List(); - WriteDebug(string.Format("Filters provided are: StartTime - {0} " + + WriteDebug(string.Format("Filters provided are: StartTime - {0} " + "EndTime - {1} Status - {2} Operation - {3} Type - {4}", From, To, @@ -120,49 +120,58 @@ public override void ExecuteCmdlet() Operation, BackupManagementType)); - int resultCount = 0; - var adapterResponse = ServiceClientAdapter.GetJobs(JobId, - Status.HasValue ? Status.ToString() : null, - Operation.HasValue ? Operation.ToString() : null, - rangeStart, - rangeEnd, - BackupManagementType.HasValue ? - Helpers.JobConversions.GetJobTypeForService(BackupManagementType.Value) : null); - JobConversions.AddServiceClientJobsToPSList(adapterResponse, result, ref resultCount); - - while (!string.IsNullOrEmpty(adapterResponse.ItemList.NextLink)) + if (JobId == null) { - if (resultCount >= JobConstants.MaximumJobsToFetch) + int resultCount = 0; + var adapterResponse = ServiceClientAdapter.GetJobs(JobId, + Status.HasValue ? Status.ToString() : null, + Operation.HasValue ? Operation.ToString() : null, + rangeStart, + rangeEnd, + BackupManagementType.HasValue ? + Helpers.JobConversions.GetJobTypeForService(BackupManagementType.Value) : null); + + JobConversions.AddServiceClientJobsToPSList(adapterResponse, result, ref resultCount); + + while (!string.IsNullOrEmpty(adapterResponse.ItemList.NextLink)) { - // trace a warning that there are more jobs and user has to refine filters. - WriteWarning(Resources.JobRefineFilters); - break; + if (resultCount >= JobConstants.MaximumJobsToFetch) + { + // trace a warning that there are more jobs and user has to refine filters. + WriteWarning(Resources.JobRefineFilters); + break; + } + + string skipToken; + ServiceClientHelpers.GetSkipTokenFromNextLink( + adapterResponse.ItemList.NextLink, out skipToken); + if (skipToken != null) + { + adapterResponse = ServiceClientAdapter.GetJobs(JobId, + Status.HasValue ? Status.ToString() : null, + Operation.HasValue ? Operation.ToString() : null, + rangeStart, + rangeEnd, + BackupManagementType.HasValue ? + Helpers.JobConversions.GetJobTypeForService(BackupManagementType.Value) : null, + null, + skipToken); + JobConversions.AddServiceClientJobsToPSList(adapterResponse, result, ref resultCount); + } + else + { + break; + } } - string skipToken; - ServiceClientHelpers.GetSkipTokenFromNextLink( - adapterResponse.ItemList.NextLink, out skipToken); - if (skipToken != null) - { - adapterResponse = ServiceClientAdapter.GetJobs(JobId, - Status.HasValue ? Status.ToString() : null, - Operation.HasValue ? Operation.ToString() : null, - rangeStart, - rangeEnd, - BackupManagementType.HasValue ? - Helpers.JobConversions.GetJobTypeForService(BackupManagementType.Value) : null, - null, - skipToken); - JobConversions.AddServiceClientJobsToPSList(adapterResponse, result, ref resultCount); - } - else - { - break; - } + WriteDebug("Number of jobs fetched: " + result.Count); + WriteObject(result, enumerateCollection: true); + } + else + { + // When JobId is non null call GetJob instead of ListJobs + WriteObject(GetJobObject(JobId)); } - - WriteDebug("Number of jobs fetched: " + result.Count); - WriteObject(result, enumerateCollection: true); }); } } From 3b2e84cf0069316f469886318e8fa128e13db959 Mon Sep 17 00:00:00 2001 From: dragonfly91 Date: Fri, 6 May 2016 13:37:09 +0530 Subject: [PATCH 2/3] Traced number of weeks, months and years in the ToString() method of Retention Policy models --- .../CommonModels/PolicyRetentionObjects.cs | 80 +++++++++---------- 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/CommonModels/PolicyRetentionObjects.cs b/src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/CommonModels/PolicyRetentionObjects.cs index 82cd4e629402..66212a38c0f1 100644 --- a/src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/CommonModels/PolicyRetentionObjects.cs +++ b/src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/CommonModels/PolicyRetentionObjects.cs @@ -31,7 +31,7 @@ public class LongTermRetentionPolicy : RetentionPolicyBase public bool IsMonthlyScheduleEnabled { get; set; } public bool IsYearlyScheduleEnabled { get; set; } public DailyRetentionSchedule DailySchedule { get; set; } - public WeeklyRetentionSchedule WeeklySchedule { get; set; } + public WeeklyRetentionSchedule WeeklySchedule { get; set; } public MonthlyRetentionSchedule MonthlySchedule { get; set; } public YearlyRetentionSchedule YearlySchedule { get; set; } @@ -98,8 +98,8 @@ public override void Validate() { YearlySchedule.Validate(); } - } - } + } + } public override string ToString() { @@ -114,7 +114,7 @@ public override string ToString() YearlySchedule == null ? "NULL" : YearlySchedule.ToString()); } } - + /// /// Base class for retention schedule. /// @@ -127,15 +127,15 @@ public virtual void Validate() if (RetentionTimes == null || RetentionTimes.Count == 0 || RetentionTimes.Count != 1) { throw new ArgumentException(Resources.InvalidRetentionTimesInPolicyException); - } - } + } + } public override string ToString() { - return string.Format("RetentionTimes: {0}", TraceUtils.GetString(RetentionTimes)); + return string.Format("RetentionTimes: {0}", TraceUtils.GetString(RetentionTimes)); } } - + /// /// Daily rentention schedule. /// @@ -149,18 +149,17 @@ public override void Validate() if (DurationCountInDays <= 0 || DurationCountInDays > PolicyConstants.MaxAllowedRetentionDurationCount) { throw new ArgumentException(Resources.RetentionDurationCountInvalidException); - } + } base.Validate(); } - + public override string ToString() { - return string.Format("DurationCountInDays: {0}, {1}", - DurationCountInDays, base.ToString()); + return string.Format("DurationCountInDays: {0}, {1}", DurationCountInDays, base.ToString()); } } - + /// /// Weekly rentention schedule. /// @@ -183,16 +182,15 @@ public override void Validate() } base.Validate(); - } + } public override string ToString() { - return string.Format("DaysOfTheWeek: {0}, {1}", - TraceUtils.GetString(DaysOfTheWeek), - base.ToString()); + return string.Format("DurationCountInWeeks: {0}, DaysOfTheWeek: {1}, {2}", + DurationCountInWeeks, TraceUtils.GetString(DaysOfTheWeek), base.ToString()); } } - + /// /// Monthly rentention schedule. /// @@ -208,7 +206,7 @@ public class MonthlyRetentionSchedule : RetentionScheduleBase public MonthlyRetentionSchedule() : base() - { + { } public override void Validate() @@ -219,7 +217,7 @@ public override void Validate() { throw new ArgumentException(Resources.RetentionDurationCountInvalidException); } - + if (RetentionScheduleFormatType == RetentionScheduleFormat.Daily) { if (RetentionScheduleDaily == null) @@ -234,23 +232,24 @@ public override void Validate() { if (RetentionScheduleWeekly == null) { - throw new ArgumentException(Resources.MonthlyYearlyRetentionWeeklySchedulePolicyNULLException); + throw new ArgumentException(Resources.MonthlyYearlyRetentionWeeklySchedulePolicyNULLException); } RetentionScheduleWeekly.Validate(); } - } + } public override string ToString() { - return string.Format("RetentionScheduleType:{0}, {1}, RetentionScheduleDaily:{2}," + - "RetentionScheduleWeekly:{3}, {4}", RetentionScheduleFormatType, base.ToString(), + return string.Format("DurationCountInMonths:{0}, RetentionScheduleType:{1}, {2}, RetentionScheduleDaily:{3}," + + "RetentionScheduleWeekly:{4}, {5}", + DurationCountInMonths, RetentionScheduleFormatType, base.ToString(), RetentionScheduleDaily == null ? "NULL" : RetentionScheduleDaily.ToString(), RetentionScheduleWeekly == null ? "NULL" : RetentionScheduleWeekly.ToString(), base.ToString()); } } - + /// /// Yearly rentention schedule. /// @@ -261,13 +260,13 @@ public class YearlyRetentionSchedule : RetentionScheduleBase public List MonthsOfYear { get; set; } public DailyRetentionFormat RetentionScheduleDaily { get; set; } - + public WeeklyRetentionFormat RetentionScheduleWeekly { get; set; } public YearlyRetentionSchedule() : base() { - + } public override void Validate() @@ -278,12 +277,12 @@ public override void Validate() { throw new ArgumentException(Resources.RetentionDurationCountInvalidException); } - + if (MonthsOfYear == null || MonthsOfYear.Count == 0 || MonthsOfYear.Count != MonthsOfYear.Distinct().Count()) { throw new ArgumentException(Resources.YearlyScheduleMonthsOfYearException); } - + if (RetentionScheduleFormatType == RetentionScheduleFormat.Daily) { if (RetentionScheduleDaily == null) @@ -303,20 +302,19 @@ public override void Validate() RetentionScheduleWeekly.Validate(); } - } + } public override string ToString() { - return string.Format("RetentionScheduleType:{0}, {1}, RetentionScheduleDaily:{2}," + - "RetentionScheduleWeekly:{3}, MonthsOfYear: {4}, {5}", - RetentionScheduleFormatType.ToString(), - base.ToString(), + return string.Format("DurationCountInYears:{0}, RetentionScheduleType:{1}, {2}, RetentionScheduleDaily:{3}," + + "RetentionScheduleWeekly:{4}, MonthsOfYear: {5}, {6}", + DurationCountInYears, RetentionScheduleFormatType.ToString(), base.ToString(), RetentionScheduleDaily == null ? "NULL" : RetentionScheduleDaily.ToString(), RetentionScheduleWeekly == null ? "NULL" : RetentionScheduleWeekly.ToString(), TraceUtils.GetString(MonthsOfYear), base.ToString()); } } - + /// /// Daily rentention format. /// @@ -343,13 +341,13 @@ public void Validate() foreach (Day day in DaysOfTheMonth) { day.Validate(); - if(day.IsLast) + if (day.IsLast) { countOfIsLast++; } } - if(countOfIsLast > 1) + if (countOfIsLast > 1) { throw new ArgumentException(Resources.InvalidDayInDaysOfMonthOfMonthlyYearlyRetentionPolicyException); } @@ -360,7 +358,7 @@ public override string ToString() return string.Format("DaysOfTheMonth:{0}", TraceUtils.GetString(DaysOfTheMonth)); } } - + /// /// Weekly rentention format. /// @@ -376,13 +374,13 @@ public void Validate() DaysOfTheWeek.Count != DaysOfTheWeek.Distinct().Count()) { throw new ArgumentException(Resources.InvalidDaysOfWeekInMonthlyYearlyRetentionPolicyException); - } + } if (WeeksOfTheMonth == null || WeeksOfTheMonth.Count == 0 || WeeksOfTheMonth.Count != WeeksOfTheMonth.Distinct().Count()) { throw new ArgumentException(Resources.InvalidWeeksOfMonthInMonthlyYearlyRetentionPolicyException); - } + } } public override string ToString() @@ -419,5 +417,5 @@ public override string ToString() { return string.Format("Date:{0}, IsLast:{1}", Date, IsLast); } - } + } } From c4ae3ee52f400786a183f9ee88ed8c8e5b0099a4 Mon Sep 17 00:00:00 2001 From: dragonfly91 Date: Fri, 6 May 2016 14:46:43 +0530 Subject: [PATCH 3/3] Revert "Fix Get Job by Id bug" This reverts commit 79c9469b505dd6f8a0eb3acfa11cb9c6e3756e2a. --- .../GetAzureRmRecoveryServicesBackupJob.cs | 89 +++++++++---------- 1 file changed, 40 insertions(+), 49 deletions(-) diff --git a/src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup/Cmdlets/Jobs/GetAzureRmRecoveryServicesBackupJob.cs b/src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup/Cmdlets/Jobs/GetAzureRmRecoveryServicesBackupJob.cs index ac277eac5ccf..18072d3eeaeb 100644 --- a/src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup/Cmdlets/Jobs/GetAzureRmRecoveryServicesBackupJob.cs +++ b/src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup/Cmdlets/Jobs/GetAzureRmRecoveryServicesBackupJob.cs @@ -24,7 +24,7 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets /// /// Get list of jobs /// - [Cmdlet(VerbsCommon.Get, "AzureRmRecoveryServicesBackupJob"), + [Cmdlet(VerbsCommon.Get, "AzureRmRecoveryServicesBackupJob"), OutputType(typeof(JobBase), typeof(IList))] public class GetAzureRmRecoveryServicesBackupJob : RecoveryServicesBackupCmdletBase { @@ -112,7 +112,7 @@ public override void ExecuteCmdlet() List result = new List(); - WriteDebug(string.Format("Filters provided are: StartTime - {0} " + + WriteDebug(string.Format("Filters provided are: StartTime - {0} " + "EndTime - {1} Status - {2} Operation - {3} Type - {4}", From, To, @@ -120,58 +120,49 @@ public override void ExecuteCmdlet() Operation, BackupManagementType)); - if (JobId == null) + int resultCount = 0; + var adapterResponse = ServiceClientAdapter.GetJobs(JobId, + Status.HasValue ? Status.ToString() : null, + Operation.HasValue ? Operation.ToString() : null, + rangeStart, + rangeEnd, + BackupManagementType.HasValue ? + Helpers.JobConversions.GetJobTypeForService(BackupManagementType.Value) : null); + JobConversions.AddServiceClientJobsToPSList(adapterResponse, result, ref resultCount); + + while (!string.IsNullOrEmpty(adapterResponse.ItemList.NextLink)) { - int resultCount = 0; - var adapterResponse = ServiceClientAdapter.GetJobs(JobId, - Status.HasValue ? Status.ToString() : null, - Operation.HasValue ? Operation.ToString() : null, - rangeStart, - rangeEnd, - BackupManagementType.HasValue ? - Helpers.JobConversions.GetJobTypeForService(BackupManagementType.Value) : null); - - JobConversions.AddServiceClientJobsToPSList(adapterResponse, result, ref resultCount); - - while (!string.IsNullOrEmpty(adapterResponse.ItemList.NextLink)) + if (resultCount >= JobConstants.MaximumJobsToFetch) { - if (resultCount >= JobConstants.MaximumJobsToFetch) - { - // trace a warning that there are more jobs and user has to refine filters. - WriteWarning(Resources.JobRefineFilters); - break; - } - - string skipToken; - ServiceClientHelpers.GetSkipTokenFromNextLink( - adapterResponse.ItemList.NextLink, out skipToken); - if (skipToken != null) - { - adapterResponse = ServiceClientAdapter.GetJobs(JobId, - Status.HasValue ? Status.ToString() : null, - Operation.HasValue ? Operation.ToString() : null, - rangeStart, - rangeEnd, - BackupManagementType.HasValue ? - Helpers.JobConversions.GetJobTypeForService(BackupManagementType.Value) : null, - null, - skipToken); - JobConversions.AddServiceClientJobsToPSList(adapterResponse, result, ref resultCount); - } - else - { - break; - } + // trace a warning that there are more jobs and user has to refine filters. + WriteWarning(Resources.JobRefineFilters); + break; } - WriteDebug("Number of jobs fetched: " + result.Count); - WriteObject(result, enumerateCollection: true); - } - else - { - // When JobId is non null call GetJob instead of ListJobs - WriteObject(GetJobObject(JobId)); + string skipToken; + ServiceClientHelpers.GetSkipTokenFromNextLink( + adapterResponse.ItemList.NextLink, out skipToken); + if (skipToken != null) + { + adapterResponse = ServiceClientAdapter.GetJobs(JobId, + Status.HasValue ? Status.ToString() : null, + Operation.HasValue ? Operation.ToString() : null, + rangeStart, + rangeEnd, + BackupManagementType.HasValue ? + Helpers.JobConversions.GetJobTypeForService(BackupManagementType.Value) : null, + null, + skipToken); + JobConversions.AddServiceClientJobsToPSList(adapterResponse, result, ref resultCount); + } + else + { + break; + } } + + WriteDebug("Number of jobs fetched: " + result.Count); + WriteObject(result, enumerateCollection: true); }); } }