Search in sources :

Example 46 with RMContainer

use of org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer in project hadoop by apache.

the class LeafQueue method allocateResource.

void allocateResource(Resource clusterResource, SchedulerApplicationAttempt application, Resource resource, String nodePartition, RMContainer rmContainer) {
    try {
        writeLock.lock();
        super.allocateResource(clusterResource, resource, nodePartition);
        // handle ignore exclusivity container
        if (null != rmContainer && rmContainer.getNodeLabelExpression().equals(RMNodeLabelsManager.NO_LABEL) && !nodePartition.equals(RMNodeLabelsManager.NO_LABEL)) {
            TreeSet<RMContainer> rmContainers = null;
            if (null == (rmContainers = ignorePartitionExclusivityRMContainers.get(nodePartition))) {
                rmContainers = new TreeSet<>();
                ignorePartitionExclusivityRMContainers.put(nodePartition, rmContainers);
            }
            rmContainers.add(rmContainer);
        }
        // Update user metrics
        String userName = application.getUser();
        // Increment user's resource usage.
        User user = usersManager.updateUserResourceUsage(userName, resource, nodePartition, true);
        // Note this is a bit unconventional since it gets the object and modifies
        // it here, rather then using set routine
        // headroom
        Resources.subtractFrom(application.getHeadroom(), resource);
        metrics.setAvailableResourcesToUser(userName, application.getHeadroom());
        if (LOG.isDebugEnabled()) {
            LOG.debug(getQueueName() + " user=" + userName + " used=" + queueUsage.getUsed(nodePartition) + " numContainers=" + numContainers + " headroom = " + application.getHeadroom() + " user-resources=" + user.getUsed());
        }
    } finally {
        writeLock.unlock();
    }
}
Also used : User(org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.UsersManager.User) RMContainer(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer)

Example 47 with RMContainer

use of org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer in project hadoop by apache.

the class LeafQueue method releaseResource.

void releaseResource(Resource clusterResource, FiCaSchedulerApp application, Resource resource, String nodePartition, RMContainer rmContainer) {
    try {
        writeLock.lock();
        super.releaseResource(clusterResource, resource, nodePartition);
        // handle ignore exclusivity container
        if (null != rmContainer && rmContainer.getNodeLabelExpression().equals(RMNodeLabelsManager.NO_LABEL) && !nodePartition.equals(RMNodeLabelsManager.NO_LABEL)) {
            if (ignorePartitionExclusivityRMContainers.containsKey(nodePartition)) {
                Set<RMContainer> rmContainers = ignorePartitionExclusivityRMContainers.get(nodePartition);
                rmContainers.remove(rmContainer);
                if (rmContainers.isEmpty()) {
                    ignorePartitionExclusivityRMContainers.remove(nodePartition);
                }
            }
        }
        // Update user metrics
        String userName = application.getUser();
        User user = usersManager.updateUserResourceUsage(userName, resource, nodePartition, false);
        metrics.setAvailableResourcesToUser(userName, application.getHeadroom());
        if (LOG.isDebugEnabled()) {
            LOG.debug(getQueueName() + " used=" + queueUsage.getUsed() + " numContainers=" + numContainers + " user=" + userName + " user-resources=" + user.getUsed());
        }
    } finally {
        writeLock.unlock();
    }
}
Also used : User(org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.UsersManager.User) RMContainer(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer)

Example 48 with RMContainer

use of org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer in project hadoop by apache.

the class LeafQueue method internalReleaseContainer.

private void internalReleaseContainer(Resource clusterResource, SchedulerContainer<FiCaSchedulerApp, FiCaSchedulerNode> schedulerContainer) {
    RMContainer rmContainer = schedulerContainer.getRmContainer();
    LeafQueue targetLeafQueue = schedulerContainer.getSchedulerApplicationAttempt().getCSLeafQueue();
    if (targetLeafQueue == this) {
        // When trying to preempt containers from the same queue
        if (rmContainer.getState() == RMContainerState.RESERVED) {
            // For other reserved containers
            // This is a reservation exchange, complete previous reserved container
            completedContainer(clusterResource, schedulerContainer.getSchedulerApplicationAttempt(), schedulerContainer.getSchedulerNode(), rmContainer, SchedulerUtils.createAbnormalContainerStatus(rmContainer.getContainerId(), SchedulerUtils.UNRESERVED_CONTAINER), RMContainerEventType.RELEASED, null, false);
        }
    } else {
        // When trying to preempt containers from different queue -- this
        // is for lazy preemption feature (kill preemption candidate in scheduling
        // cycle).
        targetLeafQueue.completedContainer(clusterResource, schedulerContainer.getSchedulerApplicationAttempt(), schedulerContainer.getSchedulerNode(), schedulerContainer.getRmContainer(), SchedulerUtils.createPreemptedContainerStatus(rmContainer.getContainerId(), SchedulerUtils.PREEMPTED_CONTAINER), RMContainerEventType.KILL, null, false);
    }
}
Also used : RMContainer(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer)

