Skip to content

Commit c704298

Browse files
authored
Merge pull request #3208 from MabOneSdk/devSwagger
Migrating RS.Backup to Swagger
2 parents df49015 + 0d5c6a9 commit c704298

File tree

143 files changed

+198433
-22560
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+198433
-22560
lines changed

setup/azurecmdfiles.wxi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2331,6 +2331,9 @@
23312331
<Component Id="cmp902DC2364C6FF451A60B4D115B5DC7A9" Guid="*">
23322332
<File Id="filDFC93A6AA2A808957B249CC88C7D6EE5" KeyPath="yes" Source="$(var.sourceDir)\ResourceManager\AzureResourceManager\AzureRM.RecoveryServices.Backup\Microsoft.Rest.ClientRuntime.Azure.Authentication.dll" />
23332333
</Component>
2334+
<Component Id="cmpDB3F89FCB6F69647096085E3C07D2EA7" Guid="*">
2335+
<File Id="fil981731C42616352E119DFCB2CDFCF8BB" KeyPath="yes" Source="$(var.sourceDir)\ResourceManager\AzureResourceManager\AzureRM.RecoveryServices.Backup\Microsoft.Rest.ClientRuntime.Azure.dll" />
2336+
</Component>
23342337
<Component Id="cmpF8AEF0C5D785D40AEC8F1BF4ACE4E939" Guid="*">
23352338
<File Id="filA708CDDEB8C8A8363E22F4C83953E14E" KeyPath="yes" Source="$(var.sourceDir)\ResourceManager\AzureResourceManager\AzureRM.RecoveryServices.Backup\Microsoft.Rest.ClientRuntime.dll" />
23362339
</Component>
@@ -6277,6 +6280,7 @@
62776280
<ComponentRef Id="cmp13B3F08D31DD4410B1934B82517CAC9A" />
62786281
<ComponentRef Id="cmpA2EFAF047A9595A3CA7DFC6031140F27" />
62796282
<ComponentRef Id="cmp902DC2364C6FF451A60B4D115B5DC7A9" />
6283+
<ComponentRef Id="cmpDB3F89FCB6F69647096085E3C07D2EA7" />
62806284
<ComponentRef Id="cmpF8AEF0C5D785D40AEC8F1BF4ACE4E939" />
62816285
<ComponentRef Id="cmp0FB4C1F5BB0FB399774156C4B56696B8" />
62826286
<ComponentRef Id="cmp7B84FC694FB5281CF08E6F1B41D07E12" />

src/Common/Commands.Common/Commands.Common.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,4 @@
183183
</ProjectReference>
184184
</ItemGroup>
185185
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
186-
</Project>
186+
</Project>

src/ResourceManager/RecoveryServices.Backup/ChangeLog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21-
21+
* Migrated from Hyak based Azure SDK to Swagger based Azure SDK
2222
## Version 2.3.0

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,22 @@
4040
<Reference Include="Microsoft.Azure.Common">
4141
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.dll</HintPath>
4242
</Reference>
43-
<Reference Include="Microsoft.Azure.Management.RecoveryServices.Backup, Version=0.9.0.0, Culture=neutral, processorArchitecture=MSIL">
43+
<Reference Include="Microsoft.Azure.Management.RecoveryServices.Backup, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
4444
<SpecificVersion>False</SpecificVersion>
45-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.Backup.0.1.2\lib\net40\Microsoft.Azure.Management.RecoveryServices.Backup.dll</HintPath>
45+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.Backup.1.1.2-preview\lib\net45\Microsoft.Azure.Management.RecoveryServices.Backup.dll</HintPath>
46+
</Reference>
47+
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
48+
<SpecificVersion>False</SpecificVersion>
49+
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.2.3.3\lib\net45\Microsoft.Rest.ClientRuntime.dll</HintPath>
50+
</Reference>
51+
<Reference Include="Microsoft.Rest.ClientRuntime.Azure, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
52+
<SpecificVersion>False</SpecificVersion>
53+
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.3\lib\net45\Microsoft.Rest.ClientRuntime.Azure.dll</HintPath>
4654
</Reference>
4755
<Reference Include="System" />
4856
<Reference Include="System.Core" />
57+
<Reference Include="System.Net" />
58+
<Reference Include="System.Net.Http" />
4959
<Reference Include="System.Web" />
5060
<Reference Include="System.Xml.Linq" />
5161
<Reference Include="System.Data.DataSetExtensions" />
@@ -56,6 +66,8 @@
5666
<ItemGroup>
5767
<Compile Include="Conversions\JobConversions.cs" />
5868
<Compile Include="Conversions\RecoveryPointConversions.cs" />
69+
<Compile Include="Extensions\EnumExtensions.cs" />
70+
<Compile Include="Extensions\HttpHeadersExtensions.cs" />
5971
<Compile Include="HelperUtils.cs" />
6072
<Compile Include="TrackingHelpers.cs" />
6173
<Compile Include="Validations\PolicyValidations.cs" />
@@ -92,4 +104,4 @@
92104
<Target Name="AfterBuild">
93105
</Target>
94106
-->
95-
</Project>
107+
</Project>

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

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414

