Search in sources :

Example 1 with ContainerEvent

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerEvent in project hadoop by apache.

the class ContainerManagerImpl method rollbackLastReInitialization.

/**
   * Rollback the last reInitialization, if possible.
   * @param containerId Container ID.
   * @return Rollback Response.
   * @throws YarnException Yarn Exception.
   */
@Override
public RollbackResponse rollbackLastReInitialization(ContainerId containerId) throws YarnException {
    Container container = preReInitializeOrLocalizeCheck(containerId, ReInitOp.ROLLBACK);
    if (container.canRollback()) {
        dispatcher.getEventHandler().handle(new ContainerEvent(containerId, ContainerEventType.ROLLBACK_REINIT));
        container.setIsReInitializing(true);
    } else {
        throw new YarnException("Nothing to rollback to !!");
    }
    return RollbackResponse.newInstance();
}
Also used : ContainerEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerEvent) Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Example 2 with ContainerEvent

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerEvent in project hadoop by apache.

the class RecoveredContainerLaunch method call.

/**
   * Wait on the process specified in pid file and return its exit code
   */
@SuppressWarnings("unchecked")
@Override
public Integer call() {
    int retCode = ExitCode.LOST.getExitCode();
    ContainerId containerId = container.getContainerId();
    String appIdStr = containerId.getApplicationAttemptId().getApplicationId().toString();
    String containerIdStr = containerId.toString();
    dispatcher.getEventHandler().handle(new ContainerEvent(containerId, ContainerEventType.CONTAINER_LAUNCHED));
    boolean notInterrupted = true;
    try {
        File pidFile = locatePidFile(appIdStr, containerIdStr);
        if (pidFile != null) {
            String pidPathStr = pidFile.getPath();
            pidFilePath = new Path(pidPathStr);
            exec.activateContainer(containerId, pidFilePath);
            retCode = exec.reacquireContainer(new ContainerReacquisitionContext.Builder().setContainer(container).setUser(container.getUser()).setContainerId(containerId).build());
        } else {
            LOG.warn("Unable to locate pid file for container " + containerIdStr);
        }
    } catch (InterruptedException | InterruptedIOException e) {
        LOG.warn("Interrupted while waiting for exit code from " + containerId);
        notInterrupted = false;
    } catch (IOException e) {
        LOG.error("Unable to recover container " + containerIdStr, e);
    } finally {
        if (notInterrupted) {
            this.completed.set(true);
            exec.deactivateContainer(containerId);
            try {
                getContext().getNMStateStore().storeContainerCompleted(containerId, retCode);
            } catch (IOException e) {
                LOG.error("Unable to set exit code for container " + containerId);
            }
        }
    }
    if (retCode != 0) {
        LOG.warn("Recovered container exited with a non-zero exit code " + retCode);
        this.dispatcher.getEventHandler().handle(new ContainerExitEvent(containerId, ContainerEventType.CONTAINER_EXITED_WITH_FAILURE, retCode, "Container exited with a non-zero exit code " + retCode));
        return retCode;
    }
    LOG.info("Recovered container " + containerId + " succeeded");
    dispatcher.getEventHandler().handle(new ContainerEvent(containerId, ContainerEventType.CONTAINER_EXITED_WITH_SUCCESS));
    return 0;
}
Also used : ContainerEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerEvent) Path(org.apache.hadoop.fs.Path) InterruptedIOException(java.io.InterruptedIOException) ContainerExitEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerExitEvent) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) File(java.io.File)

Example 3 with ContainerEvent

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerEvent in project hadoop by apache.

the class ContainerLaunch method launchContainer.

@SuppressWarnings("unchecked")
protected int launchContainer(ContainerStartContext ctx) throws IOException {
    ContainerId containerId = container.getContainerId();
    if (container.isMarkedForKilling()) {
        LOG.info("Container " + containerId + " not launched as it has already " + "been marked for Killing");
        this.killedBeforeStart = true;
        return ExitCode.TERMINATED.getExitCode();
    }
    // LaunchContainer is a blocking call. We are here almost means the
    // container is launched, so send out the event.
    dispatcher.getEventHandler().handle(new ContainerEvent(containerId, ContainerEventType.CONTAINER_LAUNCHED));
    context.getNMStateStore().storeContainerLaunched(containerId);
    // Check if the container is signalled to be killed.
    if (!containerAlreadyLaunched.compareAndSet(false, true)) {
        LOG.info("Container " + containerId + " not launched as " + "cleanup already called");
        return ExitCode.TERMINATED.getExitCode();
    } else {
        exec.activateContainer(containerId, pidFilePath);
        return exec.launchContainer(ctx);
    }
}
Also used : ContainerEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerEvent) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId)

Example 4 with ContainerEvent

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerEvent in project hadoop by apache.

the class ContainerLaunch method handleContainerExitCode.

