Search in sources :

Example 36 with ContainerStatus

use of org.apache.hadoop.yarn.api.records.ContainerStatus in project hadoop by apache.

the class ContainerImpl method sendFinishedEvents.

@SuppressWarnings("unchecked")
private void sendFinishedEvents() {
    // Inform the application
    @SuppressWarnings("rawtypes") EventHandler eventHandler = dispatcher.getEventHandler();
    ContainerStatus containerStatus = cloneAndGetContainerStatus();
    eventHandler.handle(new ApplicationContainerFinishedEvent(containerStatus));
    // Tell the scheduler the container is Done
    eventHandler.handle(new ContainerSchedulerEvent(this, ContainerSchedulerEventType.CONTAINER_COMPLETED));
    // Remove the container from the resource-monitor
    eventHandler.handle(new ContainerStopMonitoringEvent(containerId));
    // Tell the logService too
    eventHandler.handle(new LogHandlerContainerFinishedEvent(containerId, exitCode));
}
Also used : NMContainerStatus(org.apache.hadoop.yarn.server.api.protocolrecords.NMContainerStatus) ContainerStatus(org.apache.hadoop.yarn.api.records.ContainerStatus) RecoveredContainerStatus(org.apache.hadoop.yarn.server.nodemanager.recovery.NMStateStoreService.RecoveredContainerStatus) EventHandler(org.apache.hadoop.yarn.event.EventHandler) LogHandlerContainerFinishedEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.loghandler.event.LogHandlerContainerFinishedEvent) ContainerSchedulerEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.scheduler.ContainerSchedulerEvent) ContainerStopMonitoringEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.monitor.ContainerStopMonitoringEvent) ApplicationContainerFinishedEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.application.ApplicationContainerFinishedEvent)

Example 37 with ContainerStatus

use of org.apache.hadoop.yarn.api.records.ContainerStatus in project hadoop by apache.

the class NodeManager method getContainerStatuses.

@Override
public synchronized GetContainerStatusesResponse getContainerStatuses(GetContainerStatusesRequest request) throws YarnException {
    List<ContainerStatus> statuses = new ArrayList<ContainerStatus>();
    for (ContainerId containerId : request.getContainerIds()) {
        List<Container> appContainers = containers.get(containerId.getApplicationAttemptId().getApplicationId());
        Container container = null;
        for (Container c : appContainers) {
            if (c.getId().equals(containerId)) {
                container = c;
            }
        }
        if (container != null && containerStatusMap.get(container).getState() != null) {
            statuses.add(containerStatusMap.get(container));
        }
    }
    return GetContainerStatusesResponse.newInstance(statuses, null);
}
Also used : ContainerStatus(org.apache.hadoop.yarn.api.records.ContainerStatus) Container(org.apache.hadoop.yarn.api.records.Container) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ArrayList(java.util.ArrayList)

Example 38 with ContainerStatus

use of org.apache.hadoop.yarn.api.records.ContainerStatus in project hadoop by apache.

the class NodeManager method startContainers.

@Override
public synchronized StartContainersResponse startContainers(StartContainersRequest requests) throws YarnException {
    for (StartContainerRequest request : requests.getStartContainerRequests()) {
        Token containerToken = request.getContainerToken();
        ContainerTokenIdentifier tokenId = null;
        try {
            tokenId = BuilderUtils.newContainerTokenIdentifier(containerToken);
        } catch (IOException e) {
            throw RPCUtil.getRemoteException(e);
        }
        ContainerId containerID = tokenId.getContainerID();
        ApplicationId applicationId = containerID.getApplicationAttemptId().getApplicationId();
        List<Container> applicationContainers = containers.get(applicationId);
        if (applicationContainers == null) {
            applicationContainers = new ArrayList<Container>();
            containers.put(applicationId, applicationContainers);
        }
        // Sanity check
        for (Container container : applicationContainers) {
            if (container.getId().compareTo(containerID) == 0) {
                throw new IllegalStateException("Container " + containerID + " already setup on node " + containerManagerAddress);
            }
        }
        Container container = BuilderUtils.newContainer(containerID, this.nodeId, nodeHttpAddress, // DKDC - Doesn't matter
        tokenId.getResource(), // DKDC - Doesn't matter
        null, // DKDC - Doesn't matter
        null);
        ContainerStatus containerStatus = BuilderUtils.newContainerStatus(container.getId(), ContainerState.NEW, "", -1000, container.getResource());
        applicationContainers.add(container);
        containerStatusMap.put(container, containerStatus);
        Resources.subtractFrom(available, tokenId.getResource());
        Resources.addTo(used, tokenId.getResource());
        if (LOG.isDebugEnabled()) {
            LOG.debug("startContainer:" + " node=" + containerManagerAddress + " application=" + applicationId + " container=" + container + " available=" + available + " used=" + used);
        }
    }
    StartContainersResponse response = StartContainersResponse.newInstance(null, null, null);
    return response;
}
Also used : Container(org.apache.hadoop.yarn.api.records.Container) ContainerStatus(org.apache.hadoop.yarn.api.records.ContainerStatus) StartContainersResponse(org.apache.hadoop.yarn.api.protocolrecords.StartContainersResponse) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) Token(org.apache.hadoop.yarn.api.records.Token) IOException(java.io.IOException) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) StartContainerRequest(org.apache.hadoop.yarn.api.protocolrecords.StartContainerRequest) ContainerTokenIdentifier(org.apache.hadoop.yarn.security.ContainerTokenIdentifier)

Example 39 with ContainerStatus

use of org.apache.hadoop.yarn.api.records.ContainerStatus in project hadoop by apache.

