Skip to content

Commit

Permalink
Job support for mercury
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharth7 committed Nov 29, 2018
1 parent ea3c132 commit 04d52b7
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<CmdletModel.AzureJobErrorInfo>();
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<string, string>();
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<CmdletModel.AzureVmWorkloadJobSubTask>();
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<string>();
psErrorInfo.Recommendations.AddRange(workloadError.Recommendations);
}

return psErrorInfo;
}

private static int GetJobErrorCode(int? errorCode)
{
return errorCode ?? default(int);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Represents Azure Workload specific job class.
/// </summary>
public class AzureVmWorkloadJob : AzureJob { }

/// <summary>
/// Azure Workload specific job details class.
/// </summary>
public class AzureVmWorkloadJobDetails : AzureVmWorkloadJob
{
/// <summary>
/// Context sensitive error message that might be helpful in debugging the issue.
/// Mostly this contains trace dumps from Workload.
/// </summary>
public string DynamicErrorMessage { get; set; }

/// <summary>
/// Property bag consisting of the some Azure Workload specific job details.
/// </summary>
public Dictionary<string, string> Properties { get; set; }

/// <summary>
/// List of sub tasks triggered as part of this job's operation.
/// </summary>
public List<AzureVmWorkloadJobSubTask> SubTasks { get; set; }
}

/// <summary>
/// Azure Workload specific job error info class.
/// </summary>
public class AzureVmWorkloadJobErrorInfo : AzureJobErrorInfo { }

/// <summary>
/// Azure Workload specific job sub-task class.
/// </summary>
public class AzureVmWorkloadJobSubTask : AzureJobSubTask { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<Compile Include="AzureVmModels\AzureVmRPMountScriptDetails.cs" />
<Compile Include="AzureVmModels\KeyAndSecretDetails.cs" />
<Compile Include="AzureVmModels\AzureVmRecoveryPoint.cs" />
<Compile Include="AzureVmWorkloadModels\AzureVmWorkloadJob.cs" />
<Compile Include="BaseObjects.cs" />
<Compile Include="CmdletParamEnums.cs" />
<Compile Include="CommonModels\ResourceBackupStatus.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\..\..\tools\Common.Dependencies.Test.targets" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
Expand Down Expand Up @@ -57,6 +57,7 @@
<Compile Include="ScenarioTests\AzureFiles\JobTests.cs" />
<Compile Include="ScenarioTests\AzureFiles\PolicyTests.cs" />
<Compile Include="ScenarioTests\AzureFiles\ProtectionCheckTests.cs" />
<Compile Include="ScenarioTests\AzureWorkload\JobTests.cs" />
<Compile Include="ScenarioTests\IaasVm\ProtectionCheckTests.cs" />
<Compile Include="TestConstants.cs" />
<None Include="packages.config">
Expand Down Expand Up @@ -89,6 +90,9 @@
<None Include="ScenarioTests\AzureSql\PolicyTests.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="ScenarioTests\AzureWorkload\JobTests.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="ScenarioTests\Common.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ public class TestConstants
public const string MAB = "MAB";

public const string AzureFS = "AzureFS";

public const string AzureVmWorkload = "AzureVmWorkload";
}
}

0 comments on commit 04d52b7

Please sign in to comment.