Skip to content

Commit

Permalink
Revert "Merge pull request Azure#8499 from Azure/revert-8349-mercury_…
Browse files Browse the repository at this point in the history
…dev_test"

This reverts commit e766f60, reversing
changes made to 8c3b2d1.
  • Loading branch information
siddharth7 committed Feb 14, 2019
1 parent 48cd964 commit 00f2c6f
Show file tree
Hide file tree
Showing 90 changed files with 1,391,239 additions and 327 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
using System;
using System.Collections.Generic;
using ServiceClientModel = Microsoft.Azure.Management.RecoveryServices.Backup.Models;

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers
Expand Down Expand Up @@ -55,6 +55,11 @@ public static ContainerBase GetContainerModel(ServiceClientModel.ProtectionConta
{
containerModel = new AzureFileShareContainer(protectionContainer);
}
else if (protectionContainer.Properties.GetType() ==
typeof(ServiceClientModel.AzureVMAppContainerProtectionContainer))
{
containerModel = new AzureVmWorkloadContainer(protectionContainer);
}
}

return containerModel;
Expand Down Expand Up @@ -190,7 +195,7 @@ public static PolicyBase GetPolicyModelForAzureSql(ServiceClientModel.Protection
ServiceClientModel.SimpleRetentionPolicy azureSqlRetentionPolicy =
(ServiceClientModel.SimpleRetentionPolicy)azureSqlPolicy.RetentionPolicy;
sqlPolicyModel.RetentionPolicy =
PolicyHelpers.GetPSSimpleRetentionPolicy(azureSqlRetentionPolicy, null);
PolicyHelpers.GetPSSimpleRetentionPolicy(azureSqlRetentionPolicy, null, "AzureSql");
return policyModel;
}

Expand Down Expand Up @@ -236,6 +241,86 @@ public static PolicyBase GetPolicyModelForAzureFileShare(ServiceClientModel.Prot
return policyModel;
}

