Skip to content

Commit dedc459

Browse files
committed
Job support for mercury
1 parent 14d2239 commit dedc459

File tree

5 files changed

+214
-2
lines changed

5 files changed

+214
-2
lines changed

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

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public static CmdletModel.JobBase GetPSJob(JobResource serviceClientJob)
4747
{
4848
response = GetPSAzureFileShareJob(serviceClientJob);
4949
}
50+
else if (serviceClientJob.Properties.GetType() == typeof(AzureWorkloadJob))
51+
{
52+
response = GetPSAzureWorkloadJob(serviceClientJob);
53+
}
5054

5155
return response;
5256
}
@@ -234,6 +238,88 @@ private static CmdletModel.AzureJobErrorInfo GetPSAzureFileShareErrorInfo(AzureS
234238
return psErrorInfo;
235239
}
236240

241+
private static CmdletModel.JobBase GetPSAzureWorkloadJob(JobResource serviceClientJob)
242+
{
243+
CmdletModel.AzureVmWorkloadJob response;
244+
245+
AzureWorkloadJob workloadJob = serviceClientJob.Properties as AzureWorkloadJob;
246+
247+
if (workloadJob.ExtendedInfo != null)
248+
{
249+
response = new CmdletModel.AzureVmWorkloadJobDetails();
250+
}
251+
else
252+
{
253+
response = new CmdletModel.AzureVmWorkloadJob();
254+
}
255+
256+
response.JobId = GetLastIdFromFullId(serviceClientJob.Id);
257+
response.StartTime = GetJobStartTime(workloadJob.StartTime);
258+
response.EndTime = workloadJob.EndTime;
259+
response.Duration = GetJobDuration(workloadJob.Duration);
260+
response.Status = workloadJob.Status;
261+
response.WorkloadName = workloadJob.EntityFriendlyName;
262+
response.ActivityId = workloadJob.ActivityId;
263+
response.BackupManagementType =
264+
CmdletModel.ConversionUtils.GetPsBackupManagementType(workloadJob.BackupManagementType);
265+
response.Operation = workloadJob.Operation;
266+
267+
if (workloadJob.ErrorDetails != null)
268+
{
269+
response.ErrorDetails = new List<CmdletModel.AzureJobErrorInfo>();
270+
foreach (var workloadError in workloadJob.ErrorDetails)
271+
{
272+
response.ErrorDetails.Add(GetPSAzureWorkloadErrorInfo(workloadError));
273+
}
274+
}
275+
276+
// fill extended info if present
277+
if (workloadJob.ExtendedInfo != null)
278+
{
279+
CmdletModel.AzureVmWorkloadJobDetails detailedResponse =
280+
response as CmdletModel.AzureVmWorkloadJobDetails;
281+
282+
detailedResponse.DynamicErrorMessage = workloadJob.ExtendedInfo.DynamicErrorMessage;
283+
if (workloadJob.ExtendedInfo.PropertyBag != null)
284+
{
285+
detailedResponse.Properties = new Dictionary<string, string>();
286+
foreach (var key in workloadJob.ExtendedInfo.PropertyBag.Keys)
287+
{
288+
detailedResponse.Properties.Add(key, workloadJob.ExtendedInfo.PropertyBag[key]);
289+
}
290+
}
291+
292+
if (workloadJob.ExtendedInfo.TasksList != null)
293+
{
294+
detailedResponse.SubTasks = new List<CmdletModel.AzureVmWorkloadJobSubTask>();
295+
foreach (var workloadJobTask in workloadJob.ExtendedInfo.TasksList)
296+
{
297+
detailedResponse.SubTasks.Add(new CmdletModel.AzureVmWorkloadJobSubTask()
298+
{
299+
Name = workloadJobTask.TaskId,
300+
Status = workloadJobTask.Status
301+
});
302+
}
303+
}
304+
}
305+
306+
return response;
307+
}
308+
309+
private static CmdletModel.AzureJobErrorInfo GetPSAzureWorkloadErrorInfo(AzureWorkloadErrorInfo workloadError)
310+
{
311+
CmdletModel.AzureVmWorkloadJobErrorInfo psErrorInfo = new CmdletModel.AzureVmWorkloadJobErrorInfo();
312+
psErrorInfo.ErrorCode = GetJobErrorCode(workloadError.ErrorCode);
313+
psErrorInfo.ErrorMessage = workloadError.ErrorString;
314+
if (workloadError.Recommendations != null)
315+
{
316+
psErrorInfo.Recommendations = new List<string>();
317+
psErrorInfo.Recommendations.AddRange(workloadError.Recommendations);
318+
}
319+
320+
return psErrorInfo;
321+
}
322+
237323
private static int GetJobErrorCode(int? errorCode)
238324
{
239325
return errorCode ?? default(int);

src/RecoveryServices/RecoveryServices.Backup.Test/Commands.RecoveryServices.Backup.Test.csproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
<Compile Include="ScenarioTests\AzureFiles\JobTests.cs" />
5858
<Compile Include="ScenarioTests\AzureFiles\PolicyTests.cs" />
5959
<Compile Include="ScenarioTests\AzureFiles\ProtectionCheckTests.cs" />
60-
<Compile Include="ScenarioTests\AzureWorkload\PolicyTests.cs" />
60+
<Compile Include="ScenarioTests\AzureWorkload\JobTests.cs" />
61+
<Compile Include="ScenarioTests\AzureWorkload\PolicyTests.cs" />
6162
<Compile Include="ScenarioTests\IaasVm\ProtectionCheckTests.cs" />
6263
<Compile Include="TestConstants.cs" />
6364
<None Include="packages.config">
@@ -90,7 +91,10 @@
9091
<None Include="ScenarioTests\AzureSql\PolicyTests.ps1">
9192
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
9293
</None>
93-
<None Include="ScenarioTests\AzureWorkload\PolicyTests.ps1">
94+
<None Include="ScenarioTests\AzureWorkload\JobTests.ps1">
95+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
96+
</None>
97+
<None Include="ScenarioTests\AzureWorkload\PolicyTests.ps1">
9498
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
9599
</None>
96100
<None Include="ScenarioTests\Common.ps1">
Lines changed: 33 additions & 0 deletions
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 Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
16+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
18+
using Xunit;
19+
20+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Test.ScenarioTests
21+
{
22+
public partial class JobTests : RMTestBase
23+
{
24+
[Fact]
25+
[Trait(Category.AcceptanceType, Category.CheckIn)]
26+
[Trait(TestConstants.Workload, TestConstants.AzureVmWorkload)]
27+
public void TestAzureVmWorkloadGetJob()
28+
{
29+
TestController.NewInstance.RunPsTest(
30+
_logger, PsBackupProviderTypes.AzureWorkload, "Test-AzureVmWorkloadGetJob");
31+
}
32+
}
33+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
$location = "southeastasia"
16+
$resourceGroupName = "shracrgnew"
17+
$vaultName = "shracvault"
18+
19+
function Test-AzureVmWorkloadGetJob
20+
{
21+
try
22+
{
23+
$vault = Get-AzureRmRecoveryServicesVault -ResourceGroupName $resourceGroupName -Name $vaultName
24+
25+
$startDate1 = Get-QueryDateInUtc $((Get-Date).AddDays(-20)) "StartDate1"
26+
$endDate1 = Get-QueryDateInUtc $(Get-Date) "EndDate1"
27+
28+
$jobs = Get-AzureRmRecoveryServicesBackupJob -VaultId $vault.ID -BackupManagementType AzureWorkload -From $startDate1 -To $endDate1
29+
}
30+
finally
31+
{
32+
# Cleanup
33+
}
34+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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.Collections.Generic;
16+
17+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
18+
{
19+
/// <summary>
20+
/// Represents Azure Workload specific job class.
21+
/// </summary>
22+
public class AzureVmWorkloadJob : AzureJob { }
23+
24+
/// <summary>
25+
/// Azure Workload specific job details class.
26+
/// </summary>
27+
public class AzureVmWorkloadJobDetails : AzureVmWorkloadJob
28+
{
29+
/// <summary>
30+
/// Context sensitive error message that might be helpful in debugging the issue.
31+
/// Mostly this contains trace dumps from Workload.
32+
/// </summary>
33+
public string DynamicErrorMessage { get; set; }
34+
35+
/// <summary>
36+
/// Property bag consisting of the some Azure Workload specific job details.
37+
/// </summary>
38+
public Dictionary<string, string> Properties { get; set; }
39+
40+
/// <summary>
41+
/// List of sub tasks triggered as part of this job's operation.
42+
/// </summary>
43+
public List<AzureVmWorkloadJobSubTask> SubTasks { get; set; }
44+
}
45+
46+
/// <summary>
47+
/// Azure Workload specific job error info class.
48+
/// </summary>
49+
public class AzureVmWorkloadJobErrorInfo : AzureJobErrorInfo { }
50+
51+
/// <summary>
52+
/// Azure Workload specific job sub-task class.
53+
/// </summary>
54+
public class AzureVmWorkloadJobSubTask : AzureJobSubTask { }
55+
}

0 commit comments

Comments
 (0)