Skip to content

Commit cc03e1e

Browse files
author
jasper-schneider
committed
Remove Batch compute node and file cmdlets
1 parent c6c9279 commit cc03e1e

File tree

9 files changed

+298
-2
lines changed

9 files changed

+298
-2
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
</Reference>
6161
<Reference Include="Microsoft.Azure.Management.Batch">
6262
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Batch.1.5.0\lib\net40\Microsoft.Azure.Management.Batch.dll</HintPath>
63-
</Reference>
63+
</Reference>
6464
<Reference Include="Microsoft.Azure.ResourceManager">
6565
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Resources.2.18.7-preview\lib\net40\Microsoft.Azure.ResourceManager.dll</HintPath>
6666
</Reference>
@@ -157,12 +157,14 @@
157157
<Compile Include="Certificates\RemoveBatchCertificateCommand.cs" />
158158
<Compile Include="Certificates\NewBatchCertificateCommand.cs" />
159159
<Compile Include="Certificates\StopBatchCertificateDeletionCommand.cs" />
160+
<Compile Include="ComputeNodes\RemoveBatchComputeNodeCommand.cs" />
160161
<Compile Include="ComputeNodes\ResetBatchComputeNodeCommand.cs" />
161162
<Compile Include="ComputeNodes\RestartBatchComputeNodeCommand.cs" />
162163
<Compile Include="ComputeNodeUsers\SetBatchComputeNodeUserCommand.cs" />
163164
<Compile Include="Files\GetBatchNodeFileCommand.cs" />
164165
<Compile Include="Files\GetBatchNodeFileContentCommand.cs" />
165166
<Compile Include="Files\GetBatchRemoteDesktopProtocolFileCommand.cs" />
167+
<Compile Include="Files\RemoveBatchNodeFileCommand.cs" />
166168
<Compile Include="JobSchedules\DisableBatchJobScheduleCommand.cs" />
167169
<Compile Include="JobSchedules\EnableBatchJobScheduleCommand.cs" />
168170
<Compile Include="JobSchedules\SetBatchJobScheduleCommand.cs" />
@@ -270,6 +272,7 @@
270272
<Compile Include="Models\ComputeNodeUserOperationParameters.cs" />
271273
<Compile Include="Models\RebootComputeNodeParameters.cs" />
272274
<Compile Include="Models\ReimageComputeNodeParameters.cs" />
275+
<Compile Include="Models\RemoveComputeNodeParameters.cs" />
273276
<Compile Include="Models\TaskOperationParameters.cs" />
274277
<Compile Include="Models\ComputeNodeOperationParameters.cs" />
275278
<Compile Include="Models\JobScheduleOperationParameters.cs" />
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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.Common;
17+
using Microsoft.Azure.Commands.Batch.Models;
18+
using Microsoft.Azure.Commands.Batch.Properties;
19+
using System;
20+
using System.Management.Automation;
21+
using Constants = Microsoft.Azure.Commands.Batch.Utils.Constants;
22+
23+
namespace Microsoft.Azure.Commands.Batch
24+
{
25+
[Cmdlet(VerbsCommon.Remove, Constants.AzureBatchComputeNode, DefaultParameterSetName = Constants.IdParameterSet)]
26+
public class RemoveBatchComputeNodeCommand : BatchObjectModelCmdletBase
27+
{
28+
[Parameter(Position = 0, ParameterSetName = Constants.IdParameterSet, Mandatory = true,
29+
HelpMessage = "The id of the pool that contains the compute node.")]
30+
[ValidateNotNullOrEmpty]
31+
public string PoolId { get; set; }
32+
33+
[Parameter(Position = 1, ParameterSetName = Constants.IdParameterSet, Mandatory = true,
34+
HelpMessage = "The id of the compute node to remove from the pool.")]
35+
[ValidateNotNullOrEmpty]
36+
public string Id { get; set; }
37+
38+
[Parameter(Position = 0, ParameterSetName = Constants.InputObjectParameterSet, ValueFromPipeline = true)]
39+
[ValidateNotNullOrEmpty]
40+
public PSComputeNode ComputeNode { get; set; }
41+
42+
[Parameter]
43+
public ComputeNodeDeallocationOption? DeallocationOption { get; set; }
44+
45+
[Parameter]
46+
public TimeSpan? ResizeTimeout { get; set; }
47+
48+
[Parameter]
49+
public SwitchParameter Force { get; set; }
50+
51+
protected override void ProcessRecord()
52+
{
53+
string computeNodeId = ComputeNode == null ? this.Id : ComputeNode.Id;
54+
RemoveComputeNodeParameters parameters = new RemoveComputeNodeParameters(this.BatchContext, this.PoolId,
55+
this.Id, this.ComputeNode, this.AdditionalBehaviors)
56+
{
57+
DeallocationOption = this.DeallocationOption,
58+
ResizeTimeout = this.ResizeTimeout
59+
};
60+
61+
ConfirmAction(
62+
Force.IsPresent,
63+
string.Format(Resources.RemoveComputeNodeConfirm, computeNodeId),
64+
Resources.RemoveComputeNode,
65+
computeNodeId,
66+
() => BatchClient.RemoveComputeNodeFromPool(parameters));
67+
}
68+
}
69+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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.IO;
16+
using Microsoft.Azure.Batch;
17+
using Microsoft.Azure.Commands.Batch.Models;
18+
using System;
19+
using System.Management.Automation;
20+
using Constants = Microsoft.Azure.Commands.Batch.Utils.Constants;
21+
using Microsoft.Azure.Commands.Batch.Properties;
22+
23+
namespace Microsoft.Azure.Commands.Batch
24+
{
25+
[Cmdlet(VerbsCommon.Remove, Constants.AzureBatchNodeFile)]
26+
public class RemoveBatchNodeFileCommand : BatchObjectModelCmdletBase
27+
{
28+
internal const string TaskParameterSet = "Task";
29+
internal const string ComputeNodeParameterSet = "ComputeNode";
30+
31+
[Parameter(ParameterSetName = TaskParameterSet, Mandatory = true,
32+
ValueFromPipelineByPropertyName = true, HelpMessage = "The id of the job containing the target task.")]
33+
[ValidateNotNullOrEmpty]
34+
public string JobId { get; set; }
35+
36+
[Parameter(ParameterSetName = TaskParameterSet, Mandatory = true,
37+
ValueFromPipelineByPropertyName = true, HelpMessage = "The id of the task.")]
38+
public string TaskId { get; set; }
39+
40+
[Parameter(Position = 0, ParameterSetName = ComputeNodeParameterSet, Mandatory = true,
41+
ValueFromPipelineByPropertyName = true, HelpMessage = "The id of the pool containing the compute node.")]
42+
[ValidateNotNullOrEmpty]
43+
public string PoolId { get; set; }
44+
45+
[Parameter(Position = 1, ParameterSetName = ComputeNodeParameterSet, Mandatory = true,
46+
ValueFromPipelineByPropertyName = true, HelpMessage = "The id of the compute node.")]
47+
[ValidateNotNullOrEmpty]
48+
public string ComputeNodeId { get; set; }
49+
50+
[Parameter(ParameterSetName = TaskParameterSet, Mandatory = true,
51+
HelpMessage = "The name of the node file to delete.")]
52+
[Parameter(Position = 2, ParameterSetName = ComputeNodeParameterSet, Mandatory = true)]
53+
[ValidateNotNullOrEmpty]
54+
public string Name { get; set; }
55+
56+
[Parameter(Position = 0, ParameterSetName = Constants.InputObjectParameterSet, ValueFromPipeline = true)]
57+
[ValidateNotNullOrEmpty]
58+
public PSNodeFile InputObject { get; set; }
59+
60+
[Parameter]
61+
public SwitchParameter Force { get; set; }
62+
63+
protected override void ProcessRecord()
64+
{
65+
string fileName = this.InputObject == null ? this.Name : this.InputObject.Name;
66+
NodeFileOperationParameters parameters = new NodeFileOperationParameters(this.BatchContext, this.JobId, this.TaskId, this.PoolId,
67+
this.ComputeNodeId, this.Name, this.InputObject, this.AdditionalBehaviors);
68+
69+
ConfirmAction(
70+
Force.IsPresent,
71+
string.Format(Resources.RemoveNodeFileConfirm, fileName),
72+
Resources.RemoveNodeFile,
73+
fileName,
74+
() => BatchClient.DeleteNodeFile(parameters));
75+
}
76+
}
77+
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,28 @@ public IEnumerable<PSComputeNode> ListComputeNodes(ListComputeNodeOptions option
7171
}
7272
}
7373

74+
/// <summary>
75+
/// Removes the specified compute node from the specified pool.
76+
/// </summary>
77+
/// <param name="parameters">The parameters specifying the pool and the compute node.</param>
78+
public void RemoveComputeNodeFromPool(RemoveComputeNodeParameters parameters)
79+
{
80+
if (parameters == null)
81+
{
82+
throw new ArgumentNullException("parameters");
83+
}
84+
85+
if (parameters.ComputeNode != null)
86+
{
87+
parameters.ComputeNode.omObject.RemoveFromPool(parameters.DeallocationOption, parameters.ResizeTimeout, parameters.AdditionalBehaviors);
88+
}
89+
else
90+
{
91+
PoolOperations poolOperations = parameters.Context.BatchOMClient.PoolOperations;
92+
poolOperations.RemoveFromPool(parameters.PoolId, parameters.ComputeNodeId, parameters.DeallocationOption, parameters.ResizeTimeout, parameters.AdditionalBehaviors);
93+
}
94+
}
95+
7496
/// <summary>
7597
/// Reboots the specified compute node.
7698
/// </summary>

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,43 @@ private IEnumerable<PSNodeFile> ListNodeFilesByComputeNode(ListNodeFileOptions o
145145
}
146146
}
147147

