Skip to content

Commit 8f8f3df

Browse files
authored
Adding support for fetching MAB agent jobs (#12308)
* Fetch MAB Agent jobs * Adding MabJob PS Object * Adding support for BackupManagemenType 'MAB' in Get-AzRecoveryServicesBackupJob cmdlet * updating help text and ChangeLog.md * removing new line as per review comment
1 parent f16ce88 commit 8f8f3df

File tree

6 files changed

+157
-3
lines changed

6 files changed

+157
-3
lines changed

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

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ public static CmdletModel.JobBase GetPSJob(JobResource serviceClientJob)
5151
{
5252
response = GetPSAzureWorkloadJob(serviceClientJob);
5353
}
54+
else if (serviceClientJob.Properties.GetType() == typeof(MabJob))
55+
{
56+
response = GetPSMabJob(serviceClientJob);
57+
}
5458

5559
return response;
5660
}
@@ -156,6 +160,90 @@ private static CmdletModel.AzureVmJob GetPSAzureVmJob(JobResource serviceClientJ
156160
return response;
157161
}
158162

163+
/// <summary>
164+
/// Creates the powershell MabJob object from service response.
165+
/// </summary>
166+
private static CmdletModel.JobBase GetPSMabJob(JobResource serviceClientJob)
167+
{
168+
CmdletModel.MabJob response;
169+
170+
MabJob mabJob = serviceClientJob.Properties as MabJob;
171+
172+
if (mabJob.ExtendedInfo != null)
173+
{
174+
response = new CmdletModel.MabJobDetails();
175+
}
176+
else
177+
{
178+
response = new CmdletModel.MabJob();
179+
}
180+
181+
// Transfer values from service job object to powershell job object.
182+
response.JobId = GetLastIdFromFullId(serviceClientJob.Id);
183+
response.StartTime = GetJobStartTime(mabJob.StartTime);
184+
response.EndTime = mabJob.EndTime;
185+
response.Duration = GetJobDuration(mabJob.Duration);
186+
response.Status = mabJob.Status;
187+
response.WorkloadName = mabJob.EntityFriendlyName;
188+
response.ActivityId = mabJob.ActivityId;
189+
response.BackupManagementType =
190+
CmdletModel.ConversionUtils.GetPsBackupManagementType(mabJob.BackupManagementType);
191+
response.Operation = mabJob.Operation;
192+
193+
if (mabJob.ErrorDetails != null)
194+
{
195+
response.ErrorDetails = new List<CmdletModel.AzureJobErrorInfo>();
196+
foreach (var mabError in mabJob.ErrorDetails)
197+
{
198+
response.ErrorDetails.Add(GetPSMabErrorInfo(mabError));
199+
}
200+
}
201+
202+
// fill extended info if present
203+
if (mabJob.ExtendedInfo != null)
204+
{
205+
CmdletModel.MabJobDetails detailedResponse = response as CmdletModel.MabJobDetails;
206+
207+
detailedResponse.DynamicErrorMessage = mabJob.ExtendedInfo.DynamicErrorMessage;
208+
if (mabJob.ExtendedInfo.PropertyBag != null)
209+
{
210+
detailedResponse.Properties = new Dictionary<string, string>();
211+
foreach (var key in mabJob.ExtendedInfo.PropertyBag.Keys)
212+
{
213+
detailedResponse.Properties.Add(key, mabJob.ExtendedInfo.PropertyBag[key]);
214+
}
215+
}
216+
217+
if (mabJob.ExtendedInfo.TasksList != null)
218+
{
219+
detailedResponse.SubTasks = new List<CmdletModel.MabJobSubTask>();
220+
foreach (var mabJobTask in mabJob.ExtendedInfo.TasksList)
221+
{
222+
detailedResponse.SubTasks.Add(new CmdletModel.MabJobSubTask()
223+
{
224+
Name = mabJobTask.TaskId,
225+
Status = mabJobTask.Status
226+
});
227+
}
228+
}
229+
}
230+
231+
return response;
232+
}
233+
234+
private static CmdletModel.AzureJobErrorInfo GetPSMabErrorInfo(MabErrorInfo mabError)
235+
{
236+
CmdletModel.MabJobErrorInfo psErrorInfo = new CmdletModel.MabJobErrorInfo();
237+
psErrorInfo.ErrorMessage = mabError.ErrorString;
238+
if (mabError.Recommendations != null)
239+
{
240+
psErrorInfo.Recommendations = new List<string>();
241+
psErrorInfo.Recommendations.AddRange(mabError.Recommendations);
242+
}
243+
244+
return psErrorInfo;
245+
}
246+
159247
private static CmdletModel.JobBase GetPSAzureFileShareJob(JobResource serviceClientJob)
160248
{
161249
CmdletModel.AzureFileShareJob response;

src/RecoveryServices/RecoveryServices.Backup.Helpers/ServiceClientHelpers.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ public static string
110110
case CmdletModel.BackupManagementType.AzureStorage:
111111
providerType = ServiceClientModel.BackupManagementType.AzureStorage.ToString();
112112
break;
113+
case CmdletModel.BackupManagementType.MAB:
114+
providerType = ServiceClientModel.BackupManagementType.MAB.ToString();
115+
break;
113116
default:
114117
break;
115118
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 MAB specific job class.
21+
/// </summary>
22+
public class MabJob : AzureJob { }
23+
24+
/// <summary>
25+
/// MAB specific job details class.
26+
/// </summary>
27+
public class MabJobDetails : MabJob
28+
{
29+
/// <summary>
30+
/// Context sensitive error message that might be helpful in debugging the issue.
31+
/// </summary>
32+
public string DynamicErrorMessage { get; set; }
33+
34+
/// <summary>
35+
/// Property bag consisting of the some MAB specific job details.
36+
/// </summary>
37+
public Dictionary<string, string> Properties { get; set; }
38+
39+
/// <summary>
40+
/// List of sub tasks triggered as part of this job's operation.
41+
/// </summary>
42+
public List<MabJobSubTask> SubTasks { get; set; }
43+
}
44+
45+
/// <summary>
46+
/// MAB specific job error info class.
47+
/// </summary>
48+
public class MabJobErrorInfo : AzureJobErrorInfo { }
49+
50+
/// <summary>
51+
/// MAB specific job sub-task class.
52+
/// </summary>
53+
public class MabJobSubTask : AzureJobSubTask { }
54+
}