Example 49 with RMContainer

use of org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer in project hadoop by apache.

the class CapacityScheduler method updateLabelsOnNode.

/**
   * Process node labels update on a node.
   */
private void updateLabelsOnNode(NodeId nodeId, Set<String> newLabels) {
    FiCaSchedulerNode node = nodeTracker.getNode(nodeId);
    if (null == node) {
        return;
    }
    // Get new partition, we have only one partition per node
    String newPartition;
    if (newLabels.isEmpty()) {
        newPartition = RMNodeLabelsManager.NO_LABEL;
    } else {
        newPartition = newLabels.iterator().next();
    }
    // old partition as well
    String oldPartition = node.getPartition();
    // Update resources of these containers
    for (RMContainer rmContainer : node.getCopiedListOfRunningContainers()) {
        FiCaSchedulerApp application = getApplicationAttempt(rmContainer.getApplicationAttemptId());
        if (null != application) {
            application.nodePartitionUpdated(rmContainer, oldPartition, newPartition);
        } else {
            LOG.warn("There's something wrong, some RMContainers running on" + " a node, but we cannot find SchedulerApplicationAttempt " + "for it. Node=" + node.getNodeID() + " applicationAttemptId=" + rmContainer.getApplicationAttemptId());
            continue;
        }
    }
    // Unreserve container on this node
    RMContainer reservedContainer = node.getReservedContainer();
    if (null != reservedContainer) {
        killReservedContainer(reservedContainer);
    }
    // Update node labels after we've done this
    node.updateLabels(newLabels);
}
Also used : FiCaSchedulerNode(org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerNode) FiCaSchedulerApp(org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerApp) RMContainer(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer)

Example 50 with RMContainer

use of org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer in project hadoop by apache.

the class TestRMAppAttemptTransitions method allocateApplicationAttempt.

@SuppressWarnings("unchecked")
private Container allocateApplicationAttempt() {
    scheduleApplicationAttempt();
    // Mock the allocation of AM container 
    Container container = mock(Container.class);
    Resource resource = BuilderUtils.newResource(2048, 1);
    when(container.getId()).thenReturn(BuilderUtils.newContainerId(applicationAttempt.getAppAttemptId(), 1));
    when(container.getResource()).thenReturn(resource);
    Allocation allocation = mock(Allocation.class);
    when(allocation.getContainers()).thenReturn(Collections.singletonList(container));
    when(scheduler.allocate(any(ApplicationAttemptId.class), any(List.class), any(List.class), any(List.class), any(List.class), any(ContainerUpdates.class))).thenReturn(allocation);
    RMContainer rmContainer = mock(RMContainerImpl.class);
    when(scheduler.getRMContainer(container.getId())).thenReturn(rmContainer);
    applicationAttempt.handle(new RMAppAttemptEvent(applicationAttempt.getAppAttemptId(), RMAppAttemptEventType.CONTAINER_ALLOCATED));
    assertEquals(RMAppAttemptState.ALLOCATED_SAVING, applicationAttempt.getAppAttemptState());
    applicationAttempt.handle(new RMAppAttemptEvent(applicationAttempt.getAppAttemptId(), RMAppAttemptEventType.ATTEMPT_NEW_SAVED));
    testAppAttemptAllocatedState(container);
    return container;
}
Also used : RMContainer(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer) Container(org.apache.hadoop.yarn.api.records.Container) Allocation(org.apache.hadoop.yarn.server.resourcemanager.scheduler.Allocation) ContainerUpdates(org.apache.hadoop.yarn.server.resourcemanager.scheduler.ContainerUpdates) Resource(org.apache.hadoop.yarn.api.records.Resource) ArrayList(java.util.ArrayList) List(java.util.List) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) RMContainer(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer)

Aggregations

RMContainer (org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer)166 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)55 Resource (org.apache.hadoop.yarn.api.records.Resource)49 Container (org.apache.hadoop.yarn.api.records.Container)48 Test (org.junit.Test)45 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)41 ArrayList (java.util.ArrayList)29 NodeId (org.apache.hadoop.yarn.api.records.NodeId)29 FiCaSchedulerApp (org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerApp)29 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)28 FiCaSchedulerNode (org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerNode)21 RMContainerImpl (org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainerImpl)18 HashMap (java.util.HashMap)17 ResourceRequest (org.apache.hadoop.yarn.api.records.ResourceRequest)17 RMNode (org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode)17 NodeUpdateSchedulerEvent (org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeUpdateSchedulerEvent)17 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)15 Priority (org.apache.hadoop.yarn.api.records.Priority)14 MockRM (org.apache.hadoop.yarn.server.resourcemanager.MockRM)13 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)12