Skip to content

Commit 140a676

Browse files
committed
Container support for mercury
1 parent 1ac99e4 commit 140a676

File tree

24 files changed

+817
-20
lines changed

24 files changed

+817
-20
lines changed

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Helpers/Conversions/ConversionHelpers.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ public static ContainerBase GetContainerModel(ServiceClientModel.ProtectionConta
5555
{
5656
containerModel = new AzureFileShareContainer(protectionContainer);
5757
}
58+
else if (protectionContainer.Properties.GetType() ==
59+
typeof(ServiceClientModel.AzureVMAppContainerProtectionContainer))
60+
{
61+
containerModel = new AzureWorkloadContainer(protectionContainer);
62+
}
5863
}
5964

6065
return containerModel;

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Helpers/ServiceClientHelpers.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,9 @@ public static string GetServiceClientWorkloadType(CmdletModel.WorkloadType workl
349349
case CmdletModel.WorkloadType.AzureVM:
350350
serviceClientWorkloadType = ServiceClientModel.WorkloadType.VM.ToString();
351351
break;
352+
case CmdletModel.WorkloadType.MSSQL:
353+
serviceClientWorkloadType = ServiceClientModel.WorkloadType.SQLDataBase.ToString();
354+
break;
352355
default:
353356
break;
354357
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
16+
17+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
18+
{
19+
/// <summary>
20+
/// Azure Workload specific container class.
21+
/// </summary>
22+
public class AzureWorkloadContainer : AzureContainer
23+
{
24+
/// <summary>
25+
/// Constructor. Takes the service client object representing the container
26+
/// and converts it in to the PS container model
27+
/// </summary>
28+
/// <param name="protectionContainerResource">Service client object representing the container</param>
29+
public AzureWorkloadContainer(ProtectionContainerResource protectionContainerResource)
30+
: base(protectionContainerResource) { }
31+
}
32+
}

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public enum ContainerType
4040
AzureStorage,
4141

4242
/// <summary>
43-
/// Represents any Azure Workload containers.
43+
/// Represents Azure Workload
4444
/// </summary>
4545
AzureWorkload
4646
}
@@ -75,7 +75,11 @@ public enum BackupManagementType
7575
/// Represents Azure File Storage. https://docs.microsoft.com/en-in/azure/storage/files/storage-files-introduction
7676
/// </summary>
7777
AzureStorage,
78-
AzureWorkload,
78+
79+
/// <summary>
80+
/// Represents Azure Workload
81+
/// </summary>
82+
AzureWorkload
7983
}
8084

8185
/// <summary>
@@ -109,6 +113,10 @@ public enum WorkloadType
109113
/// Represents Azure File https://docs.microsoft.com/en-in/azure/storage/files/storage-files-introduction
110114
/// </summary>
111115
AzureFiles,
116+
117+
/// <summary>
118+
/// Represents MSSQL in Azure VM.
119+
/// </summary>
112120
MSSQL,
113121
}
114122

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ public void RefreshContainer(string vaultName = null, string vaultResourceGroupN
6464
}
6565
}
6666

67-
public void RegisterContainer(string storageAccountName,
67+
public void RegisterContainer(string containerName,
6868
ProtectionContainerResource protectionContainerResource,
6969
string vaultName, string vaultResourceGroupName)
7070
{
7171
var registerResponse = ServiceClientAdapter.RegisterContainer(
72-
storageAccountName,
72+
containerName,
7373
protectionContainerResource,
7474
vaultName,
7575
vaultResourceGroupName);
@@ -79,7 +79,7 @@ public void RegisterContainer(string storageAccountName,
7979
operationId =>
8080
ServiceClientAdapter.GetRegisterContainerOperationResult(
8181
operationId,
82-
storageAccountName,
82+
containerName,
8383
vaultName: vaultName,
8484
resourceGroupName: vaultResourceGroupName));
8585

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

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

6262
void RevokeItemLevelRecoveryAccess();
63+
64+
void RegisterContainer();
6365
}
6466
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
1818
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
1919
using Microsoft.Azure.Management.Internal.Resources.Models;
20-
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
2120
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
2221
using Microsoft.Rest.Azure.OData;
2322
using System;
@@ -700,6 +699,11 @@ public List<ItemBase> ListProtectedItems()
700699
return itemModels;
701700
}
702701

