Search in sources :

Example 11 with Application

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application in project hadoop by apache.

the class TestNMWebServicesApps method testNodeSingleAppsInvalid.

@Test
public void testNodeSingleAppsInvalid() throws JSONException, Exception {
    WebResource r = resource();
    Application app = new MockApp(1);
    nmContext.getApplications().put(app.getAppId(), app);
    addAppContainers(app);
    Application app2 = new MockApp(2);
    nmContext.getApplications().put(app2.getAppId(), app2);
    addAppContainers(app2);
    try {
        r.path("ws").path("v1").path("node").path("apps").path("app_foo_0000").accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
        fail("should have thrown exception on invalid user query");
    } catch (UniformInterfaceException ue) {
        ClientResponse response = ue.getResponse();
        assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        JSONObject msg = response.getEntity(JSONObject.class);
        JSONObject exception = msg.getJSONObject("RemoteException");
        assertEquals("incorrect number of elements", 3, exception.length());
        String message = exception.getString("message");
        String type = exception.getString("exception");
        String classname = exception.getString("javaClassName");
        WebServicesTestUtils.checkStringMatch("exception message", "java.lang.IllegalArgumentException: Invalid ApplicationId prefix: " + "app_foo_0000. The valid ApplicationId should start with prefix" + " application", message);
        WebServicesTestUtils.checkStringMatch("exception type", "BadRequestException", type);
        WebServicesTestUtils.checkStringMatch("exception classname", "org.apache.hadoop.yarn.webapp.BadRequestException", classname);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) JSONObject(org.codehaus.jettison.json.JSONObject) WebResource(com.sun.jersey.api.client.WebResource) Application(org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application) Test(org.junit.Test)

Example 12 with Application

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application in project hadoop by apache.

the class TestNMWebServicesApps method testNodeSingleAppHelper.

public void testNodeSingleAppHelper(String media) throws JSONException, Exception {
    WebResource r = resource();
    Application app = new MockApp(1);
    nmContext.getApplications().put(app.getAppId(), app);
    HashMap<String, String> hash = addAppContainers(app);
    Application app2 = new MockApp(2);
    nmContext.getApplications().put(app2.getAppId(), app2);
    addAppContainers(app2);
    ClientResponse response = r.path("ws").path("v1").path("node").path("apps").path(app.getAppId().toString()).accept(media).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    JSONObject json = response.getEntity(JSONObject.class);
    verifyNodeAppInfo(json.getJSONObject("app"), app, hash);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) WebResource(com.sun.jersey.api.client.WebResource) Application(org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application)

Example 13 with Application

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application 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 14 with Application

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application 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 15 with Application

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application 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

Application (org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application)65 Test (org.junit.Test)42 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)37 Container (org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container)26 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)24 ClientResponse (com.sun.jersey.api.client.ClientResponse)22 WebResource (com.sun.jersey.api.client.WebResource)22 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)17 LocalDirsHandlerService (org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService)17 JSONObject (org.codehaus.jettison.json.JSONObject)17 Configuration (org.apache.hadoop.conf.Configuration)16 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)14 Path (org.apache.hadoop.fs.Path)14 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)13 LocalResource (org.apache.hadoop.yarn.api.records.LocalResource)13 ApplicationEvent (org.apache.hadoop.yarn.server.nodemanager.containermanager.application.ApplicationEvent)13 ApplicationLocalizationEvent (org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ApplicationLocalizationEvent)12 File (java.io.File)11 ContainerLocalizationRequestEvent (org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ContainerLocalizationRequestEvent)11