Search in sources :

Example 26 with Container

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

the class TestNMWebServicesContainers method addAppContainers.

private HashMap<String, String> addAppContainers(Application app) throws IOException {
    Dispatcher dispatcher = new AsyncDispatcher();
    ApplicationAttemptId appAttemptId = BuilderUtils.newApplicationAttemptId(app.getAppId(), 1);
    Container container1 = new MockContainer(appAttemptId, dispatcher, conf, app.getUser(), app.getAppId(), 1);
    ((MockContainer) container1).setState(ContainerState.RUNNING);
    Container container2 = new MockContainer(appAttemptId, dispatcher, conf, app.getUser(), app.getAppId(), 2);
    ((MockContainer) container2).setState(ContainerState.RUNNING);
    nmContext.getContainers().put(container1.getContainerId(), container1);
    nmContext.getContainers().put(container2.getContainerId(), container2);
    File appDir = new File(testLogDir + "/" + app.getAppId().toString());
    appDir.mkdir();
    File container1Dir = new File(appDir + "/" + container1.getContainerId().toString());
    container1Dir.mkdir();
    // Create log files for containers.
    new File(container1Dir + "/" + "syslog").createNewFile();
    new File(container1Dir + "/" + "stdout").createNewFile();
    File container2Dir = new File(appDir + "/" + container2.getContainerId().toString());
    container2Dir.mkdir();
    new File(container2Dir + "/" + "syslog").createNewFile();
    new File(container2Dir + "/" + "stdout").createNewFile();
    app.getContainers().put(container1.getContainerId(), container1);
    app.getContainers().put(container2.getContainerId(), container2);
    HashMap<String, String> hash = new HashMap<String, String>();
    hash.put(container1.getContainerId().toString(), container1.getContainerId().toString());
    hash.put(container2.getContainerId().toString(), container2.getContainerId().toString());
    return hash;
}
Also used : Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) GuiceContainer(com.sun.jersey.guice.spi.container.servlet.GuiceContainer) AsyncDispatcher(org.apache.hadoop.yarn.event.AsyncDispatcher) HashMap(java.util.HashMap) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) AsyncDispatcher(org.apache.hadoop.yarn.event.AsyncDispatcher) Dispatcher(org.apache.hadoop.yarn.event.Dispatcher) File(java.io.File)

Example 27 with Container

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container 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)

Example 28 with Container

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

the class DummyContainerManager method createContainersLauncher.

@Override
@SuppressWarnings("unchecked")
protected ContainersLauncher createContainersLauncher(Context context, ContainerExecutor exec) {
    return new ContainersLauncher(context, super.dispatcher, exec, super.dirsHandler, this) {

        @Override
        public void handle(ContainersLauncherEvent event) {
            Container container = event.getContainer();
            ContainerId containerId = container.getContainerId();
            switch(event.getType()) {
                case LAUNCH_CONTAINER:
                    dispatcher.getEventHandler().handle(new ContainerEvent(containerId, ContainerEventType.CONTAINER_LAUNCHED));
                    break;
                case CLEANUP_CONTAINER:
                    dispatcher.getEventHandler().handle(new ContainerExitEvent(containerId, ContainerEventType.CONTAINER_KILLED_ON_REQUEST, 0, "Container exited with exit code 0."));
                    break;
            }
        }
    };
}
Also used : ContainerEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerEvent) Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) ContainersLauncher(org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainersLauncher) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ContainerExitEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerExitEvent) ContainersLauncherEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainersLauncherEvent)

Example 29 with Container

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

the class ContainerLogsUtils method getContainerLogDirs.

/**
   * Finds the local directories that logs for the given container are stored
   * on.
   */
public static List<File> getContainerLogDirs(ContainerId containerId, String remoteUser, Context context) throws YarnException {
    Container container = context.getContainers().get(containerId);
    Application application = getApplicationForContainer(containerId, context);
    checkAccess(remoteUser, application, context);
    // reading container logs. 
    if (container != null) {
        checkState(container.getContainerState());
    }
    return getContainerLogDirs(containerId, context.getLocalDirsHandler());
}
Also used : Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) Application(org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application)

Example 30 with Container

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

the class ContainerLogsUtils method getContainerLogFile.

/**
   * Finds the log file with the given filename for the given container.
   */
public static File getContainerLogFile(ContainerId containerId, String fileName, String remoteUser, Context context) throws YarnException {
    Container container = context.getContainers().get(containerId);
    Application application = getApplicationForContainer(containerId, context);
    checkAccess(remoteUser, application, context);
    if (container != null) {
        checkState(container.getContainerState());
    }
    try {
        LocalDirsHandlerService dirsHandler = context.getLocalDirsHandler();
        String relativeContainerLogDir = ContainerLaunch.getRelativeContainerLogDir(application.getAppId().toString(), containerId.toString());
        Path logPath = dirsHandler.getLogPathToRead(relativeContainerLogDir + Path.SEPARATOR + fileName);
        URI logPathURI = new File(logPath.toString()).toURI();
        File logFile = new File(logPathURI.getPath());
        return logFile;
    } catch (IOException e) {
        LOG.warn("Failed to find log file", e);
        throw new NotFoundException("Cannot find this log on the local disk.");
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) IOException(java.io.IOException) LocalDirsHandlerService(org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService) Application(org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application) URI(java.net.URI) File(java.io.File)

Aggregations

Container (org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container)109 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)55 Test (org.junit.Test)43 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)33 Path (org.apache.hadoop.fs.Path)31 ArrayList (java.util.ArrayList)29 Application (org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application)29 HashMap (java.util.HashMap)27 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)27 Configuration (org.apache.hadoop.conf.Configuration)24 IOException (java.io.IOException)20 ContainerLaunchContext (org.apache.hadoop.yarn.api.records.ContainerLaunchContext)18 ContainerEvent (org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerEvent)17 LocalDirsHandlerService (org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService)16 Collection (java.util.Collection)14 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)14 LocalResourceVisibility (org.apache.hadoop.yarn.api.records.LocalResourceVisibility)14 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)14 LocalResource (org.apache.hadoop.yarn.api.records.LocalResource)13 ApplicationEvent (org.apache.hadoop.yarn.server.nodemanager.containermanager.application.ApplicationEvent)13