702+
public void RegisterContainer()
703+
{
704+
throw new NotImplementedException();
705+
}
706+
703707
private RestAzureNS.AzureOperationResponse EnableOrModifyProtection(bool disableWithRetentionData = false)
704708
{
705709
string vaultName = (string)ProviderData[VaultParams.VaultName];

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

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

488+
public void RegisterContainer()
489+
{
490+
throw new NotImplementedException();
491+
}
492+
488493
#region private
489494
private void ValidateAzureSqlWorkloadType(CmdletModel.WorkloadType type)
490495
{

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

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414

1515
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
1616
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS;
17+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
1718
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
19+
using Microsoft.Rest.Azure.OData;
1820
using System;
1921
using System.Collections.Generic;
22+
using System.Linq;
2023
using CmdletModel = Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
2124
using RestAzureNS = Microsoft.Rest.Azure;
22-
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
2325
using ServiceClientModel = Microsoft.Azure.Management.RecoveryServices.Backup.Models;
24-
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
2526

2627
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel
2728
{
@@ -35,9 +36,13 @@ public class AzureWorkloadPsBackupProvider : IPsBackupProvider
3536
private const CmdletModel.RetentionDurationType defaultFileRetentionType =
3637
CmdletModel.RetentionDurationType.Days;
3738
private const int defaultFileRetentionCount = 30;
39+
3840
Dictionary<Enum, object> ProviderData { get; set; }
41+
3942
ServiceClientAdapter ServiceClientAdapter { get; set; }
43+
4044
AzureWorkloadProviderHelper AzureWorkloadProviderHelper { get; set; }
45+
4146
/// <summary>
4247
/// Initializes the provider with the data recieved from the cmdlet layer
4348
/// </summary>
@@ -102,7 +107,18 @@ public List<ItemBase> ListProtectedItems()
102107

103108
public List<ContainerBase> ListProtectionContainers()
104109
{
105-
throw new NotImplementedException();
110+
CmdletModel.BackupManagementType? backupManagementTypeNullable =
111+
(CmdletModel.BackupManagementType?)
112+
ProviderData[ContainerParams.BackupManagementType];
113+
114+
if (backupManagementTypeNullable.HasValue)
115+
{
116+
ValidateAzureWorkloadBackupManagementType(backupManagementTypeNullable.Value);
117+
}
118+
119+
return AzureWorkloadProviderHelper.ListProtectionContainers(
120+
ProviderData,
121+
ServiceClientModel.BackupManagementType.AzureWorkload);
106122
}
107123

108124
public List<RecoveryPointBase> ListRecoveryPoints()
@@ -134,5 +150,71 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
134150
{
135151
throw new NotImplementedException();
136152
}
153+
154+
private void ValidateAzureWorkloadBackupManagementType(
155+
CmdletModel.BackupManagementType backupManagementType)
156+
{
157+
if (backupManagementType != CmdletModel.BackupManagementType.AzureWorkload)
158+
{
159+
throw new ArgumentException(string.Format(Resources.UnExpectedBackupManagementTypeException,
160+
CmdletModel.BackupManagementType.AzureWorkload.ToString(),
161+
backupManagementType.ToString()));
162+
}
163+
}
164+
165+
public void RegisterContainer()
166+
{
167+
string vaultName = (string)ProviderData[VaultParams.VaultName];
168+
string vaultResourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
169+
string containerName = (string)ProviderData[ContainerParams.Name];
170+
string backupManagementType = (string)ProviderData[ContainerParams.BackupManagementType];
171+
string workloadType = (string)ProviderData[ContainerParams.ContainerType];
172+
173+
//Trigger Discovery
174+
ODataQuery<BMSRefreshContainersQueryObject> queryParam = new ODataQuery<BMSRefreshContainersQueryObject>(
175+
q => q.BackupManagementType
176+
== ServiceClientModel.BackupManagementType.AzureWorkload);
177+
AzureWorkloadProviderHelper.RefreshContainer(vaultName, vaultResourceGroupName, queryParam);
178+
179+
List<ProtectableContainerResource> unregisteredVmContainers =
180+
GetUnRegisteredVmContainers(vaultName, vaultResourceGroupName);
181+
ProtectableContainerResource unregisteredVmContainer = unregisteredVmContainers.Find(
182+
vmContainer => string.Compare(vmContainer.Name.Split(';').Last(),
183+
containerName, true) == 0);
184+
185+
if (unregisteredVmContainer != null)
186+
{
187+
ProtectionContainerResource protectionContainerResource =
188+
new ProtectionContainerResource(unregisteredVmContainer.Id,
189+
unregisteredVmContainer.Name);
190+
AzureVMAppContainerProtectionContainer azureVMContainer = new AzureVMAppContainerProtectionContainer(
191+
friendlyName: containerName,
192+
backupManagementType: backupManagementType,
193+
sourceResourceId: unregisteredVmContainer.Properties.ContainerId,
194+
workloadType: workloadType.ToString());
195+
protectionContainerResource.Properties = azureVMContainer;
196+
197+
AzureWorkloadProviderHelper.RegisterContainer(unregisteredVmContainer.Name,
198+
protectionContainerResource,
199+
vaultName,
200+
vaultResourceGroupName);
201+
}
202+
}
203+
204+
private List<ProtectableContainerResource> GetUnRegisteredVmContainers(string vaultName = null,
205+
string vaultResourceGroupName = null)
206+
{
207+
ODataQuery<BMSContainerQueryObject> queryParams = null;
208+
queryParams = new ODataQuery<BMSContainerQueryObject>(
209+
q => q.BackupManagementType == ServiceClientModel.BackupManagementType.AzureWorkload);
210+
211+
var listResponse = ServiceClientAdapter.ListUnregisteredContainers(
212+
queryParams,
213+
vaultName: vaultName,
214+
resourceGroupName: vaultResourceGroupName);
215+
List<ProtectableContainerResource> containerModels = listResponse.ToList();
216+
217+
return containerModels;
218+
}
137219
}
138220
}

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

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

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
1919
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
2020
using Microsoft.Azure.Management.Internal.Resources.Models;
21-
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
2221
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
2322
using Microsoft.Rest.Azure.OData;
2423
using System;
@@ -812,7 +811,10 @@ public RetentionPolicyBase GetDefaultRetentionPolicyObject()
812811
return defaultRetention;
813812

814813
}
815-
814+
public void RegisterContainer()
815+
{
816+
throw new NotImplementedException();
817+
}
816818

