public virtual RMContainer Allocate(NodeType type, FSSchedulerNode node, Priority priority, ResourceRequest request, Container container) { lock (this) { // Update allowed locality level NodeType allowed = allowedLocalityLevel[priority]; if (allowed != null) { if (allowed.Equals(NodeType.OffSwitch) && (type.Equals(NodeType.NodeLocal) || type .Equals(NodeType.RackLocal))) { this.ResetAllowedLocalityLevel(priority, type); } else { if (allowed.Equals(NodeType.RackLocal) && type.Equals(NodeType.NodeLocal)) { this.ResetAllowedLocalityLevel(priority, type); } } } // Required sanity check - AM can call 'allocate' to update resource // request without locking the scheduler, hence we need to check if (GetTotalRequiredResources(priority) <= 0) { return(null); } // Create RMContainer RMContainer rmContainer = new RMContainerImpl(container, GetApplicationAttemptId( ), node.GetNodeID(), appSchedulingInfo.GetUser(), rmContext); // Add it to allContainers list. newlyAllocatedContainers.AddItem(rmContainer); liveContainers[container.GetId()] = rmContainer; // Update consumption and track allocations IList <ResourceRequest> resourceRequestList = appSchedulingInfo.Allocate(type, node , priority, request, container); Resources.AddTo(currentConsumption, container.GetResource()); // Update resource requests related to "request" and store in RMContainer ((RMContainerImpl)rmContainer).SetResourceRequests(resourceRequestList); // Inform the container rmContainer.Handle(new RMContainerEvent(container.GetId(), RMContainerEventType.Start )); if (Log.IsDebugEnabled()) { Log.Debug("allocate: applicationAttemptId=" + container.GetId().GetApplicationAttemptId () + " container=" + container.GetId() + " host=" + container.GetNodeId().GetHost () + " type=" + type); } RMAuditLogger.LogSuccess(GetUser(), RMAuditLogger.AuditConstants.AllocContainer, "SchedulerApp", GetApplicationId(), container.GetId()); return(rmContainer); } }
private RMContainer RecoverAndCreateContainer(NMContainerStatus status, RMNode node ) { Container container = Container.NewInstance(status.GetContainerId(), node.GetNodeID (), node.GetHttpAddress(), status.GetAllocatedResource(), status.GetPriority(), null); ApplicationAttemptId attemptId = container.GetId().GetApplicationAttemptId(); RMContainer rmContainer = new RMContainerImpl(container, attemptId, node.GetNodeID (), applications[attemptId.GetApplicationId()].GetUser(), rmContext, status.GetCreationTime ()); return(rmContainer); }
public virtual RMContainer Reserve(SchedulerNode node, Priority priority, RMContainer rmContainer, Container container) { lock (this) { // Create RMContainer if necessary if (rmContainer == null) { rmContainer = new RMContainerImpl(container, GetApplicationAttemptId(), node.GetNodeID (), appSchedulingInfo.GetUser(), rmContext); Resources.AddTo(currentReservation, container.GetResource()); // Reset the re-reservation count ResetReReservations(priority); } else { // Note down the re-reservation AddReReservation(priority); } rmContainer.Handle(new RMContainerReservedEvent(container.GetId(), container.GetResource (), node.GetNodeID(), priority)); IDictionary <NodeId, RMContainer> reservedContainers = this.reservedContainers[priority ]; if (reservedContainers == null) { reservedContainers = new Dictionary <NodeId, RMContainer>(); this.reservedContainers[priority] = reservedContainers; } reservedContainers[node.GetNodeID()] = rmContainer; if (Log.IsDebugEnabled()) { Log.Debug("Application attempt " + GetApplicationAttemptId() + " reserved container " + rmContainer + " on node " + node + ". This attempt currently has " + reservedContainers .Count + " reserved containers at priority " + priority + "; currentReservation " + currentReservation.GetMemory()); } return(rmContainer); } }
public virtual void TestSortedQueues() { // Setup queue configs SetupSortedQueues(csConf); IDictionary <string, CSQueue> queues = new Dictionary <string, CSQueue>(); CSQueue root = CapacityScheduler.ParseQueue(csContext, csConf, null, CapacitySchedulerConfiguration .Root, queues, queues, TestUtils.spyHook); // Setup some nodes int memoryPerNode = 10; int coresPerNode = 16; int numNodes = 1; FiCaSchedulerNode node_0 = TestUtils.GetMockNode("host_0", DefaultRack, 0, memoryPerNode * Gb); Org.Mockito.Mockito.DoNothing().When(node_0).ReleaseContainer(Matchers.Any <Container >()); Org.Apache.Hadoop.Yarn.Api.Records.Resource clusterResource = Resources.CreateResource (numNodes * (memoryPerNode * Gb), numNodes * coresPerNode); Org.Mockito.Mockito.When(csContext.GetNumClusterNodes()).ThenReturn(numNodes); // Start testing CSQueue a = queues[A]; CSQueue b = queues[B]; CSQueue c = queues[C]; CSQueue d = queues[D]; string user_0 = "user_0"; // Stub an App and its containerCompleted FiCaSchedulerApp app_0 = GetMockApplication(0, user_0); Org.Mockito.Mockito.DoReturn(true).When(app_0).ContainerCompleted(Matchers.Any <RMContainer >(), Matchers.Any <ContainerStatus>(), Matchers.Any <RMContainerEventType>()); Priority priority = TestUtils.CreateMockPriority(1); ContainerAllocationExpirer expirer = Org.Mockito.Mockito.Mock <ContainerAllocationExpirer >(); DrainDispatcher drainDispatcher = new DrainDispatcher(); RMApplicationHistoryWriter writer = Org.Mockito.Mockito.Mock <RMApplicationHistoryWriter >(); SystemMetricsPublisher publisher = Org.Mockito.Mockito.Mock <SystemMetricsPublisher >(); RMContext rmContext = Org.Mockito.Mockito.Mock <RMContext>(); Org.Mockito.Mockito.When(rmContext.GetContainerAllocationExpirer()).ThenReturn(expirer ); Org.Mockito.Mockito.When(rmContext.GetDispatcher()).ThenReturn(drainDispatcher); Org.Mockito.Mockito.When(rmContext.GetRMApplicationHistoryWriter()).ThenReturn(writer ); Org.Mockito.Mockito.When(rmContext.GetSystemMetricsPublisher()).ThenReturn(publisher ); Org.Mockito.Mockito.When(rmContext.GetYarnConfiguration()).ThenReturn(new YarnConfiguration ()); ApplicationAttemptId appAttemptId = BuilderUtils.NewApplicationAttemptId(app_0.GetApplicationId (), 1); ContainerId containerId = BuilderUtils.NewContainerId(appAttemptId, 1); Container container = TestUtils.GetMockContainer(containerId, node_0.GetNodeID(), Resources.CreateResource(1 * Gb), priority); RMContainer rmContainer = new RMContainerImpl(container, appAttemptId, node_0.GetNodeID (), "user", rmContext); // Assign {1,2,3,4} 1GB containers respectively to queues StubQueueAllocation(a, clusterResource, node_0, 1 * Gb); StubQueueAllocation(b, clusterResource, node_0, 0 * Gb); StubQueueAllocation(c, clusterResource, node_0, 0 * Gb); StubQueueAllocation(d, clusterResource, node_0, 0 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); for (int i = 0; i < 2; i++) { StubQueueAllocation(a, clusterResource, node_0, 0 * Gb); StubQueueAllocation(b, clusterResource, node_0, 1 * Gb); StubQueueAllocation(c, clusterResource, node_0, 0 * Gb); StubQueueAllocation(d, clusterResource, node_0, 0 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); } for (int i_1 = 0; i_1 < 3; i_1++) { StubQueueAllocation(a, clusterResource, node_0, 0 * Gb); StubQueueAllocation(b, clusterResource, node_0, 0 * Gb); StubQueueAllocation(c, clusterResource, node_0, 1 * Gb); StubQueueAllocation(d, clusterResource, node_0, 0 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); } for (int i_2 = 0; i_2 < 4; i_2++) { StubQueueAllocation(a, clusterResource, node_0, 0 * Gb); StubQueueAllocation(b, clusterResource, node_0, 0 * Gb); StubQueueAllocation(c, clusterResource, node_0, 0 * Gb); StubQueueAllocation(d, clusterResource, node_0, 1 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); } VerifyQueueMetrics(a, 1 * Gb, clusterResource); VerifyQueueMetrics(b, 2 * Gb, clusterResource); VerifyQueueMetrics(c, 3 * Gb, clusterResource); VerifyQueueMetrics(d, 4 * Gb, clusterResource); Log.Info("status child-queues: " + ((ParentQueue)root).GetChildQueuesToPrint()); //Release 3 x 1GB containers from D for (int i_3 = 0; i_3 < 3; i_3++) { d.CompletedContainer(clusterResource, app_0, node_0, rmContainer, null, RMContainerEventType .Kill, null, true); } VerifyQueueMetrics(a, 1 * Gb, clusterResource); VerifyQueueMetrics(b, 2 * Gb, clusterResource); VerifyQueueMetrics(c, 3 * Gb, clusterResource); VerifyQueueMetrics(d, 1 * Gb, clusterResource); //reset manually resources on node node_0 = TestUtils.GetMockNode("host_0", DefaultRack, 0, (memoryPerNode - 1 - 2 - 3 - 1) * Gb); Log.Info("status child-queues: " + ((ParentQueue)root).GetChildQueuesToPrint()); // Assign 2 x 1GB Containers to A for (int i_4 = 0; i_4 < 2; i_4++) { StubQueueAllocation(a, clusterResource, node_0, 1 * Gb); StubQueueAllocation(b, clusterResource, node_0, 0 * Gb); StubQueueAllocation(c, clusterResource, node_0, 0 * Gb); StubQueueAllocation(d, clusterResource, node_0, 0 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); } VerifyQueueMetrics(a, 3 * Gb, clusterResource); VerifyQueueMetrics(b, 2 * Gb, clusterResource); VerifyQueueMetrics(c, 3 * Gb, clusterResource); VerifyQueueMetrics(d, 1 * Gb, clusterResource); Log.Info("status child-queues: " + ((ParentQueue)root).GetChildQueuesToPrint()); //Release 1GB Container from A a.CompletedContainer(clusterResource, app_0, node_0, rmContainer, null, RMContainerEventType .Kill, null, true); VerifyQueueMetrics(a, 2 * Gb, clusterResource); VerifyQueueMetrics(b, 2 * Gb, clusterResource); VerifyQueueMetrics(c, 3 * Gb, clusterResource); VerifyQueueMetrics(d, 1 * Gb, clusterResource); //reset manually resources on node node_0 = TestUtils.GetMockNode("host_0", DefaultRack, 0, (memoryPerNode - 2 - 2 - 3 - 1) * Gb); Log.Info("status child-queues: " + ((ParentQueue)root).GetChildQueuesToPrint()); // Assign 1GB container to B StubQueueAllocation(a, clusterResource, node_0, 0 * Gb); StubQueueAllocation(b, clusterResource, node_0, 1 * Gb); StubQueueAllocation(c, clusterResource, node_0, 0 * Gb); StubQueueAllocation(d, clusterResource, node_0, 0 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); VerifyQueueMetrics(a, 2 * Gb, clusterResource); VerifyQueueMetrics(b, 3 * Gb, clusterResource); VerifyQueueMetrics(c, 3 * Gb, clusterResource); VerifyQueueMetrics(d, 1 * Gb, clusterResource); Log.Info("status child-queues: " + ((ParentQueue)root).GetChildQueuesToPrint()); //Release 1GB container resources from B b.CompletedContainer(clusterResource, app_0, node_0, rmContainer, null, RMContainerEventType .Kill, null, true); VerifyQueueMetrics(a, 2 * Gb, clusterResource); VerifyQueueMetrics(b, 2 * Gb, clusterResource); VerifyQueueMetrics(c, 3 * Gb, clusterResource); VerifyQueueMetrics(d, 1 * Gb, clusterResource); //reset manually resources on node node_0 = TestUtils.GetMockNode("host_0", DefaultRack, 0, (memoryPerNode - 2 - 2 - 3 - 1) * Gb); Log.Info("status child-queues: " + ((ParentQueue)root).GetChildQueuesToPrint()); // Assign 1GB container to A StubQueueAllocation(a, clusterResource, node_0, 1 * Gb); StubQueueAllocation(b, clusterResource, node_0, 0 * Gb); StubQueueAllocation(c, clusterResource, node_0, 0 * Gb); StubQueueAllocation(d, clusterResource, node_0, 0 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); VerifyQueueMetrics(a, 3 * Gb, clusterResource); VerifyQueueMetrics(b, 2 * Gb, clusterResource); VerifyQueueMetrics(c, 3 * Gb, clusterResource); VerifyQueueMetrics(d, 1 * Gb, clusterResource); Log.Info("status child-queues: " + ((ParentQueue)root).GetChildQueuesToPrint()); // Now do the real test, where B and D request a 1GB container // D should should get the next container if the order is correct StubQueueAllocation(a, clusterResource, node_0, 0 * Gb); StubQueueAllocation(b, clusterResource, node_0, 1 * Gb); StubQueueAllocation(c, clusterResource, node_0, 0 * Gb); StubQueueAllocation(d, clusterResource, node_0, 1 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); InOrder allocationOrder = Org.Mockito.Mockito.InOrder(d, b); allocationOrder.Verify(d).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any <FiCaSchedulerNode>(), Matchers.Any <ResourceLimits>()); allocationOrder.Verify(b).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any <FiCaSchedulerNode>(), Matchers.Any <ResourceLimits>()); VerifyQueueMetrics(a, 3 * Gb, clusterResource); VerifyQueueMetrics(b, 2 * Gb, clusterResource); VerifyQueueMetrics(c, 3 * Gb, clusterResource); VerifyQueueMetrics(d, 2 * Gb, clusterResource); //D got the container Log.Info("status child-queues: " + ((ParentQueue)root).GetChildQueuesToPrint()); }