Skip to content

Commit

Permalink
BatchAI bugfix (#347)
Browse files Browse the repository at this point in the history
* BatchAI bugfix

* session record

* comments
  • Loading branch information
lenala authored and hovsepm committed May 31, 2018
1 parent 9975005 commit 8fd576a
Show file tree
Hide file tree
Showing 20 changed files with 685 additions and 183 deletions.
4 changes: 2 additions & 2 deletions Samples/BatchAI/ManageBatchAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public static void RunSample(IAzure azure)
// =============================================================
// Create Microsoft Cognitive Toolkit job to run on the cluster
Utilities.Log("Creating Batch AI job...");
IBatchAIJob job = cluster.Jobs.Define("myJob")
.WithRegion(region)
IBatchAIJob job = azure.BatchAIJobs.Define("myJob")
.WithExistingCluster(cluster)
.WithNodeCount(1)
.WithStdOutErrPathPrefix("$AZ_BATCHAI_MOUNT_ROOT/azurefileshare")
.DefineCognitiveToolkit()
Expand Down
15 changes: 13 additions & 2 deletions Tests/Fluent.Tests/BatchAI/BatchAITests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ public void CanCreateJob()
.Create();
Assert.Equal(AllocationState.Steady, cluster.AllocationState);
Assert.Equal(userName, cluster.AdminUserName);
IBatchAIJob job = cluster.Jobs.Define("myJob")
.WithRegion(REGION)
IBatchAIJob job = manager.BatchAIJobs.Define("myJob")
.WithExistingClusterId(cluster.Id)
.WithNodeCount(1)
.WithStdOutErrPathPrefix("$AZ_BATCHAI_MOUNT_ROOT/azurefileshare")
.DefineCognitiveToolkit()
Expand Down Expand Up @@ -202,5 +202,16 @@ public void CanCreateFileServer()
manager.ResourceManager.ResourceGroups.BeginDeleteByName(groupName);
}
}