src/RecoveryServices/RecoveryServices.Backup/Cmdlets/Jobs/GetAzureRmRecoveryServicesBackupJob.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class GetAzureRmRecoveryServicesBackupJob : RSBackupVaultCmdletBase
3232
/// <summary>
3333
/// List of supported BackupManagementTypes for this cmdlet. Used in help text creation.
3434
/// </summary>
35-
private const string validBackupManagementTypes = "AzureVM, AzureStorage, AzureWorkload";
35+
private const string validBackupManagementTypes = "AzureVM, AzureStorage, AzureWorkload, MAB";
3636

3737
/// <summary>
3838
/// Filter value for status of job.

src/RecoveryServices/RecoveryServices/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020
## Upcoming Release
2121
* Azure Backup tuned cmdlets help text to be more accurate.
22+
* Azure Backup added support for fetching MAB agent jobs using `Get-AzRecoveryServicesBackupJob` cmdlet.
2223

2324
## Version 2.10.0
2425
* Azure Backup added support for fetching MAB items.

src/RecoveryServices/RecoveryServices/help/Get-AzRecoveryServicesBackupJob.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,25 @@ This script polls the first job that is currently in progress until the job has
7777

7878
Note: You can use **Wait-AzRecoveryServicesBackupJob** cmdlet to wait for an Azure Backup job to finish instead of While loop.
7979

80+
### Example 4: Get all AzureVM jobs in last 2 days which finished successfully
81+
82+
```powershell
83+
$vault = Get-AzRecoveryServicesVault -ResourceGroupName "resourceGroup" -Name "vaultName"
84+
$Jobs = Get-AzRecoveryServicesBackupJob -VaultId $vault.ID -Status Completed -From (Get-Date).AddDays(-2).ToUniversalTime() -BackupManagementType AzureVM
85+
```
86+
First cmdlet fetches the vault object. Second cmdlet stores all the AzureVM jobs in the given vault which completed in last 2 days to $jobs. Change the value of BackupManagementType parameter to MAB in order to fetch MAB agent jobs.
87+
8088
## PARAMETERS
8189

8290
### -BackupManagementType
8391

84-
The class of resources being protected. Currently the values supported for this cmdlet are AzureVM, AzureStorage, AzureWorkload.
92+
The class of resources being protected. Currently the values supported for this cmdlet are AzureVM, AzureStorage, AzureWorkload, MAB.
8593

8694
```yaml
8795
Type: System.Nullable`1[Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.BackupManagementType]
8896
Parameter Sets: (All)
8997
Aliases:
90-
Accepted values: AzureVM, AzureStorage, AzureWorkload
98+
Accepted values: AzureVM, AzureStorage, AzureWorkload, MAB
9199

92100
Required: False
93101
Position: Named

0 commit comments

Comments
 (0)