@SuppressWarnings("unchecked")
protected void handleContainerExitCode(int exitCode, Path containerLogDir) {
    ContainerId containerId = container.getContainerId();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Container " + containerId + " completed with exit code " + exitCode);
    }
    StringBuilder diagnosticInfo = new StringBuilder("Container exited with a non-zero exit code ");
    diagnosticInfo.append(exitCode);
    diagnosticInfo.append(". ");
    if (exitCode == ExitCode.FORCE_KILLED.getExitCode() || exitCode == ExitCode.TERMINATED.getExitCode()) {
        // If Container was killed before starting... NO need to do this.
        if (!killedBeforeStart) {
            dispatcher.getEventHandler().handle(new ContainerExitEvent(containerId, ContainerEventType.CONTAINER_KILLED_ON_REQUEST, exitCode, diagnosticInfo.toString()));
        }
    } else if (exitCode != 0) {
        handleContainerExitWithFailure(containerId, exitCode, containerLogDir, diagnosticInfo);
    } else {
        LOG.info("Container " + containerId + " succeeded ");
        dispatcher.getEventHandler().handle(new ContainerEvent(containerId, ContainerEventType.CONTAINER_EXITED_WITH_SUCCESS));
    }
}
Also used : ContainerEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerEvent) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ContainerExitEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerExitEvent)

Example 5 with ContainerEvent

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerEvent in project hadoop by apache.

the class DummyContainerManager method createResourceLocalizationService.

@Override
@SuppressWarnings("unchecked")
protected ResourceLocalizationService createResourceLocalizationService(ContainerExecutor exec, DeletionService deletionContext, Context context) {
    return new ResourceLocalizationService(super.dispatcher, exec, deletionContext, super.dirsHandler, context) {

        @Override
        public void handle(LocalizationEvent event) {
            switch(event.getType()) {
                case INIT_APPLICATION_RESOURCES:
                    Application app = ((ApplicationLocalizationEvent) event).getApplication();
                    // Simulate event from ApplicationLocalization.
                    dispatcher.getEventHandler().handle(new ApplicationInitedEvent(app.getAppId()));
                    break;
                case LOCALIZE_CONTAINER_RESOURCES:
                    ContainerLocalizationRequestEvent rsrcReqs = (ContainerLocalizationRequestEvent) event;
                    // simulate localization of all requested resources
                    for (Collection<LocalResourceRequest> rc : rsrcReqs.getRequestedResources().values()) {
                        for (LocalResourceRequest req : rc) {
                            LOG.info("DEBUG: " + req + ":" + rsrcReqs.getContainer().getContainerId());
                            dispatcher.getEventHandler().handle(new ContainerResourceLocalizedEvent(rsrcReqs.getContainer().getContainerId(), req, new Path("file:///local" + req.getPath().toUri().getPath())));
                        }
                    }
                    break;
                case CLEANUP_CONTAINER_RESOURCES:
                    Container container = ((ContainerLocalizationEvent) event).getContainer();
                    // TODO: delete the container dir
                    this.dispatcher.getEventHandler().handle(new ContainerEvent(container.getContainerId(), ContainerEventType.CONTAINER_RESOURCES_CLEANEDUP));
                    break;
                case DESTROY_APPLICATION_RESOURCES:
                    Application application = ((ApplicationLocalizationEvent) event).getApplication();
                    // decrement reference counts of all resources associated with this
                    // app
                    this.dispatcher.getEventHandler().handle(new ApplicationEvent(application.getAppId(), ApplicationEventType.APPLICATION_RESOURCES_CLEANEDUP));
                    break;
                default:
                    fail("Unexpected event: " + event.getType());
            }
        }
    };
}
Also used : Path(org.apache.hadoop.fs.Path) ContainerEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerEvent) LocalResourceRequest(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.LocalResourceRequest) ContainerResourceLocalizedEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerResourceLocalizedEvent) ResourceLocalizationService(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.ResourceLocalizationService) ContainerLocalizationRequestEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ContainerLocalizationRequestEvent) ContainerLocalizationEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ContainerLocalizationEvent) ApplicationEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.application.ApplicationEvent) LocalizationEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.LocalizationEvent) ContainerLocalizationEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ContainerLocalizationEvent) ApplicationLocalizationEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ApplicationLocalizationEvent) Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) ApplicationLocalizationEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ApplicationLocalizationEvent) ApplicationInitedEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.application.ApplicationInitedEvent) Application(org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application)

Aggregations

ContainerEvent (org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerEvent)21 Path (org.apache.hadoop.fs.Path)16 Container (org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container)15 DrainDispatcher (org.apache.hadoop.yarn.event.DrainDispatcher)14 Test (org.junit.Test)14 ApplicationEvent (org.apache.hadoop.yarn.server.nodemanager.containermanager.application.ApplicationEvent)13 ArrayList (java.util.ArrayList)12 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)12 LocalResourceVisibility (org.apache.hadoop.yarn.api.records.LocalResourceVisibility)12 LocalDirsHandlerService (org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService)12 Collection (java.util.Collection)11 HashMap (java.util.HashMap)11 DeletionService (org.apache.hadoop.yarn.server.nodemanager.DeletionService)11 ApplicationLocalizationEvent (org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ApplicationLocalizationEvent)11 ContainerLocalizationRequestEvent (org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ContainerLocalizationRequestEvent)11 Configuration (org.apache.hadoop.conf.Configuration)10 LocalResource (org.apache.hadoop.yarn.api.records.LocalResource)10 ContainerExecutor (org.apache.hadoop.yarn.server.nodemanager.ContainerExecutor)10 DefaultContainerExecutor (org.apache.hadoop.yarn.server.nodemanager.DefaultContainerExecutor)10 Application (org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application)10