Skip to content

Commit 79909d8

Browse files
authored
Merge pull request #618 from Azure/dev
huangpf PR: dev <- Azure:dev
2 parents 72889f6 + 308e601 commit 79909d8

File tree

166 files changed

+16714
-26787
lines changed

Some content is hidden

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

166 files changed

+16714
-26787
lines changed

src/ResourceManager/AzureBatch/AzureBatch.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
2-
# Visual Studio 2013
3-
VisualStudioVersion = 12.0.40629.0
2+
# Visual Studio 14
3+
VisualStudioVersion = 14.0.25123.0
44
MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{95C16AED-FD57-42A0-86C3-2CF4300A4817}"
66
EndProject

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/BatchModelGenerator/BatchModelGenerator.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
2-
# Visual Studio 2013
3-
VisualStudioVersion = 12.0.40629.0
2+
# Visual Studio 14
3+
VisualStudioVersion = 14.0.25123.0
44
MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BatchModelGenerator", "BatchModelGenerator.csproj", "{374701E4-539A-459A-9A00-B04E51652997}"
66
EndProject

src/ResourceManager/AzureBatch/BatchModelGenerator/Program.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ public class Program
3131

3232
private static readonly Dictionary<string, string> OMtoPSClassMappings = new Dictionary<string, string>()
3333
{
34-
{"Microsoft.Azure.Batch.NodeAgentSku", "PSNodeAgentSku"},
35-
{"Microsoft.Azure.Batch.ImageReference", "PSImageReference"},
34+
{"Microsoft.Azure.Batch.AffinityInformation", "PSAffinityInformation"},
3635
{"Microsoft.Azure.Batch.AutoPoolSpecification", "PSAutoPoolSpecification"},
3736
{"Microsoft.Azure.Batch.AutoScaleRun", "PSAutoScaleRun"},
3837
{"Microsoft.Azure.Batch.AutoScaleRunError", "PSAutoScaleRunError"},
38+
{"Microsoft.Azure.Batch.ApplicationPackageReference", "PSApplicationPackageReference"},
3939
{"Microsoft.Azure.Batch.Certificate", "PSCertificate"},
4040
{"Microsoft.Azure.Batch.CertificateReference", "PSCertificateReference"},
4141
{"Microsoft.Azure.Batch.CloudJob", "PSCloudJob"},
@@ -49,7 +49,12 @@ public class Program
4949
{"Microsoft.Azure.Batch.ComputeNodeUser", "PSComputeNodeUser"},
5050
{"Microsoft.Azure.Batch.DeleteCertificateError", "PSDeleteCertificateError"},
5151
{"Microsoft.Azure.Batch.EnvironmentSetting", "PSEnvironmentSetting"},
52+
{"Microsoft.Azure.Batch.ExitConditions", "PSExitConditions"},
53+
{"Microsoft.Azure.Batch.ExitCodeRangeMapping", "PSExitCodeRangeMapping"},
54+
{"Microsoft.Azure.Batch.ExitCodeMapping", "PSExitCodeMapping"},
55+
{"Microsoft.Azure.Batch.ExitOptions", "PSExitOptions"},
5256
{"Microsoft.Azure.Batch.FileProperties", "PSFileProperties"},
57+
{"Microsoft.Azure.Batch.ImageReference", "PSImageReference"},
5358
{"Microsoft.Azure.Batch.RemoteLoginSettings", "PSRemoteLoginSettings"},
5459
{"Microsoft.Azure.Batch.JobConstraints", "PSJobConstraints"},
5560
{"Microsoft.Azure.Batch.JobExecutionInformation", "PSJobExecutionInformation"},
@@ -67,6 +72,8 @@ public class Program
6772
{"Microsoft.Azure.Batch.MetadataItem", "PSMetadataItem"},
6873
{"Microsoft.Azure.Batch.MultiInstanceSettings", "PSMultiInstanceSettings"},
6974
{"Microsoft.Azure.Batch.NameValuePair", "PSNameValuePair"},
75+
{"Microsoft.Azure.Batch.NetworkConfiguration", "PSNetworkConfiguration"},
76+
{"Microsoft.Azure.Batch.NodeAgentSku", "PSNodeAgentSku"},
7077
{"Microsoft.Azure.Batch.NodeFile", "PSNodeFile"},
7178
{"Microsoft.Azure.Batch.PoolInformation", "PSPoolInformation"},
7279
{"Microsoft.Azure.Batch.PoolSpecification", "PSPoolSpecification"},
@@ -81,23 +88,16 @@ public class Program
8188
{"Microsoft.Azure.Batch.StartTaskInformation", "PSStartTaskInformation"},
8289
{"Microsoft.Azure.Batch.SubtaskInformation", "PSSubtaskInformation"},
8390
{"Microsoft.Azure.Batch.TaskConstraints", "PSTaskConstraints"},
91+
{"Microsoft.Azure.Batch.TaskDependencies", "PSTaskDependencies"},
8492
{"Microsoft.Azure.Batch.TaskExecutionInformation", "PSTaskExecutionInformation"},
8593
{"Microsoft.Azure.Batch.TaskInformation", "PSTaskInformation"},
8694
{"Microsoft.Azure.Batch.TaskIdRange", "PSTaskIdRange"},
8795
{"Microsoft.Azure.Batch.TaskSchedulingError", "PSTaskSchedulingError"},
8896
{"Microsoft.Azure.Batch.TaskSchedulingPolicy", "PSTaskSchedulingPolicy"},
8997
{"Microsoft.Azure.Batch.TaskStatistics", "PSTaskStatistics"},
9098
{"Microsoft.Azure.Batch.UsageStatistics", "PSUsageStatistics"},
91-
{"Microsoft.Azure.Batch.AffinityInformation", "PSAffinityInformation"},
9299
{"Microsoft.Azure.Batch.VirtualMachineConfiguration", "PSVirtualMachineConfiguration"},
93100
{"Microsoft.Azure.Batch.WindowsConfiguration", "PSWindowsConfiguration"},
94-
{"Microsoft.Azure.Batch.ApplicationPackageReference", "PSApplicationPackageReference"},
95-
{"Microsoft.Azure.Batch.TaskDependencies", "PSTaskDependencies"},
96-
{"Microsoft.Azure.Batch.NetworkConfiguration", "PSNetworkConfiguration"},
97-
{"Microsoft.Azure.Batch.ExitConditions", "PSExitConditions"},
98-
{"Microsoft.Azure.Batch.ExitOptions", "PSExitOptions"},
99-
{"Microsoft.Azure.Batch.ExitCodeRangeMapping", "PSExitCodeRangeMapping"},
100-
{"Microsoft.Azure.Batch.ExitCodeMapping", "PSExitCodeMapping"},
101101
};
102102

