Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for retry policy update for failed items #11359

Merged
merged 2 commits into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public enum PolicyParams
RetentionPolicy,
ProtectionPolicy,
ResourceGroupName,
ResourceName
ResourceName,
FixForInconsistentItems
}

public enum ItemParams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,8 @@ private RestAzureNS.AzureOperationResponse<ProtectionPolicyResource> CreateorMod
ProviderData.ContainsKey(PolicyParams.ProtectionPolicy) ?
(PolicyBase)ProviderData[PolicyParams.ProtectionPolicy] :
null;
bool fixForInconsistentItems = ProviderData.ContainsKey(PolicyParams.FixForInconsistentItems) ?
(bool)ProviderData[PolicyParams.FixForInconsistentItems] : false;
ProtectionPolicyResource serviceClientRequest = new ProtectionPolicyResource();

if (policy != null)
Expand All @@ -494,44 +496,58 @@ private RestAzureNS.AzureOperationResponse<ProtectionPolicyResource> CreateorMod
// RetentionPolicy and SchedulePolicy both should not be empty
if (retentionPolicy == null && schedulePolicy == null)
{
throw new ArgumentException(Resources.BothRetentionAndSchedulePoliciesEmpty);
}

// validate RetentionPolicy and SchedulePolicy
if (schedulePolicy != null)
{
AzureWorkloadProviderHelper.ValidateSQLSchedulePolicy(schedulePolicy);
AzureWorkloadProviderHelper.GetUpdatedSchedulePolicy(policy, (SQLSchedulePolicy)schedulePolicy);
Logger.Instance.WriteDebug("Validation of Schedule policy is successful");
if (fixForInconsistentItems == false)
{
throw new ArgumentException(Resources.BothRetentionAndSchedulePoliciesEmpty);
}
AzureVmWorkloadProtectionPolicy azureVmWorkloadModifyPolicy = new AzureVmWorkloadProtectionPolicy();
azureVmWorkloadModifyPolicy.Settings = new Settings("UTC",
((AzureVmWorkloadPolicy)policy).IsCompression,
((AzureVmWorkloadPolicy)policy).IsCompression);
azureVmWorkloadModifyPolicy.WorkLoadType = ConversionUtils.GetServiceClientWorkloadType(policy.WorkloadType.ToString());
azureVmWorkloadModifyPolicy.SubProtectionPolicy = new List<SubProtectionPolicy>();
azureVmWorkloadModifyPolicy.SubProtectionPolicy = PolicyHelpers.GetServiceClientSubProtectionPolicy((AzureVmWorkloadPolicy)policy);
azureVmWorkloadModifyPolicy.MakePolicyConsistent = true;
serviceClientRequest.Properties = azureVmWorkloadModifyPolicy;
}
if (retentionPolicy != null)
else
{
AzureWorkloadProviderHelper.ValidateSQLRetentionPolicy(retentionPolicy);
AzureWorkloadProviderHelper.GetUpdatedRetentionPolicy(policy, (SQLRetentionPolicy)retentionPolicy);
Logger.Instance.WriteDebug("Validation of Retention policy is successful");
}

// copy the backupSchedule time to retentionPolicy after converting to UTC
AzureWorkloadProviderHelper.CopyScheduleTimeToRetentionTimes(
(CmdletModel.LongTermRetentionPolicy)((AzureVmWorkloadPolicy)policy).FullBackupRetentionPolicy,
(CmdletModel.SimpleSchedulePolicy)((AzureVmWorkloadPolicy)policy).FullBackupSchedulePolicy);
Logger.Instance.WriteDebug("Copy of RetentionTime from with SchedulePolicy to RetentionPolicy is successful");

