/// <summary> /// Creates an MPI pool. /// </summary> public static void CreateMpiPoolIfNotExists(BatchController controller, BatchAccountContext context, int targetDedicated = 3) { BatchClient client = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient); ListPoolOptions listOptions = new ListPoolOptions(context) { PoolId = MpiPoolId }; try { client.ListPools(listOptions); return; // The call returned without throwing an exception, so the pool exists } catch (BatchException ex) { if (ex.RequestInformation == null || ex.RequestInformation.BatchError == null || ex.RequestInformation.BatchError.Code != BatchErrorCodeStrings.PoolNotFound) { throw; } // We got the pool not found error, so continue and create the pool } CreateTestPool(controller, context, MpiPoolId, targetDedicated); }
public static void WaitForSteadyPoolAllocation(BatchController controller, BatchAccountContext context, string poolId) { RequestInterceptor interceptor = CreateHttpRecordingInterceptor(); BatchClientBehavior[] behaviors = new BatchClientBehavior[] { interceptor }; BatchClient client = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient); ListPoolOptions options = new ListPoolOptions(context, behaviors) { PoolId = poolId }; DateTime timeout = DateTime.Now.AddMinutes(2); PSCloudPool pool = client.ListPools(options).First(); while (pool.AllocationState != AllocationState.Steady) { if (DateTime.Now > timeout) { throw new TimeoutException("Timed out waiting for steady allocation state"); } Sleep(5000); pool = client.ListPools(options).First(); } }
public static string WaitForOSVersionChange(BatchController controller, BatchAccountContext context, string poolId) { RequestInterceptor interceptor = CreateHttpRecordingInterceptor(); BatchClientBehavior[] behaviors = new BatchClientBehavior[] { interceptor }; BatchClient client = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient); ListPoolOptions options = new ListPoolOptions(context, behaviors) { PoolId = poolId }; DateTime timeout = DateTime.Now.AddMinutes(2); PSCloudPool pool = client.ListPools(options).First(); while (pool.CurrentOSVersion != pool.TargetOSVersion) { if (DateTime.Now > timeout) { throw new TimeoutException("Timed out waiting for active state pool"); } Sleep(5000); pool = client.ListPools(options).First(); } return(pool.TargetOSVersion); }
/// <summary> /// Gets the number of pools under the specified account /// </summary> public static int GetPoolCount(BatchController controller, BatchAccountContext context) { BatchClient client = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient); ListPoolOptions options = new ListPoolOptions(context); return(client.ListPools(options).Count()); }
/// <summary> /// Gets the number of pools under the specified account /// </summary> public static int GetPoolCount(BatchController controller, BatchAccountContext context) { RequestInterceptor interceptor = CreateHttpRecordingInterceptor(); BatchClientBehavior[] behaviors = new BatchClientBehavior[] { interceptor }; BatchClient client = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient); ListPoolOptions options = new ListPoolOptions(context, behaviors); return(client.ListPools(options).Count()); }
/// <summary> /// Gets the CurrentDedicated count from a pool /// </summary> public static int GetPoolCurrentDedicated(BatchController controller, BatchAccountContext context, string poolId) { BatchClient client = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient); ListPoolOptions options = new ListPoolOptions(context) { PoolId = poolId }; PSCloudPool pool = client.ListPools(options).First(); return(pool.CurrentDedicated.Value); }
/// <summary> /// Gets the CurrentDedicated count from a pool /// </summary> public static int GetPoolCurrentDedicated(BatchController controller, BatchAccountContext context, string poolId) { RequestInterceptor interceptor = CreateHttpRecordingInterceptor(); BatchClientBehavior[] behaviors = new BatchClientBehavior[] { interceptor }; BatchClient client = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient); ListPoolOptions options = new ListPoolOptions(context, behaviors) { PoolId = poolId }; PSCloudPool pool = client.ListPools(options).First(); return(pool.CurrentDedicated.Value); }
public override void ExecuteCmdlet() { ListPoolOptions options = new ListPoolOptions(this.BatchContext, this.AdditionalBehaviors) { PoolId = this.Id, Filter = this.Filter, MaxCount = this.MaxCount }; // The enumerator will internally query the service in chunks. Using WriteObject with the enumerate flag will enumerate // the entire collection first and then write the items out one by one in a single group. Using foreach, we can take // advantage of the enumerator's behavior and write output to the pipeline in bursts. foreach (PSCloudPool pool in BatchClient.ListPools(options)) { WriteObject(pool); } }
public static void WaitForSteadyPoolAllocation(BatchController controller, BatchAccountContext context, string poolId) { BatchClient client = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient); ListPoolOptions options = new ListPoolOptions(context) { PoolId = poolId }; DateTime timeout = DateTime.Now.Add(GetTimeout(TimeSpan.FromMinutes(5))); PSCloudPool pool = client.ListPools(options).First(); while (pool.AllocationState != AllocationState.Steady) { if (DateTime.Now > timeout) { throw new TimeoutException("Timed out waiting for steady allocation state"); } Sleep(5000); pool = client.ListPools(options).First(); } }
public static string WaitForOSVersionChange(BatchController controller, BatchAccountContext context, string poolId) { BatchClient client = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient); ListPoolOptions options = new ListPoolOptions(context) { PoolId = poolId }; DateTime timeout = DateTime.Now.AddMinutes(5); PSCloudPool pool = client.ListPools(options).First(); while (pool.CloudServiceConfiguration.CurrentOSVersion != pool.CloudServiceConfiguration.TargetOSVersion) { if (DateTime.Now > timeout) { throw new TimeoutException("Timed out waiting for active state pool"); } Sleep(5000); pool = client.ListPools(options).First(); } return(pool.CloudServiceConfiguration.TargetOSVersion); }
/// <summary> /// Creates an MPI pool. /// </summary> public static void CreateMpiPoolIfNotExists(BatchController controller, BatchAccountContext context, int targetDedicated = 3) { BatchClient client = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient); ListPoolOptions listOptions = new ListPoolOptions(context) { PoolId = MpiPoolId }; try { client.ListPools(listOptions); return; // The call returned without throwing an exception, so the pool exists } catch (AggregateException aex) { BatchException innerException = aex.InnerException as BatchException; if (innerException == null || innerException.RequestInformation == null || innerException.RequestInformation.AzureError == null || innerException.RequestInformation.AzureError.Code != BatchErrorCodeStrings.PoolNotFound) { throw; } // We got the pool not found error, so continue and create the pool } string blobUrl = UploadBlobAndGetUrl(MpiSetupFileContainer, MpiSetupFileName, MpiSetupFileLocalPath); StartTask startTask = new StartTask(); startTask.CommandLine = string.Format("cmd /c set & {0} -unattend -force", MpiSetupFileName); startTask.ResourceFiles = new List <ResourceFile>(); startTask.ResourceFiles.Add(new ResourceFile(blobUrl, MpiSetupFileName)); startTask.RunElevated = true; startTask.WaitForSuccess = true; CreateTestPool(controller, context, MpiPoolId, targetDedicated, startTask: startTask); }