/// <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); } }