Skip to content

[RecoveryServices.Backup] Breaking change release #8081

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

Merged
merged 6 commits into from
Dec 13, 2018
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 @@ -104,5 +104,7 @@ public enum ProtectionCheckParams
{
Name,
ResourceGroupName,
ResourceType,
ProtectableObjName
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
/// </summary>
public class ResourceBackupStatus
{
/// <summary>
/// The Resource Name.
/// </summary>
public string Name { get; set; }

/// <summary>
/// The Resource Group Name.
/// </summary>
public string ResourceGroupName { get; set; }

/// <summary>
/// If the resource is protected by some vault in the subscription, this contains the resource ID of that vault.
/// </summary>
Expand All @@ -41,16 +31,14 @@ public class ResourceBackupStatus
/// </summary>
public bool BackedUp { get; set; }

public ResourceBackupStatus(string name, string resourceGroupName, string vaultId, bool backedUp)
public ResourceBackupStatus(string vaultId, bool backedUp)
{
if (backedUp && string.IsNullOrEmpty(vaultId) ||
!backedUp && !string.IsNullOrEmpty(vaultId))
{
throw new ArgumentException($"Inconsistent parameters specified. backedUp: {backedUp} and vaultId: {vaultId}.");
}

Name = name;
ResourceGroupName = resourceGroupName;
VaultId = vaultId;
BackedUp = backedUp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,5 +303,44 @@ public static string GetServiceClientWorkloadType(string workloadType)
throw new Exception("Unsupported WorkloadType: " + workloadType);
}
}

/// <summary>
/// Returns the ARM resource type from PS workload type
/// </summary>
/// <param name="workloadType">PS workload type</param>
/// <returns>ARM resource type type</returns>
public static string GetARMResourceType(string workloadType)
{
if (workloadType == WorkloadType.AzureVM.ToString())
{
return "Microsoft.Compute/virtualMachines";
}
if (workloadType == WorkloadType.AzureFiles.ToString())
{
return "Microsoft.Storage/storageAccounts";
}

throw new Exception("Unsupported WorkloadType: " + workloadType);
}

/// <summary>
/// Returns the PS resource type from Arm workload type
/// </summary>
/// <param name="armType">Arm workload type</param>
/// <returns>PS resource type type</returns>
public static string GetWorkloadTypeFromArmType(string armType)
{
if (string.Compare(armType, "Microsoft.Compute/virtualMachines", ignoreCase: true) == 0 ||
string.Compare(armType, "Microsoft.ClassicCompute/virtualMachines", ignoreCase: true) == 0)
{
return WorkloadType.AzureVM.ToString();
}
if (string.Compare(armType, "Microsoft.Storage/storageAccounts", ignoreCase: true) == 0)
{
return WorkloadType.AzureFiles.ToString();
}

throw new Exception("Unsupported ArmType: " + armType);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,5 @@ public interface IPsBackupProvider
RPMountScriptDetails ProvisionItemLevelRecoveryAccess();

void RevokeItemLevelRecoveryAccess();

ResourceBackupStatus CheckBackupStatus();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,6 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
string vaultLocation = (string)ProviderData[VaultParams.VaultLocation];
CmdletModel.AzureFileShareRecoveryPoint recoveryPoint = ProviderData[RestoreBackupItemParams.RecoveryPoint]
as CmdletModel.AzureFileShareRecoveryPoint;
string storageAccountName = ProviderData.ContainsKey(RestoreBackupItemParams.StorageAccountName) ?
ProviderData[RestoreBackupItemParams.StorageAccountName].ToString() : null;
string storageAccountResourceGroupName = ProviderData.ContainsKey(RestoreBackupItemParams.StorageAccountResourceGroupName) ?
ProviderData[RestoreBackupItemParams.StorageAccountResourceGroupName].ToString() : null;
string copyOptions = (string)ProviderData[RestoreFSBackupItemParams.ResolveConflict];
string sourceFilePath = ProviderData.ContainsKey(RestoreFSBackupItemParams.SourceFilePath) ?
(string)ProviderData[RestoreFSBackupItemParams.SourceFilePath] : null;
Expand Down Expand Up @@ -800,54 +796,6 @@ private RestAzureNS.AzureOperationResponse EnableOrModifyProtection(bool disable
resourceGroupName: vaultResourceGroupName);
}

public ResourceBackupStatus CheckBackupStatus()
{
string fileShareName = (string)ProviderData[ProtectionCheckParams.Name];
string azureStorageAccountResourceGroupName =
(string)ProviderData[ProtectionCheckParams.ResourceGroupName];

ODataQuery<ProtectedItemQueryObject> queryParams =
new ODataQuery<ProtectedItemQueryObject>(
q => q.BackupManagementType
== ServiceClientModel.BackupManagementType.AzureStorage &&
q.ItemType == DataSourceType.AzureFileShare);

var vaultIds = ServiceClientAdapter.ListVaults();
foreach (var vaultId in vaultIds)
{
ResourceIdentifier vaultIdentifier = new ResourceIdentifier(vaultId);

var items = ServiceClientAdapter.ListProtectedItem(
queryParams,
vaultName: vaultIdentifier.ResourceName,
resourceGroupName: vaultIdentifier.ResourceGroupName);

if (items.Any(
item =>
{
ResourceIdentifier storageIdentifier =
new ResourceIdentifier(item.Properties.SourceResourceId);
var itemStorageAccountRgName = storageIdentifier.ResourceGroupName;

return item.Name.Split(';')[1].ToLower() == fileShareName.ToLower() &&
itemStorageAccountRgName.ToLower() == azureStorageAccountResourceGroupName.ToLower();
}))
{
return new ResourceBackupStatus(
fileShareName,
azureStorageAccountResourceGroupName,
vaultId,
true);
}
}

return new ResourceBackupStatus(
fileShareName,
azureStorageAccountResourceGroupName,
null,
false);
}

private void ValidateAzureStorageBackupManagementType(
CmdletModel.BackupManagementType backupManagementType)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,11 +485,6 @@ public List<ItemBase> ListProtectedItems()
return itemModels;
}

