Skip to content

Commit 2114877

Browse files
authored
Merge pull request Azure#6075 from antoniowmsft/preview
Implement Get-AzureBatchPoolNodeCounts and Start-AzureBatchComputeNodeServiceLogUpload cmdlets
2 parents 2b7bfd3 + 754ca52 commit 2114877

File tree

101 files changed

+2162
-412
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+2162
-412
lines changed

src/ResourceManager/AzureBatch/AzureRM.Batch.Netcore.psd1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ CmdletsToExport = 'Remove-AzureRmBatchAccount', 'Get-AzureRmBatchAccount',
107107
'New-AzureBatchComputeNodeUser', 'Remove-AzureBatchComputeNodeUser',
108108
'Enable-AzureBatchTask', 'Set-AzureBatchTask', 'Stop-AzureBatchTask',
109109
'Get-AzureBatchComputeNode', 'Get-AzureBatchJobSchedule',
110-
'New-AzureBatchJobSchedule', 'Remove-AzureBatchJobSchedule',
111-
'Get-AzureBatchTaskCounts'
110+
'New-AzureBatchJobSchedule', 'Remove-AzureBatchJobSchedule',
111+
'Get-AzureBatchTaskCounts', 'Get-AzureBatchPoolNodeCounts',
112+
'Start-AzureBatchComputeNodeServiceLogUpload'
112113

113114
# Variables to export from this module
114115
# VariablesToExport = @()

src/ResourceManager/AzureBatch/AzureRM.Batch.psd1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ CmdletsToExport = 'Remove-AzureRmBatchAccount', 'Get-AzureRmBatchAccount',
111111
'Enable-AzureBatchTask', 'Set-AzureBatchTask', 'Stop-AzureBatchTask',
112112
'Get-AzureBatchComputeNode', 'Get-AzureBatchJobSchedule',
113113
'New-AzureBatchJobSchedule', 'Remove-AzureBatchJobSchedule',
114-
'Get-AzureBatchTaskCounts'
114+
'Get-AzureBatchTaskCounts', 'Get-AzureBatchPoolNodeCounts',
115+
'Start-AzureBatchComputeNodeServiceLogUpload'
115116

116117
# Variables to export from this module
117118
# VariablesToExport = @()

src/ResourceManager/AzureBatch/BatchModelGenerator/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public class Program
8484
{"Microsoft.Azure.Batch.NetworkConfiguration", "PSNetworkConfiguration"},
8585
{"Microsoft.Azure.Batch.NetworkSecurityGroupRule", "PSNetworkSecurityGroupRule"},
8686
{"Microsoft.Azure.Batch.NodeAgentSku", "PSNodeAgentSku"},
87+
{"Microsoft.Azure.Batch.NodeCounts", "PSNodeCounts"},
8788
{"Microsoft.Azure.Batch.NodeFile", "PSNodeFile"},
8889
{"Microsoft.Azure.Batch.OSDisk", "PSOSDisk"},
8990
{"Microsoft.Azure.Batch.OutputFile", "PSOutputFile"},
@@ -92,6 +93,7 @@ public class Program
9293
{"Microsoft.Azure.Batch.OutputFileBlobContainerDestination", "PSOutputFileBlobContainerDestination"},
9394
{"Microsoft.Azure.Batch.PoolEndpointConfiguration", "PSPoolEndpointConfiguration"},
9495
{"Microsoft.Azure.Batch.PoolInformation", "PSPoolInformation"},
96+
{"Microsoft.Azure.Batch.PoolNodeCounts", "PSPoolNodeCounts"},
9597
{"Microsoft.Azure.Batch.PoolSpecification", "PSPoolSpecification"},
9698
{"Microsoft.Azure.Batch.PoolStatistics", "PSPoolStatistics"},
9799
{"Microsoft.Azure.Batch.PoolUsageMetrics", "PSPoolUsageMetrics"},
@@ -114,6 +116,7 @@ public class Program
114116
{"Microsoft.Azure.Batch.TaskFailureInformation", "PSTaskFailureInformation"},
115117
{"Microsoft.Azure.Batch.TaskSchedulingPolicy", "PSTaskSchedulingPolicy"},
116118
{"Microsoft.Azure.Batch.TaskStatistics", "PSTaskStatistics"},
119+
{"Microsoft.Azure.Batch.UploadBatchServiceLogsResult", "PSStartComputeNodeServiceLogUploadResult"},
117120
{"Microsoft.Azure.Batch.UsageStatistics", "PSUsageStatistics"},
118121
{"Microsoft.Azure.Batch.UserAccount", "PSUserAccount"},
119122
{"Microsoft.Azure.Batch.UserIdentity", "PSUserIdentity"},

