Skip to content

Commit 4ac0d1f

Browse files
authored
Merge pull request Azure#8081 from MabOneSdk/upstream_preview
[RecoveryServices.Backup] Breaking change release
2 parents 01997cb + 396c23b commit 4ac0d1f

File tree

23 files changed

+45931
-72663
lines changed

23 files changed

+45931
-72663
lines changed

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/CmdletParamEnums.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,7 @@ public enum ProtectionCheckParams
104104
{
105105
Name,
106106
ResourceGroupName,
107+
ResourceType,
108+
ProtectableObjName
107109
}
108110
}

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/CommonModels/ResourceBackupStatus.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,6 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
2121
/// </summary>
2222
public class ResourceBackupStatus
2323
{
24-
/// <summary>
25-
/// The Resource Name.
26-
/// </summary>
27-
public string Name { get; set; }
28-
29-
/// <summary>
30-
/// The Resource Group Name.
31-
/// </summary>
32-
public string ResourceGroupName { get; set; }
33-
3424
/// <summary>
3525
/// If the resource is protected by some vault in the subscription, this contains the resource ID of that vault.
3626
/// </summary>
@@ -41,16 +31,14 @@ public class ResourceBackupStatus
4131
/// </summary>
4232
public bool BackedUp { get; set; }
4333

44-
public ResourceBackupStatus(string name, string resourceGroupName, string vaultId, bool backedUp)
34+
public ResourceBackupStatus(string vaultId, bool backedUp)
4535
{
4636
if (backedUp && string.IsNullOrEmpty(vaultId) ||
4737
!backedUp && !string.IsNullOrEmpty(vaultId))
4838
{
4939
throw new ArgumentException($"Inconsistent parameters specified. backedUp: {backedUp} and vaultId: {vaultId}.");
5040
}
5141

52-
Name = name;
53-
ResourceGroupName = resourceGroupName;
5442
VaultId = vaultId;
5543
BackedUp = backedUp;
5644
}

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/CommonModels/Utils.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,5 +303,44 @@ public static string GetServiceClientWorkloadType(string workloadType)
303303
throw new Exception("Unsupported WorkloadType: " + workloadType);
304304
}
305305
}
306+
307+
/// <summary>
308+
/// Returns the ARM resource type from PS workload type
309+
/// </summary>
310+
/// <param name="workloadType">PS workload type</param>
311+
/// <returns>ARM resource type type</returns>
312+
public static string GetARMResourceType(string workloadType)
313+
{
314+
if (workloadType == WorkloadType.AzureVM.ToString())
315+
{
316+
return "Microsoft.Compute/virtualMachines";
317+
}
318+
if (workloadType == WorkloadType.AzureFiles.ToString())
319+
{
320+
return "Microsoft.Storage/storageAccounts";
321+
}
322+
323+
throw new Exception("Unsupported WorkloadType: " + workloadType);
324+
}
325+
326+
/// <summary>
327+
/// Returns the PS resource type from Arm workload type
328+
/// </summary>
329+
/// <param name="armType">Arm workload type</param>
330+
/// <returns>PS resource type type</returns>
331+
public static string GetWorkloadTypeFromArmType(string armType)
332+
{
333+
if (string.Compare(armType, "Microsoft.Compute/virtualMachines", ignoreCase: true) == 0 ||
334+
string.Compare(armType, "Microsoft.ClassicCompute/virtualMachines", ignoreCase: true) == 0)
335+
{
336+
return WorkloadType.AzureVM.ToString();
337+
}
338+
if (string.Compare(armType, "Microsoft.Storage/storageAccounts", ignoreCase: true) == 0)
339+
{
340+
return WorkloadType.AzureFiles.ToString();
341+
}
342+
343+
throw new Exception("Unsupported ArmType: " + armType);
344+
}
306345
}
307346
}

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/IPsBackupProvider.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,5 @@ public interface IPsBackupProvider
6060
RPMountScriptDetails ProvisionItemLevelRecoveryAccess();
6161