148+
/// <summary>
149+
/// Deletes the specified file from its compute node.
150+
/// </summary>
151+
/// <param name="parameters">Specifies which node file to delete.</param>
152+
public void DeleteNodeFile(NodeFileOperationParameters parameters)
153+
{
154+
if (parameters == null)
155+
{
156+
throw new ArgumentNullException("parameters");
157+
}
158+
159+
switch (parameters.NodeFileType)
160+
{
161+
case PSNodeFileType.Task:
162+
{
163+
JobOperations jobOperations = parameters.Context.BatchOMClient.JobOperations;
164+
jobOperations.DeleteNodeFile(parameters.JobId, parameters.TaskId, parameters.NodeFileName, parameters.AdditionalBehaviors);
165+
break;
166+
}
167+
case PSNodeFileType.ComputeNode:
168+
{
169+
PoolOperations poolOperations = parameters.Context.BatchOMClient.PoolOperations;
170+
poolOperations.DeleteNodeFile(parameters.PoolId, parameters.ComputeNodeId, parameters.NodeFileName, parameters.AdditionalBehaviors);
171+
break;
172+
}
173+
case PSNodeFileType.PSNodeFileInstance:
174+
{
175+
parameters.NodeFile.omObject.Delete(parameters.AdditionalBehaviors);
176+
break;
177+
}
178+
default:
179+
{
180+
throw new ArgumentException(Resources.NoNodeFile);
181+
}
182+
}
183+
}
184+
148185
/// <summary>
149186
/// Downloads a node file using the specified options.
150187
/// </summary>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public void CreatePool(NewPoolParameters parameters)
8787
pool.ResizeTimeout = parameters.ResizeTimeout;
8888
pool.MaxTasksPerComputeNode = parameters.MaxTasksPerComputeNode;
8989
pool.InterComputeNodeCommunicationEnabled = parameters.InterComputeNodeCommunicationEnabled;
90+
pool.TargetOSVersion = parameters.TargetOSVersion;
9091