103103

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

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,19 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
583583
return response;
584584
}
585585

586+
/// <summary>
587+
/// Builds a CloudJobGetResponse object
588+
/// </summary>
589+
public static AzureOperationResponse<ProxyModels.CloudJob, ProxyModels.JobGetHeaders> CreateCloudJobGetResponse(ProxyModels.CloudJob job)
590+
{
591+
var response = new AzureOperationResponse<ProxyModels.CloudJob, ProxyModels.JobGetHeaders>
592+
{
593+
Response = new HttpResponseMessage(HttpStatusCode.OK),
594+
Body = job
595+
};
596+
return response;
597+
}
598+
586599
/// <summary>
587600
/// Builds a CloudJobListResponse object
588601
/// </summary>
@@ -620,6 +633,16 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
620633

621634
return response;
622635
}
636+
/// <summary>
637+
/// Builds a CloudTaskGetResponse object
638+
/// </summary>
639+
public static AzureOperationResponse<ProxyModels.CloudTask, ProxyModels.TaskGetHeaders> CreateCloudTaskGetResponse(ProxyModels.CloudTask task)
640+
{
641+
var response = new AzureOperationResponse<ProxyModels.CloudTask, ProxyModels.TaskGetHeaders>();
642+
response.Response = new HttpResponseMessage(HttpStatusCode.OK);
643+
response.Body = task;
644+
return response;
645+
}
623646

