Skip to content

Commit ec7e6fd

Browse files
committed
Incorporated changes suggested by comments
1 parent 53874be commit ec7e6fd

File tree

10 files changed

+121
-41
lines changed

10 files changed

+121
-41
lines changed

src/ResourceManager/RecoveryServices.Backup/Cmdlets/Jobs/GetAzureRmRecoveryServicesJob.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ public class GetAzureRmRecoveryServicesJob : RecoveryServicesBackupCmdletBase
4747

4848
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Job.BackupManagementTypeFilter)]
4949
[ValidateNotNullOrEmpty]
50-
public string BackupManagementType { get; set; }
50+
public BackupManagementType BackupManagementType { get; set; }
5151

5252
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Job.OperationFilter)]
5353
[ValidateNotNullOrEmpty]
54-
public string Operation { get; set; }
54+
public JobOperation Operation { get; set; }
5555

5656
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Job.StatusFilter)]
5757
[ValidateNotNullOrEmpty]
58-
public string Status { get; set; }
58+
public JobStatus Status { get; set; }
5959

6060
public override void ExecuteCmdlet()
6161
{
@@ -104,8 +104,8 @@ public override void ExecuteCmdlet()
104104
// TODO: Initialize Vault object from base cmdlet once support is added
105105
List<AzureRmRecoveryServicesJobBase> result = new List<AzureRmRecoveryServicesJobBase>();
106106
int resultCount = 0;
107-
var adapterResponse = HydraAdapter.GetJobs(Vault.ResouceGroupName, Vault.Name, JobId, Status, Operation, rangeStart, rangeEnd,
108-
BackupManagementType);
107+
var adapterResponse = HydraAdapter.GetJobs(Vault.ResouceGroupName, Vault.Name, JobId, Status.ToString(), Operation.ToString(), rangeStart, rangeEnd,
108+
BackupManagementType.ToString());
109109
JobConversions.AddHydraJobsToPSList(adapterResponse, result, ref resultCount);
110110

111111
while (!string.IsNullOrEmpty(adapterResponse.ItemList.NextLink))
@@ -121,8 +121,8 @@ public override void ExecuteCmdlet()
121121
HydraHelpers.GetSkipTokenFromNextLink(adapterResponse.ItemList.NextLink, out skipToken);
122122
if (skipToken != null)
123123
{
124-
adapterResponse = HydraAdapter.GetJobs(Vault.ResouceGroupName, Vault.Name, JobId, Status, Operation,
125-
rangeStart, rangeEnd, BackupManagementType, null, skipToken);
124+
adapterResponse = HydraAdapter.GetJobs(Vault.ResouceGroupName, Vault.Name, JobId, Status.ToString(), Operation.ToString(),
125+
rangeStart, rangeEnd, BackupManagementType.ToString(), null, skipToken);
126126
JobConversions.AddHydraJobsToPSList(adapterResponse, result, ref resultCount);
127127
}
128128
else

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<Compile Include="Cmdlets\Container\GetAzureRmRecoveryServicesContainer.cs" />
7272
<Compile Include="Cmdlets\Jobs\GetAzureRmRecoveryServicesJob.cs" />
7373
<Compile Include="Cmdlets\Jobs\GetAzureRmRecoveryServicesJobDetails.cs" />
74+
<Compile Include="Cmdlets\Jobs\WaitAzureRmRecoveryServicesJob.cs" />
7475
<Compile Include="Cmdlets\ProtectionPolicy\GetAzureRmRecoveryServicesPolicy.cs" />
7576
<Compile Include="Cmdlets\ProtectionPolicy\GetAzureRMBackupSchedulePolicyObject.cs" />
7677
<Compile Include="Cmdlets\ProtectionPolicy\GetAzureRMBackupRetentionPolicyObject.cs" />

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ public static AzureRmRecoveryServicesJobBase GetPSJob(JobResource hydraJob)
3939
{
4040
AzureRmRecoveryServicesJobBase response = null;
4141

42-
if (hydraJob.Properties.GetType() == typeof(AzureIaaSVMJob))
42+
// hydra doesn't initialize Properties if the type of job is not known to current version of hydra.
43+
if (hydraJob.Properties == null)
44+
{
45+
// unsupported job type.
46+
}
47+
else if (hydraJob.Properties.GetType() == typeof(AzureIaaSVMJob))
4348
{
4449
response = GetPSAzureVmJob(hydraJob);
4550
}
@@ -53,8 +58,12 @@ public static void AddHydraJobsToPSList(JobListResponse hydraJobs, List<AzureRmR
5358
{
5459
foreach (var job in hydraJobs.ItemList.Value)
5560
{
56-
jobsCount++;
57-
psJobs.Add(GetPSJob(job));
61+
AzureRmRecoveryServicesJobBase convertedJob = GetPSJob(job);
62+
if (convertedJob != null)
63+
{
64+
jobsCount++;
65+
psJobs.Add(convertedJob);
66+
}
5867
}
5968
}
6069
}

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

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

15-
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
16-
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
1715
using System;
18-
using System.Collections.Generic;
19-
using System.Linq;
20-
using System.Text;
21-
using System.Threading.Tasks;
22-
using System.Globalization;
23-
using System.Web;
2416
using System.Collections.Specialized;
17+
using System.Web;
18+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
19+
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
2520

2621
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers
2722
{
@@ -64,15 +59,6 @@ public static string GetHydraProviderType(WorkloadType workloadType)
6459
return providerType;
6560
}
6661

67-
public static string GetDateTimeStringForService(DateTime date)
68-
{
69-
// our service expects date time to be serialized in the following format
70-
// we have to use english culture because our user might be running
71-
// PS in another culture and our service can't understand it.
72-
DateTimeFormatInfo dateFormat = new CultureInfo("en-US").DateTimeFormat;
73-
return date.ToString("yyyy-MM-dd hh:mm:ss tt", dateFormat);
74-
}
75-
7662
public static void GetSkipTokenFromNextLink(string url, out string nextLink)
7763
{
7864
Uri uriObj = new Uri(url);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ public CommonJobQueryFilters GetQueryObject(
125125
CommonJobQueryFilters commonFilters = new CommonJobQueryFilters()
126126
{
127127
BackupManagementType = backupManagementType,
128-
StartTime = HydraHelpers.GetDateTimeStringForService(startTime),
129-
EndTime = HydraHelpers.GetDateTimeStringForService(endTime),
128+
StartTime = CommonHelpers.GetDateTimeStringForService(startTime),
129+
EndTime = CommonHelpers.GetDateTimeStringForService(endTime),
130130
JobId = jobId,
131131
Status = status,
132132
Operation = operation

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,13 @@
6464
<Compile Include="BMSAPIs\ContainerAPIs.cs" />
6565
<Compile Include="ClientProxy.cs" />
6666
<Compile Include="ClientProxyBase.cs" />
67+
<Compile Include="CommonHelpers.cs" />
6768
<Compile Include="HydraAdapter.cs" />
6869
<Compile Include="Properties\AssemblyInfo.cs" />
6970
</ItemGroup>
7071
<ItemGroup>
7172
<Content Include="Resources\Microsoft.Azure.Management.RecoveryServicesBackupManagement.dll" />
7273
</ItemGroup>
73-
<ItemGroup>
74-
<ProjectReference Include="..\Commands.RecoveryServices.Backup.Helpers\Commands.RecoveryServices.Backup.Helpers.csproj">
75-
<Project>{0e1d3f36-e6c8-4764-8c7d-6f9ee537490c}</Project>
76-
<Name>Commands.RecoveryServices.Backup.Helpers</Name>
77-
</ProjectReference>
78-
</ItemGroup>
7974
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
8075
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
8176
Other similar extension points exist, see Microsoft.Common.targets.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 System;
16+
using System.Globalization;
17+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
18+
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
19+
20+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.HydraAdapter
21+
{
22+
public class CommonHelpers
23+
{
24+
public static string GetDateTimeStringForService(DateTime date)
25+
{
26+
// our service expects date time to be serialized in the following format
27+
// we have to use english culture because our user might be running
28+
// PS in another culture and our service can't understand it.
29+
DateTimeFormatInfo dateFormat = new CultureInfo("en-US").DateTimeFormat;
30+
return date.ToString("yyyy-MM-dd hh:mm:ss tt", dateFormat);
31+
}
32+
}
33+
}

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

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

15-
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
1615
using System;
1716
using System.Collections.Generic;
18-
using System.Linq;
19-
using System.Text;
20-
using System.Threading.Tasks;
17+
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
2118

2219
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
2320
{
@@ -29,6 +26,43 @@ public virtual void Validate()
2926
}
3027
}
3128

29+
public class AzureRmRecoveryServicesVaultContext : AzureRmRecoveryServicesObjectBase
30+
{
31+
/// <summary>
32+
/// Name of the resource.
33+
/// </summary>
34+
public string ResourceName { get; set; }
35+
36+
/// <summary>
37+
/// Name of resource group to which this resource belongs
38+
/// </summary>
39+
public string ResourceGroupName { get; set; }
40+
41+
/// <summary>
42+
/// Location of the resource
43+
/// </summary>
44+
public string Location { get; set; }
45+
46+
public AzureRmRecoveryServicesVaultContext()
47+
{
48+
}
49+
50+
public AzureRmRecoveryServicesVaultContext(
51+
string resourceName,
52+
string resourceGroupName,
53+
string location)
54+
{
55+
this.ResourceGroupName = resourceGroupName;
56+
this.ResourceName = ResourceName;
57+
this.Location = location;
58+
}
59+
60+
public override void Validate()
61+
{
62+
base.Validate();
63+
}
64+
}
65+
3266
/// <summary>
3367
/// Represents Recovery Services Vault Credentials Class
3468
/// </summary>
@@ -177,7 +211,7 @@ public override void Validate()
177211
}
178212
}
179213

180-
public class AzureRmRecoveryServicesJobBase : AzureRmRecoveryServicesObjectBase
214+
public class AzureRmRecoveryServicesJobBase : AzureRmRecoveryServicesVaultContext
181215
{
182216
public string ActivityId { get; set; }
183217

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,27 @@ public enum RetentionScheduleFormat
9797
Invalid = 0,
9898
Daily = 1,
9999
Weekly = 2
100-
}
100+
}
101+
102+
public enum JobOperation
103+
{
104+
Invalid = 0,
105+
Backup,
106+
Restore,
107+
ConfigureBackup,
108+
RemoveBackup
109+
}
110+
111+
public enum JobStatus
112+
{
113+
Invalid = 0,
114+
InProgress,
115+
Cancelling,
116+
Cancelled,
117+
Completed,
118+
CompletedWithWarnings,
119+
Failed
120+
}
101121

102122
#endregion
103123

src/ResourceManager/RecoveryServices.Backup/RecoveryServicesBackupCmdletBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,7 @@ private void HandleException(Exception exception)
110110
WriteError(errorRecord);
111111
}
112112
}
113+
114+
113115
}
114116
}

0 commit comments

Comments
 (0)