[Fact]
public void CanListUsages()
{
using (var context = FluentMockContext.Start(this.GetType().FullName))
{
var manager = TestHelper.CreateBatchAIManager();
var usages = manager.BatchAIUsages.ListByRegion(Region.EuropeWest);
Assert.NotNull(usages);
}
}
}
}
300 changes: 187 additions & 113 deletions Tests/Fluent.Tests/SessionRecords/Fluent.Tests.BatchAI/CanCreateJob.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"Entries": [
{
"RequestUri": "/subscriptions/1c638cf4-608f-4ee6-b680-c329e824c3a8/providers/Microsoft.BatchAI/locations/westeurope/usages?api-version=2018-03-01",
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvMWM2MzhjZjQtNjA4Zi00ZWU2LWI2ODAtYzMyOWU4MjRjM2E4L3Byb3ZpZGVycy9NaWNyb3NvZnQuQmF0Y2hBSS9sb2NhdGlvbnMvd2VzdGV1cm9wZS91c2FnZXM/YXBpLXZlcnNpb249MjAxOC0wMy0wMQ==",
"RequestMethod": "GET",
"RequestBody": "",
"RequestHeaders": {
"x-ms-client-request-id": [
"10861217-f289-423a-a1af-adbc6422f5ee"
],
"accept-language": [
"en-US"
],
"User-Agent": [
"FxVersion/4.6.25211.01",
"Microsoft.Azure.Management.BatchAI.Fluent.BatchAIManagementClient/1.10.0.0",
"MacAddressHash/cc0dc995bd7689190d87305dca6418746f27065181fa649f43731fb8fc5f1b10"
]
},
"ResponseBody": "{\r\n \"value\": [\r\n {\r\n \"unit\": \"Count\",\r\n \"currentValue\": 2,\r\n \"limit\": 100,\r\n \"name\": {\r\n \"value\": \"Clusters\",\r\n \"localizedValue\": \"Clusters\"\r\n }\r\n },\r\n {\r\n \"unit\": \"Count\",\r\n \"currentValue\": 2,\r\n \"limit\": 24,\r\n \"name\": {\r\n \"value\": \"Total Cluster Dedicated Regional vCPUs\",\r\n \"localizedValue\": \"Total Cluster Dedicated Regional vCPUs\"\r\n }\r\n },\r\n {\r\n \"unit\": \"Count\",\r\n \"currentValue\": 0,\r\n \"limit\": 24,\r\n \"name\": {\r\n \"value\": \"Standard D Family Cluster Dedicated vCPUs\",\r\n \"localizedValue\": \"Standard D Family Cluster Dedicated vCPUs\"\r\n }\r\n },\r\n {\r\n \"unit\": \"Count\",\r\n \"currentValue\": 2,\r\n \"limit\": 24,\r\n \"name\": {\r\n \"value\": \"Standard Dv2 Family Cluster Dedicated vCPUs\",\r\n \"localizedValue\": \"Standard Dv2 Family Cluster Dedicated vCPUs\"\r\n }\r\n },\r\n {\r\n \"unit\": \"Count\",\r\n \"currentValue\": 0,\r\n \"limit\": 24,\r\n \"name\": {\r\n \"value\": \"Standard NC Family Cluster Dedicated vCPUs\",\r\n \"localizedValue\": \"Standard NC Family Cluster Dedicated vCPUs\"\r\n }\r\n },\r\n {\r\n \"unit\": \"Count\",\r\n \"currentValue\": 0,\r\n \"limit\": 0,\r\n \"name\": {\r\n \"value\": \"Standard NCv2 Family Cluster Dedicated vCPUs\",\r\n \"localizedValue\": \"Standard NCv2 Family Cluster Dedicated vCPUs\"\r\n }\r\n },\r\n {\r\n \"unit\": \"Count\",\r\n \"currentValue\": 0,\r\n \"limit\": 0,\r\n \"name\": {\r\n \"value\": \"Standard NCv3 Family Cluster Dedicated vCPUs\",\r\n \"localizedValue\": \"Standard NCv3 Family Cluster Dedicated vCPUs\"\r\n }\r\n },\r\n {\r\n \"unit\": \"Count\",\r\n \"currentValue\": 0,\r\n \"limit\": 0,\r\n \"name\": {\r\n \"value\": \"Standard ND Family Cluster Dedicated vCPUs\",\r\n \"localizedValue\": \"Standard ND Family Cluster Dedicated vCPUs\"\r\n }\r\n },\r\n {\r\n \"unit\": \"Count\",\r\n \"currentValue\": 0,\r\n \"limit\": 24,\r\n \"name\": {\r\n \"value\": \"Standard NV Family Cluster Dedicated vCPUs\",\r\n \"localizedValue\": \"Standard NV Family Cluster Dedicated vCPUs\"\r\n }\r\n },\r\n {\r\n \"unit\": \"Count\",\r\n \"currentValue\": 0,\r\n \"limit\": 24,\r\n \"name\": {\r\n \"value\": \"Total Cluster LowPriority Regional vCPUs\",\r\n \"localizedValue\": \"Total Cluster Low Priority Regional vCPUs\"\r\n }\r\n },\r\n {\r\n \"unit\": \"Count\",\r\n \"currentValue\": 0,\r\n \"limit\": 24,\r\n \"name\": {\r\n \"value\": \"Standard D Family Cluster LowPriority vCPUs\",\r\n \"localizedValue\": \"Standard D Family Cluster Low Priority vCPUs\"\r\n }\r\n },\r\n {\r\n \"unit\": \"Count\",\r\n \"currentValue\": 0,\r\n \"limit\": 24,\r\n \"name\": {\r\n \"value\": \"Standard Dv2 Family Cluster LowPriority vCPUs\",\r\n \"localizedValue\": \"Standard Dv2 Family Cluster Low Priority vCPUs\"\r\n }\r\n },\r\n {\r\n \"unit\": \"Count\",\r\n \"currentValue\": 0,\r\n \"limit\": 24,\r\n \"name\": {\r\n \"value\": \"Standard NC Family Cluster LowPriority vCPUs\",\r\n \"localizedValue\": \"Standard NC Family Cluster Low Priority vCPUs\"\r\n }\r\n },\r\n {\r\n \"unit\": \"Count\",\r\n \"currentValue\": 0,\r\n \"limit\": 0,\r\n \"name\": {\r\n \"value\": \"Standard NCv2 Family Cluster LowPriority vCPUs\",\r\n \"localizedValue\": \"Standard NCv2 Family Cluster Low Priority vCPUs\"\r\n }\r\n },\r\n {\r\n \"unit\": \"Count\",\r\n \"currentValue\": 0,\r\n \"limit\": 0,\r\n \"name\": {\r\n \"value\": \"Standard NCv3 Family Cluster LowPriority vCPUs\",\r\n \"localizedValue\": \"Standard NCv3 Family Cluster Low Priority vCPUs\"\r\n }\r\n },\r\n {\r\n \"unit\": \"Count\",\r\n \"currentValue\": 0,\r\n \"limit\": 0,\r\n \"name\": {\r\n \"value\": \"Standard ND Family Cluster LowPriority vCPUs\",\r\n \"localizedValue\": \"Standard ND Family Cluster Low Priority vCPUs\"\r\n }\r\n },\r\n {\r\n \"unit\": \"Count\",\r\n \"currentValue\": 0,\r\n \"limit\": 24,\r\n \"name\": {\r\n \"value\": \"Standard NV Family Cluster LowPriority vCPUs\",\r\n \"localizedValue\": \"Standard NV Family Cluster Low Priority vCPUs\"\r\n }\r\n },\r\n {\r\n \"unit\": \"Count\",\r\n \"currentValue\": 0,\r\n \"limit\": 300,\r\n \"name\": {\r\n \"value\": \"ActiveJobs\",\r\n \"localizedValue\": \"Active Jobs\"\r\n }\r\n }\r\n ]\r\n}",
"ResponseHeaders": {
"Content-Type": [
"application/json; charset=utf-8"
],
"Expires": [
"-1"
],
"Cache-Control": [
"no-cache"
],
"Date": [
"Wed, 30 May 2018 20:53:42 GMT"
],
"Pragma": [
"no-cache"
],
"Transfer-Encoding": [
"chunked"
],
"Server": [
"Microsoft-HTTPAPI/2.0"
],
"Vary": [
"Accept-Encoding"
],
"x-ms-ratelimit-remaining-subscription-reads": [
"14999"
],
"request-id": [
"6855e329-3642-4c01-92d6-a928794b6d0c"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains"
],
"X-Content-Type-Options": [
"nosniff"
],
"x-ms-request-id": [
"77848541-1275-4de2-8c7f-0051127bb582"
],
"x-ms-correlation-request-id": [
"77848541-1275-4de2-8c7f-0051127bb582"
],
"x-ms-routing-request-id": [
"WESTUS2:20180530T205342Z:77848541-1275-4de2-8c7f-0051127bb582"
]
},
"StatusCode": 200
}
],
"Names": {},
"Variables": {
"ServicePrincipal": "6ffb9e60-5c90-4acb-9701-16d6147f83e7",
"AADTenant": "72f988bf-86f1-41af-91ab-2d7cd011db47",
"SubscriptionId": "1c638cf4-608f-4ee6-b680-c329e824c3a8"
}
}
27 changes: 27 additions & 0 deletions src/ResourceManagement/Azure.Fluent/Azure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using Microsoft.Azure.Management.TrafficManager.Fluent;
using System;
using System.Linq;
using Microsoft.Azure.Management.Batchai.Fluent;
using ISubscriptions = Microsoft.Azure.Management.ResourceManager.Fluent.ISubscriptions;
using ISubscription = Microsoft.Azure.Management.ResourceManager.Fluent.ISubscription;
using Microsoft.Azure.Management.ContainerInstance.Fluent;
Expand Down Expand Up @@ -481,6 +482,22 @@ public IBatchAIClusters BatchAIClusters
}
}

