Skip to content

Commit 17d2ef9

Browse files
committed
Merge pull request #217 from MabOneSdk/dev1-sudreddy
Minor fixes in policy and added more traces
2 parents 62233cd + 5412aab commit 17d2ef9

File tree

13 files changed

+111
-46
lines changed

13 files changed

+111
-46
lines changed

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,31 @@ public class GetAzureRmRecoveryServicesProtectionPolicy : RecoveryServicesBackup
4444
[Parameter(ParameterSetName = WorkloadParamSet, Position = 2, Mandatory = true, HelpMessage = ParamHelpMsg.Common.WorkloadType)]
4545
[Parameter(ParameterSetName = WorkloadBackupMangementTypeParamSet, Position = 2, Mandatory = true, HelpMessage = ParamHelpMsg.Common.WorkloadType)]
4646
[ValidateNotNullOrEmpty]
47-
public WorkloadType WorkloadType { get; set; }
47+
public WorkloadType? WorkloadType { get; set; }
4848

4949
[Parameter(ParameterSetName = WorkloadBackupMangementTypeParamSet, Position = 3, Mandatory = true, HelpMessage = ParamHelpMsg.Common.BackupManagementType)]
5050
[ValidateNotNullOrEmpty]
51-
public BackupManagementType BackupManagementType { get; set; }
51+
public BackupManagementType? BackupManagementType { get; set; }
5252

