Skip to content

Commit cadd870

Browse files
Squashed hotfix/reactive-task into feature/batch-integration-sept-2016
1 parent 9f30526 commit cadd870

File tree

10 files changed

+334
-2
lines changed

10 files changed

+334
-2
lines changed

src/ResourceManager/AzureBatch/AzureRM.Batch.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ CmdletsToExport = '*'
7676
VariablesToExport = '*'
7777

7878
# Aliases to export from this module
79-
AliasesToExport = @()
79+
AliasesToExport = @('Reactivate-AzureBatchTask')
8080

8181
# List of all modules packaged with this module
8282
ModuleList = @()

src/ResourceManager/AzureBatch/Commands.Batch.Test/Commands.Batch.Test.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,14 @@
272272
<Compile Include="JobSchedules\NewBatchJobScheduleCommandTests.cs" />
273273
<Compile Include="JobSchedules\RemoveBatchJobScheduleCommandTests.cs" />
274274
<Compile Include="Tasks\SetBatchTaskCommandTests.cs" />
275+
<Compile Include="Tasks\EnableBatchTaskCommandTests.cs" />
275276
<Compile Include="Tasks\StopBatchTaskCommandTests.cs" />
276277
</ItemGroup>
277278
<ItemGroup>
278279
<None Include="..\..\Common\Commands.ScenarioTests.ResourceManager.Common\AzureRM.Resources.ps1">
279280
<Link>ScenarioTests\AzureRM.Resources.ps1</Link>
280281
</None>
282+
<None Include="app.config" />
281283
<None Include="MSSharedLibKey.snk" />
282284
<None Include="packages.config">
283285
<SubType>Designer</SubType>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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 Microsoft.Azure.Batch;
16+
using Microsoft.Azure.Batch.Protocol;
17+
using Microsoft.Azure.Batch.Protocol.Models;
18+
using Microsoft.Rest.Azure;
19+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
20+
using Moq;
21+
using System;
22+
using System.Collections.Generic;
23+
using System.Management.Automation;
24+
using Xunit;
25+
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
26+
27+
namespace Microsoft.Azure.Commands.Batch.Test.Tasks
28+
{
29+
public class EnableBatchTaskCommandTests
30+
{
31+
private EnableBatchTaskCommand cmdlet;
32+
private Mock<BatchClient> batchClientMock;
33+
private Mock<ICommandRuntime> commandRuntimeMock;
34+
35+
public EnableBatchTaskCommandTests(Xunit.Abstractions.ITestOutputHelper output)
36+
{
37+
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output));
38+
batchClientMock = new Mock<BatchClient>();
39+
commandRuntimeMock = new Mock<ICommandRuntime>();
40+
cmdlet = new EnableBatchTaskCommand()
41+
{
42+
CommandRuntime = commandRuntimeMock.Object,
43+
BatchClient = batchClientMock.Object,
44+
};
45+
}
46+
47+
[Fact]
48+
[Trait(Category.AcceptanceType, Category.CheckIn)]
49+
public void OmittingMandatoryParametersCausesException()
50+
{
51+
// Setup cmdlet without the required parameters
52+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
53+
cmdlet.BatchContext = context;
54+
55+
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
56+
57+
cmdlet.JobId = "job-1";
58+
59+
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
60+
61+
cmdlet.Id = "testTask";
62+
63+
// Don't go to the service on a Restart CloudTask call
64+
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<TaskReactivateOptions, AzureOperationHeaderResponse<TaskReactivateHeaders>>();
65+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
66+
67+
// Verify no exceptions when required parameters are set
68+
cmdlet.ExecuteCmdlet();
69+
}
70+
}
71+
}

src/ResourceManager/AzureBatch/Commands.Batch.Test/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<package id="Microsoft.Azure.Management.Batch" version="2.0.0" targetFramework="net45" />
1111
<package id="Microsoft.Azure.Management.Resources" version="2.20.0-preview" targetFramework="net45" />
1212
<package id="Microsoft.Azure.Test.Framework" version="1.0.6052.28118-prerelease" targetFramework="net45" />
13-
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.6.7-preview" targetFramework="net45" />
13+
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.6.7-preview" targetFramework="net45" />
1414
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
1515
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
1616
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />

