Skip to content

Commit 49a9403

Browse files
Samuel Anudeepsiddharth7
authored andcommitted
Added FileShare support for Job cmdlets and get RPs
1 parent 2e63119 commit 49a9403

File tree

21 files changed

+743
-310
lines changed

21 files changed

+743
-310
lines changed

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

Lines changed: 124 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public static CmdletModel.JobBase GetPSJob(JobResource serviceClientJob)
4343
{
4444
response = GetPSAzureVmJob(serviceClientJob);
4545
}
46+
else if (serviceClientJob.Properties.GetType() == typeof(AzureStorageJob))
47+
{
48+
response = GetPSAzureFileShareJob(serviceClientJob);
49+
}
4650

4751
return response;
4852
}
@@ -95,29 +99,20 @@ private static CmdletModel.AzureVmJob GetPSAzureVmJob(JobResource serviceClientJ
9599
}
96100

97101
response.JobId = GetLastIdFromFullId(serviceClientJob.Id);
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-
}
102+
response.StartTime = GetJobStartTime(vmJob.StartTime);
107103
response.EndTime = vmJob.EndTime;
108-
response.Duration =
109-
vmJob.Duration.HasValue ? (TimeSpan)vmJob.Duration : default(TimeSpan);
104+
response.Duration = GetJobDuration(vmJob.Duration);
110105
response.Status = vmJob.Status;
111106
response.VmVersion = vmJob.VirtualMachineVersion;
112107
response.WorkloadName = vmJob.EntityFriendlyName;
113108
response.ActivityId = vmJob.ActivityId;
114-
response.BackupManagementType = CmdletModel.EnumUtils.GetEnum<CmdletModel.BackupManagementType>(
115-
GetPSBackupManagementType(vmJob.BackupManagementType.ToString()));
109+
response.BackupManagementType =
110+
CmdletModel.ConversionUtils.GetPsBackupManagementType(vmJob.BackupManagementType);
116111
response.Operation = vmJob.Operation;
117112

