Skip to content

Commit 9f574e8

Browse files
committed
Incorporating changes from comments of PR
1 parent 19a914e commit 9f574e8

File tree

7 files changed

+105
-40
lines changed

7 files changed

+105
-40
lines changed

src/ResourceManager/RecoveryServices.Backup/CmdletWarningAndErrorMessages.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System.Management.Automation;
1818
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
1919
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
20+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
2021

2122
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
2223
{
@@ -79,11 +80,11 @@ public override void ExecuteCmdlet()
7980
// validate filters
8081
if (rangeEnd <= rangeStart)
8182
{
82-
throw new Exception(CmdletWarningAndErrorMessages.Job.ToShouldBeGreaterThanFrom);
83+
throw new Exception(Resources.JobToShouldBeGreaterThanFrom);
8384
}
8485
else if (rangeEnd.Subtract(rangeStart) > TimeSpan.FromDays(30))
8586
{
86-
throw new Exception(CmdletWarningAndErrorMessages.Job.AllowedDateTimeRangeExceeded);
87+
throw new Exception(Resources.JobAllowedDateTimeRangeExceeded);
8788
}
8889

8990
// validate JobId and Job objects
@@ -92,7 +93,7 @@ public override void ExecuteCmdlet()
9293
// if JobId and Job are provided together and they don't match then throw exception
9394
if (Job != null && JobId != Job.InstanceId)
9495
{
95-
throw new Exception(CmdletWarningAndErrorMessages.Job.JobIdAndJobMismatch);
96+
throw new Exception(Resources.JobJobIdAndJobMismatch);
9697
}
9798
}
9899
else if (Job != null)
@@ -115,7 +116,7 @@ public override void ExecuteCmdlet()
115116
if (resultCount >= JobConstants.MaximumJobsToFetch)
116117
{
117118
// trace a warning that there are more jobs and user has to refine filters.
118-
WriteWarning(CmdletWarningAndErrorMessages.Job.RefineFilters);
119+
WriteWarning(Resources.JobRefineFilters);
119120
break;
120121
}
121122

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System.Management.Automation;
1818
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
1919
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
20+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
2021

2122
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
2223
{
@@ -57,7 +58,7 @@ public override void ExecuteCmdlet()
5758
else
5859
{
5960
// not a valid object. throw exception.
60-
throw new Exception(CmdletWarningAndErrorMessages.Job.WaitJobInvalidInput + Job.GetType().FullName);
61+
throw new Exception(string.Format(Resources.JobWaitJobInvalidInput, Job.GetType().FullName));
6162
}
6263

6364
// now wait until timeout happens or all jobs complete execution

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
<Compile Include="Cmdlets\ProtectionPolicy\PolicyCmdletHelpers.cs" />
8282
<Compile Include="Cmdlets\ProtectionPolicy\SetAzureRmRecoveryServicesPolicy.cs" />
8383
<Compile Include="Cmdlets\ProtectionPolicy\NewAzureRmRecoveryServicesPolicy.cs" />
84-
<Compile Include="CmdletWarningAndErrorMessages.cs" />
8584
<Compile Include="Constants.cs" />
8685
<Compile Include="Cmdlets\RecoveryPoint\GetAzureRMRecoveryServicesRecoveryPoint.cs" />
8786
<Compile Include="Cmdlets\Restore\RestoreAzureRMRecoveryServicesBackupItem.cs" />

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/Properties/Resources.Designer.cs

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/Properties/Resources.resx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,19 @@
264264
<data name="UpdateToNewAzurePowershellWarning" xml:space="preserve">
265265
<value>Data truncated. Please upgrade to latest version of Azure Powershell</value>
266266
</data>
267+
<data name="JobAllowedDateTimeRangeExceeded" xml:space="preserve">
268+
<value>To filter should not be more than 30 days away from From filter.</value>
269+
</data>
270+
<data name="JobJobIdAndJobMismatch" xml:space="preserve">
271+
<value>JobID and Job object provided don't match each other.</value>
272+
</data>
273+
<data name="JobRefineFilters" xml:space="preserve">
274+
<value>There are more than 1000 jobs for the filter combination you have provided. Kindly refine your filters to fetch the job you want.</value>
275+
</data>
276+
<data name="JobToShouldBeGreaterThanFrom" xml:space="preserve">
277+
<value>To filter should not be less than From filter.</value>
278+
</data>
279+
<data name="JobWaitJobInvalidInput" xml:space="preserve">
280+
<value>Please pass Job or List of Jobs as input. Your input is of type: {0}</value>
281+
</data>
267282
</root>

src/ResourceManager/RecoveryServices.Backup/RecoveryServicesBackupCmdletBase.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
using System.Text;
2727
using System.Threading.Tasks;
2828
using HydraAdapterNS = Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.HydraAdapter;
29+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
30+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
31+
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
32+
using System.Threading;
2933

3034
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
3135
{
@@ -34,6 +38,9 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
3438
/// </summary>
3539
public abstract class RecoveryServicesBackupCmdletBase : AzureRMCmdlet
3640
{
41+
// in seconds
42+
private int _defaultSleepForOperationTracking = 15;
43+
3744
protected HydraAdapterNS.HydraAdapter HydraAdapter { get; set; }
3845

3946
protected void InitializeAzureBackupCmdlet()
@@ -119,5 +126,36 @@ public override void ExecuteCmdlet()
119126

120127
InitializeAzureBackupCmdlet();
121128
}
129+
130+
public AzureRmRecoveryServicesJobBase GetJobObject(string jobId)
131+
{
132+
return JobConversions.GetPSJob(HydraAdapter.GetJob(jobId));
133+
}
134+
135+
public List<AzureRmRecoveryServicesJobBase> GetJobObject(List<string> jobIds)
136+
{
137+
List<AzureRmRecoveryServicesJobBase> result = new List<AzureRmRecoveryServicesJobBase>();
138+
foreach (string jobId in jobIds)
139+
{
140+
result.Add(GetJobObject(jobId));
141+
}
142+
return result;
143+
}
144+
145+
public BackUpOperationStatusResponse WaitForOperation(string url)
146+
{
147+
// using this directly because it doesn't matter which function we use.
148+
// return type is same and currently we are using it in only two places.
149+
// protected item and policy.
150+
BackUpOperationStatusResponse response = HydraAdapter.GetProtectedItemOperationStatusByURL(url);
151+
152+
while (response.OperationStatus.Status == OperationStatusValues.InProgress.ToString())
153+
{
154+
Thread.Sleep(_defaultSleepForOperationTracking * 1000);
155+
response = HydraAdapter.GetProtectedItemOperationStatusByURL(url);
156+
}
157+
158+
return response;
159+
}
122160
}
123161
}

0 commit comments

Comments
 (0)