Skip to content

Commit 2056c93

Browse files
committed
Merge pull request #241 from MabOneSdk/pikumar-dev1
Pikumar dev1
2 parents 7220965 + e65336a commit 2056c93

File tree

17 files changed

+186
-20
lines changed

17 files changed

+186
-20
lines changed

src/ResourceManager/RecoveryServices.Backup/Cmdlets/Container/GetAzureRmBackupManagementServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public override void ExecuteCmdlet()
4949

5050
IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(ContainerType.Windows, BackupManagementType.Scdpm);
5151

52-
var containerModels = psBackupProvider.ListProtectionContainers();
52+
var containerModels = psBackupProvider.ListBackupManagementServers();
5353

5454
if (containerModels.Count == 1)
5555
{

src/ResourceManager/RecoveryServices.Backup/Cmdlets/Container/UnregisterAzureRmRecoveryServicesBackupContainer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public override void ExecuteCmdlet()
4444
{
4545
throw new ArgumentException(String.Format("Please provide Container of containerType Windows and backupManagementType Mars. Provided Container has containerType {0} and backupManagementType {1}", Container.ContainerType, Container.BackupManagementType));
4646
}
47-
string containerName = Container.Name;
47+
AzureRmRecoveryServicesMabContainer mabContainer = Container as AzureRmRecoveryServicesMabContainer;
48+
string containerName = mabContainer.FriendlyName;
4849
HydraAdapter.UnregisterContainers(containerName);
4950
});
5051
}

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static AzureRmRecoveryServicesContainerBase GetContainerModel(ProtectionC
3737
{
3838
containerModel = new AzureRmRecoveryServicesIaasVmContainer(protectionContainer);
3939
}
40-
if (protectionContainer.Properties.GetType().IsSubclassOf(typeof(MabProtectionContainer)))
40+
if (protectionContainer.Properties.GetType() == typeof(MabProtectionContainer))
4141
{
4242
containerModel = new AzureRmRecoveryServicesMabContainer(protectionContainer);
4343
}
@@ -46,6 +46,22 @@ public static AzureRmRecoveryServicesContainerBase GetContainerModel(ProtectionC
4646
return containerModel;
4747
}
4848

49+
public static AzureRmRecoveryServicesBackupEngineBase GetBackupEngineModel(BackupEngineResource backupEngine)
50+
{
51+
AzureRmRecoveryServicesBackupEngineBase backupEngineModel = null;
52+
53+
if (backupEngine != null &&
54+
backupEngine.Properties != null)
55+
{
56+
if (backupEngine.Properties.GetType() == (typeof(DpmBackupEngine)))
57+
{
58+
backupEngineModel = new AzureRmRecoveryServicesDpmBackupEngine(backupEngine);
59+
}
60+
}
61+
62+
return backupEngineModel;
63+
}
64+
4965
public static List<AzureRmRecoveryServicesContainerBase> GetContainerModelList(IEnumerable<ProtectionContainerResource> protectionContainers)
5066
{
5167
List<AzureRmRecoveryServicesContainerBase> containerModels = new List<AzureRmRecoveryServicesContainerBase>();
@@ -58,6 +74,18 @@ public static List<AzureRmRecoveryServicesContainerBase> GetContainerModelList(I
5874
return containerModels;
5975
}
6076

77+
public static List<AzureRmRecoveryServicesBackupEngineBase> GetBackupEngineModelList(IEnumerable<BackupEngineResource> backupEngines)
78+
{
79+
List<AzureRmRecoveryServicesBackupEngineBase> backupEngineModel = new List<AzureRmRecoveryServicesBackupEngineBase>();
80+
81+
foreach (var backupEngine in backupEngines)
82+
{
83+
backupEngineModel.Add(GetBackupEngineModel(backupEngine));
84+
}
85+
86+
return backupEngineModel;
87+
}
88+
6189
#endregion
6290

6391
#region policy

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ public IEnumerable<ProtectionContainerResource> ListContainers(ProtectionContain
3535
return listResponse.ItemList.ProtectionContainers;
3636
}
3737

38+
/// <summary>
39+
/// Fetches backup engine in the vault according to the query params
40+
/// </summary>
41+
/// <param name="parameters"></param>
42+
/// <returns></returns>
43+
public IEnumerable<BackupEngineResource> ListBackupEngines(BackupEngineListQueryParams queryParams)
44+
{
45+
var listResponse = BmsAdapter.Client.BackupEngine.ListAsync(BmsAdapter.GetResourceGroupName(), BmsAdapter.GetResourceName(), queryParams,
46+
BmsAdapter.GetCustomRequestHeaders(), BmsAdapter.CmdletCancellationToken).Result;
47+
return listResponse.ItemList.BackupEngines;
48+
}
49+
3850
/// <summary>
3951
/// Triggers refresh of container catalog in service
4052
/// </summary>

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ public AzureRmRecoveryServicesContainerContext(ContainerType containerType, stri
5252
}
5353
}
5454

55+
public class AzureRmRecoveryServicesBackupEngineContext : AzureRmRecoveryServicesBackupManagementContext
56+
{
57+
public BackupEngineType BackupEngineType { get; set; }
58+
59+
public AzureRmRecoveryServicesBackupEngineContext() { }
60+
61+
public AzureRmRecoveryServicesBackupEngineContext(BackupEngineType backupEngineType, string backupManagementType)
62+
: base(backupManagementType)
63+
{
64+
BackupEngineType = backupEngineType;
65+
}
66+
}
67+
5568
public class AzureRmRecoveryServicesContainerBase : AzureRmRecoveryServicesContainerContext
5669
{
5770
/// <summary>
@@ -67,6 +80,21 @@ public AzureRmRecoveryServicesContainerBase(ProtectionContainerResource protecti
6780
}
6881
}
6982

83+
public class AzureRmRecoveryServicesBackupEngineBase : AzureRmRecoveryServicesBackupEngineContext
84+
{
85+
/// <summary>
86+
/// Container Name
87+
/// </summary>
88+
public string Name { get; set; }
89+
90+
public AzureRmRecoveryServicesBackupEngineBase(BackupEngineResource backupEngine)
91+
: base(ConversionUtils.GetPsBackupEngineType(((BackupEngineBase)backupEngine.Properties).BackupEngineType),
92+
((BackupEngineBase)backupEngine.Properties).BackupManagementType)
93+
{
94+
Name = backupEngine.Name;
95+
}
96+
}
97+
7098
/// <summary>
7199
/// Represents Azure Backup Item Context Class
72100
/// </summary>

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/Commands.RecoveryServices.Backup.Models.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<Compile Include="AzureVmModels\AzureRmRecoveryServicesAzureVmPolicy.cs" />
5454
<Compile Include="AzureVmModels\AzureRmRecoveryServicesAzureVmItem.cs" />
5555
<Compile Include="AzureVmModels\AzureRmRecoveryServicesAzureVmContainer.cs" />
56+
<Compile Include="DpmModels\AzureRmRecoveryServicesDpmBackupEngine.cs" />
5657
<Compile Include="DpmModels\AzureRmRecoveryServicesDpmContainer.cs" />
5758
<Compile Include="MabModels\AzureRmRecoveryServicesMabContainer.cs" />
5859
<Compile Include="Properties\AssemblyInfo.cs" />

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ public enum ContainerType
2727
Windows
2828
}
2929