src/ResourceManager/AzureBatch/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* Release new cmdlet Get-AzureBatchPoolNodeCounts
22+
* Release new cmdlet Start-AzureBatchComputeNodeServiceLogUpload
2123

2224
## Version 4.0.7
2325
* Set minimum dependency of module to PowerShell 5.0

src/ResourceManager/AzureBatch/Commands.Batch.Test/BatchTestHelpers.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,17 @@ public static AzureOperationResponse<
712712
return response;
713713
}
714714

715+
public static AzureOperationResponse<IPage<ProxyModels.PoolNodeCounts>, ProxyModels.AccountListPoolNodeCountsHeaders> CreatePoolNodeCountsGetResponse(
716+
IEnumerable<ProxyModels.PoolNodeCounts> poolNodeCounts)
717+
{
718+
var response = new AzureOperationResponse<IPage<ProxyModels.PoolNodeCounts>, ProxyModels.AccountListPoolNodeCountsHeaders>();
719+
response.Response = new HttpResponseMessage(HttpStatusCode.OK);
720+
721+
response.Body = new MockPagedEnumerable<ProxyModels.PoolNodeCounts>(poolNodeCounts);
722+
723+
return response;
724+
}
725+
715726
/// <summary>
716727
/// Builds a CloudTaskListResponse object
717728
/// </summary>
@@ -980,6 +991,23 @@ public static CloudTask CreateFakeBoundTask(BatchAccountContext context)
980991
return context.BatchOMClient.JobOperations.GetTask("jobId", taskId, additionalBehaviors: new BatchClientBehavior[] { interceptor });
981992
}
982993

