Skip to content

Commit edc6dde

Browse files
committed
Minor fixes in policy
1 parent 818d39c commit edc6dde

File tree

5 files changed

+58
-16
lines changed

5 files changed

+58
-16
lines changed

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: 12 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

src/ResourceManager/RecoveryServices.Backup/RecoveryServicesBackupCmdletBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public BackUpOperationStatusResponse WaitForOperationCompletionUsingStatusLink(
153153

154154
while (response.OperationStatus.Status == OperationStatusValues.InProgress.ToString())
155155
{
156+
WriteDebug("Tracking operation completion using status link: " + statusUrlLink);
156157
Thread.Sleep(_defaultSleepForOperationTracking * 1000);
157158
response = hydraFunc(statusUrlLink);
158159
}

0 commit comments

Comments
 (0)