Skip to content

Commit b4c2966

Browse files
fanglfangl
authored andcommitted
Merge remote-tracking branch 'refs/remotes/upstream/preview'
2 parents 1310355 + 2683def commit b4c2966

File tree

40 files changed

+3706
-3667
lines changed

40 files changed

+3706
-3667
lines changed

src/ResourceManager/AzureBatch/AzureRM.Batch.psd1

Lines changed: 68 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -72,40 +72,74 @@ NestedModules = @('.\Microsoft.Azure.Commands.Batch.dll')
7272
FunctionsToExport = @()
7373

7474
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
75-
CmdletsToExport = 'Remove-AzureRmBatchAccount', 'Get-AzureRmBatchAccount',
76-
'Get-AzureRmBatchAccountKeys', 'New-AzureRmBatchAccount',
77-
'New-AzureRmBatchAccountKey', 'Set-AzureRmBatchAccount',
78-
'New-AzureRmBatchApplicationPackage', 'Get-AzureBatchJobStatistics',
79-
'Remove-AzureRmBatchApplication',
80-
'Remove-AzureRmBatchApplicationPackage',
81-
'Get-AzureRmBatchApplicationPackage', 'Get-AzureRmBatchApplication',
82-
'Set-AzureRmBatchApplication', 'New-AzureRmBatchApplication',
83-
'Get-AzureBatchCertificate', 'Remove-AzureBatchCertificate',
84-
'New-AzureBatchCertificate', 'Stop-AzureBatchCertificateDeletion',
85-
'Disable-AzureBatchComputeNodeScheduling',
86-
'Enable-AzureBatchComputeNodeScheduling',
87-
'Get-AzureBatchRemoteLoginSettings', 'Remove-AzureBatchComputeNode',
88-
'Reset-AzureBatchComputeNode', 'Restart-AzureBatchComputeNode',
89-
'Set-AzureBatchComputeNodeUser', 'Get-AzureBatchNodeFile',
90-
'Get-AzureBatchNodeFileContent',
91-
'Get-AzureBatchRemoteDesktopProtocolFile',
92-
'Remove-AzureBatchNodeFile', 'Disable-AzureBatchJobSchedule',
93-
'Enable-AzureBatchJobSchedule', 'Set-AzureBatchJobSchedule',
94-
'Stop-AzureBatchJobSchedule', 'Disable-AzureBatchJob',
95-
'Enable-AzureBatchJob', 'New-AzureBatchJob', 'Remove-AzureBatchJob',
96-
'Set-AzureBatchJob', 'Stop-AzureBatchJob', 'Get-AzureBatchJob',
97-
'Disable-AzureBatchAutoScale', 'Enable-AzureBatchAutoScale',
98-
'Get-AzureBatchPoolStatistics', 'Get-AzureBatchPoolUsageMetrics',
99-
'Get-AzureBatchPool', 'Get-AzureBatchNodeAgentSku',
100-
'New-AzureBatchPool', 'Remove-AzureBatchPool', 'Set-AzureBatchPool',
101-
'Set-AzureBatchPoolOSVersion', 'Start-AzureBatchPoolResize',
102-
'Stop-AzureBatchPoolResize', 'Test-AzureBatchAutoScale',
103-
'Get-AzureRmBatchLocationQuotas', 'Get-AzureBatchSubtask',
104-
'Get-AzureBatchTask', 'New-AzureBatchTask', 'Remove-AzureBatchTask',
105-
'New-AzureBatchComputeNodeUser', 'Remove-AzureBatchComputeNodeUser',
106-
'Enable-AzureBatchTask', 'Set-AzureBatchTask', 'Stop-AzureBatchTask',
107-
'Get-AzureBatchComputeNode', 'Get-AzureBatchJobSchedule',
108-
'New-AzureBatchJobSchedule', 'Remove-AzureBatchJobSchedule'
75+
CmdletsToExport = 'Remove-AzureRmBatchAccount',
76+
'Get-AzureRmBatchAccount',
77+
'Get-AzureRmBatchAccountKeys',
78+
'New-AzureRmBatchAccount',
79+
'New-AzureRmBatchAccountKey',
80+
'Set-AzureRmBatchAccount',
81+
'New-AzureRmBatchApplicationPackage',
82+
'Get-AzureBatchJobStatistics',
83+
'Remove-AzureRmBatchApplication',
84+
'Remove-AzureRmBatchApplicationPackage',
85+
'Get-AzureRmBatchApplicationPackage',
86+
'Get-AzureRmBatchApplication',
87+
'Set-AzureRmBatchApplication',
88+
'New-AzureRmBatchApplication',
89+
'Get-AzureBatchCertificate',
90+
'Remove-AzureBatchCertificate',
91+
'New-AzureBatchCertificate',
92+
'Stop-AzureBatchCertificateDeletion',
93+
'Disable-AzureBatchComputeNodeScheduling',
94+
'Enable-AzureBatchComputeNodeScheduling',
95+
'Get-AzureBatchRemoteLoginSettings',
96+
'Remove-AzureBatchComputeNode',
97+
'Reset-AzureBatchComputeNode',
98+
'Restart-AzureBatchComputeNode',
99+
'Set-AzureBatchComputeNodeUser',
100+
'Get-AzureBatchNodeFile',
101+
'Get-AzureBatchNodeFileContent',
102+
'Get-AzureBatchRemoteDesktopProtocolFile',
103+
'Remove-AzureBatchNodeFile',
104+
'Disable-AzureBatchJobSchedule',
105+
'Enable-AzureBatchJobSchedule',
106+
'Set-AzureBatchJobSchedule',
107+
'Stop-AzureBatchJobSchedule',
108+
'Disable-AzureBatchJob',
109+
'Enable-AzureBatchJob',
110+
'New-AzureBatchJob',
111+
'Remove-AzureBatchJob',
112+
'Set-AzureBatchJob',
113+
'Stop-AzureBatchJob',
114+
'Get-AzureBatchJob',
115+
'Get-AzureBatchJobPreparationAndReleaseTaskStatus',
116+
'Disable-AzureBatchAutoScale',
117+
'Enable-AzureBatchAutoScale',
118+
'Get-AzureBatchPoolStatistics',
119+
'Get-AzureBatchPoolUsageMetrics',
120+
'Get-AzureBatchPool',
121+
'Get-AzureBatchNodeAgentSku',
122+
'New-AzureBatchPool',
123+
'Remove-AzureBatchPool',
124+
'Set-AzureBatchPool',
125+
'Set-AzureBatchPoolOSVersion',
126+
'Start-AzureBatchPoolResize',
127+
'Stop-AzureBatchPoolResize',
128+
'Test-AzureBatchAutoScale',
129+
'Get-AzureRmBatchLocationQuotas',
130+
'Get-AzureBatchSubtask',
131+
'Get-AzureBatchTask',
132+
'New-AzureBatchTask',
133+
'Remove-AzureBatchTask',
134+
'New-AzureBatchComputeNodeUser',
135+
'Remove-AzureBatchComputeNodeUser',
136+
'Enable-AzureBatchTask',
137+
'Set-AzureBatchTask',
138+
'Stop-AzureBatchTask',
139+
'Get-AzureBatchComputeNode',
140+
'Get-AzureBatchJobSchedule',
141+
'New-AzureBatchJobSchedule',
142+
'Remove-AzureBatchJobSchedule'
109143

