/// <summary>
        /// Method to wait until node creation is complete
        /// </summary>
        /// <param name="node">The compute node</param>
        /// <param name="desiredState">The desired state of the pool</param>
        /// <returns>Returns a boolean when the pool is ready</returns>
        public async Task <bool> AwaitDesiredNodeState(ComputeNode node, ComputeNodeState desiredState)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();

            watch.Start();

            do
            {
                // Refresh pool to get latest state
                await node.RefreshAsync();

                // Timeout after 30 minutes or if the node is an invalid state
                if (watch.ElapsedTicks > TimeSpan.TicksPerHour / 2 ||
                    node.State == ComputeNodeState.Unknown ||
                    node.State == ComputeNodeState.Unusable ||
                    node.State == ComputeNodeState.Offline ||
                    node.State == ComputeNodeState.StartTaskFailed ||
                    node.State == ComputeNodeState.Preempted)
                {
                    return(false);
                }

                await Task.Delay(5000);
            }while (node.State != desiredState);

            return(true);
        }
        internal static string ToSerializedValue(this ComputeNodeState value)
        {
            switch (value)
            {
            case ComputeNodeState.Idle:
                return("idle");

            case ComputeNodeState.Rebooting:
                return("rebooting");

            case ComputeNodeState.Reimaging:
                return("reimaging");

            case ComputeNodeState.Running:
                return("running");

            case ComputeNodeState.Unusable:
                return("unusable");

            case ComputeNodeState.Creating:
                return("creating");

            case ComputeNodeState.Starting:
                return("starting");

            case ComputeNodeState.WaitingForStartTask:
                return("waitingforstarttask");

            case ComputeNodeState.StartTaskFailed:
                return("starttaskfailed");

            case ComputeNodeState.Unknown:
                return("unknown");

            case ComputeNodeState.LeavingPool:
                return("leavingpool");

            case ComputeNodeState.Offline:
                return("offline");

            case ComputeNodeState.Preempted:
                return("preempted");
            }
            return(null);
        }
예제 #3
0
        /// <summary>
        /// Asynchronous method that delays execution until the nodes within the specified pool reach the specified state.
        /// </summary>
        /// <param name="client">A fully intitialized <see cref="BatchClient"/>.</param>
        /// <param name="poolId">The ID of the pool containing the nodes to monitor.</param>
        /// <param name="targetNodeState">The node state to monitor.</param>
        /// <param name="timeout">The maximum time to wait for the nodes to reach the specified state.</param>
        /// <returns>A <see cref="System.Threading.Tasks.Task"/> object that represents the asynchronous operation.</returns>
        public static async Task WaitForNodesToReachStateAsync(BatchClient client, string poolId, ComputeNodeState targetNodeState, TimeSpan timeout)
        {
            Console.WriteLine("Waiting for nodes to reach state {0}", targetNodeState);

            DateTime startTime = DateTime.UtcNow;
            DateTime timeoutAfterThisTimeUtc = startTime.Add(timeout);

            CloudPool pool = await client.PoolOperations.GetPoolAsync(poolId).ConfigureAwait(continueOnCapturedContext: false);

            ODATADetailLevel          detail       = new ODATADetailLevel(selectClause: "id,state");
            IEnumerable <ComputeNode> computeNodes = pool.ListComputeNodes(detail);

            while (computeNodes.Any(computeNode => computeNode.State != targetNodeState))
            {
                Console.Write(".");

                await Task.Delay(TimeSpan.FromSeconds(10)).ConfigureAwait(continueOnCapturedContext: false);

                computeNodes = pool.ListComputeNodes(detail).ToList();

                if (DateTime.UtcNow > timeoutAfterThisTimeUtc)
                {
                    throw new TimeoutException(string.Format("Timed out waiting for compute nodes in pool {0} to reach state {1}", poolId, targetNodeState.ToString()));
                }
            }

            Console.WriteLine();
        }
        /// <summary>
        /// Asynchronous method that delays execution until the nodes within the specified pool reach the specified state.
        /// </summary>
        /// <param name="client">A fully intitialized <see cref="BatchClient"/>.</param>
        /// <param name="poolId">The ID of the pool containing the nodes to monitor.</param>
        /// <param name="targetNodeState">The node state to monitor.</param>
        /// <param name="timeout">The maximum time to wait for the nodes to reach the specified state.</param>
        /// <returns>A <see cref="System.Threading.Tasks.Task"/> object that represents the asynchronous operation.</returns>
        public static async Task WaitForNodesToReachStateAsync(BatchClient client, string poolId, ComputeNodeState targetNodeState, TimeSpan timeout)
        {
            Console.WriteLine("Waiting for nodes to reach state {0}", targetNodeState);

            DateTime startTime = DateTime.UtcNow;
            DateTime timeoutAfterThisTimeUtc = startTime.Add(timeout);

            CloudPool pool = await client.PoolOperations.GetPoolAsync(poolId);

            ODATADetailLevel detail = new ODATADetailLevel(selectClause: "id,state");
            IEnumerable<ComputeNode> computeNodes = pool.ListComputeNodes(detail);

            while (computeNodes.Any(computeNode => computeNode.State != targetNodeState))
            {
                Console.Write(".");

                await Task.Delay(TimeSpan.FromSeconds(10));
                computeNodes = pool.ListComputeNodes(detail).ToList();

                if (DateTime.UtcNow > timeoutAfterThisTimeUtc)
                {
                    Console.WriteLine();
                    Console.WriteLine("Timed out waiting for compute nodes in pool {0} to reach state {1}", poolId, targetNodeState.ToString());

                    return;
                }
            }

            Console.WriteLine();
        }
예제 #5
0
 public static string ToSerialString(this ComputeNodeState value) => value switch
 {