示例#1
0
        private Org.Apache.Hadoop.Yarn.Api.Records.Resource AssignContainer(FSSchedulerNode
                                                                            node, bool reserved)
        {
            if (Log.IsDebugEnabled())
            {
                Log.Debug("Node offered to app: " + GetName() + " reserved: " + reserved);
            }
            ICollection <Priority> prioritiesToTry = (reserved) ? Arrays.AsList(node.GetReservedContainer
                                                                                    ().GetReservedPriority()) : GetPriorities();

            // For each priority, see if we can schedule a node local, rack local
            // or off-switch request. Rack of off-switch requests may be delayed
            // (not scheduled) in order to promote better locality.
            lock (this)
            {
                foreach (Priority priority in prioritiesToTry)
                {
                    if (GetTotalRequiredResources(priority) <= 0 || !HasContainerForNode(priority, node
                                                                                         ))
                    {
                        continue;
                    }
                    AddSchedulingOpportunity(priority);
                    // Check the AM resource usage for the leaf queue
                    if (GetLiveContainers().Count == 0 && !GetUnmanagedAM())
                    {
                        if (!((FSLeafQueue)GetQueue()).CanRunAppAM(GetAMResource()))
                        {
                            return(Resources.None());
                        }
                    }
                    ResourceRequest rackLocalRequest = GetResourceRequest(priority, node.GetRackName(
                                                                              ));
                    ResourceRequest localRequest = GetResourceRequest(priority, node.GetNodeName());
                    if (localRequest != null && !localRequest.GetRelaxLocality())
                    {
                        Log.Warn("Relax locality off is not supported on local request: " + localRequest);
                    }
                    NodeType allowedLocality;
                    if (scheduler.IsContinuousSchedulingEnabled())
                    {
                        allowedLocality = GetAllowedLocalityLevelByTime(priority, scheduler.GetNodeLocalityDelayMs
                                                                            (), scheduler.GetRackLocalityDelayMs(), scheduler.GetClock().GetTime());
                    }
                    else
                    {
                        allowedLocality = GetAllowedLocalityLevel(priority, scheduler.GetNumClusterNodes(
                                                                      ), scheduler.GetNodeLocalityThreshold(), scheduler.GetRackLocalityThreshold());
                    }
                    if (rackLocalRequest != null && rackLocalRequest.GetNumContainers() != 0 && localRequest
                        != null && localRequest.GetNumContainers() != 0)
                    {
                        return(AssignContainer(node, localRequest, NodeType.NodeLocal, reserved));
                    }
                    if (rackLocalRequest != null && !rackLocalRequest.GetRelaxLocality())
                    {
                        continue;
                    }
                    if (rackLocalRequest != null && rackLocalRequest.GetNumContainers() != 0 && (allowedLocality
                                                                                                 .Equals(NodeType.RackLocal) || allowedLocality.Equals(NodeType.OffSwitch)))
                    {
                        return(AssignContainer(node, rackLocalRequest, NodeType.RackLocal, reserved));
                    }
                    ResourceRequest offSwitchRequest = GetResourceRequest(priority, ResourceRequest.Any
                                                                          );
                    if (offSwitchRequest != null && !offSwitchRequest.GetRelaxLocality())
                    {
                        continue;
                    }
                    if (offSwitchRequest != null && offSwitchRequest.GetNumContainers() != 0)
                    {
                        if (!HasNodeOrRackLocalRequests(priority) || allowedLocality.Equals(NodeType.OffSwitch
                                                                                            ))
                        {
                            return(AssignContainer(node, offSwitchRequest, NodeType.OffSwitch, reserved));
                        }
                    }
                }
            }
            return(Resources.None());
        }