994+
/// <summary>
995+
/// Builds a ComputeNodeGetResponse object
996+
/// </summary>
997+
public static AzureOperationResponse<ProxyModels.UploadBatchServiceLogsResult, ProxyModels.ComputeNodeUploadBatchServiceLogsHeaders> CreateComputeNodeServiceLogsAddResponse(int numberOfFilesUploaded, string virtualDirectoryName)
998+
{
999+
var response = new AzureOperationResponse<ProxyModels.UploadBatchServiceLogsResult, ProxyModels.ComputeNodeUploadBatchServiceLogsHeaders>();
1000+
response.Response = new HttpResponseMessage(HttpStatusCode.OK);
1001+
1002+
ProxyModels.UploadBatchServiceLogsResult result = new ProxyModels.UploadBatchServiceLogsResult();
1003+
result.NumberOfFilesUploaded = numberOfFilesUploaded;
1004+
result.VirtualDirectoryName = virtualDirectoryName;
1005+
1006+
response.Body = result;
1007+
1008+
return response;
1009+
}
1010+
9831011
/// <summary>
9841012
/// Uses Reflection to set a property value on an object. Can be used to bypass restricted set accessors.
9851013
/// </summary>

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<HintPath>..\..\..\packages\Hyak.Common.1.0.3\lib\portable-net403+win+wpa81\Hyak.Common.dll</HintPath>
4646
</Reference>
4747
<Reference Include="Microsoft.Azure.Batch, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
48-
<HintPath>..\..\..\packages\Azure.Batch.8.0.0\lib\net452\Microsoft.Azure.Batch.dll</HintPath>
48+
<HintPath>..\..\..\packages\Azure.Batch.8.1.1\lib\net452\Microsoft.Azure.Batch.dll</HintPath>
4949
</Reference>
5050
<Reference Include="Microsoft.Azure.Common">
5151
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.dll</HintPath>
@@ -93,14 +93,14 @@
9393
<SpecificVersion>False</SpecificVersion>
9494
<HintPath>..\..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.28.3\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
9595
</Reference>
96+
<Reference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
97+
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.Authentication.2.2.9-preview\lib\net45\Microsoft.Rest.ClientRuntime.Azure.Authentication.dll</HintPath>
98+
<Private>True</Private>
99+
</Reference>
96100
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms, Version=2.28.3.860, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
97101
<SpecificVersion>False</SpecificVersion>
98102
<HintPath>..\..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.28.3\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll</HintPath>
99103
</Reference>
100-
<Reference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
101-
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.Authentication.2.2.9-preview\lib\net45\Microsoft.Rest.ClientRuntime.Azure.Authentication.dll</HintPath>
102-
<Private>True</Private>
103-
</Reference>
104104
<Reference Include="Microsoft.Rest.ClientRuntime.Azure.TestFramework">
105105
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.TestFramework.1.5.0-preview\lib\net45\Microsoft.Rest.ClientRuntime.Azure.TestFramework.dll</HintPath>
106106
<Private>True</Private>
@@ -186,6 +186,7 @@
186186
<Compile Include="Certificates\StopBatchCertificateDeletionCommandTests.cs" />
187187
<Compile Include="ComputeNodes\DisableBatchComputeNodeSchedulingCommandTests.cs" />
188188
<Compile Include="ComputeNodes\EnableBatchComputeNodeSchedulingCommandTests.cs" />
189+
<Compile Include="ComputeNodes\StartBatchComputeNodeServiceLogUploadCommandTests.cs" />
189190
<Compile Include="ComputeNodes\GetBatchComputeNodeLoginSettingsCommandTests.cs" />
190191
<Compile Include="ComputeNodes\RemoveBatchComputeNodeCommandTests.cs" />
191192
<Compile Include="ComputeNodes\ResetBatchComputeNodeCommandTests.cs" />
@@ -212,6 +213,7 @@
212213
<Compile Include="Models\BatchAccountContextTest.cs" />
213214
<Compile Include="Pools\DisableBatchAutoScaleCommandTests.cs" />
214215
<Compile Include="Pools\EnableBatchAutoScaleCommandTests.cs" />
216+
<Compile Include="Pools\GetBatchPoolNodeCountsCommandTests.cs" />
215217
<Compile Include="Pools\GetBatchPoolCommandTests.cs" />
216218
<Compile Include="Pools\GetBatchPoolStatisticsCommandTests.cs" />
217219
<Compile Include="Pools\GetBatchPoolUsageMetricsCommandTests.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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.Commands.Batch.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+
using ProxyModels = Microsoft.Azure.Batch.Protocol.Models;
27+
28+
namespace Microsoft.Azure.Commands.Batch.Test.ComputeNodes
29+
{
30+
public class StartBatchComputeNodeServiceLogUploadCommandTests : WindowsAzure.Commands.Test.Utilities.Common.RMTestBase
31+
{
32+
private StartBatchComputeNodeServiceLogUploadCommand startComputeNodeServiceLogUploadCommand;
33+
private GetBatchComputeNodeCommand getComputeNodeCommand;
34+
private Mock<BatchClient> batchClientMock;
35+
private Mock<ICommandRuntime> commandRuntimeMock;
36+
private const string fakeUrl = "https://containerUrl?sv==";
37+
38+
public StartBatchComputeNodeServiceLogUploadCommandTests(Xunit.Abstractions.ITestOutputHelper output)
39+
{
40+
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output));
41+
batchClientMock = new Mock<BatchClient>();
42+
commandRuntimeMock = new Mock<ICommandRuntime>();
43+
44+
getComputeNodeCommand = new GetBatchComputeNodeCommand()
45+
{
46+
CommandRuntime = commandRuntimeMock.Object,
47+
BatchClient = batchClientMock.Object,
48+
};
49+
50+
startComputeNodeServiceLogUploadCommand = new StartBatchComputeNodeServiceLogUploadCommand()
51+
{
52+
CommandRuntime = commandRuntimeMock.Object,
53+
BatchClient = batchClientMock.Object,
54+
};
55+
}
56+
57+
[Fact]
58+
[Trait(Category.AcceptanceType, Category.CheckIn)]
59+
public void WhenStartBatchComputeNodeServiceLogUploadCommandIsCalledWithPoolIdAndComputeNodeId_ShouldSucceed()
60+
{
61+
// Setup cmdlet to get a compute node by id
62+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
63+
startComputeNodeServiceLogUploadCommand.BatchContext = context;
64+
startComputeNodeServiceLogUploadCommand.PoolId = "pool";
65+
startComputeNodeServiceLogUploadCommand.ComputeNodeId = "tvm";
66+
startComputeNodeServiceLogUploadCommand.ContainerUrl = fakeUrl;
67+
startComputeNodeServiceLogUploadCommand.StartTime = DateTime.UtcNow;
68+
69+
const int numberOfFilesUploaded = 2;
70+
const string virtualDirectoryName = "pool1/tvm";
71+
72+
// Build a compute node instead of querying the service on a Get ComputeNode call
73+
AzureOperationResponse<ProxyModels.UploadBatchServiceLogsResult, ProxyModels.ComputeNodeUploadBatchServiceLogsHeaders> response =
74+
BatchTestHelpers.CreateComputeNodeServiceLogsAddResponse(numberOfFilesUploaded, virtualDirectoryName);
75+
76+
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<
77+
ProxyModels.ComputeNodeUploadBatchServiceLogsOptions,
78+
AzureOperationResponse<ProxyModels.UploadBatchServiceLogsResult, ProxyModels.ComputeNodeUploadBatchServiceLogsHeaders>>(response);
79+
80+
startComputeNodeServiceLogUploadCommand.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
81+
82+
// Setup the cmdlet to write pipeline output to a list that can be examined later
83+
PSStartComputeNodeServiceLogUploadResult result = null;
84+
commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny<PSStartComputeNodeServiceLogUploadResult>())).Callback<object>(c => result = (PSStartComputeNodeServiceLogUploadResult)c);
85+
86+
startComputeNodeServiceLogUploadCommand.ExecuteCmdlet();
87+
88+
Assert.NotNull(result);
89+
Assert.Equal(result.NumberOfFilesUploaded, numberOfFilesUploaded);
90+
Assert.Equal(result.VirtualDirectoryName, virtualDirectoryName);
91+
}
92+
93+
[Fact]
94+
[Trait(Category.AcceptanceType, Category.CheckIn)]
95+
public void WhenStartBatchComputeNodeServiceLogUploadCommandIsCalledWithComputeNode_ShouldSucceed()
96+
{
97+
// First get a fake tvm
98+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
99+
getComputeNodeCommand.BatchContext = context;
100+
getComputeNodeCommand.PoolId = "Pool1";
101+
getComputeNodeCommand.Id = null;
102+
getComputeNodeCommand.Filter = null;
103+
104+
AzureOperationResponse<IPage<ProxyModels.ComputeNode>, ProxyModels.ComputeNodeListHeaders> response1 =
105+
BatchTestHelpers.CreateComputeNodeListResponse(new[] { "tvm1" });
106+
107+
RequestInterceptor interceptor1 = BatchTestHelpers.CreateFakeServiceResponseInterceptor<
108+
ProxyModels.ComputeNodeListOptions,
109+
AzureOperationResponse<IPage<ProxyModels.ComputeNode>, ProxyModels.ComputeNodeListHeaders>>(response1);
110+
111+
var computeNodes = new List<PSComputeNode>();
112+
commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny<PSComputeNode>()))
113+
.Callback<object>(c => computeNodes.Add((PSComputeNode) c));
114+
115+
getComputeNodeCommand.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor1 };
116+
117+
getComputeNodeCommand.ExecuteCmdlet();
118+
119+
// test StartBatchComputeNodeServiceLogUploadCommand
120+
startComputeNodeServiceLogUploadCommand.BatchContext = context;
121+
startComputeNodeServiceLogUploadCommand.ComputeNode = computeNodes[0];
122+
startComputeNodeServiceLogUploadCommand.ContainerUrl = fakeUrl;
123+
124+
var utcNow = DateTime.UtcNow;
125+
startComputeNodeServiceLogUploadCommand.StartTime = utcNow.AddDays(-1);
126+
startComputeNodeServiceLogUploadCommand.EndTime = utcNow;
127+
128+
const int numberOfFilesUploaded = 2;
129+
const string virtualDirectoryName = "pool1/tvm";
130+
131+
AzureOperationResponse<ProxyModels.UploadBatchServiceLogsResult, ProxyModels.ComputeNodeUploadBatchServiceLogsHeaders> response2 =
132+
BatchTestHelpers.CreateComputeNodeServiceLogsAddResponse(numberOfFilesUploaded, virtualDirectoryName);
133+
134+
RequestInterceptor interceptor2 = BatchTestHelpers.CreateFakeServiceResponseInterceptor<
135+
ProxyModels.ComputeNodeUploadBatchServiceLogsOptions,
136+
AzureOperationResponse<ProxyModels.UploadBatchServiceLogsResult, ProxyModels.ComputeNodeUploadBatchServiceLogsHeaders>>(response2);
137+
138+
startComputeNodeServiceLogUploadCommand.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor2 };
139+
140+
// Setup the cmdlet to write pipeline output to a list that can be examined later
141+
PSStartComputeNodeServiceLogUploadResult result = null;
142+
commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny<PSStartComputeNodeServiceLogUploadResult>())).Callback<object>(c => result = (PSStartComputeNodeServiceLogUploadResult)c);
143+
144+
startComputeNodeServiceLogUploadCommand.ExecuteCmdlet();
145+
146+
Assert.NotNull(result);
147+
Assert.Equal(result.NumberOfFilesUploaded, numberOfFilesUploaded);
148+
Assert.Equal(result.VirtualDirectoryName, virtualDirectoryName);
149+
}
150+
}
151+
}

0 commit comments

Comments
 (0)