public IBatchAIJobs BatchAIJobs
{
get
{
return batchAIManager.BatchAIJobs;
}
}

public IBatchAIUsages BatchAIUsages
{
get
{
return batchAIManager.BatchAIUsages;
}
}

public IBatchAIFileServers BatchAIFileServers
{
get
Expand Down Expand Up @@ -875,6 +892,16 @@ public interface IAzureBeta : IBeta
/// </summary>
IBatchAIFileServers BatchAIFileServers { get; }

/// <summary>
/// Entry point to Batch AI jobs management.
/// </summary>
IBatchAIJobs BatchAIJobs { get; }

/// <summary>
/// Entry point to Batch AI usages management.
/// </summary>
IBatchAIUsages BatchAIUsages { get; }

/// <summary>
/// Entry point to listing activity log events in Azure.
/// </summary>
Expand Down
10 changes: 0 additions & 10 deletions src/ResourceManagement/BatchAI/BatchAIClusterImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public partial class BatchAIClusterImpl :
{
private ClusterCreateParametersInner createParameters = new ClusterCreateParametersInner();
private ClusterUpdateParametersInner updateParameters = new ClusterUpdateParametersInner();
private BatchAIJobsImpl jobs;
public Models.ResourceId Subnet()
{
return Inner.Subnet;
Expand Down Expand Up @@ -283,15 +282,6 @@ public AllocationState AllocationState()
return Inner.AllocationState.GetValueOrDefault();
}

public IBatchAIJobs Jobs()
{
if (jobs == null)
{
jobs = new BatchAIJobsImpl(this);
}
return jobs;
}

private ScaleSettings EnsureScaleSettings()
{
if (createParameters.ScaleSettings == null)
Expand Down
27 changes: 22 additions & 5 deletions src/ResourceManagement/BatchAI/BatchAIJobImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,10 @@ public IWithCreate WithExperimentName(string experimentName)

public override async Task<Microsoft.Azure.Management.BatchAI.Fluent.IBatchAIJob> CreateResourceAsync(CancellationToken cancellationToken = default(CancellationToken))
{
createParameters.Cluster = new Models.ResourceId(parent.Id);
if (parent == null)
{
parent = await Manager.BatchAIClusters.GetByIdAsync(createParameters.Cluster.Id, cancellationToken);
}
createParameters.Location = parent.RegionName;
var inner = await Manager.Inner.Jobs.CreateAsync(parent.ResourceGroupName, this.Name, createParameters, cancellationToken);
SetInner(inner);
Expand Down Expand Up @@ -463,6 +466,22 @@ public BatchAIJobImpl WithEnvironmentVariableSecretValue(string name, string key
return this;
}

///GENMHASH:A851295FCC0E9F4FE107D9566C40A6D0:444BB1540F15B3A5BECC3E92D812699B
public BatchAIJobImpl WithExistingCluster(IBatchAICluster cluster)
{
parent = cluster;
createParameters.Cluster = new Models.ResourceId(cluster.Id);

return this;
}

///GENMHASH:A1AF6041EECB4ABC084125DFBF602670:8843DDA8D11922F11FAC857055250E18
public BatchAIJobImpl WithExistingClusterId(string clusterId)
{
createParameters.Cluster = new Models.ResourceId(clusterId);
return this;
}

public BatchAIJobImpl WithInputDirectory(string id, string path)
{
if (createParameters.InputDirectories == null)
Expand All @@ -482,11 +501,9 @@ public BatchAIJobImpl WithCommandLine(string commandLine)
return this;
}

internal BatchAIJobImpl(string name, BatchAIClusterImpl parent, JobInner inner)
: base(name, inner, parent.Manager)
internal BatchAIJobImpl(string name, JobInner inner, IBatchAIManager manager)
: base(name, inner, manager)
{
this.parent = parent;
WithExistingResourceGroup(parent.ResourceGroupName);
}

public ChainerSettings ChainerSettings()
Expand Down
36 changes: 5 additions & 31 deletions src/ResourceManagement/BatchAI/BatchAIJobsImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,43 +24,22 @@ public partial class BatchAIJobsImpl :
IBatchAIManager>,
IBatchAIJobs
{
private BatchAIClusterImpl parent;
public IBatchAICluster Parent()
internal BatchAIJobsImpl(IBatchAIManager batchAIManager)
: base(batchAIManager.Inner.Jobs, batchAIManager)
{
return this.parent;
}

internal BatchAIJobsImpl(BatchAIClusterImpl parent)
: base(parent.Manager.Inner.Jobs, parent.Manager)
{
this.parent = parent;
}

public BatchAIJobImpl Define(string name)
{
return WrapModel(name);
}

public IBatchAIJob GetByName(string name)
{
return Extensions.Synchronize(() => GetByNameAsync(name));
}

protected async Task DeleteInnerAsync(string resourceGroupName, string name, CancellationToken cancellationToken = default(CancellationToken))
{
await Inner.DeleteAsync(resourceGroupName, name);
}

public void DeleteByName(string name)
{
Extensions.Synchronize(() => DeleteByNameAsync(name));
}

public async Task<Microsoft.Azure.Management.BatchAI.Fluent.IBatchAIJob> GetByNameAsync(string name, CancellationToken cancellationToken = default(CancellationToken))
{
return WrapModel(await Inner.GetAsync(parent.ResourceGroupName, name));
}

public IEnumerable<Microsoft.Azure.Management.BatchAI.Fluent.IBatchAIJob> List()
{
return Extensions.Synchronize(() => ListAsync());
Expand All @@ -80,7 +59,7 @@ public void DeleteByName(string name)

protected override BatchAIJobImpl WrapModel(string name)
{
return new BatchAIJobImpl(name, parent, new JobInner(location: parent.RegionName));
return new BatchAIJobImpl(name, new JobInner(name: name), this.Manager);
}

protected override IBatchAIJob WrapModel(JobInner inner)
Expand All @@ -89,15 +68,10 @@ protected override IBatchAIJob WrapModel(JobInner inner)
{
return null;
}
return new BatchAIJobImpl(inner.Name, parent, inner);
}

public async Task DeleteByNameAsync(string name, CancellationToken cancellationToken = default(CancellationToken))
{
await Inner.DeleteAsync(parent.ResourceGroupName, name);
return new BatchAIJobImpl(inner.Name, inner, this.Manager);
}

protected override async Task<JobInner> GetInnerByGroupAsync(string groupName, string name, CancellationToken cancellationToken)
protected override async Task<JobInner> GetInnerByGroupAsync(string groupName, string name, CancellationToken cancellationToken)
{
return await Inner.GetAsync(groupName, name, cancellationToken);
}
Expand Down
29 changes: 29 additions & 0 deletions src/ResourceManagement/BatchAI/BatchAIManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Azure.Management.ResourceManager.Fluent.Core;
using System;
using System.Linq;
using Microsoft.Azure.Management.Batchai.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent.Authentication;
namespace Microsoft.Azure.Management.BatchAI.Fluent
{
Expand All @@ -15,6 +16,8 @@ public class BatchAIManager : Manager<IBatchAIManagementClient>, IBatchAIManager
#region Fluent private collections
private IBatchAIClusters batchAIClusters;
private IBatchAIFileServers batchAIFileServers;
private IBatchAIJobs batchAIJobs;
private IBatchAIUsages batchAIUsages;
#endregion

#region ctrs
Expand Down Expand Up @@ -111,6 +114,30 @@ public IBatchAIFileServers BatchAIFileServers
return batchAIFileServers;
}
}

public IBatchAIJobs BatchAIJobs
{
get
{
if (batchAIJobs == null)
{
batchAIJobs = new BatchAIJobsImpl(this);
}
return batchAIJobs;
}
}

public IBatchAIUsages BatchAIUsages
{
get
{
if (batchAIUsages == null)
{
batchAIUsages = new BatchAIUsagesImpl(this);
}
return batchAIUsages;
}
}
}
/// <summary>
/// Entry point to Azure BatchAI resource management.
Expand All @@ -119,5 +146,7 @@ public interface IBatchAIManager : IManager<IBatchAIManagementClient>
{
IBatchAIClusters BatchAIClusters { get; }
IBatchAIFileServers BatchAIFileServers { get; }
IBatchAIJobs BatchAIJobs { get; }
IBatchAIUsages BatchAIUsages { get; }
}
}
Loading

0 comments on commit 8fd576a

Please sign in to comment.