public ResourceBackupStatus CheckBackupStatus()
{
throw new NotImplementedException();
}

#region private
private void ValidateAzureSqlWorkloadType(CmdletModel.WorkloadType type)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,5 @@ public List<ItemBase> ListProtectedItems()
{
throw new NotImplementedException();
}

public ResourceBackupStatus CheckBackupStatus()
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -813,54 +813,6 @@ public RetentionPolicyBase GetDefaultRetentionPolicyObject()

}

public ResourceBackupStatus CheckBackupStatus()
{
string azureVmName = (string)ProviderData[ProtectionCheckParams.Name];
string azureVmResourceGroupName =
(string)ProviderData[ProtectionCheckParams.ResourceGroupName];

ODataQuery<ProtectedItemQueryObject> queryParams =
new ODataQuery<ProtectedItemQueryObject>(
q => q.BackupManagementType
== ServiceClientModel.BackupManagementType.AzureIaasVM &&
q.ItemType == DataSourceType.VM);

var vaultIds = ServiceClientAdapter.ListVaults();
foreach (var vaultId in vaultIds)
{
ResourceIdentifier vaultIdentifier = new ResourceIdentifier(vaultId);

var items = ServiceClientAdapter.ListProtectedItem(
queryParams,
vaultName: vaultIdentifier.ResourceName,
resourceGroupName: vaultIdentifier.ResourceGroupName);

if (items.Any(
item =>
{
ResourceIdentifier vmIdentifier =
new ResourceIdentifier(item.Properties.SourceResourceId);
var itemVmName = vmIdentifier.ResourceName;
var itemVmRgName = vmIdentifier.ResourceGroupName;

return itemVmName.ToLower() == azureVmName.ToLower() &&
itemVmRgName.ToLower() == azureVmResourceGroupName.ToLower();
}))
{
return new ResourceBackupStatus(
azureVmName,
azureVmResourceGroupName,
vaultId,
true);
}
}

return new ResourceBackupStatus(
azureVmName,
azureVmResourceGroupName,
null,
false);
}

#region private

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,5 @@ public List<ItemBase> ListProtectedItems()
{
throw new NotImplementedException();
}

public ResourceBackupStatus CheckBackupStatus()
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
using Microsoft.Rest.Azure.OData;
using RestAzureNS = Microsoft.Rest.Azure;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS
{
Expand Down Expand Up @@ -144,5 +145,36 @@ public RestAzureNS.AzureOperationResponse TriggerBackup(
triggerBackupRequest,
cancellationToken: BmsAdapter.CmdletCancellationToken).Result;
}

/// <summary>
/// Checks backup status for a given resource
/// </summary>
/// <param name="type">Resource type</param>
/// <param name="resourceId">Resource id</param>
/// <param name="resourceLocation">Resource location</param>
/// <param name="protectableObjName">Protectable object name</param>
/// <returns>Backup status</returns>
public RestAzureNS.AzureOperationResponse<BackupStatusResponse> CheckBackupStatus(
string type,
string resourceId,
string resourceLocation,
string protectableObjName)
{
ODataQuery<ProtectionPolicyQueryObject> queryParams =
new ODataQuery<ProtectionPolicyQueryObject>();

BackupStatusRequest request = new BackupStatusRequest();
request.ResourceType = ConversionUtils.GetServiceClientWorkloadType(type);
request.ResourceId = resourceId;
if(!string.IsNullOrWhiteSpace(protectableObjName))
{
request.PoLogicalName = protectableObjName;
}

return BmsAdapter.Client.BackupStatus.GetWithHttpMessagesAsync(
resourceLocation,
request,
cancellationToken: BmsAdapter.CmdletCancellationToken).Result;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClient
public partial class ServiceClientAdapter
{


/// <summary>
/// Get azure resource
/// </summary>
/// <param name="resourceId">Resource id of the Azure resource to get</param>
/// <returns>Generic resource returned from the service</returns>
public GenericResource GetAzureResource(string resourceId)
{
GenericResource resource = RMAdapter.Client.Resources.GetByIdWithHttpMessagesAsync(
resourceId,
"2015-06-15",
null,
cancellationToken: RMAdapter.CmdletCancellationToken).Result.Body;
return resource;
}

/// <summary>
/// Get storage accounts according to the query params
/// </summary>
Expand Down
Loading