624647
/// <summary>
625648
/// Builds a CloudTaskListResponse object
@@ -798,25 +821,22 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
798821
/// <summary>
799822
/// Fabricates a CloudJob that's in the bound state
800823
/// </summary>
801-
public static CloudJob CreateFakeBoundJob(BatchAccountContext context)
824+
public static CloudJob CreateFakeBoundJob(BatchAccountContext context, ProxyModels.CloudJob cloudJob)
802825
{
803-
string jobId = "testJob";
804-
805826
RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
806827
{
807828
JobGetBatchRequest request = (JobGetBatchRequest)baseRequest;
808829

809830
request.ServiceRequestFunc = (cancellationToken) =>
810831
{
811-
var response = new AzureOperationResponse<ProxyModels.CloudJob, ProxyModels.JobGetHeaders>();
812-
response.Body = new ProxyModels.CloudJob(id: jobId, poolInfo: new ProxyModels.PoolInformation());
832+
var response = new AzureOperationResponse<ProxyModels.CloudJob, ProxyModels.JobGetHeaders> { Body = cloudJob };
813833

814834
Task<AzureOperationResponse<ProxyModels.CloudJob, ProxyModels.JobGetHeaders>> task = Task.FromResult(response);
815835
return task;
816836
};
817837
});
818838

819-
return context.BatchOMClient.JobOperations.GetJob(jobId, additionalBehaviors: new BatchClientBehavior[] { interceptor });
839+
return context.BatchOMClient.JobOperations.GetJob(cloudJob.Id, additionalBehaviors: new BatchClientBehavior[] { interceptor });
820840
}
821841

822842
/// <summary>

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@
4444
<Reference Include="Hyak.Common">
4545
<HintPath>..\..\..\packages\Hyak.Common.1.0.3\lib\portable-net403+win+wpa81\Hyak.Common.dll</HintPath>
4646
</Reference>
47-
<Reference Include="Microsoft.Azure.Batch, Version=5.0.0.0, Culture=neutral, processorArchitecture=MSIL">
48-
<HintPath>..\..\..\packages\Azure.Batch.5.0.0\lib\net45\Microsoft.Azure.Batch.dll</HintPath>
47+
<Reference Include="Microsoft.Azure.Batch, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
48+
<SpecificVersion>False</SpecificVersion>
49+
<HintPath>..\..\..\packages\Azure.Batch.5.1.0\lib\net45\Microsoft.Azure.Batch.dll</HintPath>
50+
<Private>True</Private>
4951
</Reference>
5052
<Reference Include="Microsoft.Azure.Common">
5153
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.dll</HintPath>
@@ -270,6 +272,7 @@
270272
<Compile Include="JobSchedules\NewBatchJobScheduleCommandTests.cs" />
271273
<Compile Include="JobSchedules\RemoveBatchJobScheduleCommandTests.cs" />
272274
<Compile Include="Tasks\SetBatchTaskCommandTests.cs" />
275+
<Compile Include="Tasks\EnableBatchTaskCommandTests.cs" />
273276
<Compile Include="Tasks\StopBatchTaskCommandTests.cs" />
274277
</ItemGroup>
275278
<ItemGroup>
@@ -526,6 +529,9 @@
526529
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.JobScheduleTests\TestUpdateJobSchedule.json">
527530
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
528531
</None>
532+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.JobTests\IfJobSetsAutoFailure_ItCompletesWhenAnyTaskFails.json" >
533+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
534+
</None>
529535
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.JobTests\TestDeleteJob.json">
530536
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
531537
</None>
@@ -713,4 +719,4 @@
713719
<WCFMetadata Include="Service References\" />
714720
</ItemGroup>
715721
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
716-
</Project>
722+
</Project>