// Now validate both RetentionPolicy and SchedulePolicy matches or not
PolicyHelpers.ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
(CmdletModel.LongTermRetentionPolicy)((AzureVmWorkloadPolicy)policy).FullBackupRetentionPolicy,
(CmdletModel.SimpleSchedulePolicy)((AzureVmWorkloadPolicy)policy).FullBackupSchedulePolicy);
Logger.Instance.WriteDebug("Validation of Retention policy with Schedule policy is successful");
// validate RetentionPolicy and SchedulePolicy
if (schedulePolicy != null)
{
AzureWorkloadProviderHelper.ValidateSQLSchedulePolicy(schedulePolicy);
AzureWorkloadProviderHelper.GetUpdatedSchedulePolicy(policy, (SQLSchedulePolicy)schedulePolicy);
Logger.Instance.WriteDebug("Validation of Schedule policy is successful");
}
if (retentionPolicy != null)
{
AzureWorkloadProviderHelper.ValidateSQLRetentionPolicy(retentionPolicy);
AzureWorkloadProviderHelper.GetUpdatedRetentionPolicy(policy, (SQLRetentionPolicy)retentionPolicy);
Logger.Instance.WriteDebug("Validation of Retention policy is successful");
}

// construct Service Client policy request
AzureVmWorkloadProtectionPolicy azureVmWorkloadProtectionPolicy = new AzureVmWorkloadProtectionPolicy();
azureVmWorkloadProtectionPolicy.Settings = new Settings("UTC",
((AzureVmWorkloadPolicy)policy).IsCompression,
((AzureVmWorkloadPolicy)policy).IsCompression);
azureVmWorkloadProtectionPolicy.WorkLoadType = ConversionUtils.GetServiceClientWorkloadType(policy.WorkloadType.ToString());
azureVmWorkloadProtectionPolicy.SubProtectionPolicy = new List<SubProtectionPolicy>();
azureVmWorkloadProtectionPolicy.SubProtectionPolicy = PolicyHelpers.GetServiceClientSubProtectionPolicy((AzureVmWorkloadPolicy)policy);
serviceClientRequest.Properties = azureVmWorkloadProtectionPolicy;
// copy the backupSchedule time to retentionPolicy after converting to UTC
AzureWorkloadProviderHelper.CopyScheduleTimeToRetentionTimes(
(CmdletModel.LongTermRetentionPolicy)((AzureVmWorkloadPolicy)policy).FullBackupRetentionPolicy,
(CmdletModel.SimpleSchedulePolicy)((AzureVmWorkloadPolicy)policy).FullBackupSchedulePolicy);
Logger.Instance.WriteDebug("Copy of RetentionTime from with SchedulePolicy to RetentionPolicy is successful");

// Now validate both RetentionPolicy and SchedulePolicy matches or not
PolicyHelpers.ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
(CmdletModel.LongTermRetentionPolicy)((AzureVmWorkloadPolicy)policy).FullBackupRetentionPolicy,
(CmdletModel.SimpleSchedulePolicy)((AzureVmWorkloadPolicy)policy).FullBackupSchedulePolicy);
Logger.Instance.WriteDebug("Validation of Retention policy with Schedule policy is successful");

// construct Service Client policy request
AzureVmWorkloadProtectionPolicy azureVmWorkloadProtectionPolicy = new AzureVmWorkloadProtectionPolicy();
azureVmWorkloadProtectionPolicy.Settings = new Settings("UTC",
((AzureVmWorkloadPolicy)policy).IsCompression,
((AzureVmWorkloadPolicy)policy).IsCompression);
azureVmWorkloadProtectionPolicy.WorkLoadType = ConversionUtils.GetServiceClientWorkloadType(policy.WorkloadType.ToString());
azureVmWorkloadProtectionPolicy.SubProtectionPolicy = new List<SubProtectionPolicy>();
azureVmWorkloadProtectionPolicy.SubProtectionPolicy = PolicyHelpers.GetServiceClientSubProtectionPolicy((AzureVmWorkloadPolicy)policy);
serviceClientRequest.Properties = azureVmWorkloadProtectionPolicy;
}
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ function Test-AzureVmWorkloadPolicy
Assert-AreEqual $schedulePolicy.IsDifferentialBackupEnabled $true
Assert-AreEqual $schedulePolicy.IsLogBackupEnabled $true

# Fix Policy Update for failed items
Set-AzRecoveryServicesBackupProtectionPolicy `
-VaultId $vault.ID `
-FixForInconsistentItems `
-Policy $policy

# Delete policy
Remove-AzRecoveryServicesBackupProtectionPolicy `
-VaultId $vault.ID `
Expand Down
Loading