5353
public override void ExecuteCmdlet()
5454
{
5555
ExecutionBlock(() =>
5656
{
5757
base.ExecuteCmdlet();
5858

59-
List<AzureRmRecoveryServicesPolicyBase> policyList = new List<AzureRmRecoveryServicesPolicyBase>();
59+
WriteDebug(string.Format("Input params - Name:{0}, " +
60+
"WorkloadType: {1}, BackupManagementType:{2}, " +
61+
"ParameterSetName: {3}",
62+
Name == null ? "NULL" : Name,
63+
WorkloadType.HasValue ? WorkloadType.ToString() : "NULL",
64+
BackupManagementType.HasValue ? BackupManagementType.ToString() : "NULL",
65+
this.ParameterSetName));
66+
6067

68+
List<AzureRmRecoveryServicesPolicyBase> policyList = new List<AzureRmRecoveryServicesPolicyBase>();
69+
6170
if (this.ParameterSetName == PolicyNameParamSet)
62-
{
71+
{
6372
// validate policyName
6473
PolicyCmdletHelpers.ValidateProtectionPolicyName(Name);
6574

@@ -82,7 +91,7 @@ public override void ExecuteCmdlet()
8291
case WorkloadParamSet:
8392
if (WorkloadType == Models.WorkloadType.AzureVM)
8493
{
85-
hydraProviderType = HydraHelpers.GetHydraProviderType(WorkloadType);
94+
hydraProviderType = HydraHelpers.GetHydraProviderType(Models.WorkloadType.AzureVM);
8695
}
8796
break;
8897

@@ -93,7 +102,7 @@ public override void ExecuteCmdlet()
93102
{
94103
throw new ArgumentException(Resources.AzureVMUnsupportedBackupManagementTypeException);
95104
}
96-
hydraProviderType = HydraHelpers.GetHydraProviderType(WorkloadType);
105+
hydraProviderType = HydraHelpers.GetHydraProviderType(Models.WorkloadType.AzureVM);
97106
}
98107
else
99108
{
@@ -116,19 +125,12 @@ public override void ExecuteCmdlet()
116125
{
117126
BackupManagementType = hydraProviderType
118127
};
128+
129+
WriteDebug("going to query service to get list of policies");
119130
HydraModel.ProtectionPolicyListResponse respList = HydraAdapter.ListProtectionPolicy(queryParams);
120-
if (respList != null && respList.ItemList != null &&
121-
respList.ItemList.Value != null && respList.ItemList.Value.Count != 0)
122-
{
123-
foreach (HydraModel.ProtectionPolicyResource policy in respList.ItemList.Value)
124-
{
125-
AzureRmRecoveryServicesPolicyBase psModel = ConversionHelpers.GetPolicyModel(policy);
126-
if (psModel != null)
127-
{
128-
policyList.Add(ConversionHelpers.GetPolicyModel(policy));
129-
}
130-
}
131-
}
131+
WriteDebug("Successfully got response from service");
132+
133+
policyList = ConversionHelpers.GetPolicyModelList(respList);
132134
}
133135

134136
WriteObject(policyList);

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ public override void ExecuteCmdlet()
5858
{
5959
base.ExecuteCmdlet();
6060

61+
WriteDebug(string.Format("Input params - Name:{0}, WorkloadType:{1}, " +
62+
"BackupManagementType: {2}, " +
63+
"RetentionPolicy:{3}, SchedulePolicy:{4}",
64+
Name, WorkloadType.ToString(),
65+
BackupManagementType.HasValue ? BackupManagementType.ToString() : "NULL",
66+
RetentionPolicy == null ? "NULL" : RetentionPolicy.ToString(),
67+
SchedulePolicy == null ? "NULL" : SchedulePolicy.ToString()));
68+
6169
// validate policy name
6270
PolicyCmdletHelpers.ValidateProtectionPolicyName(Name);
6371

@@ -79,10 +87,12 @@ public override void ExecuteCmdlet()
7987
IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(WorkloadType, BackupManagementType);
8088
psBackupProvider.CreatePolicy();
8189

90+
WriteDebug("Successfully created policy, now fetching it from service: " + Name);
91+
8292
// now get the created policy and return
8393
HydraModel.ProtectionPolicyResponse policy = PolicyCmdletHelpers.GetProtectionPolicyByName(
84-
Name,
85-
HydraAdapter);
94+
Name,
95+
HydraAdapter);
8696
// now convert hydraPolicy to PSObject
8797
WriteObject(ConversionHelpers.GetPolicyModel(policy.Item));
8898
});

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ public static ProtectionPolicyResponse GetProtectionPolicyByName(string policyNa
5151
ProtectionPolicyResponse response = null;
5252

5353
try
54-
{
54+
{
5555
response = hydraAdapter.GetProtectionPolicy(policyName);
56+
Logger.Instance.WriteDebug("Successfully fetched policy from service: " + policyName);
5657
}
5758
catch
5859
{

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

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ public override void ExecuteCmdlet()
5050
{
5151
base.ExecuteCmdlet();
5252

53+
WriteDebug(string.Format("Input params - Policy: {0}" +
54+
"RetentionPolicy:{1}, SchedulePolicy:{2}",
55+
Policy == null ? "NULL" : Policy.ToString(),
56+
RetentionPolicy == null ? "NULL" : RetentionPolicy.ToString(),
57+
SchedulePolicy == null ? "NULL" : SchedulePolicy.ToString()));
58+
5359
// Validate policy name
5460
PolicyCmdletHelpers.ValidateProtectionPolicyName(Policy.Name);
5561

@@ -71,26 +77,45 @@ public override void ExecuteCmdlet()
7177
IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(Policy.WorkloadType,
7278
Policy.BackupManagementType);
7379
ProtectionPolicyResponse policyResponse = psBackupProvider.ModifyPolicy();
80+
WriteDebug("ModifyPolicy http response from service: " + policyResponse.StatusCode.ToString());
7481

7582
if(policyResponse.StatusCode == System.Net.HttpStatusCode.Accepted)
7683
{
84+
WriteDebug("Tracking operation status URL for completion: " +
85+
policyResponse.AzureAsyncOperation);
86+
7787
// Track OperationStatus URL for operation completion
7888
BackUpOperationStatusResponse operationResponse = WaitForOperationCompletionUsingStatusLink(
7989
policyResponse.AzureAsyncOperation,
8090
HydraAdapter.GetProtectionPolicyOperationStatusByURL);
81-
82-
if(operationResponse.OperationStatus.Status == OperationStatusValues.Failed.ToString())
91+
92+
WriteDebug("Final operation status: " + operationResponse.OperationStatus.Status);
93+
94+
if (operationResponse.OperationStatus.Properties != null &&
95+
((OperationStatusJobsExtendedInfo)operationResponse.OperationStatus.Properties).JobIds != null)
8396
{
84-
// if operation failed, then trace warning/error
97+
// get list of jobIds and return jobResponses
98+
WriteObject(GetJobObject(((OperationStatusJobsExtendedInfo)operationResponse.OperationStatus.Properties).JobIds));
8599
}
86100

87-
// get list of jobIds and return jobResponses
88-
WriteObject(GetJobObject(((OperationStatusJobsExtendedInfo)operationResponse.OperationStatus.Properties).JobIds));
101+
if (operationResponse.OperationStatus.Status == OperationStatusValues.Failed.ToString())
102+
{
103+
// if operation failed, then trace error and throw exception
104+
if (operationResponse.OperationStatus.OperationStatusError != null)
105+
{
106+
WriteDebug(string.Format(
107+
"OperationStatus Error: {0} " +
108+
"OperationStatus Code: {1}",
109+
operationResponse.OperationStatus.OperationStatusError.Message,
110+
operationResponse.OperationStatus.OperationStatusError.Code));
111+
}
112+
}
89113
}
90114
else
91115
{
92116
// Hydra will return OK if NO datasources are associated with this policy
93-
// just trace and return
117+
WriteDebug("No datasources are associated with Policy, http response code: " +
118+
policyResponse.StatusCode.ToString());
94119
}
95120
});
96121
}

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public static AzureRmRecoveryServicesPolicyBase GetPolicyModel(ProtectionPolicyR
6363

6464
if(hydraResponse == null || hydraResponse.Properties == null)
6565
{
66+
Logger.Instance.WriteDebug("Policy Hydra response is Null/Empty");
6667
throw new ArgumentException(Resources.EmptyHydraResponseException);
6768
}
6869

@@ -71,15 +72,17 @@ public static AzureRmRecoveryServicesPolicyBase GetPolicyModel(ProtectionPolicyR
7172
if(((AzureIaaSVMProtectionPolicy)hydraResponse.Properties).RetentionPolicy.GetType() !=
7273
typeof(LongTermRetentionPolicy))
7374
{
74-
Logger.Instance.WriteDebug(Resources.UpdateToNewAzurePowershellWarning);
75+
Logger.Instance.WriteDebug("Unknown RetentionPolicy object received: " +
76+
((AzureIaaSVMProtectionPolicy)hydraResponse.Properties).RetentionPolicy.GetType());
7577
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
7678
return null;
7779
}
7880

7981
if (((AzureIaaSVMProtectionPolicy)hydraResponse.Properties).SchedulePolicy.GetType() !=
8082
typeof(SimpleSchedulePolicy))
8183
{
82-
Logger.Instance.WriteDebug(Resources.UpdateToNewAzurePowershellWarning);
84+
Logger.Instance.WriteDebug("Unknown SchedulePolicy object received: " +
85+
((AzureIaaSVMProtectionPolicy)hydraResponse.Properties).SchedulePolicy.GetType());
8386
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
8487
return null;
8588
}
@@ -94,11 +97,11 @@ public static AzureRmRecoveryServicesPolicyBase GetPolicyModel(ProtectionPolicyR
9497
((AzureIaaSVMProtectionPolicy)hydraResponse.Properties).SchedulePolicy);
9598
}
9699
else
97-
{
98-
// trace warning message, ignore and return
100+
{
99101
// we will enter this case when service supports new workload and customer
100-
// still using old version of azure powershell
101-
Logger.Instance.WriteDebug(Resources.UpdateToNewAzurePowershellWarning);
102+
// still using old version of azure powershell. Trace warning message, ignore and return
103+
Logger.Instance.WriteDebug("Unknown Policy object received: " +
104+
hydraResponse.Properties.GetType());
102105
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
103106
return null;
104107
}
@@ -108,11 +111,13 @@ public static AzureRmRecoveryServicesPolicyBase GetPolicyModel(ProtectionPolicyR
108111
return policyModel;
109112
}
110113

111-
public static List<AzureRmRecoveryServicesPolicyBase> GetPolicyModelList(ProtectionPolicyListResponse hydraListResponse)
114+
public static List<AzureRmRecoveryServicesPolicyBase> GetPolicyModelList(
115+
ProtectionPolicyListResponse hydraListResponse)
112116
{
113117
if(hydraListResponse == null || hydraListResponse.ItemList == null ||
114118
hydraListResponse.ItemList.Value == null || hydraListResponse.ItemList.Value.Count == 0)
115119
{
120+
Logger.Instance.WriteDebug("Received empty list of policies from service");
116121
return null;
117122
}
118123

@@ -128,6 +133,7 @@ public static List<AzureRmRecoveryServicesPolicyBase> GetPolicyModelList(Protect
128133
}
129134
}
130135

136+
Logger.Instance.WriteDebug("Total policies in list: " + policyModels.Count);
131137
return policyModels;
132138
}
133139

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/BaseObjects.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,23 @@ public class AzureRmRecoveryServicesPolicyBase : AzureRmRecoveryServicesBackupMa
151151

152152
public override void Validate()
153153
{
154+
base.Validate();
154155
}
155156
}
156157

157158
public class AzureRmRecoveryServicesRetentionPolicyBase : AzureRmRecoveryServicesObjectBase
158159
{
159160
public override void Validate()
160161
{
162+
base.Validate();
161163
}
162164
}
163165

164166
public class AzureRmRecoveryServicesSchedulePolicyBase : AzureRmRecoveryServicesObjectBase
165167
{
166168
public override void Validate()
167169
{
170+
base.Validate();
168171
}
169172
}
170173

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/CommonModels/PolicyRetentionObjects.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ public AzureRmRecoveryServicesLongTermRetentionPolicy()
4040
IsYearlyScheduleEnabled = false;
4141
}
4242
public override void Validate()
43-
{
43+
{
44+
base.Validate();
45+
4446
if (IsDailyScheduleEnabled == false && IsWeeklyScheduleEnabled == false &&
4547
IsMonthlyScheduleEnabled == false && IsYearlyScheduleEnabled == false)
4648
{

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/CommonModels/PolicyScheduleObjects.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public override void Validate()
4141
throw new ArgumentException(Resources.InvalidScheduleTimeInScheduleException);
4242
}
4343

44+
if(ScheduleRunTimes[0].Kind != DateTimeKind.Utc)
45+
{
46+
throw new ArgumentException(Resources.ScheduleTimeNotInUTCTimeZoneException);
47+
}
48+
4449
if (ScheduleRunFrequency == ScheduleRunType.Weekly)
4550
{
4651
if (ScheduleRunDays == null || ScheduleRunDays.Count == 0 ||

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

Lines changed: 9 additions & 0 deletions
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@
269269
</data>
270270
<data name="JobCouldNotCancelJob" xml:space="preserve">
271271
<value>Failed to cancel the job. Error code: {0}</value>
272-
<comment> </comment>
273272
</data>
274273
<data name="JobJobIdAndJobMismatch" xml:space="preserve">
275274
<value>JobID and Job object provided don't match each other.</value>
@@ -286,4 +285,7 @@
286285
<data name="JobWaitJobInvalidInput" xml:space="preserve">
287286
<value>Please pass Job or List of Jobs as input. Your input is of type: {0}</value>
288287
</data>
288+
<data name="ScheduleTimeNotInUTCTimeZoneException" xml:space="preserve">
289+
<value>ScheduleRunTimes in Schedule Policy should be in UTC Timezone</value>
290+
</data>
289291
</root>

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,10 @@ public ProtectionPolicyResponse CreatePolicy()
209209
CopyScheduleTimeToRetentionTimes((AzureRmRecoveryServicesLongTermRetentionPolicy)retentionPolicy,
210210
(AzureRmRecoveryServicesSimpleSchedulePolicy)schedulePolicy);
211211

212-
// validate both RetentionPolicy and SchedulePolicy
213-
ValidateAzureVMRetentionPolicy(retentionPolicy);
214-
ValidateAzureVMSchedulePolicy(schedulePolicy);
212+
// validate RetentionPolicy
213+
ValidateAzureVMRetentionPolicy(retentionPolicy);
215214

216-
// Now validate both RetentionPolicy and SchedulePolicy matches or not
215+
// Now validate both RetentionPolicy and SchedulePolicy together
217216
PolicyHelpers.ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
218217
(AzureRmRecoveryServicesLongTermRetentionPolicy)retentionPolicy,
219218
(AzureRmRecoveryServicesSimpleSchedulePolicy)schedulePolicy);
@@ -696,9 +695,7 @@ private HttpStatusCode TrackRefreshContainerOperation(string operationResultLink
696695
private void CopyScheduleTimeToRetentionTimes(AzureRmRecoveryServicesLongTermRetentionPolicy retPolicy,
697696
AzureRmRecoveryServicesSimpleSchedulePolicy schPolicy)
698697
{
699-
// first convert schedule run times to UTC
700-
schPolicy.ScheduleRunTimes = PolicyHelpers.ParseScheduleRunTimesToUTC(schPolicy.ScheduleRunTimes);
701-
698+
// schedule runTimes is already validated if in UTC/not during validate()
702699
// now copy times from schedule to retention policy
703700
if (retPolicy.IsDailyScheduleEnabled && retPolicy.DailySchedule != null)
704701
{

0 commit comments

Comments
 (0)