src/ResourceManager/AzureBatch/Commands.Batch.Test/Jobs/GetBatchJobCommandTests.cs

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using System.Linq;
2424
using System.Management.Automation;
2525
using System.Threading.Tasks;
26+
using Microsoft.Azure.Batch.Common;
2627
using Xunit;
2728
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
2829
using ProxyModels = Microsoft.Azure.Batch.Protocol.Models;
@@ -58,7 +59,15 @@ public void GetBatchJobTest()
5859
cmdlet.Filter = null;
5960

6061
// Build a CloudJob instead of querying the service on a Get CloudJob call
61-
AzureOperationResponse<ProxyModels.CloudJob, ProxyModels.JobGetHeaders> response = BatchTestHelpers.CreateCloudJobGetResponse(cmdlet.Id);
62+
ProxyModels.CloudJob job = new ProxyModels.CloudJob
63+
{
64+
Id = cmdlet.Id,
65+
OnAllTasksComplete = ProxyModels.OnAllTasksComplete.TerminateJob,
66+
OnTaskFailure = ProxyModels.OnTaskFailure.PerformExitOptionsJobAction
67+
};
68+
69+
AzureOperationResponse<ProxyModels.CloudJob, ProxyModels.JobGetHeaders> response = BatchTestHelpers.CreateCloudJobGetResponse(job);
70+
6271
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<
6372
ProxyModels.JobGetOptions,
6473
AzureOperationResponse<ProxyModels.CloudJob, ProxyModels.JobGetHeaders>>(response);
@@ -74,6 +83,8 @@ public void GetBatchJobTest()
7483
// Verify that the cmdlet wrote the job returned from the OM to the pipeline
7584
Assert.Equal(1, pipeline.Count);
7685
Assert.Equal(cmdlet.Id, pipeline[0].Id);
86+
Assert.Equal(OnTaskFailure.PerformExitOptionsJobAction, pipeline[0].OnTaskFailure);
87+
Assert.Equal(OnAllTasksComplete.TerminateJob, pipeline[0].OnAllTasksComplete);
7788
}
7889

7990
[Fact]
@@ -229,5 +240,53 @@ public void ListJobsMaxCountTest()
229240

230241
Assert.Equal(idsOfConstructedJobs.Length, pipeline.Count);
231242
}
243+
244+
[Fact]
245+
[Trait(Category.AcceptanceType, Category.CheckIn)]
246+
public void WhenGettingAJobFromTheService_ApplicationPackageReferencesAreMapped()
247+
{
248+
// Setup cmdlet to get a Job by id
249+
250+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
251+
cmdlet.BatchContext = context;
252+
cmdlet.Id = "job-1";
253+
cmdlet.Filter = null;
254+
255+
// Build a CloudJob instead of querying the service on a Get CloudJob call
256+
string applicationId = "foo";
257+
string applicationVersion = "beta";
258+
ProxyModels.CloudJob cloudTask = new ProxyModels.CloudJob
259+
{
260+
Id = "job-1",
261+
JobManagerTask = new ProxyModels.JobManagerTask
262+
{
263+
ApplicationPackageReferences = new[]
264+
{
265+
new ProxyModels.ApplicationPackageReference(applicationId, applicationVersion)
266+
}
267+
}
268+
};
269+
270+
AzureOperationResponse<ProxyModels.CloudJob, ProxyModels.JobGetHeaders> response = BatchTestHelpers.CreateCloudJobGetResponse(cloudTask);
271+
272+
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<ProxyModels.JobGetOptions,
273+
AzureOperationResponse<ProxyModels.CloudJob, ProxyModels.JobGetHeaders>>(response);
274+
275+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior> { interceptor };
276+
277+
// Setup the cmdlet to write pipeline output to a list that can be examined later
278+
var pipeline = new List<PSCloudJob>();
279+
commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny<PSCloudJob>())).Callback<object>(t => pipeline.Add((PSCloudJob)t));
280+
281+
cmdlet.ExecuteCmdlet();
282+
283+
// Verify that the cmdlet wrote the task returned from the OM to the pipeline
284+
Assert.Equal(1, pipeline.Count);
285+
Assert.Equal(cmdlet.Id, pipeline[0].Id);
286+
287+
var psApplicationPackageReference = pipeline[0].JobManagerTask.ApplicationPackageReferences.First();
288+
Assert.Equal(applicationId, psApplicationPackageReference.ApplicationId);
289+
Assert.Equal(applicationVersion, psApplicationPackageReference.Version);
290+
}
232291
}
233292
}

