Skip to content

Commit e658bfe

Browse files
committed
merge from dev
2 parents 1dc7a71 + 4efcae1 commit e658bfe

File tree

19 files changed

+944
-22
lines changed

19 files changed

+944
-22
lines changed

src/ResourceManager/AzureBackup/Commands.AzureBackup.Test/Commands.AzureBackup.Test.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,12 @@
155155
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
156156
</None>
157157
<None Include="SessionRecords\Microsoft.Azure.Commands.AzureBackup.Test.ScenarioTests.AzureBackupTests\BackUpAzureBackUpItem.json" />
158+
<None Include="SessionRecords\Microsoft.Azure.Commands.AzureBackup.Test.ScenarioTests.AzureBackupTests\GetAzureBackupJobTests.json" />
158159
<None Include="SessionRecords\Microsoft.Azure.Commands.AzureBackup.Test.ScenarioTests.AzureBackupTests\GetRecoveryPointTests.json" />
159160
<None Include="SessionRecords\Microsoft.Azure.Commands.AzureBackup.Test.ScenarioTests.AzureBackupTests\ListProtectionPolicyTests.json">
160161
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
161162
</None>
163+
<None Include="SessionRecords\Microsoft.Azure.Commands.AzureBackup.Test.ScenarioTests.AzureBackupTests\StopAzureBackupJobTests.json" />
162164
</ItemGroup>
163165
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
164166
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />

src/ResourceManager/AzureBackup/Commands.AzureBackup.Test/ScenarioTests/AzureBackupTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ public void EnableDisableAzureBackupProtectionTest()
3838
}
3939

