Search in sources :

Example 1 with AllocationExpirationInfo

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

the class RMNodeImpl method handleContainerStatus.

private void handleContainerStatus(List<ContainerStatus> containerStatuses) {
    // Filter the map to only obtain just launched containers and finished
    // containers.
    List<ContainerStatus> newlyLaunchedContainers = new ArrayList<ContainerStatus>();
    List<ContainerStatus> newlyCompletedContainers = new ArrayList<ContainerStatus>();
    int numRemoteRunningContainers = 0;
    for (ContainerStatus remoteContainer : containerStatuses) {
        ContainerId containerId = remoteContainer.getContainerId();
        // more about this container
        if (containersToClean.contains(containerId)) {
            LOG.info("Container " + containerId + " already scheduled for " + "cleanup, no further processing");
            continue;
        }
        ApplicationId containerAppId = containerId.getApplicationAttemptId().getApplicationId();
        if (finishedApplications.contains(containerAppId)) {
            LOG.info("Container " + containerId + " belongs to an application that is already killed," + " no further processing");
            continue;
        } else if (!runningApplications.contains(containerAppId)) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Container " + containerId + " is the first container get launched for application " + containerAppId);
            }
            handleRunningAppOnNode(this, context, containerAppId, nodeId);
        }
        // Process running containers
        if (remoteContainer.getState() == ContainerState.RUNNING || remoteContainer.getState() == ContainerState.SCHEDULED) {
            ++numRemoteRunningContainers;
            if (!launchedContainers.contains(containerId)) {
                // Just launched container. RM knows about it the first time.
                launchedContainers.add(containerId);
                newlyLaunchedContainers.add(remoteContainer);
                // Unregister from containerAllocationExpirer.
                containerAllocationExpirer.unregister(new AllocationExpirationInfo(containerId));
            }
        } else {
            // A finished container
            launchedContainers.remove(containerId);
            if (completedContainers.add(containerId)) {
                newlyCompletedContainers.add(remoteContainer);
            }
            // Unregister from containerAllocationExpirer.
            containerAllocationExpirer.unregister(new AllocationExpirationInfo(containerId));
        }
    }
    List<ContainerStatus> lostContainers = findLostContainers(numRemoteRunningContainers, containerStatuses);
    for (ContainerStatus remoteContainer : lostContainers) {
        ContainerId containerId = remoteContainer.getContainerId();
        if (completedContainers.add(containerId)) {
            newlyCompletedContainers.add(remoteContainer);
        }
    }
    if (newlyLaunchedContainers.size() != 0 || newlyCompletedContainers.size() != 0) {
        nodeUpdateQueue.add(new UpdatedContainerInfo(newlyLaunchedContainers, newlyCompletedContainers));
    }
}
Also used : AllocationExpirationInfo(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.AllocationExpirationInfo) NMContainerStatus(org.apache.hadoop.yarn.server.api.protocolrecords.NMContainerStatus) ContainerStatus(org.apache.hadoop.yarn.api.records.ContainerStatus) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ArrayList(java.util.ArrayList) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId)

Example 2 with AllocationExpirationInfo

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

the class TestRMNodeTransitions method testContainerExpire.

@Test
public void testContainerExpire() throws Exception {
    ContainerAllocationExpirer mockExpirer = mock(ContainerAllocationExpirer.class);
    ApplicationId appId = ApplicationId.newInstance(System.currentTimeMillis(), 1);
    ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1);
    rmContext.getRMApps().put(appId, Mockito.mock(RMApp.class));
    ContainerId containerId1 = ContainerId.newContainerId(appAttemptId, 1L);
    ContainerId containerId2 = ContainerId.newContainerId(appAttemptId, 2L);
    AllocationExpirationInfo expirationInfo1 = new AllocationExpirationInfo(containerId1);
    AllocationExpirationInfo expirationInfo2 = new AllocationExpirationInfo(containerId2);
    mockExpirer.register(expirationInfo1);
    mockExpirer.register(expirationInfo2);
    verify(mockExpirer).register(expirationInfo1);
    verify(mockExpirer).register(expirationInfo2);
    ((RMContextImpl) rmContext).setContainerAllocationExpirer(mockExpirer);
    RMNodeImpl rmNode = getRunningNode();
    ContainerStatus status1 = ContainerStatus.newInstance(containerId1, ContainerState.RUNNING, "", 0);
    ContainerStatus status2 = ContainerStatus.newInstance(containerId2, ContainerState.COMPLETE, "", 0);
    List<ContainerStatus> statusList = new ArrayList<ContainerStatus>();
    statusList.add(status1);
    statusList.add(status2);
    RMNodeStatusEvent statusEvent = getMockRMNodeStatusEvent(statusList);
    rmNode.handle(statusEvent);
    verify(mockExpirer).unregister(expirationInfo1);
    verify(mockExpirer).unregister(expirationInfo2);
}
Also used : AllocationExpirationInfo(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.AllocationExpirationInfo) RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) ContainerStatus(org.apache.hadoop.yarn.api.records.ContainerStatus) RMNodeStatusEvent(org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNodeStatusEvent) ContainerAllocationExpirer(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.ContainerAllocationExpirer) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ArrayList(java.util.ArrayList) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) RMNodeImpl(org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNodeImpl) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)2 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)2 ContainerStatus (org.apache.hadoop.yarn.api.records.ContainerStatus)2 AllocationExpirationInfo (org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.AllocationExpirationInfo)2 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)1 NMContainerStatus (org.apache.hadoop.yarn.server.api.protocolrecords.NMContainerStatus)1 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)1 ContainerAllocationExpirer (org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.ContainerAllocationExpirer)1 RMNodeImpl (org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNodeImpl)1 RMNodeStatusEvent (org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNodeStatusEvent)1 Test (org.junit.Test)1