-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1970 from matthchr/feature/add-batch
Add Azure Batch C# client (autogenerated, tooling, testing, and handcrafted helpers)
- Loading branch information
Showing
647 changed files
with
118,579 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.24720.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Batch", "Src\Batch.csproj", "{3328FBBF-9C20-4775-B367-856C09DC13BF}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Src", "Src", "{9EC38B72-3B6D-46DF-89B4-1CF689C3CB2C}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Batch.Unit.Tests", "Tests\ObjectModel\Azure.Batch.Unit.Tests\Azure.Batch.Unit.Tests.csproj", "{37F66AC7-C54C-4FE2-B691-5260D3971BAB}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{C62E0485-00BD-4C9E-912D-752B0B50E050}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ObjectModel", "ObjectModel", "{973E84B0-A7DE-46EC-AD73-A5224D8041C8}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Azure.Batch.Unit.Tests", "Azure.Batch.Unit.Tests", "{1C4CF4F3-AE0A-4194-9C99-087DFC6E3DC2}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BatchTestCommon", "Tests\ObjectModel\Common\BatchTestCommon.csproj", "{B697759F-6EF9-4142-8BD3-D78BF18C678E}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{29D10BE2-8818-46D0-9104-39FD62BD7A24}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BatchClientIntegrationTests", "Tests\ObjectModel\BatchClientIntegrationTests\BatchClientIntegrationTests.csproj", "{C809285A-784D-48E4-9D7A-F5685A19F595}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BatchClientIntegrationTests", "BatchClientIntegrationTests", "{62E96F01-6F15-420C-BA43-0BA18914DE5E}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BatchProxyIntegrationTests", "Tests\ProtocolLayer\BatchProxyIntegrationTests\BatchProxyIntegrationTests.csproj", "{FFA1A7D5-AE12-4F66-91A8-C2DE2E383E12}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ProtocolLayer", "ProtocolLayer", "{E105A452-302D-4CC8-A371-49EF488B4DF1}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BatchProxyIntegrationTests", "BatchProxyIntegrationTests", "{565840EA-7ADC-438C-8CB3-23D56A0C57BD}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{3DE96B66-463F-470B-92F2-7284A2DD022C}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeGenerationLibrary", "Tools\ObjectModelCodeGeneration\CodeGenerationLibrary\CodeGenerationLibrary.csproj", "{4D93A489-2576-400B-93CD-9340A892B0E8}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ObjectModelCodeGeneration", "ObjectModelCodeGeneration", "{CB71AF88-3513-4109-92D4-0BA8770BB454}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CodeGenerationLibrary", "CodeGenerationLibrary", "{64425AA2-0B20-46B6-8BC6-A4D64C1C50D0}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ObjectModelCodeGenerator", "Tools\ObjectModelCodeGeneration\ObjectModelCodeGenerator\ObjectModelCodeGenerator.csproj", "{8734474A-543E-46C3-8E1B-6B37E4B97C78}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ObjectModelCodeGenerator", "ObjectModelCodeGenerator", "{380D5910-2411-4E93-AE2B-1533033A8D79}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Net45-Debug|Any CPU = Net45-Debug|Any CPU | ||
Net45-Release|Any CPU = Net45-Release|Any CPU | ||
Portable-Debug|Any CPU = Portable-Debug|Any CPU | ||
Portable-Release|Any CPU = Portable-Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{3328FBBF-9C20-4775-B367-856C09DC13BF}.Net45-Debug|Any CPU.ActiveCfg = Net45-Debug|Any CPU | ||
{3328FBBF-9C20-4775-B367-856C09DC13BF}.Net45-Debug|Any CPU.Build.0 = Net45-Debug|Any CPU | ||
{3328FBBF-9C20-4775-B367-856C09DC13BF}.Net45-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU | ||
{3328FBBF-9C20-4775-B367-856C09DC13BF}.Net45-Release|Any CPU.Build.0 = Net45-Release|Any CPU | ||
{3328FBBF-9C20-4775-B367-856C09DC13BF}.Portable-Debug|Any CPU.ActiveCfg = Portable-Debug|Any CPU | ||
{3328FBBF-9C20-4775-B367-856C09DC13BF}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU | ||
{37F66AC7-C54C-4FE2-B691-5260D3971BAB}.Net45-Debug|Any CPU.ActiveCfg = Net45-Debug|Any CPU | ||
{37F66AC7-C54C-4FE2-B691-5260D3971BAB}.Net45-Debug|Any CPU.Build.0 = Net45-Debug|Any CPU | ||
{37F66AC7-C54C-4FE2-B691-5260D3971BAB}.Net45-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU | ||
{37F66AC7-C54C-4FE2-B691-5260D3971BAB}.Portable-Debug|Any CPU.ActiveCfg = Portable-Debug|Any CPU | ||
{37F66AC7-C54C-4FE2-B691-5260D3971BAB}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU | ||
{B697759F-6EF9-4142-8BD3-D78BF18C678E}.Net45-Debug|Any CPU.ActiveCfg = Net45-Debug|Any CPU | ||
{B697759F-6EF9-4142-8BD3-D78BF18C678E}.Net45-Debug|Any CPU.Build.0 = Net45-Debug|Any CPU | ||
{B697759F-6EF9-4142-8BD3-D78BF18C678E}.Net45-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU | ||
{B697759F-6EF9-4142-8BD3-D78BF18C678E}.Portable-Debug|Any CPU.ActiveCfg = Portable-Debug|Any CPU | ||
{B697759F-6EF9-4142-8BD3-D78BF18C678E}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU | ||
{C809285A-784D-48E4-9D7A-F5685A19F595}.Net45-Debug|Any CPU.ActiveCfg = Net45-Debug|Any CPU | ||
{C809285A-784D-48E4-9D7A-F5685A19F595}.Net45-Debug|Any CPU.Build.0 = Net45-Debug|Any CPU | ||
{C809285A-784D-48E4-9D7A-F5685A19F595}.Net45-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU | ||
{C809285A-784D-48E4-9D7A-F5685A19F595}.Portable-Debug|Any CPU.ActiveCfg = Portable-Debug|Any CPU | ||
{C809285A-784D-48E4-9D7A-F5685A19F595}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU | ||
{FFA1A7D5-AE12-4F66-91A8-C2DE2E383E12}.Net45-Debug|Any CPU.ActiveCfg = Net45-Debug|Any CPU | ||
{FFA1A7D5-AE12-4F66-91A8-C2DE2E383E12}.Net45-Debug|Any CPU.Build.0 = Net45-Debug|Any CPU | ||
{FFA1A7D5-AE12-4F66-91A8-C2DE2E383E12}.Net45-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU | ||
{FFA1A7D5-AE12-4F66-91A8-C2DE2E383E12}.Portable-Debug|Any CPU.ActiveCfg = Portable-Debug|Any CPU | ||
{FFA1A7D5-AE12-4F66-91A8-C2DE2E383E12}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU | ||
{4D93A489-2576-400B-93CD-9340A892B0E8}.Net45-Debug|Any CPU.ActiveCfg = Net45-Debug|Any CPU | ||
{4D93A489-2576-400B-93CD-9340A892B0E8}.Net45-Debug|Any CPU.Build.0 = Net45-Debug|Any CPU | ||
{4D93A489-2576-400B-93CD-9340A892B0E8}.Net45-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU | ||
{4D93A489-2576-400B-93CD-9340A892B0E8}.Portable-Debug|Any CPU.ActiveCfg = Portable-Release|Any CPU | ||
{4D93A489-2576-400B-93CD-9340A892B0E8}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU | ||
{8734474A-543E-46C3-8E1B-6B37E4B97C78}.Net45-Debug|Any CPU.ActiveCfg = Net45-Debug|Any CPU | ||
{8734474A-543E-46C3-8E1B-6B37E4B97C78}.Net45-Debug|Any CPU.Build.0 = Net45-Debug|Any CPU | ||
{8734474A-543E-46C3-8E1B-6B37E4B97C78}.Net45-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU | ||
{8734474A-543E-46C3-8E1B-6B37E4B97C78}.Portable-Debug|Any CPU.ActiveCfg = Portable-Debug|Any CPU | ||
{8734474A-543E-46C3-8E1B-6B37E4B97C78}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{3328FBBF-9C20-4775-B367-856C09DC13BF} = {9EC38B72-3B6D-46DF-89B4-1CF689C3CB2C} | ||
{37F66AC7-C54C-4FE2-B691-5260D3971BAB} = {1C4CF4F3-AE0A-4194-9C99-087DFC6E3DC2} | ||
{973E84B0-A7DE-46EC-AD73-A5224D8041C8} = {C62E0485-00BD-4C9E-912D-752B0B50E050} | ||
{1C4CF4F3-AE0A-4194-9C99-087DFC6E3DC2} = {973E84B0-A7DE-46EC-AD73-A5224D8041C8} | ||
{B697759F-6EF9-4142-8BD3-D78BF18C678E} = {29D10BE2-8818-46D0-9104-39FD62BD7A24} | ||
{29D10BE2-8818-46D0-9104-39FD62BD7A24} = {973E84B0-A7DE-46EC-AD73-A5224D8041C8} | ||
{C809285A-784D-48E4-9D7A-F5685A19F595} = {62E96F01-6F15-420C-BA43-0BA18914DE5E} | ||
{62E96F01-6F15-420C-BA43-0BA18914DE5E} = {973E84B0-A7DE-46EC-AD73-A5224D8041C8} | ||
{FFA1A7D5-AE12-4F66-91A8-C2DE2E383E12} = {565840EA-7ADC-438C-8CB3-23D56A0C57BD} | ||
{E105A452-302D-4CC8-A371-49EF488B4DF1} = {C62E0485-00BD-4C9E-912D-752B0B50E050} | ||
{565840EA-7ADC-438C-8CB3-23D56A0C57BD} = {E105A452-302D-4CC8-A371-49EF488B4DF1} | ||
{4D93A489-2576-400B-93CD-9340A892B0E8} = {64425AA2-0B20-46B6-8BC6-A4D64C1C50D0} | ||
{CB71AF88-3513-4109-92D4-0BA8770BB454} = {3DE96B66-463F-470B-92F2-7284A2DD022C} | ||
{64425AA2-0B20-46B6-8BC6-A4D64C1C50D0} = {CB71AF88-3513-4109-92D4-0BA8770BB454} | ||
{8734474A-543E-46C3-8E1B-6B37E4B97C78} = {380D5910-2411-4E93-AE2B-1533033A8D79} | ||
{380D5910-2411-4E93-AE2B-1533033A8D79} = {CB71AF88-3513-4109-92D4-0BA8770BB454} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using System.Threading; | ||
using Microsoft.Azure.Batch.Common; | ||
|
||
namespace Microsoft.Azure.Batch | ||
{ | ||
// TODO: the original documentation stated that this is for controlling parallelism but it's not clear what | ||
// you would do here in order to do that - that seems to be more governed by the parallelOptions argument to | ||
// AddTaskAsync. | ||
|
||
/// <summary> | ||
/// A <see cref="BatchClientBehavior"/> which you can use to specify under what conditions an operation to | ||
/// add multiple tasks to a job should retry, terminate or be considered successful. | ||
/// </summary> | ||
/// <remarks>You do not need to specify this behavior explicitly; if you do not, a default behavior | ||
/// is used. This behavior uses the <see cref="DefaultAddTaskCollectionResultHandler(AddTaskResult, CancellationToken)"/> | ||
/// criteria.</remarks> | ||
public class AddTaskCollectionResultHandler : BatchClientBehavior | ||
{ | ||
/// <summary> | ||
/// Gets or sets the function that defines whether a particular Add Task operation is considered | ||
/// successful or unsuccessful, and whether it may be retried. | ||
/// </summary> | ||
public Func<AddTaskResult, CancellationToken, AddTaskResultStatus> ResultHandler { get; set; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AddTaskCollectionResultHandler"/> class with the specified result handler function. | ||
/// </summary> | ||
/// <param name="resultHandler">A function that defines whether a particular Add Task operation is considered | ||
/// successful or unsuccessful, and whether it may be retried.</param> | ||
public AddTaskCollectionResultHandler(Func<AddTaskResult, CancellationToken, AddTaskResultStatus> resultHandler) | ||
{ | ||
if (resultHandler == null) | ||
{ | ||
throw new ArgumentNullException("resultHandler"); | ||
} | ||
|
||
this.ResultHandler = resultHandler; | ||
} | ||
|
||
/// <summary> | ||
/// The default result handler for the <see cref="AddTaskCollectionResultHandler"/> behavior. This handler | ||
/// treats success and 'TaskExists' errors as successful, retries server errors (HTTP 5xx), and throws | ||
/// <see cref="AddTaskCollectionTerminatedException"/> on client error (HTTP 4xx). | ||
/// </summary> | ||
/// <param name="addTaskResult">The result of a single Add Task operation.</param> | ||
/// <param name="cancellationToken">The cancellation token associated with the AddTaskCollection operation.</param> | ||
/// <returns>An <see cref="AddTaskResultStatus"/> which indicates whether the <paramref name="addTaskResult"/> | ||
/// is classified as a success or as requiring a retry.</returns> | ||
public static AddTaskResultStatus DefaultAddTaskCollectionResultHandler(AddTaskResult addTaskResult, CancellationToken cancellationToken) | ||
{ | ||
if (addTaskResult == null) | ||
{ | ||
throw new ArgumentNullException("addTaskResult"); | ||
} | ||
|
||
AddTaskResultStatus status = AddTaskResultStatus.Success; | ||
if (addTaskResult.Error != null) | ||
{ | ||
//Check status code | ||
if (addTaskResult.Status == AddTaskStatus.ServerError) | ||
{ | ||
status = AddTaskResultStatus.Retry; | ||
} | ||
else if (addTaskResult.Status == AddTaskStatus.ClientError && addTaskResult.Error.Code == BatchErrorCodeStrings.TaskExists) | ||
{ | ||
status = AddTaskResultStatus.Success; //Count TaskExists as a success always | ||
} | ||
else | ||
{ | ||
//Anything else is a failure -- abort the work flow | ||
throw new AddTaskCollectionTerminatedException(string.Format(BatchErrorMessages.AddTaskCollectionTerminated, addTaskResult.TaskId, addTaskResult.Status)); | ||
} | ||
} | ||
return status; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
namespace Microsoft.Azure.Batch | ||
{ | ||
using System; | ||
|
||
public partial class AddTaskResult | ||
{ | ||
private readonly CloudTask task; | ||
private readonly int retryCount; | ||
|
||
internal AddTaskResult(CloudTask task, int retryCount, Protocol.Models.TaskAddResult addTaskResult) : this(addTaskResult) | ||
{ | ||
this.task = task; | ||
this.retryCount = retryCount; | ||
} | ||
|
||
/// <summary> | ||
/// Gets details of the task. | ||
/// </summary> | ||
public CloudTask Task | ||
{ | ||
get { return this.task; } | ||
} | ||
|
||
/// <summary> | ||
/// Gets the number of times the Add Task operation was retried for this task. | ||
/// </summary> | ||
public int RetryCount | ||
{ | ||
get { return this.retryCount; } | ||
} | ||
|
||
}; | ||
|
||
/// <summary> | ||
/// Used by <see cref="AddTaskCollectionResultHandler"/> to classify an <see cref="AddTaskResult"/> as successful or | ||
/// requiring a retry. | ||
/// </summary> | ||
/// <remarks>AddTaskResultStatus is not used to report non-retryable failure; a result handler should throw | ||
/// <see cref="AddTaskCollectionTerminatedException"/> for that.</remarks> | ||
public enum AddTaskResultStatus | ||
{ | ||
/// <summary> | ||
/// Classifies the result as a success. | ||
/// </summary> | ||
Success, | ||
|
||
/// <summary> | ||
/// Classifies the result as requiring a retry. | ||
/// </summary> | ||
Retry | ||
} | ||
} |
Oops, something went wrong.