From 04d52b7e2e9b38c7a53a5207237e1e9a47e0acf9 Mon Sep 17 00:00:00 2001 From: Siddharth Singh Date: Thu, 29 Nov 2018 14:45:56 +0530 Subject: [PATCH] Job support for mercury --- .../Conversions/JobConversions.cs | 86 +++++++++++++++++++ .../AzureVmWorkloadJob.cs | 55 ++++++++++++ ...ands.RecoveryServices.Backup.Models.csproj | 1 + ...mmands.RecoveryServices.Backup.Test.csproj | 6 +- .../ScenarioTests/AzureWorkload/JobTests.cs | 33 +++++++ .../ScenarioTests/AzureWorkload/JobTests.ps1 | 34 ++++++++ .../TestConstants.cs | 2 + 7 files changed, 216 insertions(+), 1 deletion(-) create mode 100644 src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/AzureVmWorkloadModels/AzureVmWorkloadJob.cs create mode 100644 src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/ScenarioTests/AzureWorkload/JobTests.cs create mode 100644 src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/ScenarioTests/AzureWorkload/JobTests.ps1 diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Helpers/Conversions/JobConversions.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Helpers/Conversions/JobConversions.cs index b1e6c4c7f8a9..6eee80086d01 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Helpers/Conversions/JobConversions.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Helpers/Conversions/JobConversions.cs @@ -47,6 +47,10 @@ public static CmdletModel.JobBase GetPSJob(JobResource serviceClientJob) { response = GetPSAzureFileShareJob(serviceClientJob); } + else if (serviceClientJob.Properties.GetType() == typeof(AzureWorkloadJob)) + { + response = GetPSAzureWorkloadJob(serviceClientJob); + } return response; } @@ -234,6 +238,88 @@ private static CmdletModel.AzureJobErrorInfo GetPSAzureFileShareErrorInfo(AzureS return psErrorInfo; } + private static CmdletModel.JobBase GetPSAzureWorkloadJob(JobResource serviceClientJob) + { + CmdletModel.AzureVmWorkloadJob response; + + AzureWorkloadJob workloadJob = serviceClientJob.Properties as AzureWorkloadJob; + + if (workloadJob.ExtendedInfo != null) + { + response = new CmdletModel.AzureVmWorkloadJobDetails(); + } + else + { + response = new CmdletModel.AzureVmWorkloadJob(); + } + + response.JobId = GetLastIdFromFullId(serviceClientJob.Id); + response.StartTime = GetJobStartTime(workloadJob.StartTime); + response.EndTime = workloadJob.EndTime; + response.Duration = GetJobDuration(workloadJob.Duration); + response.Status = workloadJob.Status; + response.WorkloadName = workloadJob.EntityFriendlyName; + response.ActivityId = workloadJob.ActivityId; + response.BackupManagementType = + CmdletModel.ConversionUtils.GetPsBackupManagementType(workloadJob.BackupManagementType); + response.Operation = workloadJob.Operation; + + if (workloadJob.ErrorDetails != null) + { + response.ErrorDetails = new List(); + foreach (var workloadError in workloadJob.ErrorDetails) + { + response.ErrorDetails.Add(GetPSAzureWorkloadErrorInfo(workloadError)); + } + } + + // fill extended info if present + if (workloadJob.ExtendedInfo != null) + { + CmdletModel.AzureVmWorkloadJobDetails detailedResponse = + response as CmdletModel.AzureVmWorkloadJobDetails; + + detailedResponse.DynamicErrorMessage = workloadJob.ExtendedInfo.DynamicErrorMessage; + if (workloadJob.ExtendedInfo.PropertyBag != null) + { + detailedResponse.Properties = new Dictionary(); + foreach (var key in workloadJob.ExtendedInfo.PropertyBag.Keys) + { + detailedResponse.Properties.Add(key, workloadJob.ExtendedInfo.PropertyBag[key]); + } + } + + if (workloadJob.ExtendedInfo.TasksList != null) + { + detailedResponse.SubTasks = new List(); + foreach (var workloadJobTask in workloadJob.ExtendedInfo.TasksList) + { + detailedResponse.SubTasks.Add(new CmdletModel.AzureVmWorkloadJobSubTask() + { + Name = workloadJobTask.TaskId, + Status = workloadJobTask.Status + }); + } + } + } + + return response; + } + + private static CmdletModel.AzureJobErrorInfo GetPSAzureWorkloadErrorInfo(AzureWorkloadErrorInfo workloadError) + { + CmdletModel.AzureVmWorkloadJobErrorInfo psErrorInfo = new CmdletModel.AzureVmWorkloadJobErrorInfo(); + psErrorInfo.ErrorCode = GetJobErrorCode(workloadError.ErrorCode); + psErrorInfo.ErrorMessage = workloadError.ErrorString; + if (workloadError.Recommendations != null) + { + psErrorInfo.Recommendations = new List(); + psErrorInfo.Recommendations.AddRange(workloadError.Recommendations); + } + + return psErrorInfo; + } + private static int GetJobErrorCode(int? errorCode) { return errorCode ?? default(int); diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/AzureVmWorkloadModels/AzureVmWorkloadJob.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/AzureVmWorkloadModels/AzureVmWorkloadJob.cs new file mode 100644 index 000000000000..a8e3a4f2247c --- /dev/null +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/AzureVmWorkloadModels/AzureVmWorkloadJob.cs @@ -0,0 +1,55 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System.Collections.Generic; + +namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models +{ + /// + /// Represents Azure Workload specific job class. + /// + public class AzureVmWorkloadJob : AzureJob { } + + /// + /// Azure Workload specific job details class. + /// + public class AzureVmWorkloadJobDetails : AzureVmWorkloadJob + { + /// + /// Context sensitive error message that might be helpful in debugging the issue. + /// Mostly this contains trace dumps from Workload. + /// + public string DynamicErrorMessage { get; set; } + + /// + /// Property bag consisting of the some Azure Workload specific job details. + /// + public Dictionary Properties { get; set; } + + /// + /// List of sub tasks triggered as part of this job's operation. + /// + public List SubTasks { get; set; } + } + + /// + /// Azure Workload specific job error info class. + /// + public class AzureVmWorkloadJobErrorInfo : AzureJobErrorInfo { } + + /// + /// Azure Workload specific job sub-task class. + /// + public class AzureVmWorkloadJobSubTask : AzureJobSubTask { } +} diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/Commands.RecoveryServices.Backup.Models.csproj b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/Commands.RecoveryServices.Backup.Models.csproj index 685947393a89..a5e3a14e1357 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/Commands.RecoveryServices.Backup.Models.csproj +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/Commands.RecoveryServices.Backup.Models.csproj @@ -66,6 +66,7 @@ + diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/Commands.RecoveryServices.Backup.Test.csproj b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/Commands.RecoveryServices.Backup.Test.csproj index 3096e4a73b89..76403a1bd574 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/Commands.RecoveryServices.Backup.Test.csproj +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/Commands.RecoveryServices.Backup.Test.csproj @@ -1,4 +1,4 @@ - + @@ -57,6 +57,7 @@ + @@ -89,6 +90,9 @@ Always + + Always + Always diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/ScenarioTests/AzureWorkload/JobTests.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/ScenarioTests/AzureWorkload/JobTests.cs new file mode 100644 index 000000000000..db6fb26c2b20 --- /dev/null +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/ScenarioTests/AzureWorkload/JobTests.cs @@ -0,0 +1,33 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models; +using Microsoft.WindowsAzure.Commands.ScenarioTest; +using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; +using Xunit; + +namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Test.ScenarioTests +{ + public partial class JobTests : RMTestBase + { + [Fact] + [Trait(Category.AcceptanceType, Category.CheckIn)] + [Trait(TestConstants.Workload, TestConstants.AzureVmWorkload)] + public void TestAzureVmWorkloadGetJob() + { + TestController.NewInstance.RunPsTest( + _logger, PsBackupProviderTypes.AzureWorkload, "Test-AzureVmWorkloadGetJob"); + } + } +} diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/ScenarioTests/AzureWorkload/JobTests.ps1 b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/ScenarioTests/AzureWorkload/JobTests.ps1 new file mode 100644 index 000000000000..49d32278b7d1 --- /dev/null +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/ScenarioTests/AzureWorkload/JobTests.ps1 @@ -0,0 +1,34 @@ +# ---------------------------------------------------------------------------------- +# +# Copyright Microsoft Corporation +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ---------------------------------------------------------------------------------- + +$location = "southeastasia" +$resourceGroupName = "shracrgnew" +$vaultName = "shracvault" + +function Test-AzureVmWorkloadGetJob +{ + try + { + $vault = Get-AzureRmRecoveryServicesVault -ResourceGroupName $resourceGroupName -Name $vaultName + + $startDate1 = Get-QueryDateInUtc $((Get-Date).AddDays(-20)) "StartDate1" + $endDate1 = Get-QueryDateInUtc $(Get-Date) "EndDate1" + + $jobs = Get-AzureRmRecoveryServicesBackupJob -VaultId $vault.ID -BackupManagementType AzureWorkload -From $startDate1 -To $endDate1 + } + finally + { + # Cleanup + } +} \ No newline at end of file diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/TestConstants.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/TestConstants.cs index ed14871dd2d9..4dc07218666f 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/TestConstants.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/TestConstants.cs @@ -30,5 +30,7 @@ public class TestConstants public const string MAB = "MAB"; public const string AzureFS = "AzureFS"; + + public const string AzureVmWorkload = "AzureVmWorkload"; } }