Skip to content

Commit

Permalink
Update Azure Batch to 5.1.0 (Azure#3513)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthchr authored and ro-joowan committed Jul 28, 2017
1 parent 0bbe518 commit a01781f
Show file tree
Hide file tree
Showing 15 changed files with 962 additions and 364 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,20 @@ public async Task BatchAccountEndToEndAsync()

try
{
// Check if the account exists
var checkAvailabilityResult = await this.BatchManagementClient.Location.CheckNameAvailabilityAsync(this.Location, batchAccountName);
Assert.True(checkAvailabilityResult.NameAvailable);

// Create an account
BatchAccountCreateParameters createParams = new BatchAccountCreateParameters(this.Location);
await this.BatchManagementClient.BatchAccount.CreateAsync(resourceGroupName, batchAccountName, createParams);

// Check if the account exists now
checkAvailabilityResult = await this.BatchManagementClient.Location.CheckNameAvailabilityAsync(this.Location, batchAccountName);
Assert.False(checkAvailabilityResult.NameAvailable);
Assert.NotNull(checkAvailabilityResult.Message);
Assert.NotNull(checkAvailabilityResult.Reason);

// Get the account and verify some properties
BatchAccount batchAccount = await this.BatchManagementClient.BatchAccount.GetAsync(resourceGroupName, batchAccountName);
Assert.Equal(batchAccountName, batchAccount.Name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,46 @@ protected MockContext StartMockContextAndInitializeClients(string className,
string methodName = "")
{
MockContext context = MockContext.Start(className, methodName);
Initialize(context);
this.Location = FindLocation(context);

this.ResourceManagementClient = context.GetServiceClient<ResourceManagementClient>();
this.BatchManagementClient = context.GetServiceClient<BatchManagementClient>();
return context;
}

private void Initialize(MockContext context)
private static string FindLocation(MockContext context)
{
this.ResourceManagementClient = context.GetServiceClient<ResourceManagementClient>();
this.BatchManagementClient = context.GetServiceClient<BatchManagementClient>();
var resourceManagementClient = context.GetServiceClient<ResourceManagementClient>();
Provider provider = resourceManagementClient.Providers.Get("Microsoft.Batch");
IList <string> locations = provider.ResourceTypes.First(resType => resType.ResourceType == "batchAccounts").Locations;
return locations.First(location => location == "East US");
}

// Can be used to find a region to test against, but probably shouldn't record tests that use this as it will leave your subscription account details in the
// logs
private static string FindLocationWithQuotaCheck(MockContext context)
{
var resourceManagementClient = context.GetServiceClient<ResourceManagementClient>();
var batchManagementClient = context.GetServiceClient<BatchManagementClient>();

Provider provider = resourceManagementClient.Providers.Get("Microsoft.Batch");
IEnumerable<string> locations = provider.ResourceTypes.First(resType => resType.ResourceType == "batchAccounts").Locations.DefaultIfEmpty("westus");

var locationQuotaInUse = batchManagementClient.BatchAccount.List().GroupBy(acct => acct.Location).ToDictionary(a => a.Key, x => x.Count());

foreach(var location in locations)
{
var transformedLocation = location.Replace(" ", "").ToLower();
var quotas = batchManagementClient.Location.GetQuotas(location);
int accountsInUse;
locationQuotaInUse.TryGetValue(transformedLocation, out accountsInUse);
if (quotas.AccountQuota - accountsInUse > 0)
{
return location;
}
}

Provider provider = this.ResourceManagementClient.Providers.Get("Microsoft.Batch");
IList<string> locations = provider.ResourceTypes.Where((resType) => resType.ResourceType == "batchAccounts").First().Locations;
this.Location = locations.DefaultIfEmpty("westus").First();
throw new ArgumentException("No location found that satisfies quota requirements");
}
}
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
"RequestBody": "",
"RequestHeaders": {
"x-ms-client-request-id": [
"addfd377-78c7-4eb4-b9f4-3b9266f36c7e"
"a444fc9a-eb0d-4fda-a1ed-521f66e44dc8"
],
"accept-language": [
"en-US"
],
"User-Agent": [
"FxVersion/4.6.25009.03",
"Microsoft.Azure.Management.ResourceManager.ResourceManagementClient/1.1.3-preview"
"FxVersion/4.6.25211.01",
"Microsoft.Azure.Management.ResourceManager.ResourceManagementClient/1.1.3.0"
]
},
"ResponseBody": "{\r\n \"id\": \"/subscriptions/2915bbd6-1252-405f-8173-6c00428146d9/providers/Microsoft.Batch\",\r\n \"namespace\": \"Microsoft.Batch\",\r\n \"authorization\": {\r\n \"applicationId\": \"ddbf3205-c6bd-46ae-8127-60eb93363864\",\r\n \"roleDefinitionId\": \"b7f84953-1d03-4eab-9ea4-45f065258ff8\"\r\n },\r\n \"resourceTypes\": [\r\n {\r\n \"resourceType\": \"batchAccounts\",\r\n \"locations\": [\r\n \"West Europe\",\r\n \"East US\",\r\n \"East US 2\",\r\n \"West US\",\r\n \"North Central US\",\r\n \"Brazil South\",\r\n \"North Europe\",\r\n \"Central US\",\r\n \"East Asia\",\r\n \"Japan East\",\r\n \"Australia Southeast\",\r\n \"Japan West\",\r\n \"Korea South\",\r\n \"Korea Central\",\r\n \"Southeast Asia\",\r\n \"South Central US\",\r\n \"Australia East\",\r\n \"South India\",\r\n \"Central India\",\r\n \"West India\",\r\n \"Canada Central\",\r\n \"Canada East\",\r\n \"UK South\",\r\n \"UK West\",\r\n \"West Central US\",\r\n \"West US 2\",\r\n \"East US 2 EUAP\",\r\n \"Central US EUAP\"\r\n ],\r\n \"apiVersions\": [\r\n \"2017-05-01\",\r\n \"2017-01-01\",\r\n \"2015-12-01\",\r\n \"2015-09-01\",\r\n \"2015-07-01\",\r\n \"2014-05-01-privatepreview\"\r\n ],\r\n \"capabilities\": \"CrossResourceGroupResourceMove, CrossSubscriptionResourceMove\"\r\n },\r\n {\r\n \"resourceType\": \"operations\",\r\n \"locations\": [\r\n \"West Europe\",\r\n \"East US\",\r\n \"East US 2\",\r\n \"West US\",\r\n \"North Central US\",\r\n \"Brazil South\",\r\n \"North Europe\",\r\n \"Central US\",\r\n \"East Asia\",\r\n \"Japan East\",\r\n \"Australia Southeast\",\r\n \"Japan West\",\r\n \"Korea South\",\r\n \"Korea Central\",\r\n \"Southeast Asia\",\r\n \"South Central US\",\r\n \"Australia East\",\r\n \"South India\",\r\n \"Central India\",\r\n \"West India\",\r\n \"Canada Central\",\r\n \"Canada East\",\r\n \"UK South\",\r\n \"UK West\",\r\n \"West Central US\",\r\n \"West US 2\",\r\n \"East US 2 EUAP\",\r\n \"Central US EUAP\"\r\n ],\r\n \"apiVersions\": [\r\n \"2017-05-01\",\r\n \"2017-01-01\",\r\n \"2015-12-01\",\r\n \"2015-09-01\"\r\n ]\r\n },\r\n {\r\n \"resourceType\": \"locations\",\r\n \"locations\": [],\r\n \"apiVersions\": [\r\n \"2017-05-01\",\r\n \"2017-01-01\",\r\n \"2015-12-01\",\r\n \"2015-09-01\"\r\n ]\r\n },\r\n {\r\n \"resourceType\": \"locations/quotas\",\r\n \"locations\": [\r\n \"West Europe\",\r\n \"East US\",\r\n \"East US 2\",\r\n \"West US\",\r\n \"North Central US\",\r\n \"Brazil South\",\r\n \"North Europe\",\r\n \"Central US\",\r\n \"East Asia\",\r\n \"Japan East\",\r\n \"Australia Southeast\",\r\n \"Japan West\",\r\n \"Korea South\",\r\n \"Korea Central\",\r\n \"Southeast Asia\",\r\n \"South Central US\",\r\n \"Australia East\",\r\n \"South India\",\r\n \"Central India\",\r\n \"West India\",\r\n \"Canada Central\",\r\n \"Canada East\",\r\n \"UK South\",\r\n \"UK West\",\r\n \"West Central US\",\r\n \"West US 2\",\r\n \"East US 2 EUAP\",\r\n \"Central US EUAP\"\r\n ],\r\n \"apiVersions\": [\r\n \"2017-05-01\",\r\n \"2017-01-01\",\r\n \"2015-12-01\",\r\n \"2015-09-01\"\r\n ]\r\n }\r\n ],\r\n \"registrationState\": \"Registered\"\r\n}",
"ResponseBody": "{\r\n \"id\": \"/subscriptions/2915bbd6-1252-405f-8173-6c00428146d9/providers/Microsoft.Batch\",\r\n \"namespace\": \"Microsoft.Batch\",\r\n \"authorization\": {\r\n \"applicationId\": \"ddbf3205-c6bd-46ae-8127-60eb93363864\",\r\n \"roleDefinitionId\": \"b7f84953-1d03-4eab-9ea4-45f065258ff8\"\r\n },\r\n \"resourceTypes\": [\r\n {\r\n \"resourceType\": \"batchAccounts\",\r\n \"locations\": [\r\n \"West Europe\",\r\n \"East US\",\r\n \"East US 2\",\r\n \"West US\",\r\n \"North Central US\",\r\n \"Brazil South\",\r\n \"North Europe\",\r\n \"Central US\",\r\n \"East Asia\",\r\n \"Japan East\",\r\n \"Australia Southeast\",\r\n \"Japan West\",\r\n \"Korea South\",\r\n \"Korea Central\",\r\n \"Southeast Asia\",\r\n \"South Central US\",\r\n \"Australia East\",\r\n \"South India\",\r\n \"Central India\",\r\n \"West India\",\r\n \"Canada Central\",\r\n \"Canada East\",\r\n \"UK South\",\r\n \"UK West\",\r\n \"West Central US\",\r\n \"West US 2\",\r\n \"East US 2 EUAP\",\r\n \"Central US EUAP\"\r\n ],\r\n \"apiVersions\": [\r\n \"2017-05-01\",\r\n \"2017-01-01\",\r\n \"2015-12-01\",\r\n \"2015-09-01\",\r\n \"2015-07-01\",\r\n \"2014-05-01-privatepreview\"\r\n ],\r\n \"capabilities\": \"CrossResourceGroupResourceMove, CrossSubscriptionResourceMove\"\r\n },\r\n {\r\n \"resourceType\": \"operations\",\r\n \"locations\": [\r\n \"West Europe\",\r\n \"East US\",\r\n \"East US 2\",\r\n \"West US\",\r\n \"North Central US\",\r\n \"Brazil South\",\r\n \"North Europe\",\r\n \"Central US\",\r\n \"East Asia\",\r\n \"Japan East\",\r\n \"Australia Southeast\",\r\n \"Japan West\",\r\n \"Korea South\",\r\n \"Korea Central\",\r\n \"Southeast Asia\",\r\n \"South Central US\",\r\n \"Australia East\",\r\n \"South India\",\r\n \"Central India\",\r\n \"West India\",\r\n \"Canada Central\",\r\n \"Canada East\",\r\n \"UK South\",\r\n \"UK West\",\r\n \"West Central US\",\r\n \"West US 2\",\r\n \"East US 2 EUAP\",\r\n \"Central US EUAP\"\r\n ],\r\n \"apiVersions\": [\r\n \"2017-05-01\",\r\n \"2017-01-01\",\r\n \"2015-12-01\",\r\n \"2015-09-01\"\r\n ]\r\n },\r\n {\r\n \"resourceType\": \"locations\",\r\n \"locations\": [],\r\n \"apiVersions\": [\r\n \"2017-05-01\",\r\n \"2017-01-01\",\r\n \"2015-12-01\",\r\n \"2015-09-01\"\r\n ]\r\n },\r\n {\r\n \"resourceType\": \"locations/quotas\",\r\n \"locations\": [\r\n \"West Europe\",\r\n \"East US\",\r\n \"East US 2\",\r\n \"West US\",\r\n \"North Central US\",\r\n \"Brazil South\",\r\n \"North Europe\",\r\n \"Central US\",\r\n \"East Asia\",\r\n \"Japan East\",\r\n \"Australia Southeast\",\r\n \"Japan West\",\r\n \"Korea South\",\r\n \"Korea Central\",\r\n \"Southeast Asia\",\r\n \"South Central US\",\r\n \"Australia East\",\r\n \"South India\",\r\n \"Central India\",\r\n \"West India\",\r\n \"Canada Central\",\r\n \"Canada East\",\r\n \"UK South\",\r\n \"UK West\",\r\n \"West Central US\",\r\n \"West US 2\",\r\n \"East US 2 EUAP\",\r\n \"Central US EUAP\"\r\n ],\r\n \"apiVersions\": [\r\n \"2017-05-01\",\r\n \"2017-01-01\",\r\n \"2015-12-01\",\r\n \"2015-09-01\"\r\n ]\r\n },\r\n {\r\n \"resourceType\": \"locations/checkNameAvailability\",\r\n \"locations\": [\r\n \"West Europe\",\r\n \"East US\",\r\n \"East US 2\",\r\n \"West US\",\r\n \"North Central US\",\r\n \"Brazil South\",\r\n \"North Europe\",\r\n \"Central US\",\r\n \"East Asia\",\r\n \"Japan East\",\r\n \"Australia Southeast\",\r\n \"Japan West\",\r\n \"Korea South\",\r\n \"Korea Central\",\r\n \"Southeast Asia\",\r\n \"South Central US\",\r\n \"Australia East\",\r\n \"South India\",\r\n \"Central India\",\r\n \"West India\",\r\n \"Canada Central\",\r\n \"Canada East\",\r\n \"UK South\",\r\n \"UK West\",\r\n \"West Central US\",\r\n \"West US 2\",\r\n \"East US 2 EUAP\",\r\n \"Central US EUAP\"\r\n ],\r\n \"apiVersions\": [\r\n \"2017-05-01\"\r\n ]\r\n }\r\n ],\r\n \"registrationState\": \"Registered\"\r\n}",
"ResponseHeaders": {
"Content-Type": [
"application/json; charset=utf-8"
Expand All @@ -29,7 +29,7 @@
"no-cache"
],
"Date": [
"Tue, 09 May 2017 21:49:14 GMT"
"Tue, 25 Jul 2017 01:08:12 GMT"
],
"Pragma": [
"no-cache"
Expand All @@ -38,16 +38,16 @@
"Accept-Encoding"
],
"x-ms-ratelimit-remaining-subscription-reads": [
"14996"
"14998"
],
"x-ms-request-id": [
"79cbc4ce-3a5a-4927-ab71-c0fe0ead9c95"
"45c64218-ea62-4f93-8653-7a6f0b490718"
],
"x-ms-correlation-request-id": [
"79cbc4ce-3a5a-4927-ab71-c0fe0ead9c95"
"45c64218-ea62-4f93-8653-7a6f0b490718"
],
"x-ms-routing-request-id": [
"WESTUS2:20170509T214915Z:79cbc4ce-3a5a-4927-ab71-c0fe0ead9c95"
"WESTUS2:20170725T010812Z:45c64218-ea62-4f93-8653-7a6f0b490718"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains"
Expand All @@ -56,20 +56,20 @@
"StatusCode": 200
},
{
"RequestUri": "/subscriptions/2915bbd6-1252-405f-8173-6c00428146d9/providers/Microsoft.Batch/locations/West%20Europe/quotas?api-version=2017-05-01",
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvMjkxNWJiZDYtMTI1Mi00MDVmLTgxNzMtNmMwMDQyODE0NmQ5L3Byb3ZpZGVycy9NaWNyb3NvZnQuQmF0Y2gvbG9jYXRpb25zL1dlc3QlMjBFdXJvcGUvcXVvdGFzP2FwaS12ZXJzaW9uPTIwMTctMDUtMDE=",
"RequestUri": "/subscriptions/2915bbd6-1252-405f-8173-6c00428146d9/providers/Microsoft.Batch/locations/East%20US/quotas?api-version=2017-05-01",
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvMjkxNWJiZDYtMTI1Mi00MDVmLTgxNzMtNmMwMDQyODE0NmQ5L3Byb3ZpZGVycy9NaWNyb3NvZnQuQmF0Y2gvbG9jYXRpb25zL0Vhc3QlMjBVUy9xdW90YXM/YXBpLXZlcnNpb249MjAxNy0wNS0wMQ==",
"RequestMethod": "GET",
"RequestBody": "",
"RequestHeaders": {
"x-ms-client-request-id": [
"ae97f5c4-47d4-43e5-8ab8-ee288c5cd5f6"
"08451340-60cf-4fb8-937b-cbf1495244ea"
],
"accept-language": [
"en-US"
],
"User-Agent": [
"FxVersion/4.6.25009.03",
"Microsoft.Azure.Management.Batch.BatchManagementClient/5.0.0"
"FxVersion/4.6.25211.01",
"Microsoft.Azure.Management.Batch.BatchManagementClient/5.1.0.0"
]
},
"ResponseBody": "{\r\n \"accountQuota\": 1\r\n}",
Expand All @@ -84,7 +84,7 @@
"no-cache"
],
"Date": [
"Tue, 09 May 2017 21:49:16 GMT"
"Tue, 25 Jul 2017 01:08:14 GMT"
],
"Pragma": [
"no-cache"
Expand All @@ -99,25 +99,22 @@
"Accept-Encoding"
],
"x-ms-ratelimit-remaining-subscription-reads": [
"14998"
"14996"
],
"request-id": [
"833342df-fd6a-4be1-8928-1e6fdfc84523"
"x-ms-request-id": [
"8ed6428d-2652-4db3-a6a3-bf4186995e9a"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains"
],
"X-Content-Type-Options": [
"nosniff"
],
"x-ms-request-id": [
"fa3138ae-1ee3-4660-9a81-8bdffa5f69c5"
],
"x-ms-correlation-request-id": [
"fa3138ae-1ee3-4660-9a81-8bdffa5f69c5"
"c417748d-6735-4d6a-b7d8-aa201d88ecdb"
],
"x-ms-routing-request-id": [
"WESTUS2:20170509T214917Z:fa3138ae-1ee3-4660-9a81-8bdffa5f69c5"
"WESTUS2:20170725T010815Z:c417748d-6735-4d6a-b7d8-aa201d88ecdb"
]
},
"StatusCode": 200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,32 @@ public partial interface ILocationOperations
/// Thrown when a required parameter is null
/// </exception>
Task<AzureOperationResponse<BatchLocationQuota>> GetQuotasWithHttpMessagesAsync(string locationName, Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Checks whether the Batch account name is available in the specified
/// region.
/// </summary>
/// <param name='locationName'>
/// The desired region for the name check.
/// </param>
/// <param name='name'>
/// The name to check for availability
/// </param>
/// <param name='customHeaders'>
/// The headers that will be added to request.
/// </param>
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
/// <exception cref="Microsoft.Rest.Azure.CloudException">
/// Thrown when the operation returned an invalid status code
/// </exception>
/// <exception cref="Microsoft.Rest.SerializationException">
/// Thrown when unable to deserialize the response
/// </exception>
/// <exception cref="Microsoft.Rest.ValidationException">
/// Thrown when a required parameter is null
/// </exception>
Task<AzureOperationResponse<CheckNameAvailabilityResult>> CheckNameAvailabilityWithHttpMessagesAsync(string locationName, string name, Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
}
}

Loading

0 comments on commit a01781f

Please sign in to comment.