118113
if (vmJob.ErrorDetails != null)
119114
{
120-
response.ErrorDetails = new List<CmdletModel.AzureVmJobErrorInfo>();
115+
response.ErrorDetails = new List<CmdletModel.AzureJobErrorInfo>();
121116
foreach (var vmError in vmJob.ErrorDetails)
122117
{
123118
response.ErrorDetails.Add(GetPSAzureVmErrorInfo(vmError));
@@ -157,69 +152,146 @@ private static CmdletModel.AzureVmJob GetPSAzureVmJob(JobResource serviceClientJ
157152
return response;
158153
}
159154

160-
/// <summary>
161-
/// Helper function to convert ps azure vm backup job error info from service response.
162-
/// </summary>
163-
private static CmdletModel.AzureVmJobErrorInfo GetPSAzureVmErrorInfo(AzureIaaSVMErrorInfo serviceClientError)
155+
private static CmdletModel.JobBase GetPSAzureFileShareJob(JobResource serviceClientJob)
164156
{
165-
CmdletModel.AzureVmJobErrorInfo psErrorInfo = new CmdletModel.AzureVmJobErrorInfo();
166-
psErrorInfo.ErrorCode = serviceClientError.ErrorCode ?? default(int);
167-
psErrorInfo.ErrorMessage = serviceClientError.ErrorString;
168-
if (serviceClientError.Recommendations != null)
157+
CmdletModel.AzureFileShareJob response;
158+
159+
AzureStorageJob fileShareJob = serviceClientJob.Properties as AzureStorageJob;
160+
161+
if (fileShareJob.ExtendedInfo != null)
162+
{
163+
response = new CmdletModel.AzureFileShareJobDetails();
164+
}
165+
else
166+
{
167+
response = new CmdletModel.AzureFileShareJob();
168+
}
169+
170+
response.JobId = GetLastIdFromFullId(serviceClientJob.Id);
171+
response.StartTime = GetJobStartTime(fileShareJob.StartTime);
172+
response.EndTime = fileShareJob.EndTime;
173+
response.Duration = GetJobDuration(fileShareJob.Duration);
174+
response.Status = fileShareJob.Status;
175+
response.WorkloadName = fileShareJob.EntityFriendlyName;
176+
response.ActivityId = fileShareJob.ActivityId;
177+
response.BackupManagementType =
178+
CmdletModel.ConversionUtils.GetPsBackupManagementType(fileShareJob.BackupManagementType);
179+
response.Operation = fileShareJob.Operation;
180+
181+
if (fileShareJob.ErrorDetails != null)
182+
{
183+
response.ErrorDetails = new List<CmdletModel.AzureJobErrorInfo>();
184+
foreach (var fileShareError in fileShareJob.ErrorDetails)
185+
{
186+
response.ErrorDetails.Add(GetPSAzureFileShareErrorInfo(fileShareError));
187+
}
188+
}
189+
190+
// fill extended info if present
191+
if (fileShareJob.ExtendedInfo != null)
192+
{
193+
CmdletModel.AzureFileShareJobDetails detailedResponse =
194+
response as CmdletModel.AzureFileShareJobDetails;
195+
196+
detailedResponse.DynamicErrorMessage = fileShareJob.ExtendedInfo.DynamicErrorMessage;
197+
if (fileShareJob.ExtendedInfo.PropertyBag != null)
198+
{
199+
detailedResponse.Properties = new Dictionary<string, string>();
200+
foreach (var key in fileShareJob.ExtendedInfo.PropertyBag.Keys)
201+
{
202+
detailedResponse.Properties.Add(key, fileShareJob.ExtendedInfo.PropertyBag[key]);
203+
}
204+
}
205+
206+
if (fileShareJob.ExtendedInfo.TasksList != null)
207+
{
208+
detailedResponse.SubTasks = new List<CmdletModel.AzureFileShareJobSubTask>();
209+
foreach (var fileShareJobTask in fileShareJob.ExtendedInfo.TasksList)
210+
{
211+
detailedResponse.SubTasks.Add(new CmdletModel.AzureFileShareJobSubTask()
212+
{
213+
Name = fileShareJobTask.TaskId,
214+
Status = fileShareJobTask.Status
215+
});
216+
}
217+
}
218+
}
219+
220+
return response;
221+
}
222+
223+
private static CmdletModel.AzureJobErrorInfo GetPSAzureFileShareErrorInfo(AzureStorageErrorInfo fileShareError)
224+
{
225+
CmdletModel.AzureFileShareJobErrorInfo psErrorInfo = new CmdletModel.AzureFileShareJobErrorInfo();
226+
psErrorInfo.ErrorCode = GetJobErrorCode(fileShareError.ErrorCode);
227+
psErrorInfo.ErrorMessage = fileShareError.ErrorString;
228+
if (fileShareError.Recommendations != null)
169229
{
170230
psErrorInfo.Recommendations = new List<string>();
171-
psErrorInfo.Recommendations.AddRange(serviceClientError.Recommendations);
231+
psErrorInfo.Recommendations.AddRange(fileShareError.Recommendations);
172232
}
173233

174234
return psErrorInfo;
175235
}
176236

177-
/// <summary>
178-
/// Helper function to get last index value from full id.
179-
/// </summary>
180-
public static string GetLastIdFromFullId(string fullId)
237+
private static int GetJobErrorCode(int? errorCode)
181238
{
182-
string[] splitArr = fullId.Split("/".ToCharArray());
183-
return splitArr[splitArr.Length - 1];
239+
return errorCode ?? default(int);
184240
}
185241

186-
#endregion
187-
188-
#endregion
189-
190-
#region Enum translators
242+
private static TimeSpan GetJobDuration(TimeSpan? duration)
243+
{
244+
return duration.HasValue ? (TimeSpan)duration : default(TimeSpan);
245+
}
191246

247+
private static DateTime GetJobStartTime(DateTime? startTime)
248+
{
249+
if (startTime.HasValue)
250+
{
251+
return (DateTime)startTime;
252+
}
253+
else
254+
{
255+
throw new ArgumentNullException("Job Start Time is null");
256+
}
257+
}
192258

193259
/// <summary>
194-
/// Helper function to get job type from ps backup management type.
260+
/// Helper function to convert ps azure vm backup job error info from service response.
195261
/// </summary>
196-
public static string GetJobTypeForService(
197-
CmdletModel.BackupManagementType mgmtType)
262+
private static CmdletModel.AzureVmJobErrorInfo GetPSAzureVmErrorInfo(AzureIaaSVMErrorInfo serviceClientError)
198263
{
199-
switch (mgmtType)
264+
CmdletModel.AzureVmJobErrorInfo psErrorInfo = new CmdletModel.AzureVmJobErrorInfo();
265+
psErrorInfo.ErrorCode = GetJobErrorCode(serviceClientError.ErrorCode);
266+
psErrorInfo.ErrorMessage = serviceClientError.ErrorString;
267+
psErrorInfo.Recommendations = GetJobErrorRecommendations(serviceClientError.Recommendations);
268+
269+
return psErrorInfo;
270+
}
271+
272+
private static List<string> GetJobErrorRecommendations(IList<string> recommendations)
273+
{
274+
if (recommendations != null)
200275
{
201-
case CmdletModel.BackupManagementType.AzureVM:
202-
return BackupManagementType.AzureIaasVM.ToString();
203-
default:
204-
throw new Exception("Invalid BackupManagementType provided: " + mgmtType);
276+
var psRecommendations = new List<string>();
277+
psRecommendations.AddRange(recommendations);
278+
return psRecommendations;
205279
}
280+
281+
return null;
206282
}
207283

208284
/// <summary>
209-
/// Helper function to get ps backup management type from job type.
285+
/// Helper function to get last index value from full id.
210286
/// </summary>
211-
public static string GetPSBackupManagementType(string jobType)
287+
public static string GetLastIdFromFullId(string fullId)
212288
{
213-
if (jobType == BackupManagementType.AzureIaasVM.ToString())
214-
{
215-
return CmdletModel.BackupManagementType.AzureVM.ToString();
216-
}
217-
else
218-
{
219-
throw new Exception("Invalid JobType provided: " + jobType);
220-
}
289+
string[] splitArr = fullId.Split("/".ToCharArray());
290+
return splitArr[splitArr.Length - 1];
221291
}
222292

223293
#endregion
294+
295+
#endregion
224296
}
225297
}

0 commit comments

Comments
 (0)