public ListComputeNodes ( Microsoft.Azure.Commands.Batch.Models.ListComputeNodeOptions options ) : IEnumerable |
||
options | Microsoft.Azure.Commands.Batch.Models.ListComputeNodeOptions | The options to use when querying for compute nodes. |
return | IEnumerable |
public IEnumerable<PSComputeNode> ListComputeNodes(ListComputeNodeOptions options)
{
if (options == null)
{
throw new ArgumentNullException("options");
}
string poolId = options.Pool == null ? options.PoolId : options.Pool.Id;
// Get the single compute node matching the specified id
if (!string.IsNullOrEmpty(options.ComputeNodeId))
{
WriteVerbose(string.Format(Resources.GetComputeNodeById, options.ComputeNodeId, poolId));
PoolOperations poolOperations = options.Context.BatchOMClient.PoolOperations;
ODATADetailLevel getDetailLevel = new ODATADetailLevel(selectClause: options.Select);
ComputeNode computeNode = poolOperations.GetComputeNode(poolId, options.ComputeNodeId, detailLevel: getDetailLevel, additionalBehaviors: options.AdditionalBehaviors);
PSComputeNode psComputeNode = new PSComputeNode(computeNode);
return new PSComputeNode[] { psComputeNode };
}
// List compute nodes using the specified filter
else
{
string verboseLogString = null;
ODATADetailLevel listDetailLevel = new ODATADetailLevel(selectClause: options.Select);
if (!string.IsNullOrEmpty(options.Filter))
{
verboseLogString = string.Format(Resources.GetComputeNodeByOData, poolId);
listDetailLevel.FilterClause = options.Filter;
}
else
{
verboseLogString = string.Format(Resources.GetComputeNodeNoFilter, poolId);
}
WriteVerbose(verboseLogString);
PoolOperations poolOperations = options.Context.BatchOMClient.PoolOperations;
IPagedEnumerable<ComputeNode> computeNodes = poolOperations.ListComputeNodes(poolId, listDetailLevel, options.AdditionalBehaviors);
Func<ComputeNode, PSComputeNode> mappingFunction = c => { return new PSComputeNode(c); };
return PSPagedEnumerable<PSComputeNode, ComputeNode>.CreateWithMaxCount(
computeNodes, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount)));
}
}
/// <summary> /// Waits for a compute node to get to the idle state /// </summary> public static void WaitForIdleComputeNode(BatchController controller, BatchAccountContext context, string poolId, string computeNodeId) { RequestInterceptor interceptor = CreateHttpRecordingInterceptor(); BatchClientBehavior[] behaviors = new BatchClientBehavior[] { interceptor }; BatchClient client = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient); ListComputeNodeOptions options = new ListComputeNodeOptions(context, poolId, null, behaviors) { ComputeNodeId = computeNodeId }; DateTime timeout = DateTime.Now.AddMinutes(2); PSComputeNode computeNode = client.ListComputeNodes(options).First(); if (computeNode.State != ComputeNodeState.Idle) { if (DateTime.Now > timeout) { throw new TimeoutException("Timed out waiting for idle compute node"); } Sleep(5000); computeNode = client.ListComputeNodes(options).First(); } }