1515
using System;
1616
using System.Collections.Generic;
17-
using System.Linq;
18-
using System.Text;
19-
using System.Threading.Tasks;
2017
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
21-
using CmdletModels = Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
2218
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
2319
using ServiceClientModel = Microsoft.Azure.Management.RecoveryServices.Backup.Models;
2420

@@ -41,16 +37,16 @@ public static ContainerBase GetContainerModel(ServiceClientModel.ProtectionConta
4137
if (protectionContainer != null &&
4238
protectionContainer.Properties != null)
4339
{
44-
if (protectionContainer.Properties.GetType().IsSubclassOf(typeof(ServiceClientModel.AzureIaaSVMProtectionContainer)))
40+
if (protectionContainer.Properties.GetType().IsSubclassOf(typeof(ServiceClientModel.IaaSVMContainer)))
4541
{
4642
containerModel = new AzureVmContainer(protectionContainer);
4743
}
48-
if (protectionContainer.Properties.GetType() == typeof(ServiceClientModel.MabProtectionContainer))
44+
if (protectionContainer.Properties.GetType() == typeof(ServiceClientModel.MabContainer))
4945
{
5046
containerModel = new MabContainer(protectionContainer);
5147
}
5248
else if (protectionContainer.Properties.GetType() ==
53-
typeof(ServiceClientModel.AzureSqlProtectionContainer))
49+
typeof(ServiceClientModel.AzureSqlContainer))
5450
{
5551
containerModel = new AzureSqlContainer(protectionContainer);
5652
}
@@ -62,13 +58,22 @@ public static ContainerBase GetContainerModel(ServiceClientModel.ProtectionConta
6258
/// <summary>
6359
/// Helper function to convert ps backup engine model from service response.
6460
/// </summary>
65-
public static BackupEngineBase GetBackupEngineModel(ServiceClientModel.BackupEngineResource backupEngine)
61+
public static BackupEngineBase GetBackupEngineModel(
62+
ServiceClientModel.BackupEngineBaseResource backupEngine)
6663
{
6764
BackupEngineBase backupEngineModel = null;
6865

6966
if (backupEngine != null &&
7067
backupEngine.Properties != null)
7168
{
69+
string friendlyName = backupEngine.Properties.FriendlyName;
70+
string backupManagementType =
71+
backupEngine.Properties.BackupManagementType.ToString();
72+
string registrationStatus = backupEngine.Properties.RegistrationStatus;
73+
string healthStatus = backupEngine.Properties.HealthStatus;
74+
bool? canReRegister = backupEngine.Properties.CanReRegister;
75+
string backupEngineId = backupEngine.Properties.BackupEngineId;
76+
7277
if (backupEngine.Properties.GetType() == (typeof(ServiceClientModel.DpmBackupEngine)))
7378
{
7479
backupEngineModel = new DpmBackupEngine(backupEngine);
@@ -100,7 +105,8 @@ public static List<ContainerBase> GetContainerModelList(IEnumerable<ServiceClien
100105
/// <summary>
101106
/// Helper function to convert ps backup engine model list from service response.
102107
/// </summary>
103-
public static List<BackupEngineBase> GetBackupEngineModelList(IEnumerable<ServiceClientModel.BackupEngineResource> backupEngines)
108+
public static List<BackupEngineBase> GetBackupEngineModelList(
109+
IEnumerable<ServiceClientModel.BackupEngineBaseResource> backupEngines)
104110
{
105111
List<BackupEngineBase> backupEngineModel = new List<BackupEngineBase>();
106112

@@ -151,8 +157,8 @@ public static PolicyBase GetPolicyModel(ServiceClientModel.ProtectionPolicyResou
151157

152158
policyModel = new AzureVmPolicy();
153159
AzureVmPolicy iaasPolicyModel = policyModel as AzureVmPolicy;
154-
iaasPolicyModel.WorkloadType = Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.WorkloadType.AzureVM;
155-
iaasPolicyModel.BackupManagementType = Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.BackupManagementType.AzureVM;
160+
iaasPolicyModel.WorkloadType = WorkloadType.AzureVM;
161+
iaasPolicyModel.BackupManagementType = BackupManagementType.AzureVM;
156162
iaasPolicyModel.RetentionPolicy = PolicyHelpers.GetPSLongTermRetentionPolicy((ServiceClientModel.LongTermRetentionPolicy)
157163
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).RetentionPolicy);
158164
iaasPolicyModel.SchedulePolicy = PolicyHelpers.GetPSSimpleSchedulePolicy((ServiceClientModel.SimpleSchedulePolicy)
@@ -175,8 +181,8 @@ public static PolicyBase GetPolicyModel(ServiceClientModel.ProtectionPolicyResou
175181

176182
policyModel = new AzureSqlPolicy();
177183
AzureSqlPolicy sqlPolicyModel = policyModel as AzureSqlPolicy;
178-
sqlPolicyModel.WorkloadType = CmdletModels.WorkloadType.AzureSQLDatabase;
179-
sqlPolicyModel.BackupManagementType = CmdletModels.BackupManagementType.AzureSQL;
184+
sqlPolicyModel.WorkloadType = WorkloadType.AzureSQLDatabase;
185+
sqlPolicyModel.BackupManagementType = BackupManagementType.AzureSQL;
180186

181187
ServiceClientModel.SimpleRetentionPolicy azureSqlRetentionPolicy =
182188
(ServiceClientModel.SimpleRetentionPolicy)azureSqlPolicy.RetentionPolicy;
@@ -203,10 +209,9 @@ public static PolicyBase GetPolicyModel(ServiceClientModel.ProtectionPolicyResou
203209
/// Helper function to convert ps backup policy list model from service response.
204210
/// </summary>
205211
public static List<PolicyBase> GetPolicyModelList(
206-
ServiceClientModel.ProtectionPolicyListResponse serviceClientListResponse)
212+
List<ServiceClientModel.ProtectionPolicyResource> serviceClientListResponse)
207213
{
208-
if (serviceClientListResponse == null || serviceClientListResponse.ItemList == null ||
209-
serviceClientListResponse.ItemList.Value == null || serviceClientListResponse.ItemList.Value.Count == 0)
214+
if (serviceClientListResponse == null && serviceClientListResponse.Count == 0)
210215
{
211216
Logger.Instance.WriteDebug("Received empty list of policies from service");
212217
return null;
@@ -215,7 +220,8 @@ public static List<PolicyBase> GetPolicyModelList(
215220
List<PolicyBase> policyModels = new List<PolicyBase>();
216221
PolicyBase policyModel = null;
217222

218-
foreach (ServiceClientModel.ProtectionPolicyResource resource in serviceClientListResponse.ItemList.Value)
223+
foreach (ServiceClientModel.ProtectionPolicyResource resource
224+
in serviceClientListResponse)
219225
{
220226
policyModel = GetPolicyModel(resource);
221227
if (policyModel != null)
@@ -260,18 +266,18 @@ public static ItemBase GetItemModel(ServiceClientModel.ProtectedItemResource pro
260266
itemModel = new AzureVmItem(
261267
protectedItem,
262268
IdUtils.GetNameFromUri(containerUri),
263-
Cmdlets.Models.ContainerType.AzureVM,
269+
ContainerType.AzureVM,
264270
policyName);
265271
}
266272

267-
if (protectedItem.Properties.GetType() ==
273+
if (protectedItem.Properties.GetType() ==
268274
typeof(ServiceClientModel.AzureSqlProtectedItem))
269275
{
270276
ServiceClientModel.AzureSqlProtectedItem azureSqlProtectedItem =
271277
(ServiceClientModel.AzureSqlProtectedItem)protectedItem.Properties;
272278
string policyName = null;
273279
string policyId = azureSqlProtectedItem.PolicyId;
274-
if (!String.IsNullOrEmpty(policyId))
280+
if (!string.IsNullOrEmpty(policyId))
275281
{
276282
Dictionary<UriEnums, string> keyVauleDict =
277283
HelperUtils.ParseUri(policyId);
@@ -285,7 +291,7 @@ public static ItemBase GetItemModel(ServiceClientModel.ProtectedItemResource pro
285291
itemModel = new AzureSqlItem(
286292
protectedItem,
287293
IdUtils.GetNameFromUri(containerUri),
288-
Cmdlets.Models.ContainerType.AzureSQL,
294+
ContainerType.AzureSQL,
289295
policyName);
290296
}
291297
}

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

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,6 @@ public class JobConversions
2727
{
2828
#region ServiceClient to PS convertors
2929

30-
/// <summary>
31-
/// This function returns either job object or job details object based on
32-
/// what ServiceClient object contains.
33-
/// To elaborate, if ServiceClient job's ExtendedInfo is filled then this function will
34-
/// return a job details object. Otherwise it will return a job object.
35-
/// </summary>
36-
/// <param name="ServiceClientJob"></param>
37-
/// <returns></returns>
38-
public static CmdletModel.JobBase GetPSJob(JobResponse serviceClientJob)
39-
{
40-
return GetPSJob(serviceClientJob.Item);
41-
}
42-
4330
/// <summary>
4431
/// Helper function to convert ps backup job model from service response.
4532
/// </summary>
@@ -63,18 +50,26 @@ public static CmdletModel.JobBase GetPSJob(JobResource serviceClientJob)
6350
/// <summary>
6451
/// Helper function to convert ps backup job list model from service response.
6552
/// </summary>
66-
public static void AddServiceClientJobsToPSList(JobListResponse serviceClientJobs, List<CmdletModel.JobBase> psJobs, ref int jobsCount)
53+
public static void AddServiceClientJobsToPSList(
54+
List<JobResource> serviceClientJobs,
55+
List<CmdletModel.JobBase> psJobs,
56+
ref int jobsCount)
6757
{
68-
if (serviceClientJobs.ItemList != null && serviceClientJobs.ItemList.Value != null)
58+
if (serviceClientJobs != null)
6959
{
70-
foreach (var job in serviceClientJobs.ItemList.Value)
60+
foreach (var job in serviceClientJobs)
7161
{
7262
CmdletModel.JobBase convertedJob = GetPSJob(job);
7363
if (convertedJob != null)
7464
{
7565
jobsCount++;
7666
psJobs.Add(convertedJob);
7767
}
68+
else
69+
{
70+
Logger.Instance.WriteDebug(
71+
"Ignoring some of the unexpected job while conversion");
72+
}
7873
}
7974
}
8075
}
@@ -100,15 +95,24 @@ private static CmdletModel.AzureVmJob GetPSAzureVmJob(JobResource serviceClientJ
10095
}
10196

10297
response.JobId = GetLastIdFromFullId(serviceClientJob.Id);
103-
response.StartTime = vmJob.StartTime;
98+
DateTime startTime = DateTime.MinValue;
99+
if (vmJob.StartTime.HasValue)
100+
{
101+
response.StartTime = (DateTime)vmJob.StartTime;
102+
}
103+
else
104+
{
105+
throw new ArgumentNullException("Job Start Time is null");
106+
}
104107
response.EndTime = vmJob.EndTime;
105-
response.Duration = vmJob.Duration;
108+
response.Duration =
109+
vmJob.Duration.HasValue ? (TimeSpan)vmJob.Duration : default(TimeSpan);
106110
response.Status = vmJob.Status;
107111
response.VmVersion = vmJob.VirtualMachineVersion;
108112
response.WorkloadName = vmJob.EntityFriendlyName;
109113
response.ActivityId = vmJob.ActivityId;
110114
response.BackupManagementType = CmdletModel.EnumUtils.GetEnum<CmdletModel.BackupManagementType>(
111-
GetPSBackupManagementType(vmJob.BackupManagementType));
115+
GetPSBackupManagementType(vmJob.BackupManagementType.ToString()));
112116
response.Operation = vmJob.Operation;
113117

114118
if (vmJob.ErrorDetails != null)
@@ -159,7 +163,7 @@ private static CmdletModel.AzureVmJob GetPSAzureVmJob(JobResource serviceClientJ
159163
private static CmdletModel.AzureVmJobErrorInfo GetPSAzureVmErrorInfo(AzureIaaSVMErrorInfo serviceClientError)
160164
{
161165
CmdletModel.AzureVmJobErrorInfo psErrorInfo = new CmdletModel.AzureVmJobErrorInfo();
162-
psErrorInfo.ErrorCode = serviceClientError.ErrorCode;
166+
psErrorInfo.ErrorCode = serviceClientError.ErrorCode ?? default(int);
163167
psErrorInfo.ErrorMessage = serviceClientError.ErrorString;
164168
if (serviceClientError.Recommendations != null)
165169
{
@@ -189,12 +193,13 @@ public static string GetLastIdFromFullId(string fullId)
189193
/// <summary>
190194
/// Helper function to get job type from ps backup management type.
191195
/// </summary>
192-
public static string GetJobTypeForService(CmdletModel.BackupManagementType mgmtType)
196+
public static BackupManagementType GetJobTypeForService(
197+
CmdletModel.BackupManagementType mgmtType)
193198
{
194199
switch (mgmtType)
195200
{
196201
case CmdletModel.BackupManagementType.AzureVM:
197-
return BackupManagementType.AzureIaasVM.ToString();
202+
return BackupManagementType.AzureIaasVM;
198203
default:
199204
throw new Exception("Invalid BackupManagementType provided: " + mgmtType);
200205
}
@@ -214,7 +219,7 @@ public static string GetPSBackupManagementType(string jobType)
214219
throw new Exception("Invalid JobType provided: " + jobType);
215220
}
216221
}
217-
222+
218223
#endregion
219224
}
220225
}

0 commit comments

Comments
 (0)