Exemple #1
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        public virtual UpdateNodeResourceResponse UpdateNodeResource(UpdateNodeResourceRequest
                                                                     request)
        {
            string argName            = "updateNodeResource";
            UserGroupInformation user = CheckAcls(argName);

            CheckRMStatus(user.GetShortUserName(), argName, "update node resource.");
            IDictionary <NodeId, ResourceOption> nodeResourceMap = request.GetNodeResourceMap(
                );
            ICollection <NodeId> nodeIds = nodeResourceMap.Keys;

            // verify nodes are all valid first.
            // if any invalid nodes, throw exception instead of partially updating
            // valid nodes.
            foreach (NodeId nodeId in nodeIds)
            {
                RMNode node = this.rmContext.GetRMNodes()[nodeId];
                if (node == null)
                {
                    Log.Error("Resource update get failed on all nodes due to change " + "resource on an unrecognized node: "
                              + nodeId);
                    throw RPCUtil.GetRemoteException("Resource update get failed on all nodes due to change resource "
                                                     + "on an unrecognized node: " + nodeId);
                }
            }
            // do resource update on each node.
            // Notice: it is still possible to have invalid NodeIDs as nodes decommission
            // may happen just at the same time. This time, only log and skip absent
            // nodes without throwing any exceptions.
            bool allSuccess = true;

            foreach (KeyValuePair <NodeId, ResourceOption> entry in nodeResourceMap)
            {
                ResourceOption newResourceOption = entry.Value;
                NodeId         nodeId_1          = entry.Key;
                RMNode         node = this.rmContext.GetRMNodes()[nodeId_1];
                if (node == null)
                {
                    Log.Warn("Resource update get failed on an unrecognized node: " + nodeId_1);
                    allSuccess = false;
                }
                else
                {
                    // update resource to RMNode
                    this.rmContext.GetDispatcher().GetEventHandler().Handle(new RMNodeResourceUpdateEvent
                                                                                (nodeId_1, newResourceOption));
                    Log.Info("Update resource on node(" + node.GetNodeID() + ") with resource(" + newResourceOption
                             .ToString() + ")");
                }
            }
            if (allSuccess)
            {
                RMAuditLogger.LogSuccess(user.GetShortUserName(), argName, "AdminService");
            }
            UpdateNodeResourceResponse response = UpdateNodeResourceResponse.NewInstance();

            return(response);
        }