示例#1
0
        public void Bug1771163TestGetComputeNode_RefreshComputeNode()
        {
            Action test = () =>
            {
                using (BatchClient batchCli = TestUtilities.OpenBatchClientAsync(TestUtilities.GetCredentialsFromEnvironment()).Result)
                {
                    PoolOperations poolOperations = batchCli.PoolOperations;

                    List <ComputeNode> computeNodeList = poolOperations.ListComputeNodes(this.poolFixture.PoolId).ToList();

                    ComputeNode computeNodeToGet = computeNodeList.First();
                    string      computeNodeId    = computeNodeToGet.Id;
                    //
                    // Get compute node via the manager
                    //

                    ComputeNode computeNodeFromManager = poolOperations.GetComputeNode(this.poolFixture.PoolId, computeNodeId);
                    CompareComputeNodeObjects(computeNodeToGet, computeNodeFromManager);

                    //
                    // Get compute node via the pool
                    //
                    CloudPool pool = poolOperations.GetPool(this.poolFixture.PoolId);

                    ComputeNode computeNodeFromPool = pool.GetComputeNode(computeNodeId);
                    CompareComputeNodeObjects(computeNodeToGet, computeNodeFromPool);
                    //
                    // Refresh compute node
                    //

                    //Refresh with a detail level
                    computeNodeToGet.Refresh(new ODATADetailLevel()
                    {
                        SelectClause = "affinityId,id"
                    });

                    //Confirm we have the reduced detail level
                    Assert.Equal(computeNodeToGet.AffinityId, computeNodeFromManager.AffinityId);
                    Assert.Null(computeNodeToGet.IPAddress);
                    Assert.Null(computeNodeToGet.LastBootTime);
                    Assert.Null(computeNodeToGet.State);
                    Assert.Null(computeNodeToGet.StartTaskInformation);

                    //Refresh again with increased detail level
                    computeNodeToGet.Refresh();
                    CompareComputeNodeObjects(computeNodeToGet, computeNodeFromManager);
                }
            };

            SynchronizationContextHelper.RunTest(test, TestTimeout);
        }
示例#2
0
        /// <summary>
        /// Lists the compute nodes matching the specified filter options.
        /// </summary>
        /// <param name="options">The options to use when querying for compute nodes.</param>
        /// <returns>The compute nodes matching the specified filter options.</returns>
        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);
                return(PSPagedEnumerable <PSComputeNode, ComputeNode> .CreateWithMaxCount
                       (
                           computeNodes,
                           c => { return new PSComputeNode(c); },
                           options.MaxCount,
                           () => WriteMaxCount(options.MaxCount)
                       ));
            }
        }
        /// <summary>
        /// Lists the compute nodes matching the specified filter options.
        /// </summary>
        /// <param name="options">The options to use when querying for compute nodes.</param>
        /// <returns>The compute nodes matching the specified filter options.</returns>
        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.GBCN_GetById, options.ComputeNodeId, poolId));
                PoolOperations poolOperations = options.Context.BatchOMClient.PoolOperations;
                ComputeNode    computeNode    = poolOperations.GetComputeNode(poolId, options.ComputeNodeId, additionalBehaviors: options.AdditionalBehaviors);
                PSComputeNode  psComputeNode  = new PSComputeNode(computeNode);
                return(new PSComputeNode[] { psComputeNode });
            }
            // List compute nodes using the specified filter
            else
            {
                ODATADetailLevel odata            = null;
                string           verboseLogString = null;
                if (!string.IsNullOrEmpty(options.Filter))
                {
                    verboseLogString = string.Format(Resources.GBCN_GetByOData, poolId);
                    odata            = new ODATADetailLevel(filterClause: options.Filter);
                }
                else
                {
                    verboseLogString = string.Format(Resources.GBCN_NoFilter, poolId);
                }
                WriteVerbose(verboseLogString);

                PoolOperations poolOperations = options.Context.BatchOMClient.PoolOperations;
                IPagedEnumerable <ComputeNode>    computeNodes    = poolOperations.ListComputeNodes(poolId, odata, 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))));
            }
        }