6262
void RevokeItemLevelRecoveryAccess();
63-
64-
ResourceBackupStatus CheckBackupStatus();
6563
}
6664
}

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/AzureFilesPsBackupProvider.cs

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,6 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
153153
string vaultLocation = (string)ProviderData[VaultParams.VaultLocation];
154154
CmdletModel.AzureFileShareRecoveryPoint recoveryPoint = ProviderData[RestoreBackupItemParams.RecoveryPoint]
155155
as CmdletModel.AzureFileShareRecoveryPoint;
156-
string storageAccountName = ProviderData.ContainsKey(RestoreBackupItemParams.StorageAccountName) ?
157-
ProviderData[RestoreBackupItemParams.StorageAccountName].ToString() : null;
158-
string storageAccountResourceGroupName = ProviderData.ContainsKey(RestoreBackupItemParams.StorageAccountResourceGroupName) ?
159-
ProviderData[RestoreBackupItemParams.StorageAccountResourceGroupName].ToString() : null;
160156
string copyOptions = (string)ProviderData[RestoreFSBackupItemParams.ResolveConflict];
161157
string sourceFilePath = ProviderData.ContainsKey(RestoreFSBackupItemParams.SourceFilePath) ?
162158
(string)ProviderData[RestoreFSBackupItemParams.SourceFilePath] : null;
@@ -800,54 +796,6 @@ private RestAzureNS.AzureOperationResponse EnableOrModifyProtection(bool disable
800796
resourceGroupName: vaultResourceGroupName);
801797
}
802798

803-
public ResourceBackupStatus CheckBackupStatus()
804-
{
805-
string fileShareName = (string)ProviderData[ProtectionCheckParams.Name];
806-
string azureStorageAccountResourceGroupName =
807-
(string)ProviderData[ProtectionCheckParams.ResourceGroupName];
808-
809-
ODataQuery<ProtectedItemQueryObject> queryParams =
810-
new ODataQuery<ProtectedItemQueryObject>(
811-
q => q.BackupManagementType
812-
== ServiceClientModel.BackupManagementType.AzureStorage &&
813-
q.ItemType == DataSourceType.AzureFileShare);
814-
815-
var vaultIds = ServiceClientAdapter.ListVaults();
816-
foreach (var vaultId in vaultIds)
817-
{
818-
ResourceIdentifier vaultIdentifier = new ResourceIdentifier(vaultId);
819-
820-
var items = ServiceClientAdapter.ListProtectedItem(
821-
queryParams,
822-
vaultName: vaultIdentifier.ResourceName,
823-
resourceGroupName: vaultIdentifier.ResourceGroupName);
824-
825-
if (items.Any(
826-
item =>
827-
{
828-
ResourceIdentifier storageIdentifier =
829-
new ResourceIdentifier(item.Properties.SourceResourceId);
830-
var itemStorageAccountRgName = storageIdentifier.ResourceGroupName;
831-
832-
return item.Name.Split(';')[1].ToLower() == fileShareName.ToLower() &&
833-
itemStorageAccountRgName.ToLower() == azureStorageAccountResourceGroupName.ToLower();
834-
}))
835-
{
836-
return new ResourceBackupStatus(
837-
fileShareName,
838-
azureStorageAccountResourceGroupName,
839-
vaultId,
840-
true);
841-
}
842-
}
843-
844-
return new ResourceBackupStatus(
845-
fileShareName,
846-
azureStorageAccountResourceGroupName,
847-
null,
848-
false);
849-
}
850-
851799
private void ValidateAzureStorageBackupManagementType(
852800
CmdletModel.BackupManagementType backupManagementType)
853801
{

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/AzureSqlPsBackupProvider.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -485,11 +485,6 @@ public List<ItemBase> ListProtectedItems()
485485
return itemModels;
486486
}
487487

488-
public ResourceBackupStatus CheckBackupStatus()
489-
{
490-
throw new NotImplementedException();
491-
}
492-
493488
#region private
494489
private void ValidateAzureSqlWorkloadType(CmdletModel.WorkloadType type)
495490
{

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/DpmPsBackupProvider.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,5 @@ public List<ItemBase> ListProtectedItems()
154154
{
155155
throw new NotImplementedException();
156156
}
157-
158-
public ResourceBackupStatus CheckBackupStatus()
159-
{
160-
throw new NotImplementedException();
161-
}
162157
}
163158
}

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/IaasVmPsBackupProvider.cs

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -813,54 +813,6 @@ public RetentionPolicyBase GetDefaultRetentionPolicyObject()
813813

814814
}
815815