30+
public enum BackupEngineType
31+
{
32+
Invalid = 0,
33+
34+
DpmEngine,
35+
36+
DpmVenusEngine
37+
}
38+
3039
public enum BackupManagementType
3140
{
3241
AzureVM = 1,
@@ -53,6 +62,12 @@ public enum ContainerRegistrationStatus
5362
Registering,
5463
}
5564

65+
public enum BackupEngineRegistrationStatus
66+
{
67+
Registered = 1,
68+
Registering,
69+
}
70+
5671
public enum ItemProtectionStatus
5772
{
5873
Healthy = 1,

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ public static BackupManagementType GetPsBackupManagementType(string backupManage
124124
{
125125
case ProviderType.AzureIaasVM:
126126
return BackupManagementType.AzureVM;
127+
case ProviderType.MAB:
128+
return BackupManagementType.Mars;
127129
default:
128130
throw new Exception("Unsupported BackupManagmentType: " + backupManagementType);
129131
}
@@ -136,12 +138,23 @@ public static ContainerType GetPsContainerType(string containerType)
136138
{
137139
return ContainerType.AzureVM;
138140
}
141+
else if (containerType == Microsoft.Azure.Management.RecoveryServices.Backup.Models.ContainerType.MABContainer.ToString())
142+
{
143+
return ContainerType.Windows;
144+
}
139145
else
140146
{
141147
throw new Exception("Unsupported ContainerType: " + containerType);
142148
}
143149
}
144150

151+
public static BackupEngineType GetPsBackupEngineType(string backupEngineType)
152+
{
153+
BackupEngineType type = 0;
154+
Enum.TryParse(backupEngineType, out type);
155+
return type;
156+
}
157+
145158
public static WorkloadType GetPsWorkloadType(string workloadType)
146159
{
147160
if (workloadType == Microsoft.Azure.Management.RecoveryServices.Backup.Models.WorkloadType.VM)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
using System;
17+
using System.Collections.Generic;
18+
using System.Linq;
19+
using System.Text;
20+
using System.Threading.Tasks;
21+
22+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
23+
{
24+
public class AzureRmRecoveryServicesDpmBackupEngine : AzureRmRecoveryServicesBackupEngineBase
25+
{
26+
/// <summary>
27+
/// Resource Group where the Container is present
28+
/// </summary>
29+
public string ResourceGroupName { get; set; }
30+
31+
/// <summary>
32+
/// Friendly name of the container
33+
/// </summary>
34+
public string FriendlyName { get; set; }
35+
36+
/// <summary>
37+
/// Registration Status
38+
/// </summary>
39+
public BackupEngineRegistrationStatus Status { get; set; }
40+
41+
public AzureRmRecoveryServicesDpmBackupEngine(BackupEngineResource backupEngine)
42+
: base(backupEngine)
43+
{
44+
DpmBackupEngine dpmBackupEngine = (DpmBackupEngine)backupEngine.Properties;
45+
ResourceGroupName = IdUtils.GetResourceGroupName(backupEngine.Id);
46+
FriendlyName = dpmBackupEngine.FriendlyName;
47+
Status = EnumUtils.GetEnum<BackupEngineRegistrationStatus>(dpmBackupEngine.RegistrationStatus);
48+
}
49+
}
50+
}

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/MabModels/AzureRmRecoveryServicesMabContainer.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
2323
{
2424
public class AzureRmRecoveryServicesMabContainer : AzureRmRecoveryServicesContainerBase
2525
{
26-
/// <summary>
27-
/// Resource Group where the Container is present
28-
/// </summary>
29-
public string ResourceGroupName { get; set; }
30-
3126
/// <summary>
3227
/// Friendly name of the container
3328
/// </summary>
@@ -42,7 +37,6 @@ public AzureRmRecoveryServicesMabContainer(ProtectionContainerResource protectio
4237
: base(protectionContainer)
4338
{
4439
MabProtectionContainer mabProtectionContainer = (MabProtectionContainer)protectionContainer.Properties;
45-
ResourceGroupName = IdUtils.GetResourceGroupName(protectionContainer.Id);
4640
FriendlyName = mabProtectionContainer.FriendlyName;
4741
Status = EnumUtils.GetEnum<ContainerRegistrationStatus>(mabProtectionContainer.RegistrationStatus);
4842
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public interface IPsBackupProvider
5050

5151
List<AzureRmRecoveryServicesContainerBase> ListProtectionContainers();
5252

53+
List<AzureRmRecoveryServicesBackupEngineBase> ListBackupManagementServers();
54+
5355
List<AzureRmRecoveryServicesItemBase> ListProtectedItems();
5456
}
5557
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ public Management.RecoveryServices.Backup.Models.ProtectionPolicyResponse Modify
7676
public List<Models.AzureRmRecoveryServicesContainerBase> ListProtectionContainers()
7777
{
7878
throw new NotImplementedException();
79-
}
79+
}
80+
81+
public List<AzureRmRecoveryServicesBackupEngineBase> ListBackupManagementServers()
82+
{
83+
throw new NotImplementedException();
84+
}
8085

8186
public AzureRmRecoveryServicesBackupSchedulePolicyBase GetDefaultSchedulePolicyObject()
8287
{

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,23 +82,24 @@ public ProtectionPolicyResponse ModifyPolicy()
8282
public List<Models.AzureRmRecoveryServicesContainerBase> ListProtectionContainers()
8383
{
8484
throw new NotImplementedException();
85+
}
8586

87+
public List<Models.AzureRmRecoveryServicesBackupEngineBase> ListBackupManagementServers()
88+
{
8689
string name = (string)this.ProviderData.ProviderParameters[ContainerParams.Name];
8790

88-
ProtectionContainerListQueryParams queryParams = new ProtectionContainerListQueryParams();
91+
BackupEngineListQueryParams queryParams = new BackupEngineListQueryParams();
8992

90-
// 1. Filter by Name
91-
queryParams.FriendlyName = name;
93+
queryParams.ProviderType = ProviderType.DPM.ToString();
94+
95+
var listResponse = HydraAdapter.ListBackupEngines(queryParams);
9296

93-
// 2. Filter by ContainerType
9497
queryParams.ProviderType = ProviderType.DPM.ToString();
9598

96-
//ToDo: Piyush to call Get Backup Engine
97-
//var listResponse = HydraAdapter.ListContainers(queryParams);
9899

99-
//List<AzureRmRecoveryServicesContainerBase> containerModels = ConversionHelpers.GetContainerModelList(listResponse);
100-
101-
//return containerModels;
100+
List<AzureRmRecoveryServicesBackupEngineBase> backupEngineModels = ConversionHelpers.GetBackupEngineModelList(listResponse);
101+
102+
return backupEngineModels;
102103
}
103104

104105
public Management.RecoveryServices.Backup.Models.ProtectionPolicyResponse GetPolicy()

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,11 @@ public List<AzureRmRecoveryServicesContainerBase> ListProtectionContainers()
417417
return containerModels;
418418
}
419419

420+
public List<AzureRmRecoveryServicesBackupEngineBase> ListBackupManagementServers()
421+
{
422+
throw new NotImplementedException();
423+
}
424+
420425
public List<AzureRmRecoveryServicesItemBase> ListProtectedItems()
421426
{
422427
AzureRmRecoveryServicesContainerBase container =

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
using System.Linq;
1818
using System.Text;
1919
using System.Threading.Tasks;
20-
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
2120
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
2221
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
22+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
2323

2424
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel
2525
{
@@ -98,6 +98,11 @@ public ProtectionPolicyResponse ModifyPolicy()
9898
return containerModels;
9999
}
100100

101+
public List<AzureRmRecoveryServicesBackupEngineBase> ListBackupManagementServers()
102+
{
103+
throw new NotImplementedException();
104+
}
105+
101106
public Management.RecoveryServices.Backup.Models.ProtectionPolicyResponse GetPolicy()
102107
{
103108
throw new NotImplementedException();

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ public IPsBackupProvider GetProviderInstance(PsBackupProviderTypes providerType)
124124
case PsBackupProviderTypes.AzureSql:
125125
psBackupProvider = new AzureSqlPsBackupProvider();
126126
break;
127+
case PsBackupProviderTypes.Mab:
128+
psBackupProvider = new MabPsBackupProvider();
129+
break;
130+
case PsBackupProviderTypes.Dpm:
131+
psBackupProvider = new DpmPsBackupProvider();
132+
break;
127133
default:
128134
break;
129135
}

0 commit comments

Comments
 (0)