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

Item support for mercury #386

Open
wants to merge 2 commits into
base: mercury_dev
Choose a base branch
from
Open
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 @@ -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 @@ -322,6 +322,7 @@ public static ItemBase GetItemModel(ServiceClientModel.ProtectedItemResource pro
if (protectedItem != null &&
protectedItem.Properties != null)
{
string z = protectedItem.Properties.GetType().ToString();
if (protectedItem.Properties.GetType().IsSubclassOf(typeof(ServiceClientModel.AzureIaaSVMProtectedItem)))
{
itemModel = GetAzureVmItemModel(protectedItem);
Expand All @@ -338,8 +339,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,
IdUtils.GetNameFromUri(containerUri),
ContainerType.AzureWorkload,
policyName);
return itemModel;
}

Expand Down Expand Up @@ -418,7 +449,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,
IdUtils.GetNameFromUri(containerUri),
ContainerType.AzureWorkload);

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 +497,21 @@ public static List<ItemBase> GetItemModelList(IEnumerable<ServiceClientModel.Pro

return itemModels;
}

/// <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 @@ -76,6 +76,9 @@ public static string GetServiceClientProviderType(CmdletModel.WorkloadType workl
case CmdletModel.WorkloadType.AzureFiles:
providerType = ServiceClientModel.BackupManagementType.AzureStorage.ToString();
break;
case CmdletModel.WorkloadType.MSSQL:
providerType = ServiceClientModel.BackupManagementType.AzureWorkload.ToString();
break;
default:
break;
}
Expand Down Expand Up @@ -353,4 +356,4 @@ public static string GetServiceClientWorkloadType(CmdletModel.WorkloadType workl
return serviceClientWorkloadType;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Management.RecoveryServices.Backup.Models;

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
{
/// <summary>
/// Azure workload protectable item Class
/// </summary>
public class AzureWorkloadProtectableItem : ProtectableItemBase
{
/// <summary>
/// name for instance or AG
/// </summary>
public string ParentName { get; set; }

/// <summary>
/// Name of the Parent Only Applicable for data bases where the parent would be either
/// Instance or a SQL AG.
/// </summary>
public string ParentUniqueName { get; set; }

/// <summary>
/// host/Cluster Name for instance or AG
/// </summary>
public string ServerName { get; set; }

/// <summary>
/// indicates if protectable item is auto-protectable
/// </summary>
public bool? IsAutoProtectable { get; set; }

/// <summary>
/// for instance or AG, indicates number of DB's present
/// </summary>
public int? Subinquireditemcount { get; set; }

/// <summary>
/// for instance or AG, indicates number of DB's to be protected
/// </summary>
public int? Subprotectableitemcount { get; set; }

/// <summary>
/// pre-backup validation for protectable objects
/// </summary>
public PreBackupValidation Prebackupvalidation { get; set; }

/// <summary>
/// Constructor. Takes the service client object representing the protected item
/// and converts it in to the PS protected item model
/// </summary>
/// <param name="protectedItemResource">Service client object representing the protected item resource</param>
/// <param name="containerName">Name of the container associated with this protected item</param>
/// <param name="containerType">Type of the container associated with this protected item</param>
public AzureWorkloadProtectableItem(WorkloadProtectableItemResource workloadProtectableItemResource,
string containerName, ContainerType containerType)
: base(workloadProtectableItemResource, containerName, containerType)
{
AzureVmWorkloadProtectableItem protectedItem = (AzureVmWorkloadProtectableItem)workloadProtectableItemResource.Properties;
ParentName = protectedItem.ParentName;
ParentUniqueName = protectedItem.ParentUniqueName;
ServerName = protectedItem.ServerName;
IsAutoProtectable = protectedItem.IsAutoProtectable;
Subinquireditemcount = protectedItem.Subinquireditemcount;
Subprotectableitemcount = protectedItem.Subprotectableitemcount;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Management.RecoveryServices.Backup.Models;

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
{
/// <summary>
/// Azure sql database workload Item Class
/// </summary>
public class AzureWorkloadSQLDatabaseProtectedItem : AzureItem
{
/// <summary>
/// friendly name of the DB represented by this backup item.
/// </summary>
public string FriendlyName { get; set; }

/// <summary>
/// host/Cluster Name for instance or AG.
/// </summary>
public string ServerName { get; set; }

/// <summary>
/// parent name of the DB such as Instance or Availability Group.
/// </summary>
public string ParentName { get; set; }

/// <summary>
/// protected item, example: for a DB, standalone server
/// or distributed.
/// </summary>
public string ParentType { get; set; }

/// <summary>
/// error details in last backup
/// </summary>
public ErrorDetail LastBackupErrorDetail { get; set; }

/// <summary>
///ID of the protected item.
/// </summary>
public string ProtectedItemDataSourceId { get; set; }

/// <summary>
/// health status of the backup item
/// </summary>
public string ProtectedItemHealthStatus { get; set; }

/// <summary>
/// Constructor. Takes the service client object representing the protected item
/// and converts it in to the PS protected item model
/// </summary>
/// <param name="protectedItemResource">Service client object representing the protected item resource</param>
/// <param name="containerName">Name of the container associated with this protected item</param>
/// <param name="containerType">Type of the container associated with this protected item</param>
/// <param name="policyName">Name of the protection policy associated with this protected item</param>
public AzureWorkloadSQLDatabaseProtectedItem(ProtectedItemResource protectedItemResource,
string containerName, ContainerType containerType, string policyName)
: base(protectedItemResource, containerName, containerType, policyName)
{
AzureVmWorkloadSQLDatabaseProtectedItem protectedItem = (AzureVmWorkloadSQLDatabaseProtectedItem)protectedItemResource.Properties;
FriendlyName = protectedItem.FriendlyName;
ServerName = protectedItem.ServerName;
ParentName = protectedItem.ParentName;
ParentType = protectedItem.ParentType;
LastBackupErrorDetail = protectedItem.LastBackupErrorDetail;
ProtectedItemDataSourceId = protectedItem.ProtectedItemDataSourceId;
ProtectedItemHealthStatus = protectedItem.ProtectedItemHealthStatus;
LastBackupStatus = protectedItem.LastBackupStatus;
LastBackupTime = protectedItem.LastBackupTime;
ProtectionState =
EnumUtils.GetEnum<ItemProtectionState>(protectedItem.ProtectionState.ToString());
ProtectionStatus = EnumUtils.GetEnum<ItemProtectionStatus>(protectedItem.ProtectionStatus);
}
}

/// <summary>
/// Azure Workload Item ExtendedInfo Class
/// </summary>
public class AzureWorkloadSQLDatabaseProtectedItemExtendedInfo : AzureItemExtendedInfo
{ }
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

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

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
Expand Down Expand Up @@ -160,6 +160,37 @@ public ItemContext(ServiceClientModel.ProtectedItem protectedItem,
}
}

/// <summary>
/// Represents Azure Backup Item Context Class
/// </summary>
public class ProtectableItemContext : ContainerContext
{
/// <summary>
/// Workload Type of Item
/// </summary>
public WorkloadType WorkloadType { get; set; }

/// <summary>
/// Unique name of the Container
/// </summary>
public string ContainerName { get; set; }

public ProtectableItemContext()
: base()
{

}

public ProtectableItemContext(ServiceClientModel.WorkloadProtectableItem protectableItem,
string containerName, ContainerType containerType)
: base(containerType, protectableItem.BackupManagementType)
{
WorkloadType = ConversionUtils.GetPsWorkloadType(
protectableItem.WorkloadType.ToString());
ContainerName = containerName;
}
}

/// <summary>
/// Represents Azure Backup Item Base Class
/// </summary>
Expand Down Expand Up @@ -197,6 +228,31 @@ public ItemBase(ServiceClientModel.ProtectedItemResource protectedItemResource,
}
}

/// <summary>
/// Represents Azure Backup Protectable Item Base Class
/// </summary>
public class ProtectableItemBase : ProtectableItemContext
{
/// <summary>
/// Name of the item
/// </summary>
public string Name { get; set; }

/// <summary>
/// Id of the item
/// </summary>
public string Id { get; set; }

public ProtectableItemBase(ServiceClientModel.WorkloadProtectableItemResource workloadProtectableItemResource,
string containerName, ContainerType containerType)
: base(workloadProtectableItemResource.Properties, containerName, containerType)
{
ServiceClientModel.WorkloadProtectableItem protectableItem = workloadProtectableItemResource.Properties;
Name = workloadProtectableItemResource.Name;
Id = workloadProtectableItemResource.Id;
}
}

/// <summary>
/// Represents Azure Backup Item ExtendedInfo Base Class
/// </summary>
Expand Down
Loading