4040
[Fact]
41+
42+
public void GetAzureBackupJobTests()
43+
{
44+
this.RunPowerShellTest("Test-GetAzureBackupJob");
45+
}
46+
47+
[Fact]
48+
public void StopAzureBackupJobTests()
49+
{
50+
this.RunPowerShellTest("Test-StopAzureBackupJob");
51+
}
4152
public void GetRecoveryPointTests()
4253
{
4354
this.RunPowerShellTest("GetAzureRecoveryPointTest");

src/ResourceManager/AzureBackup/Commands.AzureBackup.Test/ScenarioTests/AzureBackupTests.ps1

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Tests creating new resource group and a simple resource.
2929
#>
3030
function Test-GetAzureBackupProtectionPolicyTests
3131
{
32-
$protectionPolicies = Get-AzureBackupProtectionPolicy -ResourceGroupName $ResourceGroupName -ResourceName $ResourceName -Location "wus"
32+
$protectionPolicies = Get-AzureBackupProtectionPolicy -ResourceGroupName $ResourceGroupName -ResourceName $ResourceName -Location $Location
3333
Assert-NotNull $protectionPolicies 'Protection Policies should not be null'
3434
foreach($protectionPolicy in $protectionPolicies)
3535
{
@@ -55,7 +55,8 @@ function GetAzureRecoveryPointTest
5555
$azureBackUpItem.DataSourceId = $DataSourceId
5656
$azureBackUpItem.Type = $DataSourceType
5757
$recoveryPoints = Get-AzureBackupRecoveryPoint -item $azureBackUpItem
58-
Assert-NotNull $recoveryPoints 'Recovery Points should not be null'
58+
if (!($recoveryPoints -eq $null))
59+
{
5960
foreach($recoveryPoint in $recoveryPoints)
6061
{
6162
Assert-NotNull $recoveryPoint.RecoveryPointTime 'RecoveryPointTime should not be null'
@@ -115,6 +116,7 @@ function Test-EnableDisableAzureBackupProtectionTest
115116
sleep(20)
116117
$jobId2 = Enable-AzureBackupProtection -item $azureBackUpItem -Policy $policy
117118
}
119+
}
118120

119121
function BackUpAzureBackUpItemTest
120122
{
@@ -130,3 +132,43 @@ function BackUpAzureBackUpItemTest
130132
}
131133

132134

135+
function Test-GetAzureBackupJob
136+
{
137+
$OneMonthBack = Get-Date;
138+
$OneMonthBack = $OneMonthBack.AddDays(-30);
139+
$jobs = Get-AzureBackupJob -ResourceGroupName $ResourceGroupName -ResourceName $ResourceName -Location $Location -From $OneMonthBack -Debug
140+
Assert-NotNull $jobs 'Jobs list should not be null'
141+
foreach($job in $jobs)
142+
{
143+
Assert-NotNull $jobs.InstanceId 'JobID should not be null';
144+
Assert-NotNull $jobs.StartTime 'StartTime should not be null';
145+
Assert-NotNull $jobs.WorkloadType 'WorkloadType should not be null';
146+
Assert-NotNull $jobs.WorkloadName 'WorkloadName should not be null';
147+
Assert-NotNull $jobs.Status 'Status should not be null';
148+
Assert-NotNull $jobs.Operation 'Operation should not be null';
149+
150+
$jobDetails = Get-AzureBackupJobDetails -ResourceGroupName $ResourceGroupName -ResourceName $ResourceName -Location $Location -Job $job
151+
Assert-NotNull $jobDetails.InstanceId 'JobID should not be null';
152+
Assert-NotNull $jobDetails.StartTime 'StartTime should not be null';
153+
Assert-NotNull $jobDetails.WorkloadType 'WorkloadType should not be null';
154+
Assert-NotNull $jobDetails.WorkloadName 'WorkloadName should not be null';
155+
Assert-NotNull $jobDetails.Status 'Status should not be null';
156+
Assert-NotNull $jobDetails.Operation 'Operation should not be null';
157+
Assert-NotNull $jobDetails.Properties 'Properties in job details cannot be null';
158+
Assert-NotNull $jobDetails.SubTasks 'SubTasks in job details cannot be null';
159+
}
160+
}
161+
162+
163+
function Test-StopAzureBackupJob
164+
{
165+
$OneMonthBack = Get-Date;
166+
$OneMonthBack = $OneMonthBack.AddDays(-30);
167+
#TODO
168+
#Call trigger backup and get an inprogress job
169+
$jobsList = Get-AzureBackupJob -ResourceGroupName $ResourceGroupName -ResourceName $ResourceName -Location $Location -From $OneMonthBack #-Operation 'Backup' -Status 'InProgress'
170+
171+
Stop-AzureBackupJob -ResourceGroupName $ResourceGroupName -ResourceName $ResourceName -Location $Location -Job $jobsList[0];
172+
$jobDetails = Get-AzureBackupJobDetails -ResourceGroupName $ResourceGroupName -ResourceName $ResourceName -Location $Location -Job $jobsList[0];
173+
#Assert-AreEqual 'Cancelling' $jobDetails.Status
174+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"Entries": [
3+
{
4+
"RequestUri": "/Subscriptions/f5303a0b-fae4-4cdb-b44d-0e4c032dde26/resourceGroups/swatirg1/providers/Microsoft.Backupseadev01/BackupVault/swatirn1/jobs?api-version=2014-09-01&StartTime=2015-05-16%2008:56:56%20AM&EndTime=2015-06-15%2008:56:56%20AM",
5+
"EncodedRequestUri": "L1N1YnNjcmlwdGlvbnMvZjUzMDNhMGItZmFlNC00Y2RiLWI0NGQtMGU0YzAzMmRkZTI2L3Jlc291cmNlR3JvdXBzL3N3YXRpcmcxL3Byb3ZpZGVycy9NaWNyb3NvZnQuQmFja3Vwc2VhZGV2MDEvQmFja3VwVmF1bHQvc3dhdGlybjEvam9icz9hcGktdmVyc2lvbj0yMDE0LTA5LTAxJlN0YXJ0VGltZT0yMDE1LTA1LTE2JTIwMDglM0E1NiUzQTU2JTIwQU0mRW5kVGltZT0yMDE1LTA2LTE1JTIwMDglM0E1NiUzQTU2JTIwQU0=",
6+
"RequestMethod": "GET",
7+
"RequestBody": "",
8+
"RequestHeaders": {
9+
"Accept-Language": [
10+
"en-us"
11+
],
12+
"x-ms-client-request-id": [
13+
"7d6be94c-d6a6-442d-8f7b-c5670524e7f4-2015-06-15 08:56:56Z-PS"
14+
],
15+
"User-Agent": [
16+
"Microsoft.Azure.Management.BackupServices.BackupServicesManagementClient/0.0.0.0"
17+
]
18+
},
19+
"ResponseBody": "{\r\n \"Objects\": [],\r\n \"ResultCount\": 0,\r\n \"Skiptoken\": \"-1\"\r\n}",
20+
"ResponseHeaders": {
21+
"Content-Length": [
22+
"47"
23+
],
24+
"Content-Type": [
25+
"application/json"
26+
],
27+
"Expires": [
28+
"-1"
29+
],
30+
"Pragma": [
31+
"no-cache"
32+
],
33+
"x-ms-request-id": [
34+
"4b0b4398-2544-445f-b7a9-43e4cc035097"
35+
],
36+
"x-ms-client-request-id": [
37+
"7d6be94c-d6a6-442d-8f7b-c5670524e7f4-2015-06-15 08:56:56Z-PS",
38+
"7d6be94c-d6a6-442d-8f7b-c5670524e7f4-2015-06-15 08:56:56Z-PS"
39+
],
40+
"Strict-Transport-Security": [
41+
"max-age=31536000; includeSubDomains"
42+
],
43+
"x-ms-ratelimit-remaining-subscription-reads": [
44+
"14999"
45+
],
46+
"x-ms-correlation-request-id": [
47+
"4b0b4398-2544-445f-b7a9-43e4cc035097"
48+
],
49+
"x-ms-routing-request-id": [
50+
"CENTRALUS:20150615T085659Z:4b0b4398-2544-445f-b7a9-43e4cc035097"
51+
],
52+
"Cache-Control": [
53+
"no-cache"
54+
],
55+
"Date": [
56+
"Mon, 15 Jun 2015 08:56:58 GMT"
57+
],
58+
"Server": [
59+
"Microsoft-IIS/8.0"
60+
],
61+
"X-Powered-By": [
62+
"ASP.NET"
63+
]
64+
},
65+
"StatusCode": 200
66+
}
67+
],
68+
"Names": {},
69+
"Variables": {
70+
"SubscriptionId": "f5303a0b-fae4-4cdb-b44d-0e4c032dde26"
71+
}
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"Entries": [
3+
{
4+
"RequestUri": "/Subscriptions/f5303a0b-fae4-4cdb-b44d-0e4c032dde26/resourceGroups/swatirg1/providers/Microsoft.Backupseadev01/BackupVault/swatirn1/jobs?api-version=2014-09-01&StartTime=2015-05-16%2007:32:11%20AM&EndTime=2015-06-15%2007:32:11%20AM",
5+
"EncodedRequestUri": "L1N1YnNjcmlwdGlvbnMvZjUzMDNhMGItZmFlNC00Y2RiLWI0NGQtMGU0YzAzMmRkZTI2L3Jlc291cmNlR3JvdXBzL3N3YXRpcmcxL3Byb3ZpZGVycy9NaWNyb3NvZnQuQmFja3Vwc2VhZGV2MDEvQmFja3VwVmF1bHQvc3dhdGlybjEvam9icz9hcGktdmVyc2lvbj0yMDE0LTA5LTAxJlN0YXJ0VGltZT0yMDE1LTA1LTE2JTIwMDclM0EzMiUzQTExJTIwQU0mRW5kVGltZT0yMDE1LTA2LTE1JTIwMDclM0EzMiUzQTExJTIwQU0=",
6+
"RequestMethod": "GET",
7+
"RequestBody": "",
8+
"RequestHeaders": {
9+
"Accept-Language": [
10+
"en-us"
11+
],
12+
"x-ms-client-request-id": [
13+
"c7f3adaa-253e-4a49-a60a-725648ca5ea0-2015-06-15 07:32:11Z-PS"
14+
],
15+
"User-Agent": [
16+
"Microsoft.Azure.Management.BackupServices.BackupServicesManagementClient/0.0.0.0"
17+
]
18+
},
19+
"ResponseBody": "{\r\n \"Objects\": [],\r\n \"ResultCount\": 0,\r\n \"Skiptoken\": \"-1\"\r\n}",
20+
"ResponseHeaders": {
21+
"Content-Length": [
22+
"47"
23+
],
24+
"Content-Type": [
25+
"application/json"
26+
],
27+
"Expires": [
28+
"-1"
29+
],
30+
"Pragma": [
31+
"no-cache"
32+
],
33+
"x-ms-request-id": [
34+
"e6bf8224-c66c-4ff3-a777-8c41c378e687"
35+
],
36+
"x-ms-client-request-id": [
37+
"c7f3adaa-253e-4a49-a60a-725648ca5ea0-2015-06-15 07:32:11Z-PS",
38+
"c7f3adaa-253e-4a49-a60a-725648ca5ea0-2015-06-15 07:32:11Z-PS"
39+
],
40+
"Strict-Transport-Security": [
41+
"max-age=31536000; includeSubDomains"
42+
],
43+
"x-ms-ratelimit-remaining-subscription-reads": [
44+
"14999"
45+
],
46+
"x-ms-correlation-request-id": [
47+
"e6bf8224-c66c-4ff3-a777-8c41c378e687"
48+
],
49+
"x-ms-routing-request-id": [
50+
"CENTRALUS:20150615T073214Z:e6bf8224-c66c-4ff3-a777-8c41c378e687"
51+
],
52+
"Cache-Control": [
53+
"no-cache"
54+
],
55+
"Date": [
56+
"Mon, 15 Jun 2015 07:32:14 GMT"
57+
],
58+
"Server": [
59+
"Microsoft-IIS/8.0"
60+
],
61+
"X-Powered-By": [
62+
"ASP.NET"
63+
]
64+
},
65+
"StatusCode": 200
66+
}
67+
],
68+
"Names": {},
69+
"Variables": {
70+
"SubscriptionId": "f5303a0b-fae4-4cdb-b44d-0e4c032dde26"
71+
}
72+
}

src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletHelpMessage.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,29 @@ internal static class AzureBackupCmdletHelpMessage
2626
public const string ContainerId = "The container ID.";
2727
public const string ContainerRegistrationStatus = "The container registration status.";
2828
public const string ContainerType = "The container type.";
29+
30+
public const string JobFilterJobIdHelpMessage = "The job ID to filter jobs";
31+
public const string JobFilterJobHelpMessage = "The job for filtering";
32+
public const string JobFilterStartTimeHelpMessage = "The start time of query range";
33+
public const string JobFilterEndTimeHelpMessage = "The end time of query range";
34+
public const string JobFilterOperationHelpMessage = "The operation for filtering jos";
35+
public const string JobFilterStatusHelpMessage = "The status for filtering jobs";
36+
public const string JobFitlerVaultHelpMessage = "The vault of which jobs have to be filtered";
37+
public const string JobFilterTypeHelpMessage = "The type of workload whose jobs have to be filtered";
38+
39+
public const string JobDetailsFilterJobIdHelpMessage = "The job ID to get details";
40+
public const string JobDetailsFilterVaultHelpMessage = "The vault of which job details should be fetched";
41+
public const string JobDetailsFilterJobHelpMessage = "The job whose full details should be fetched";
42+
43+
public const string StopJobFilterJobIdHelpMessage = "The job ID to stop job";
44+
public const string StopJobFilterVaultHelpMessage = "The vault of which a job has to be stopped";
45+
public const string StopJobFilterJobHelpMessage = "The job which should be stopped";
46+
47+
public const string WaitJobFilterJobIdHelpMessage = "The job ID to stop job";
48+
public const string WaitJobFilterVaultHelpMessage = "The vault of which a job has to be stopped";
49+
public const string WaitJobFilterJobHelpMessage = "The job which should be stopped";
50+
public const string WaitJobFilterTimeoutHelpMessage = "Maximum number of seconds for which cmdlet should wait before job(s) complete running.";
51+
2952
public const string VirtualMachine = "Virtual Machine.";
3053
public const string ContainerResourceGroupName = "The container resource group name.";
3154
public const string ProtectionStatus = "Protection Status of the azure backup item.";
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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;
16+
using System.Management.Automation;
17+
using System.Collections.Generic;
18+
using System.Xml;
19+
using System.Linq;
20+
using Mgmt = Microsoft.Azure.Management.BackupServices.Models;
21+
22+
23+
namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
24+
{
25+
public enum JobStatus
26+
{
27+
Invalid = 0,
28+
29+
InProgress,
30+
31+
Completed,
32+
33+
Failed,
34+
35+
CompletedWithWarnings,
36+
37+
Cancelled,
38+
39+
Cancelling
40+
}
41+
42+
public enum JobOperationType
43+
{
44+
Invalid = 0,
45+
46+
Register,
47+
48+
ConfigureBackup,
49+
50+
Backup,
51+
52+
Restore,
53+
54+
UnProtect,
55+
56+
DeleteBackupData,
57+
58+
Unregister
59+
}
60+
61+
public static class AzureBackupJobHelper
62+
{
63+
public static bool IsValidStatus(string inputStatus)
64+
{
65+
JobStatus status;
66+
if(!Enum.TryParse<JobStatus>(inputStatus, out status) || status == JobStatus.Invalid)
67+
{
68+
return false;
69+
}
70+
return true;
71+
}
72+
73+
public static bool IsValidOperationType(string inputOperationType)
74+
{
75+
JobOperationType operationType;
76+
if(!Enum.TryParse<JobOperationType>(inputOperationType, out operationType) || operationType == JobOperationType.Invalid)
77+
{
78+
return false;
79+
}
80+
return true;
81+
}
82+
83+
public static bool IsJobRunning(string status)
84+
{
85+
return ((status.CompareTo("InProgress") == 0) || (status.CompareTo("Cancelling") == 0));
86+
}
87+
}
88+
}

0 commit comments

Comments
 (0)