src/ResourceManager/AzureBatch/Commands.Batch/Commands.Batch.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@
359359
<Compile Include="Tasks\RemoveBatchTaskCommand.cs" />
360360
<Compile Include="ComputeNodeUsers\NewBatchComputeNodeUserCommand.cs" />
361361
<Compile Include="ComputeNodeUsers\RemoveBatchComputeNodeUserCommand.cs" />
362+
<Compile Include="Tasks\EnableBatchTaskCommand.cs" />
362363
<Compile Include="Tasks\SetBatchTaskCommand.cs" />
363364
<Compile Include="Tasks\StopBatchTaskCommand.cs" />
364365
<Compile Include="NewApplicationPackageException.cs" />

src/ResourceManager/AzureBatch/Commands.Batch/Microsoft.Azure.Commands.Batch.dll-Help.xml

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,181 @@
11821182
</maml:relatedLinks>
11831183
</command:command>
11841184
<command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10" xmlns:MSHelp="http://msdn.microsoft.com/mshelp">
1185+
<!--Generated by PS Cmdlet Help Editor-->
1186+
<command:details>
1187+
<command:name>Enable-AzureBatchTask</command:name>
1188+
<maml:description>
1189+
<maml:para>Reactivates a task, allowing it to run again even if its retry count has been exhausted.</maml:para>
1190+
</maml:description>
1191+
<maml:copyright>
1192+
<maml:para />
1193+
</maml:copyright>
1194+
<command:verb>Enable</command:verb>
1195+
<command:noun>AzureBatchTask</command:noun>
1196+
<dev:version />
1197+
</command:details>
1198+
<maml:description>
1199+
<maml:para />
1200+
</maml:description>
1201+
<command:syntax>
1202+
<command:syntaxItem>
1203+
<maml:name>Enable-AzureBatchTask</maml:name>
1204+
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named">
1205+
<maml:name>BatchContext</maml:name>
1206+
<maml:description>
1207+
<maml:para>Specifies the BatchAccountContext instance that this cmdlet uses to interact with the Batch service. To obtain a BatchAccountContext object that contains access keys for your subscription, use the Get-AzureRmBatchAccountKeys cmdlet.</maml:para>
1208+
</maml:description>
1209+
<command:parameterValue required="true" variableLength="false">BatchAccountContext</command:parameterValue>
1210+
</command:parameter>
1211+
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="1">
1212+
<maml:name>Id</maml:name>
1213+
<maml:description>
1214+
<maml:para>Specifies the ID of the task to reactivate.</maml:para>
1215+
</maml:description>
1216+
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
1217+
</command:parameter>
1218+
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="0">
1219+
<maml:name>JobId</maml:name>
1220+
<maml:description>
1221+
<maml:para>Specifies the ID of the job containing the task.</maml:para>
1222+
</maml:description>
1223+
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
1224+
</command:parameter>
1225+
</command:syntaxItem>
1226+
<command:syntaxItem>
1227+
<maml:name>Enable-AzureBatchTask</maml:name>
1228+
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named">
1229+
<maml:name>BatchContext</maml:name>
1230+
<maml:description>
1231+
<maml:para>Specifies the BatchAccountContext instance that this cmdlet uses to interact with the Batch service. To obtain a BatchAccountContext object that contains access keys for your subscription, use the Get-AzureRmBatchAccountKeys cmdlet.</maml:para>
1232+
</maml:description>
1233+
<command:parameterValue required="true" variableLength="false">BatchAccountContext</command:parameterValue>
1234+
</command:parameter>
1235+
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="0">
1236+
<maml:name>Task</maml:name>
1237+
<maml:description>
1238+
<maml:para>Specifies the task that this cmdlet reactivates. To obtain a PSCloudTask object, use the Get-AzureBatchTask cmdlet.</maml:para>
1239+
</maml:description>
1240+
<command:parameterValue required="true" variableLength="false">PSCloudTask</command:parameterValue>
1241+
</command:parameter>
1242+
</command:syntaxItem>
1243+
</command:syntax>
1244+
<command:parameters>
1245+
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named">
1246+
<maml:name>BatchContext</maml:name>
1247+
<maml:description>
1248+
<maml:para>Specifies the BatchAccountContext instance that this cmdlet uses to interact with the Batch service. To obtain a BatchAccountContext object that contains access keys for your subscription, use the Get-AzureRmBatchAccountKeys cmdlet.</maml:para>
1249+
</maml:description>
1250+
<command:parameterValue required="true" variableLength="false">BatchAccountContext</command:parameterValue>
1251+
<dev:type>
1252+
<maml:name>BatchAccountContext</maml:name>
1253+
<maml:uri/>
1254+
</dev:type>
1255+
<dev:defaultValue></dev:defaultValue>
1256+
</command:parameter>
1257+
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="1">
1258+
<maml:name>Id</maml:name>
1259+
<maml:description>
1260+
<maml:para>Specifies the ID of the task to reactivate.</maml:para>
1261+
</maml:description>
1262+
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
1263+
<dev:type>
1264+
<maml:name>String</maml:name>
1265+
<maml:uri/>
1266+
</dev:type>
1267+
<dev:defaultValue></dev:defaultValue>
1268+
</command:parameter>
1269+
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="0">
1270+
<maml:name>JobId</maml:name>
1271+
<maml:description>
1272+
<maml:para>Specifies the ID of the job containing the task.</maml:para>
1273+
</maml:description>
1274+
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
1275+
<dev:type>
1276+
<maml:name>String</maml:name>
1277+
<maml:uri/>
1278+
</dev:type>
1279+
<dev:defaultValue></dev:defaultValue>
1280+
</command:parameter>
1281+
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="0">
1282+
<maml:name>Task</maml:name>
1283+
<maml:description>
1284+
<maml:para>Specifies the task that this cmdlet reactivates. To obtain a PSCloudTask object, use the Get-AzureBatchTask cmdlet.</maml:para>
1285+
</maml:description>
1286+
<command:parameterValue required="true" variableLength="false">PSCloudTask</command:parameterValue>
1287+
<dev:type>
1288+
<maml:name>PSCloudTask</maml:name>
1289+
<maml:uri/>
1290+
</dev:type>
1291+
<dev:defaultValue></dev:defaultValue>
1292+
</command:parameter>
1293+
</command:parameters>
1294+
<command:inputTypes>
1295+
</command:inputTypes>
1296+
<command:returnValues>
1297+
</command:returnValues>
1298+
<command:examples>
1299+
<command:example>
1300+
<maml:title>-------------------------- Example 1: Reactivate a task --------------------------</maml:title>
1301+
<maml:introduction>
1302+
<maml:paragraph>PS C:\&gt;</maml:paragraph>
1303+
</maml:introduction>
1304+
<dev:code>PS C:\&gt;Enable-AzureBatchTask -JobId &quot;Job7&quot; -Id &quot;Task2&quot; -BatchContext $Context</dev:code>
1305+
<dev:remarks>
1306+
<maml:para>This command reactivates the task Task2 in job Job7.</maml:para>
1307+
<maml:para />
1308+
<maml:para />
1309+
<maml:para></maml:para>
1310+
</dev:remarks>
1311+
<command:commandLines>
1312+
<command:commandLine>
1313+
<command:commandText>
1314+
<maml:para />
1315+
</command:commandText>
1316+
</command:commandLine>
1317+
</command:commandLines>
1318+
</command:example>
1319+
<command:example>
1320+
<maml:title>-------------------------- Example 2: Reactivate a task by using the pipeline --------------------------</maml:title>
1321+
<maml:introduction>
1322+
<maml:paragraph>PS C:\&gt;</maml:paragraph>
1323+
</maml:introduction>
1324+
<dev:code>PS C:\&gt;Get-AzureBatchTask -JobId &quot;Job8&quot; -Id &quot;Task3&quot; -BatchContext $Context | Enable-AzureBatchTask -BatchContext $Context</dev:code>
1325+
<dev:remarks>
1326+
<maml:para>This command gets the Batch task that has the ID Task3 in the job that has the ID Job8 by using the Get-AzureBatchTask cmdlet. The command passes that task to the current cmdlet by using the pipeline operator. The command reactivates that task.</maml:para>
1327+
<maml:para />
1328+
<maml:para />
1329+
<maml:para></maml:para>
1330+
</dev:remarks>
1331+
<command:commandLines>
1332+
<command:commandLine>
1333+
<command:commandText>
1334+
<maml:para />
1335+
</command:commandText>
1336+
</command:commandLine>
1337+
</command:commandLines>
1338+
</command:example>
1339+
</command:examples>
1340+
<maml:relatedLinks>
1341+
<maml:navigationLink>
1342+
<maml:linkText>Get-AzureBatchTask</maml:linkText>
1343+
<maml:uri></maml:uri>
1344+
</maml:navigationLink>
1345+
<maml:navigationLink>
1346+
<maml:linkText>New-AzureBatchTask</maml:linkText>
1347+
<maml:uri></maml:uri>
1348+
</maml:navigationLink>
1349+
<maml:navigationLink>
1350+
<maml:linkText>Remove-AzureBatchTask</maml:linkText>
1351+
<maml:uri></maml:uri>
1352+
</maml:navigationLink>
1353+
<maml:navigationLink>
1354+
<maml:linkText>Azure Batch Cmdlets</maml:linkText>
1355+
<maml:uri></maml:uri>
1356+
</maml:navigationLink>
1357+
</maml:relatedLinks>
1358+
</command:command>
1359+
<command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10" xmlns:MSHelp="http://msdn.microsoft.com/mshelp">
11851360
<!--Generated by PS Cmdlet Help Editor-->
11861361
<command:details>
11871362
<command:name>Get-AzureBatchCertificate</command:name>