the class MockNM method containerIncreaseStatus.

public void containerIncreaseStatus(Container container) throws Exception {
    ContainerStatus containerStatus = BuilderUtils.newContainerStatus(container.getId(), ContainerState.RUNNING, "Success", 0, container.getResource());
    List<Container> increasedConts = Collections.singletonList(container);
    nodeHeartbeat(Collections.singletonList(containerStatus), increasedConts, true, ++responseId);
}
Also used : NMContainerStatus(org.apache.hadoop.yarn.server.api.protocolrecords.NMContainerStatus) ContainerStatus(org.apache.hadoop.yarn.api.records.ContainerStatus) Container(org.apache.hadoop.yarn.api.records.Container)

Example 40 with ContainerStatus

use of org.apache.hadoop.yarn.api.records.ContainerStatus in project hadoop by apache.

the class MRAMSimulator method processResponseQueue.

@Override
@SuppressWarnings("unchecked")
protected void processResponseQueue() throws Exception {
    while (!responseQueue.isEmpty()) {
        AllocateResponse response = responseQueue.take();
        // check completed containers
        if (!response.getCompletedContainersStatuses().isEmpty()) {
            for (ContainerStatus cs : response.getCompletedContainersStatuses()) {
                ContainerId containerId = cs.getContainerId();
                if (cs.getExitStatus() == ContainerExitStatus.SUCCESS) {
                    if (assignedMaps.containsKey(containerId)) {
                        LOG.debug(MessageFormat.format("Application {0} has one" + "mapper finished ({1}).", appId, containerId));
                        assignedMaps.remove(containerId);
                        mapFinished++;
                        finishedContainers++;
                    } else if (assignedReduces.containsKey(containerId)) {
                        LOG.debug(MessageFormat.format("Application {0} has one" + "reducer finished ({1}).", appId, containerId));
                        assignedReduces.remove(containerId);
                        reduceFinished++;
                        finishedContainers++;
                    } else if (amContainer.getId().equals(containerId)) {
                        // am container released event
                        isFinished = true;
                        LOG.info(MessageFormat.format("Application {0} goes to " + "finish.", appId));
                    }
                    if (mapFinished >= mapTotal && reduceFinished >= reduceTotal) {
                        lastStep();
                    }
                } else {
                    // container to be killed
                    if (assignedMaps.containsKey(containerId)) {
                        LOG.debug(MessageFormat.format("Application {0} has one " + "mapper killed ({1}).", appId, containerId));
                        pendingFailedMaps.add(assignedMaps.remove(containerId));
                    } else if (assignedReduces.containsKey(containerId)) {
                        LOG.debug(MessageFormat.format("Application {0} has one " + "reducer killed ({1}).", appId, containerId));
                        pendingFailedReduces.add(assignedReduces.remove(containerId));
                    } else if (amContainer.getId().equals(containerId)) {
                        LOG.info(MessageFormat.format("Application {0}'s AM is " + "going to be killed. Waiting for rescheduling...", appId));
                    }
                }
            }
        }
        // check finished
        if (isAMContainerRunning && (mapFinished >= mapTotal) && (reduceFinished >= reduceTotal)) {
            isAMContainerRunning = false;
            LOG.debug(MessageFormat.format("Application {0} sends out event " + "to clean up its AM container.", appId));
            isFinished = true;
            break;
        }
        // check allocated containers
        for (Container container : response.getAllocatedContainers()) {
            if (!scheduledMaps.isEmpty()) {
                ContainerSimulator cs = scheduledMaps.remove();
                LOG.debug(MessageFormat.format("Application {0} starts a " + "launch a mapper ({1}).", appId, container.getId()));
                assignedMaps.put(container.getId(), cs);
                se.getNmMap().get(container.getNodeId()).addNewContainer(container, cs.getLifeTime());
            } else if (!this.scheduledReduces.isEmpty()) {
                ContainerSimulator cs = scheduledReduces.remove();
                LOG.debug(MessageFormat.format("Application {0} starts a " + "launch a reducer ({1}).", appId, container.getId()));
                assignedReduces.put(container.getId(), cs);
                se.getNmMap().get(container.getNodeId()).addNewContainer(container, cs.getLifeTime());
            }
        }
    }
}
Also used : AllocateResponse(org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse) ContainerSimulator(org.apache.hadoop.yarn.sls.scheduler.ContainerSimulator) ContainerStatus(org.apache.hadoop.yarn.api.records.ContainerStatus) Container(org.apache.hadoop.yarn.api.records.Container) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId)

Aggregations

ContainerStatus (org.apache.hadoop.yarn.api.records.ContainerStatus)124 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)67 Test (org.junit.Test)61 ArrayList (java.util.ArrayList)52 Container (org.apache.hadoop.yarn.api.records.Container)35 NMContainerStatus (org.apache.hadoop.yarn.server.api.protocolrecords.NMContainerStatus)28 HashMap (java.util.HashMap)24 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)23 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)22 NodeId (org.apache.hadoop.yarn.api.records.NodeId)21 GetContainerStatusesRequest (org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesRequest)20 ContainerLaunchContext (org.apache.hadoop.yarn.api.records.ContainerLaunchContext)20 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)20 StartContainerRequest (org.apache.hadoop.yarn.api.protocolrecords.StartContainerRequest)19 StartContainersRequest (org.apache.hadoop.yarn.api.protocolrecords.StartContainersRequest)18 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)18 AllocateResponse (org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse)17 Resource (org.apache.hadoop.yarn.api.records.Resource)16 Configuration (org.apache.hadoop.conf.Configuration)14 RMContainer (org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer)14