9192
if (!string.IsNullOrEmpty(parameters.AutoScaleFormula))
9293
{
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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.Common;
17+
using System;
18+
using System.Collections.Generic;
19+
20+
namespace Microsoft.Azure.Commands.Batch.Models
21+
{
22+
public class RemoveComputeNodeParameters : ComputeNodeOperationParameters
23+
{
24+
public RemoveComputeNodeParameters(BatchAccountContext context, string poolId, string computeNodeId, PSComputeNode computeNode,
25+
IEnumerable<BatchClientBehavior> additionalBehaviors = null)
26+
: base(context, poolId, computeNodeId, computeNode, additionalBehaviors)
27+
{ }
28+
29+
/// <summary>
30+
/// Specifies when nodes may be removed from the pool.
31+
/// </summary>
32+
public ComputeNodeDeallocationOption? DeallocationOption { get; set; }
33+
34+
/// <summary>
35+
/// Specifies the timeout for removal of compute nodes from the pool. The default value is 10 minutes. The minimum value is 5 minutes.
36+
/// </summary>
37+
public TimeSpan? ResizeTimeout { get; set; }
38+
}
39+
}

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

Lines changed: 37 additions & 1 deletion
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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,12 @@
345345
<data name="RemoveCertificateConfirm" xml:space="preserve">
346346
<value>Are you sure you want to remove the certificate with thumbprint {0}?</value>
347347
</data>
348+
<data name="RemoveComputeNode" xml:space="preserve">
349+
<value>Removing compute node from its pool...</value>
350+
</data>
351+
<data name="RemoveComputeNodeConfirm" xml:space="preserve">
352+
<value>Are you sure you want to remove compute node {0} from its pool?</value>
353+
</data>
348354
<data name="RemoveComputeNodeUser" xml:space="preserve">
349355
<value>Removing user ...</value>
350356
</data>
@@ -363,6 +369,12 @@
363369
<data name="RemoveJobScheduleConfirm" xml:space="preserve">
364370
<value>Are you sure you want to remove job schedule {0}?</value>
365371
</data>
372+
<data name="RemoveNodeFile" xml:space="preserve">
373+
<value>Deleting node file...</value>
374+
</data>
375+
<data name="RemoveNodeFileConfirm" xml:space="preserve">
376+
<value>Are you sure you want to delete node file {0}?</value>
377+
</data>
366378
<data name="RemovePool" xml:space="preserve">
367379
<value>Removing pool ...</value>
368380
</data>

0 commit comments

Comments
 (0)