src/ResourceManager/AzureBatch/Commands.Batch/Models/BatchClient.Tasks.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,5 +276,29 @@ public IEnumerable<PSSubtaskInformation> ListSubtasks(ListSubtaskOptions options
276276
return PSPagedEnumerable<PSSubtaskInformation, SubtaskInformation>.CreateWithMaxCount(
277277
subtasks, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount)));
278278
}
279+
280+
/// <summary>
281+
/// Reactivates a task, allowing it to run again even if its retry count has been exhausted.
282+
/// </summary>
283+
/// <param name="parameters">The parameters indicating which task to reactivate.</param>
284+
public void ReactivateTask(TaskOperationParameters parameters)
285+
{
286+
if (parameters == null)
287+
{
288+
throw new ArgumentNullException("parameters");
289+
}
290+
291+
if (parameters.Task != null)
292+
{
293+
WriteVerbose(string.Format(Resources.ReactivateTask, parameters.Task.Id));
294+
parameters.Task.omObject.Reactivate(parameters.AdditionalBehaviors);
295+
}
296+
else
297+
{
298+
WriteVerbose(string.Format(Resources.ReactivateTask, parameters.TaskId));
299+
JobOperations jobOperations = parameters.Context.BatchOMClient.JobOperations;
300+
jobOperations.ReactivateTask(parameters.JobId, parameters.TaskId, parameters.AdditionalBehaviors);
301+
}
302+
}
279303
}
280304
}