public static PolicyBase GetPolicyModelForAzureVmWorkload(ServiceClientModel.ProtectionPolicyResource serviceClientResponse,
PolicyBase policyModel)
{
ServiceClientModel.AzureVmWorkloadProtectionPolicy azureVmWorkloadPolicy =
(ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties;

foreach (var policy in azureVmWorkloadPolicy.SubProtectionPolicy)
{
if (string.Compare(policy.PolicyType, "Full") == 0)
{
if (policy.SchedulePolicy.GetType() !=
typeof(ServiceClientModel.SimpleSchedulePolicy))
{
Logger.Instance.WriteDebug("Unknown Schedule object received: " +
policy.SchedulePolicy.GetType());
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
return null;
}
if (policy.RetentionPolicy.GetType() !=
typeof(ServiceClientModel.LongTermRetentionPolicy))
{
Logger.Instance.WriteDebug("Unknown RetentionPolicy object received: " +
policy.RetentionPolicy.GetType());
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
return null;
}
}
else if (string.Compare(policy.PolicyType, "Differential") == 0)
{
if (policy.SchedulePolicy.GetType() !=
typeof(ServiceClientModel.SimpleSchedulePolicy))
{
Logger.Instance.WriteDebug("Unknown Schedule object received: " +
policy.SchedulePolicy.GetType());
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
return null;
}
if (policy.RetentionPolicy.GetType() !=
typeof(ServiceClientModel.SimpleRetentionPolicy))
{
Logger.Instance.WriteDebug("Unknown RetentionPolicy object received: " +
policy.RetentionPolicy.GetType());
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
return null;
}
}
else if (string.Compare(policy.PolicyType, "Log") == 0)
{
if (policy.SchedulePolicy.GetType() !=
typeof(ServiceClientModel.LogSchedulePolicy))
{
Logger.Instance.WriteDebug("Unknown Schedule object received: " +
policy.SchedulePolicy.GetType());
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
return null;
}
if (policy.RetentionPolicy.GetType() !=
typeof(ServiceClientModel.SimpleRetentionPolicy))
{
Logger.Instance.WriteDebug("Unknown RetentionPolicy object received: " +
policy.RetentionPolicy.GetType());
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
return null;
}
}
}

policyModel = new AzureVmWorkloadPolicy();
AzureVmWorkloadPolicy azureVmWorkloadPolicyModel = policyModel as AzureVmWorkloadPolicy;
azureVmWorkloadPolicyModel.WorkloadType = WorkloadType.MSSQL;
azureVmWorkloadPolicyModel.BackupManagementType = BackupManagementType.AzureWorkload;
azureVmWorkloadPolicyModel.IsCompression =
((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties).Settings.IsCompression;
azureVmWorkloadPolicyModel.IsDifferentialBackupEnabled = false;
azureVmWorkloadPolicyModel.IsLogBackupEnabled = false;
GetPSSubProtectionPolicy(azureVmWorkloadPolicyModel, serviceClientResponse,
((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties).Settings.TimeZone);
return policyModel;
}

/// <summary>
/// Helper function to convert ps backup policy model from service response.
/// </summary>
Expand Down Expand Up @@ -263,6 +348,11 @@ public static PolicyBase GetPolicyModel(ServiceClientModel.ProtectionPolicyResou
{
policyModel = GetPolicyModelForAzureFileShare(serviceClientResponse, policyModel);
}
else if (serviceClientResponse.Properties.GetType() ==
typeof(ServiceClientModel.AzureVmWorkloadProtectionPolicy))
{
policyModel = GetPolicyModelForAzureVmWorkload(serviceClientResponse, policyModel);
}
else
{
// we will enter this case when service supports new workload and customer
Expand Down Expand Up @@ -338,8 +428,38 @@ public static ItemBase GetItemModel(ServiceClientModel.ProtectedItemResource pro
{
itemModel = GetAzureFileShareItemModel(protectedItem);
}

if (protectedItem.Properties.GetType() ==
typeof(ServiceClientModel.AzureVmWorkloadSQLDatabaseProtectedItem))
{
itemModel = GetAzureVmWorkloadItemModel(protectedItem);
}
}

return itemModel;
}

private static ItemBase GetAzureVmWorkloadItemModel(ServiceClientModel.ProtectedItemResource protectedItem)
{
ItemBase itemModel;
string policyName = null;
string policyId = ((ServiceClientModel.AzureVmWorkloadSQLDatabaseProtectedItem)protectedItem.Properties).PolicyId;
if (!string.IsNullOrEmpty(policyId))
{
Dictionary<UriEnums, string> keyValueDict =
HelperUtils.ParseUri(policyId);
policyName = HelperUtils.GetPolicyNameFromPolicyId(keyValueDict, policyId);
}

string containerUri = HelperUtils.GetContainerUri(
HelperUtils.ParseUri(protectedItem.Id),
protectedItem.Id);

itemModel = new AzureWorkloadSQLDatabaseProtectedItem(
protectedItem,
containerUri,
ContainerType.AzureVMAppContainer,
policyName);
return itemModel;
}

Expand Down Expand Up @@ -418,7 +538,42 @@ private static ItemBase GetAzureVmItemModel(ServiceClientModel.ProtectedItemReso
}

/// <summary>
/// Helper function to convert ps backup policy item list from service response.
/// Helper function to convert ps protectable item from service response.
/// </summary>
public static ProtectableItemBase GetProtectableItemModel(ServiceClientModel.WorkloadProtectableItemResource protectableItem)
{
ProtectableItemBase itemModel = null;

if (protectableItem != null &&
protectableItem.Properties != null)
{
if (protectableItem.Properties.GetType().IsSubclassOf(typeof(ServiceClientModel.AzureVmWorkloadProtectableItem)))
{
itemModel = GetAzureWorkloadProtectableItemModel(protectableItem);
}
}

return itemModel;
}

private static ProtectableItemBase GetAzureWorkloadProtectableItemModel(ServiceClientModel.WorkloadProtectableItemResource protectableItem)
{
ProtectableItemBase itemModel;

string containerUri = HelperUtils.GetContainerUri(
HelperUtils.ParseUri(protectableItem.Id),
protectableItem.Id);

itemModel = new AzureWorkloadProtectableItem(
protectableItem,
containerUri,
ContainerType.AzureVMAppContainer);

return itemModel;
}

/// <summary>
/// Helper function to convert ps item list from service response.
/// </summary>
public static List<ItemBase> GetItemModelList(IEnumerable<ServiceClientModel.ProtectedItemResource> protectedItems)
{
Expand All @@ -431,6 +586,60 @@ public static List<ItemBase> GetItemModelList(IEnumerable<ServiceClientModel.Pro

return itemModels;
}

public static void GetPSSubProtectionPolicy(AzureVmWorkloadPolicy azureVmWorkloadPolicyModel,
ServiceClientModel.ProtectionPolicyResource serviceClientResponse, string timeZone)
{
foreach (var subProtectionPolicy in
((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties).SubProtectionPolicy)
{
if (string.Compare(subProtectionPolicy.PolicyType, "Full") == 0)
{
azureVmWorkloadPolicyModel.FullBackupSchedulePolicy = PolicyHelpers.GetPSSimpleSchedulePolicy(
(ServiceClientModel.SimpleSchedulePolicy)subProtectionPolicy.SchedulePolicy,
((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties).Settings.TimeZone);

azureVmWorkloadPolicyModel.FullBackupRetentionPolicy = PolicyHelpers.GetPSLongTermRetentionPolicy(
(ServiceClientModel.LongTermRetentionPolicy)subProtectionPolicy.RetentionPolicy,
((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties).Settings.TimeZone);
}
else if (string.Compare(subProtectionPolicy.PolicyType, "Differential") == 0)
{
azureVmWorkloadPolicyModel.DifferentialBackupSchedulePolicy = PolicyHelpers.GetPSSimpleSchedulePolicy(
(ServiceClientModel.SimpleSchedulePolicy)subProtectionPolicy.SchedulePolicy,
((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties).Settings.TimeZone);
azureVmWorkloadPolicyModel.DifferentialBackupRetentionPolicy = PolicyHelpers.GetPSSimpleRetentionPolicy(
(ServiceClientModel.SimpleRetentionPolicy)subProtectionPolicy.RetentionPolicy,
((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties).Settings.TimeZone, "AzureWorkload");
azureVmWorkloadPolicyModel.IsDifferentialBackupEnabled = true;
}
else if (string.Compare(subProtectionPolicy.PolicyType, "Log") == 0)
{
azureVmWorkloadPolicyModel.LogBackupSchedulePolicy = PolicyHelpers.GetPSLogSchedulePolicy((ServiceClientModel.LogSchedulePolicy)
subProtectionPolicy.SchedulePolicy,
((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties).Settings.TimeZone);
azureVmWorkloadPolicyModel.LogBackupRetentionPolicy = PolicyHelpers.GetPSSimpleRetentionPolicy((ServiceClientModel.SimpleRetentionPolicy)
subProtectionPolicy.RetentionPolicy,
((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties).Settings.TimeZone, "AzureWorkload");
azureVmWorkloadPolicyModel.IsLogBackupEnabled = true;
}
}
}

/// <summary>
/// Helper function to convert ps protectable item list from service response.
/// </summary>
public static List<ProtectableItemBase> GetProtectableItemModelList(IEnumerable<ServiceClientModel.WorkloadProtectableItemResource> protectableItems)
{
List<ProtectableItemBase> itemModels = new List<ProtectableItemBase>();

foreach (var protectableItem in protectableItems)
{
itemModels.Add(GetProtectableItemModel(protectableItem));
}

return itemModels;
}
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public static CmdletModel.JobBase GetPSJob(JobResource serviceClientJob)
{
response = GetPSAzureFileShareJob(serviceClientJob);
}
else if (serviceClientJob.Properties.GetType() == typeof(AzureWorkloadJob))
{
response = GetPSAzureWorkloadJob(serviceClientJob);
}

return response;
}
Expand Down Expand Up @@ -234,6 +238,88 @@ private static CmdletModel.AzureJobErrorInfo GetPSAzureFileShareErrorInfo(AzureS
return psErrorInfo;
}

private static CmdletModel.JobBase GetPSAzureWorkloadJob(JobResource serviceClientJob)
{
CmdletModel.AzureVmWorkloadJob response;

AzureWorkloadJob workloadJob = serviceClientJob.Properties as AzureWorkloadJob;

if (workloadJob.ExtendedInfo != null)
{
response = new CmdletModel.AzureVmWorkloadJobDetails();
}
else
{
response = new CmdletModel.AzureVmWorkloadJob();
}

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

if (workloadJob.ErrorDetails != null)
{
response.ErrorDetails = new List<CmdletModel.AzureJobErrorInfo>();
foreach (var workloadError in workloadJob.ErrorDetails)
{
response.ErrorDetails.Add(GetPSAzureWorkloadErrorInfo(workloadError));
}
}

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

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

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

return response;
}

private static CmdletModel.AzureJobErrorInfo GetPSAzureWorkloadErrorInfo(AzureWorkloadErrorInfo workloadError)
{
CmdletModel.AzureVmWorkloadJobErrorInfo psErrorInfo = new CmdletModel.AzureVmWorkloadJobErrorInfo();
psErrorInfo.ErrorCode = GetJobErrorCode(workloadError.ErrorCode);
psErrorInfo.ErrorMessage = workloadError.ErrorString;
if (workloadError.Recommendations != null)
{
psErrorInfo.Recommendations = new List<string>();
psErrorInfo.Recommendations.AddRange(workloadError.Recommendations);
}

return psErrorInfo;
}

private static int GetJobErrorCode(int? errorCode)
{
return errorCode ?? default(int);
Expand Down
Loading

0 comments on commit 00f2c6f

Please sign in to comment.