110144
# Variables to export from this module
111145
# VariablesToExport = @()

src/ResourceManager/AzureBatch/ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
-->
2020
## Current Release
2121

22+
## Version 4.1.0
23+
- Added new Get-AzureBatchJobPreparationAndReleaseTaskStatus cmdlet.
24+
2225
## Version 3.1.0
2326

2427
## Version 3.0.1

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,21 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
618618
return response;
619619
}
620620

621+
/// <summary>
622+
/// Builds a CloudJobPreparationAndReleaseStatus object
623+
/// </summary>
624+
public static AzureOperationResponse<
625+
IPage<ProxyModels.JobPreparationAndReleaseTaskExecutionInformation>,
626+
ProxyModels.JobListPreparationAndReleaseTaskStatusHeaders>
627+
CreateJobPreparationAndReleaseTaskStatusListResponse(List<ProxyModels.JobPreparationAndReleaseTaskExecutionInformation> infoList)
628+
{
629+
var response = new AzureOperationResponse<IPage<ProxyModels.JobPreparationAndReleaseTaskExecutionInformation>, ProxyModels.JobListPreparationAndReleaseTaskStatusHeaders>();
630+
response.Response = new HttpResponseMessage(HttpStatusCode.OK);
631+
response.Body = new MockPagedEnumerable<ProxyModels.JobPreparationAndReleaseTaskExecutionInformation>(infoList);
632+
633+
return response;
634+
}
635+
621636
/// <summary>
622637
/// Builds a JobListFromJobScheduleResponse object
623638
/// </summary>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@
224224
<Compile Include="JobSchedules\StopBatchJobScheduleCommandTests.cs" />
225225
<Compile Include="Jobs\DisableBatchJobCommandTests.cs" />
226226
<Compile Include="Jobs\EnableBatchJobCommandTests.cs" />
227+
<Compile Include="Jobs\GetBatchJobPreparationAndReleaseTaskStatusTests.cs" />
227228
<Compile Include="Jobs\GetBatchJobCommandTests.cs" />
228229
<Compile Include="Jobs\GetBatchJobStatisticsCommandTests.cs" />
229230
<Compile Include="Jobs\NewBatchJobCommandTests.cs" />
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
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.Linq;
24+
using System.Management.Automation;
25+
using System.Threading.Tasks;
26+
using Microsoft.Azure.Batch.Common;
27+
using Xunit;
28+
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
29+
using ProxyModels = Microsoft.Azure.Batch.Protocol.Models;
30+
31+
namespace Microsoft.Azure.Commands.Batch.Test.Jobs
32+
{
33+
public class GetBatchJobPreparationAndReleaseTaskStatusTests : WindowsAzure.Commands.Test.Utilities.Common.RMTestBase
34+
{
35+
private readonly GetBatchJobPreparationAndReleaseTaskStatusCommand cmdlet;
36+
private readonly Mock<BatchClient> batchClientMock;
37+
private readonly Mock<ICommandRuntime> commandRuntimeMock;
38+
39+
public GetBatchJobPreparationAndReleaseTaskStatusTests(Xunit.Abstractions.ITestOutputHelper output)
40+
{
41+
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output));
42+
batchClientMock = new Mock<BatchClient>();
43+
commandRuntimeMock = new Mock<ICommandRuntime>();
44+
cmdlet = new GetBatchJobPreparationAndReleaseTaskStatusCommand()
45+
{
46+
CommandRuntime = commandRuntimeMock.Object,
47+
BatchClient = batchClientMock.Object,
48+
};
49+
}
50+
51+
[Fact]
52+
[Trait(Category.AcceptanceType, Category.CheckIn)]
53+
public void GetBatchJobPreparationAndReleaseTaskStatusTest()
54+
{
55+
// Setup cmdlet to list jobs without filters.
56+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
57+
cmdlet.BatchContext = context;
58+
cmdlet.Id = "job-1";
59+
60+
const string poolId = "Test";
61+
// Build some PrepAndReleaseTaskStatuses instead of querying the service on a List CloudJobs call
62+
var taskExecutionInformationList = new List<ProxyModels.JobPreparationAndReleaseTaskExecutionInformation>
63+
{
64+
new ProxyModels.JobPreparationAndReleaseTaskExecutionInformation(
65+
poolId: poolId,
66+
nodeId: Guid.NewGuid().ToString(),
67+
jobPreparationTaskExecutionInfo: new ProxyModels.JobPreparationTaskExecutionInformation(
68+
retryCount: 0,
69+
state: ProxyModels.JobPreparationTaskState.Completed,
70+
startTime: DateTime.UtcNow),
71+
jobReleaseTaskExecutionInfo: new ProxyModels.JobReleaseTaskExecutionInformation(
72+
state: ProxyModels.JobReleaseTaskState.Completed,
73+
startTime: DateTime.UtcNow))
74+
};
75+
var response = BatchTestHelpers.CreateJobPreparationAndReleaseTaskStatusListResponse(taskExecutionInformationList);
76+
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<
77+
ProxyModels.JobListPreparationAndReleaseTaskStatusOptions,
78+
AzureOperationResponse<IPage<ProxyModels.JobPreparationAndReleaseTaskExecutionInformation>, ProxyModels.JobListPreparationAndReleaseTaskStatusHeaders>>(response);
79+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
80+
81+
// Setup the cmdlet to write pipeline output to a list that can be examined later
82+
var pipeline = new List<PSJobPreparationAndReleaseTaskExecutionInformation>();
83+
commandRuntimeMock.Setup(r =>
84+
r.WriteObject(It.IsAny<PSJobPreparationAndReleaseTaskExecutionInformation>()))
85+
.Callback<object>(j => pipeline.Add((PSJobPreparationAndReleaseTaskExecutionInformation)j));
86+
87+
cmdlet.ExecuteCmdlet();
88+
89+
// Verify that the cmdlet wrote the constructed jobs to the pipeline
90+
Assert.Equal(1, pipeline.Count);
91+
foreach (PSJobPreparationAndReleaseTaskExecutionInformation j in pipeline)
92+
{
93+
Assert.Equal(poolId, j.PoolId);
94+
Assert.NotNull(j.JobPreparationTaskExecutionInformation);
95+
Assert.NotNull(j.JobReleaseTaskExecutionInformation);
96+
}
97+
}
98+
99+
[Fact]
100+
[Trait(Category.AcceptanceType, Category.CheckIn)]
101+
public void GetBatchJobPreparationAndReleaseTaskStatusTestMaxCountTest()
102+
{
103+
// Verify default max count
104+
Assert.Equal(Utils.Constants.DefaultMaxCount, cmdlet.MaxCount);
105+
106+
// Setup cmdlet to list jobs without filters and a max count
107+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
108+
cmdlet.BatchContext = context;
109+
cmdlet.Id = "test";
110+
cmdlet.Filter = null;
111+
const int maxCount = 2;
112+
cmdlet.MaxCount = maxCount;
113+
114+
const string poolId = "Test";
115+
// Build some PrepAndReleaseTaskStatuses instead of querying the service on a List CloudJobs call
116+
var taskExecutionInformationList = new List<ProxyModels.JobPreparationAndReleaseTaskExecutionInformation>();
117+
const int countReturned = 3;
118+
for (int i = 0; i < countReturned; i++)
119+
{
120+
var jpjrInfo = new ProxyModels.JobPreparationAndReleaseTaskExecutionInformation(
121+
poolId: poolId,
122+
nodeId: Guid.NewGuid().ToString(),
123+
jobPreparationTaskExecutionInfo: new ProxyModels.JobPreparationTaskExecutionInformation(
124+
retryCount: 0,
125+
state: ProxyModels.JobPreparationTaskState.Completed,
126+
startTime: DateTime.UtcNow),
127+
jobReleaseTaskExecutionInfo: new ProxyModels.JobReleaseTaskExecutionInformation(
128+
state: ProxyModels.JobReleaseTaskState.Completed,
129+
startTime: DateTime.UtcNow));
130+
taskExecutionInformationList.Add(jpjrInfo);
131+
}
132+
133+
var response = BatchTestHelpers.CreateJobPreparationAndReleaseTaskStatusListResponse(taskExecutionInformationList);
134+
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<
135+
ProxyModels.JobListPreparationAndReleaseTaskStatusOptions,
136+
AzureOperationResponse<IPage<ProxyModels.JobPreparationAndReleaseTaskExecutionInformation>, ProxyModels.JobListPreparationAndReleaseTaskStatusHeaders>>(response);
137+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
138+
139+
// Setup the cmdlet to write pipeline output to a list that can be examined later
140+
var pipeline = new List<PSJobPreparationAndReleaseTaskExecutionInformation>();
141+
commandRuntimeMock.Setup(r =>
142+
r.WriteObject(It.IsAny<PSJobPreparationAndReleaseTaskExecutionInformation>()))
143+
.Callback<object>(j => pipeline.Add((PSJobPreparationAndReleaseTaskExecutionInformation)j));
144+
145+
cmdlet.ExecuteCmdlet();
146+
147+
// Verify that the max count was respected
148+
Assert.Equal(maxCount, pipeline.Count);
149+
150+
// Verify setting max count <= 0 doesn't return nothing
151+
cmdlet.MaxCount = -5;
152+
pipeline.Clear();
153+
cmdlet.ExecuteCmdlet();
154+
155+
Assert.Equal(countReturned, pipeline.Count);
156+
}
157+
}
158+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,15 @@
145145
<Compile Include="BatchAccounts\NewBatchAccountKeyCommand.cs" />
146146
<Compile Include="BatchAccounts\SetBatchAccountCommand.cs" />
147147
<Compile Include="ApplicationPackages\NewBatchApplicationPackageCommand.cs" />
148+
<Compile Include="Jobs\GetBatchJobPreparationAndReleaseTaskStatusCommand.cs" />
148149
<Compile Include="Jobs\GetBatchJobStatisticsCommand.cs" />
149150
<Compile Include="Models.Generated\PSExitCodeMapping.cs" />
150151
<Compile Include="Models.Generated\PSExitCodeRangeMapping.cs" />
151152
<Compile Include="Models.Generated\PSExitConditions.cs" />
152153
<Compile Include="Models.Generated\PSExitOptions.cs" />
153154
<Compile Include="Models.Generated\PSNetworkConfiguration.cs" />
154155
<Compile Include="Models\BatchClient.ApplicationPackages.cs" />
156+
<Compile Include="Models\ListJobPreparationAndReleaseStatusOptions.cs" />
155157
<Compile Include="Models\NewBulkTaskParameters.cs" />
156158
<Compile Include="Models\PSApplicationPackage.cs" />
157159
<Compile Include="Models\PSApplication.cs" />

0 commit comments

Comments
 (0)