src/ResourceManager/AzureBatch/Commands.Batch/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/AzureBatch/Commands.Batch/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,9 @@
336336
<data name="NoTask" xml:space="preserve">
337337
<value>No task was specified. Supply a PSCloudTask object or a job id and task id.</value>
338338
</data>
339+
<data name="ReactivateTask" xml:space="preserve">
340+
<value>Reactivating task {0}.</value>
341+
</data>
339342
<data name="RebootComputeNode" xml:space="preserve">
340343
<value>Rebooting compute node {0}.</value>
341344
</data>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 Microsoft.Azure.Commands.Batch.Models;
16+
using System.Management.Automation;
17+
using Constants = Microsoft.Azure.Commands.Batch.Utils.Constants;
18+
19+
namespace Microsoft.Azure.Commands.Batch
20+
{
21+
[Cmdlet(VerbsLifecycle.Enable, Constants.AzureBatchTask)]
22+
[Alias("Reactivate-AzureBatchTask")]
23+
public class EnableBatchTaskCommand : BatchObjectModelCmdletBase
24+
{
25+
[Parameter(Position = 0, ParameterSetName = Constants.IdParameterSet, Mandatory = true,
26+
ValueFromPipelineByPropertyName = true, HelpMessage = "The id of the job containing the task to reactivate.")]
27+
[ValidateNotNullOrEmpty]
28+
public string JobId { get; set; }
29+
30+
[Parameter(Position = 1, ParameterSetName = Constants.IdParameterSet, Mandatory = true,
31+
ValueFromPipelineByPropertyName = true, HelpMessage = "The id of the task to reactivate.")]
32+
[ValidateNotNullOrEmpty]
33+
public string Id { get; set; }
34+
35+
[Parameter(Position = 0, ParameterSetName = Constants.InputObjectParameterSet, Mandatory = true,
36+
ValueFromPipeline = true, HelpMessage = "The PSCloudTask object representing the task to reactivate.")]
37+
[ValidateNotNullOrEmpty]
38+
public PSCloudTask Task { get; set; }
39+
40+
public override void ExecuteCmdlet()
41+
{
42+
TaskOperationParameters parameters = new TaskOperationParameters(this.BatchContext, this.JobId, this.Id, this.Task, this.AdditionalBehaviors);
43+
44+
this.BatchClient.ReactivateTask(parameters);
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)