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

[Az.RecoveryServices.Backup] Customer Managed Key Encryption for recovery services vault #13593

Merged
merged 2 commits into from
Dec 24, 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 @@ -54,7 +54,11 @@ public static CmdletModel.JobBase GetPSJob(JobResource serviceClientJob)
else if (serviceClientJob.Properties.GetType() == typeof(MabJob))
{
response = GetPSMabJob(serviceClientJob);
}
}
else if (serviceClientJob.Properties.GetType() == typeof(VaultJob))
{
response = GetPSAzureVaultJob(serviceClientJob);
}

return response;
}
Expand Down Expand Up @@ -86,80 +90,86 @@ public static void AddServiceClientJobsToPSList(
}
}

#region AzureVm job private helpers
#endregion

#region Vault job private helpers


/// <summary>
/// Helper function to convert ps azure vm backup policy job from service response.
/// </summary>
private static CmdletModel.AzureVmJob GetPSAzureVmJob(JobResource serviceClientJob)
private static CmdletModel.VaultJob GetPSAzureVaultJob(JobResource serviceClientJob)
{
CmdletModel.AzureVmJob response;
CmdletModel.VaultJob response;

AzureIaaSVMJob vmJob = serviceClientJob.Properties as AzureIaaSVMJob;
VaultJob vaultJob = serviceClientJob.Properties as VaultJob;

if (vmJob.ExtendedInfo != null)
if (vaultJob.ExtendedInfo != null)
{
response = new CmdletModel.AzureVmJobDetails();
response = new CmdletModel.VaultJobDetails();
}
else
{
response = new CmdletModel.AzureVmJob();
response = new CmdletModel.VaultJob();
}

response.JobId = GetLastIdFromFullId(serviceClientJob.Id);
response.StartTime = GetJobStartTime(vmJob.StartTime);
response.EndTime = vmJob.EndTime;
response.Duration = GetJobDuration(vmJob.Duration);
response.Status = vmJob.Status;
response.VmVersion = vmJob.VirtualMachineVersion;
response.WorkloadName = vmJob.EntityFriendlyName;
response.ActivityId = vmJob.ActivityId;
response.BackupManagementType =
CmdletModel.ConversionUtils.GetPsBackupManagementType(vmJob.BackupManagementType);
response.Operation = vmJob.Operation;

if (vmJob.ErrorDetails != null)
response.StartTime = GetJobStartTime(vaultJob.StartTime);
response.EndTime = vaultJob.EndTime;
response.Duration = GetJobDuration(vaultJob.Duration);
response.Status = vaultJob.Status;
response.WorkloadName = vaultJob.EntityFriendlyName;
response.ActivityId = vaultJob.ActivityId;
response.BackupManagementType = CmdletModel.ConversionUtils.GetPsBackupManagementType(vaultJob.BackupManagementType);
response.Operation = vaultJob.Operation;

if (vaultJob.ErrorDetails != null)
{
response.ErrorDetails = new List<CmdletModel.AzureJobErrorInfo>();
foreach (var vmError in vmJob.ErrorDetails)
foreach (var vaultError in vaultJob.ErrorDetails)
{
response.ErrorDetails.Add(GetPSAzureVmErrorInfo(vmError));
response.ErrorDetails.Add(GetPSVaultErrorInfo(vaultError));
}
}

// fill extended info if present
if (vmJob.ExtendedInfo != null)
if (vaultJob.ExtendedInfo != null)
{
CmdletModel.AzureVmJobDetails detailedResponse =
response as CmdletModel.AzureVmJobDetails;
CmdletModel.VaultJobDetails detailedResponse =
response as CmdletModel.VaultJobDetails;

detailedResponse.DynamicErrorMessage = vmJob.ExtendedInfo.DynamicErrorMessage;
if (vmJob.ExtendedInfo.PropertyBag != null)
if (vaultJob.ExtendedInfo.PropertyBag != null)
{
detailedResponse.Properties = new Dictionary<string, string>();
foreach (var key in vmJob.ExtendedInfo.PropertyBag.Keys)
foreach (var key in vaultJob.ExtendedInfo.PropertyBag.Keys)
{
detailedResponse.Properties.Add(key, vmJob.ExtendedInfo.PropertyBag[key]);
}
}

if (vmJob.ExtendedInfo.TasksList != null)
{
detailedResponse.SubTasks = new List<CmdletModel.AzureVmJobSubTask>();
foreach (var vmJobTask in vmJob.ExtendedInfo.TasksList)
{
detailedResponse.SubTasks.Add(new CmdletModel.AzureVmJobSubTask()
{
Name = vmJobTask.TaskId,
Status = vmJobTask.Status
});
detailedResponse.Properties.Add(key, vaultJob.ExtendedInfo.PropertyBag[key]);
}
}
}
}

return response;
}


private static CmdletModel.AzureJobErrorInfo GetPSVaultErrorInfo(VaultJobErrorInfo vaultError)
{
CmdletModel.VaultJobErrorInfo psErrorInfo = new CmdletModel.VaultJobErrorInfo();
psErrorInfo.ErrorCode = GetJobErrorCode(vaultError.ErrorCode);
psErrorInfo.ErrorMessage = vaultError.ErrorString;
if (vaultError.Recommendations != null)
{
psErrorInfo.Recommendations = new List<string>();
psErrorInfo.Recommendations.AddRange(vaultError.Recommendations);
}

return psErrorInfo;
}


#endregion

#region MAB job private helpers

/// <summary>
/// Creates the powershell MabJob object from service response.
/// </summary>
Expand All @@ -177,7 +187,7 @@ private static CmdletModel.JobBase GetPSMabJob(JobResource serviceClientJob)
{
response = new CmdletModel.MabJob();
}