817819
#region private
818820

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

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

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,20 @@ public IPsBackupProvider GetProviderInstance
122122
containerType));
123123
}
124124
break;
125+
case ContainerType.AzureWorkload:
126+
if (backupManagementType == BackupManagementType.AzureWorkload ||
127+
backupManagementType == null)
128+
{
129+
providerType = PsBackupProviderTypes.AzureWorkload;
130+
}
131+
else
132+
{
133+
throw new ArgumentException(
134+
string.Format(
135+
Resources.BackupManagementTypeRequiredForContainerType,
136+
containerType));
137+
}
138+
break;
125139
default:
126140
throw new ArgumentException(
127141
string.Format(Resources.UnsupportedContainerType,
@@ -155,6 +169,9 @@ public IPsBackupProvider GetProviderInstance(WorkloadType workloadType)
155169
case WorkloadType.AzureFiles:
156170
providerType = PsBackupProviderTypes.AzureFiles;
157171
break;
172+
case WorkloadType.MSSQL:
173+
providerType = PsBackupProviderTypes.AzureWorkload;
174+
break;
158175
default:
159176
throw new ArgumentException(
160177
string.Format(Resources.BackupManagementTypeRequiredForWorkloadType,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using System;
16-
using System.Collections.Generic;
1715
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
1816
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
1917
using Microsoft.Rest.Azure.OData;
18+
using System;
19+
using System.Collections.Generic;
2020
using RestAzureNS = Microsoft.Rest.Azure;
2121

2222
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS

0 commit comments

Comments
 (0)