816-
public ResourceBackupStatus CheckBackupStatus()
817-
{
818-
string azureVmName = (string)ProviderData[ProtectionCheckParams.Name];
819-
string azureVmResourceGroupName =
820-
(string)ProviderData[ProtectionCheckParams.ResourceGroupName];
821-
822-
ODataQuery<ProtectedItemQueryObject> queryParams =
823-
new ODataQuery<ProtectedItemQueryObject>(
824-
q => q.BackupManagementType
825-
== ServiceClientModel.BackupManagementType.AzureIaasVM &&
826-
q.ItemType == DataSourceType.VM);
827-
828-
var vaultIds = ServiceClientAdapter.ListVaults();
829-
foreach (var vaultId in vaultIds)
830-
{
831-
ResourceIdentifier vaultIdentifier = new ResourceIdentifier(vaultId);
832-
833-
var items = ServiceClientAdapter.ListProtectedItem(
834-
queryParams,
835-
vaultName: vaultIdentifier.ResourceName,
836-
resourceGroupName: vaultIdentifier.ResourceGroupName);
837-
838-
if (items.Any(
839-
item =>
840-
{
841-
ResourceIdentifier vmIdentifier =
842-
new ResourceIdentifier(item.Properties.SourceResourceId);
843-
var itemVmName = vmIdentifier.ResourceName;
844-
var itemVmRgName = vmIdentifier.ResourceGroupName;
845-
846-
return itemVmName.ToLower() == azureVmName.ToLower() &&
847-
itemVmRgName.ToLower() == azureVmResourceGroupName.ToLower();
848-
}))
849-
{
850-
return new ResourceBackupStatus(
851-
azureVmName,
852-
azureVmResourceGroupName,
853-
vaultId,
854-
true);
855-
}
856-
}
857-
858-
return new ResourceBackupStatus(
859-
azureVmName,
860-
azureVmResourceGroupName,
861-
null,
862-
false);
863-
}
864816

865817
#region private
866818

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/MabPsBackupProvider.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,5 @@ public List<ItemBase> ListProtectedItems()
157157
{
158158
throw new NotImplementedException();
159159
}
160-
161-
public ResourceBackupStatus CheckBackupStatus()
162-
{
163-
throw new NotImplementedException();
164-
}
165160
}
166161
}

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.ServiceClientAdapter/BMSAPIs/ItemAPIs.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
1919
using Microsoft.Rest.Azure.OData;
2020
using RestAzureNS = Microsoft.Rest.Azure;
21+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
2122

2223
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS
2324
{
@@ -144,5 +145,36 @@ public RestAzureNS.AzureOperationResponse TriggerBackup(
144145
triggerBackupRequest,
145146
cancellationToken: BmsAdapter.CmdletCancellationToken).Result;
146147
}
148+
149+
/// <summary>
150+
/// Checks backup status for a given resource
151+
/// </summary>
152+
/// <param name="type">Resource type</param>
153+
/// <param name="resourceId">Resource id</param>
154+
/// <param name="resourceLocation">Resource location</param>
155+
/// <param name="protectableObjName">Protectable object name</param>
156+
/// <returns>Backup status</returns>
157+
public RestAzureNS.AzureOperationResponse<BackupStatusResponse> CheckBackupStatus(
158+
string type,
159+
string resourceId,
160+
string resourceLocation,
161+
string protectableObjName)
162+
{
163+
ODataQuery<ProtectionPolicyQueryObject> queryParams =
164+
new ODataQuery<ProtectionPolicyQueryObject>();
165+
166+
BackupStatusRequest request = new BackupStatusRequest();
167+
request.ResourceType = ConversionUtils.GetServiceClientWorkloadType(type);
168+
request.ResourceId = resourceId;
169+
if(!string.IsNullOrWhiteSpace(protectableObjName))
170+
{
171+
request.PoLogicalName = protectableObjName;
172+
}
173+
174+
return BmsAdapter.Client.BackupStatus.GetWithHttpMessagesAsync(
175+
resourceLocation,
176+
request,
177+
cancellationToken: BmsAdapter.CmdletCancellationToken).Result;
178+
}
147179
}
148180
}

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.ServiceClientAdapter/RMAPIs/ResourceAPIs.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClient
2424
public partial class ServiceClientAdapter
2525
{
2626

27+
28+
/// <summary>
29+
/// Get azure resource
30+
/// </summary>
31+
/// <param name="resourceId">Resource id of the Azure resource to get</param>
32+
/// <returns>Generic resource returned from the service</returns>
33+
public GenericResource GetAzureResource(string resourceId)
34+
{
35+
GenericResource resource = RMAdapter.Client.Resources.GetByIdWithHttpMessagesAsync(
36+
resourceId,
37+
"2015-06-15",
38+
null,
39+
cancellationToken: RMAdapter.CmdletCancellationToken).Result.Body;
40+
return resource;
41+
}
42+
2743
/// <summary>
2844
/// Get storage accounts according to the query params
2945
/// </summary>

0 commit comments

Comments
 (0)