Beispiel #1
0
        /// <summary>
        /// Assign a container to this node to facilitate
        /// <paramref name="request"/>
        /// . If node does
        /// not have enough memory, create a reservation. This is called once we are
        /// sure the particular request should be facilitated by this node.
        /// </summary>
        /// <param name="node">The node to try placing the container on.</param>
        /// <param name="request">The ResourceRequest we're trying to satisfy.</param>
        /// <param name="type">The locality of the assignment.</param>
        /// <param name="reserved">Whether there's already a container reserved for this app on the node.
        ///     </param>
        /// <returns>
        /// If an assignment was made, returns the resources allocated to the
        /// container.  If a reservation was made, returns
        /// FairScheduler.CONTAINER_RESERVED.  If no assignment or reservation was
        /// made, returns an empty resource.
        /// </returns>
        private Org.Apache.Hadoop.Yarn.Api.Records.Resource AssignContainer(FSSchedulerNode
                                                                            node, ResourceRequest request, NodeType type, bool reserved)
        {
            // How much does this request need?
            Org.Apache.Hadoop.Yarn.Api.Records.Resource capability = request.GetCapability();
            // How much does the node have?
            Org.Apache.Hadoop.Yarn.Api.Records.Resource available = node.GetAvailableResource
                                                                        ();
            Container container = null;

            if (reserved)
            {
                container = node.GetReservedContainer().GetContainer();
            }
            else
            {
                container = CreateContainer(node, capability, request.GetPriority());
            }
            // Can we allocate a container on this node?
            if (Resources.FitsIn(capability, available))
            {
                // Inform the application of the new container for this request
                RMContainer allocatedContainer = Allocate(type, node, request.GetPriority(), request
                                                          , container);
                if (allocatedContainer == null)
                {
                    // Did the application need this resource?
                    if (reserved)
                    {
                        Unreserve(request.GetPriority(), node);
                    }
                    return(Resources.None());
                }
                // If we had previously made a reservation, delete it
                if (reserved)
                {
                    Unreserve(request.GetPriority(), node);
                }
                // Inform the node
                node.AllocateContainer(allocatedContainer);
                // If this container is used to run AM, update the leaf queue's AM usage
                if (GetLiveContainers().Count == 1 && !GetUnmanagedAM())
                {
                    ((FSLeafQueue)GetQueue()).AddAMResourceUsage(container.GetResource());
                    SetAmRunning(true);
                }
                return(container.GetResource());
            }
            else
            {
                if (!FairScheduler.FitsInMaxShare(((FSLeafQueue)GetQueue()), capability))
                {
                    return(Resources.None());
                }
                // The desired container won't fit here, so reserve
                Reserve(request.GetPriority(), node, container, reserved);
                return(FairScheduler.ContainerReserved);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Called when this application already has an existing reservation on the
        /// given node.
        /// </summary>
        /// <remarks>
        /// Called when this application already has an existing reservation on the
        /// given node.  Sees whether we can turn the reservation into an allocation.
        /// Also checks whether the application needs the reservation anymore, and
        /// releases it if not.
        /// </remarks>
        /// <param name="node">Node that the application has an existing reservation on</param>
        public virtual Org.Apache.Hadoop.Yarn.Api.Records.Resource AssignReservedContainer
            (FSSchedulerNode node)
        {
            RMContainer rmContainer = node.GetReservedContainer();
            Priority    priority    = rmContainer.GetReservedPriority();

            // Make sure the application still needs requests at this priority
            if (GetTotalRequiredResources(priority) == 0)
            {
                Unreserve(priority, node);
                return(Resources.None());
            }
            // Fail early if the reserved container won't fit.
            // Note that we have an assumption here that there's only one container size
            // per priority.
            if (!Resources.FitsIn(node.GetReservedContainer().GetReservedResource(), node.GetAvailableResource
                                      ()))
            {
                return(Resources.None());
            }
            return(AssignContainer(node, true));
        }