src/ResourceManager/AzureBatch/Commands.Batch.Test/Jobs/NewBatchJobCommandTests.cs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
using Microsoft.Azure.Batch;
1616
using Microsoft.Azure.Batch.Protocol;
1717
using Microsoft.Azure.Batch.Protocol.Models;
18+
using Microsoft.Azure.Commands.Batch.Models;
1819
using Microsoft.Rest.Azure;
1920
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2021
using Moq;
2122
using System;
2223
using System.Collections.Generic;
24+
using System.Linq;
2325
using System.Management.Automation;
2426
using Xunit;
2527
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
@@ -55,9 +57,49 @@ public void NewBatchJobParametersTest()
5557
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
5658

5759
cmdlet.Id = "testJob";
60+
cmdlet.OnAllTasksComplete = Azure.Batch.Common.OnAllTasksComplete.TerminateJob;
61+
cmdlet.OnTaskFailure = Azure.Batch.Common.OnTaskFailure.PerformExitOptionsJobAction;
5862

5963
// Don't go to the service on an Add CloudJob call
60-
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<JobAddParameter, JobAddOptions, AzureOperationHeaderResponse<JobAddHeaders>>();
64+
var interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<JobAddParameter, JobAddOptions, AzureOperationHeaderResponse<JobAddHeaders>>(
65+
new AzureOperationHeaderResponse<JobAddHeaders>(),
66+
request =>
67+
{
68+
Assert.Equal(request.Parameters.OnAllTasksComplete, OnAllTasksComplete.TerminateJob);
69+
Assert.Equal(request.Parameters.OnTaskFailure, OnTaskFailure.PerformExitOptionsJobAction);
70+
});
71+
72+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
73+
74+
// Verify no exceptions when required parameters are set
75+
cmdlet.ExecuteCmdlet();
76+
}
77+
78+
[Fact]
79+
[Trait(Category.AcceptanceType, Category.CheckIn)]
80+
public void ApplicationPackageReferencesAreSentToService()
81+
{
82+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
83+
cmdlet.BatchContext = context;
84+
cmdlet.Id = "job-id";
85+
string applicationId = "foo";
86+
string applicationVersion = "beta";
87+
88+
cmdlet.JobManagerTask = new PSJobManagerTask { ApplicationPackageReferences = new[]
89+
{
90+
new PSApplicationPackageReference { ApplicationId = applicationId, Version = applicationVersion} ,
91+
}};
92+
93+
// Don't go to the service on an Add CloudJob call
94+
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<JobAddParameter, JobAddOptions, AzureOperationHeaderResponse<JobAddHeaders>>(
95+
new AzureOperationHeaderResponse<JobAddHeaders>(),
96+
request =>
97+
{
98+
var applicationPackageReference = request.Parameters.JobManagerTask.ApplicationPackageReferences.First();
99+
Assert.Equal(applicationId, applicationPackageReference.ApplicationId);
100+
Assert.Equal(applicationVersion, applicationPackageReference.Version);
101+
});
102+
61103
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
62104

63105
// Verify no exceptions when required parameters are set

0 commit comments

Comments
 (0)