// Transfer values from service job object to powershell job object.
response.JobId = GetLastIdFromFullId(serviceClientJob.Id);
response.StartTime = GetJobStartTime(mabJob.StartTime);
Expand Down Expand Up @@ -231,6 +241,7 @@ private static CmdletModel.JobBase GetPSMabJob(JobResource serviceClientJob)
return response;
}


private static CmdletModel.AzureJobErrorInfo GetPSMabErrorInfo(MabErrorInfo mabError)
{
CmdletModel.MabJobErrorInfo psErrorInfo = new CmdletModel.MabJobErrorInfo();
Expand All @@ -244,6 +255,10 @@ private static CmdletModel.AzureJobErrorInfo GetPSMabErrorInfo(MabErrorInfo mabE
return psErrorInfo;
}

#endregion

#region AFS job private helpers

private static CmdletModel.JobBase GetPSAzureFileShareJob(JobResource serviceClientJob)
{
CmdletModel.AzureFileShareJob response;
Expand Down Expand Up @@ -326,6 +341,10 @@ private static CmdletModel.AzureJobErrorInfo GetPSAzureFileShareErrorInfo(AzureS
return psErrorInfo;
}

#endregion

#region Workload job private helpers

private static CmdletModel.JobBase GetPSAzureWorkloadJob(JobResource serviceClientJob)
{
CmdletModel.AzureVmWorkloadJob response;
Expand Down Expand Up @@ -408,26 +427,80 @@ private static CmdletModel.AzureJobErrorInfo GetPSAzureWorkloadErrorInfo(AzureWo
return psErrorInfo;
}

private static int GetJobErrorCode(int? errorCode)
{
return errorCode ?? default(int);
}
#endregion

private static TimeSpan GetJobDuration(TimeSpan? duration)
{
return duration.HasValue ? (TimeSpan)duration : default(TimeSpan);
}
#region AzureVm job private helpers

private static DateTime GetJobStartTime(DateTime? startTime)
/// <summary>
/// Helper function to convert ps azure vm backup policy job from service response.
/// </summary>
private static CmdletModel.AzureVmJob GetPSAzureVmJob(JobResource serviceClientJob)
{
if (startTime.HasValue)
CmdletModel.AzureVmJob response;

AzureIaaSVMJob vmJob = serviceClientJob.Properties as AzureIaaSVMJob;

if (vmJob.ExtendedInfo != null)
{
return (DateTime)startTime;
response = new CmdletModel.AzureVmJobDetails();
}
else
{
throw new ArgumentNullException("Job Start Time is null");
response = new CmdletModel.AzureVmJob();
}

response.JobId = GetLastIdFromFullId(serviceClientJob.Id);
response.StartTime = GetJobStartTime(vmJob.StartTime);
response.EndTime = vmJob.EndTime;
response.Duration = GetJobDuration(vmJob.Duration);
response.Status = vmJob.Status;
response.VmVersion = vmJob.VirtualMachineVersion;
response.WorkloadName = vmJob.EntityFriendlyName;
response.ActivityId = vmJob.ActivityId;
response.BackupManagementType =
CmdletModel.ConversionUtils.GetPsBackupManagementType(vmJob.BackupManagementType);
response.Operation = vmJob.Operation;

if (vmJob.ErrorDetails != null)
{
response.ErrorDetails = new List<CmdletModel.AzureJobErrorInfo>();
foreach (var vmError in vmJob.ErrorDetails)
{
response.ErrorDetails.Add(GetPSAzureVmErrorInfo(vmError));
}
}

// fill extended info if present
if (vmJob.ExtendedInfo != null)
{
CmdletModel.AzureVmJobDetails detailedResponse =
response as CmdletModel.AzureVmJobDetails;

detailedResponse.DynamicErrorMessage = vmJob.ExtendedInfo.DynamicErrorMessage;
if (vmJob.ExtendedInfo.PropertyBag != null)
{
detailedResponse.Properties = new Dictionary<string, string>();
foreach (var key in vmJob.ExtendedInfo.PropertyBag.Keys)
{
detailedResponse.Properties.Add(key, vmJob.ExtendedInfo.PropertyBag[key]);
}
}

if (vmJob.ExtendedInfo.TasksList != null)
{
detailedResponse.SubTasks = new List<CmdletModel.AzureVmJobSubTask>();
foreach (var vmJobTask in vmJob.ExtendedInfo.TasksList)
{
detailedResponse.SubTasks.Add(new CmdletModel.AzureVmJobSubTask()
{
Name = vmJobTask.TaskId,
Status = vmJobTask.Status
});
}
}
}

return response;
}

/// <summary>
Expand All @@ -443,6 +516,32 @@ private static CmdletModel.AzureVmJobErrorInfo GetPSAzureVmErrorInfo(AzureIaaSVM
return psErrorInfo;
}

#endregion

#region generic helpers

private static int GetJobErrorCode(int? errorCode)
{
return errorCode ?? default(int);
}

private static TimeSpan GetJobDuration(TimeSpan? duration)
{
return duration.HasValue ? (TimeSpan)duration : default(TimeSpan);
}

private static DateTime GetJobStartTime(DateTime? startTime)
{
if (startTime.HasValue)
{
return (DateTime)startTime;
}
else
{
throw new ArgumentNullException("Job Start Time is null");
}
}

private static List<string> GetJobErrorRecommendations(IList<string> recommendations)
{
if (recommendations != null)
Expand All @@ -465,7 +564,6 @@ public static string GetLastIdFromFullId(string fullId)
}

#endregion

#endregion

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.2-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.3-preview" />
<PackageReference Include="TimeZoneConverter" Version="3.0.0" />
</ItemGroup>

Expand Down
Loading