Search in sources :

Example 56 with Application

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

the class TestNMWebServicesApps method testNodeHelper.

public void testNodeHelper(String path, 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);
    HashMap<String, String> hash2 = addAppContainers(app2);
    ClientResponse response = r.path("ws").path("v1").path("node").path(path).accept(media).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    JSONObject json = response.getEntity(JSONObject.class);
    JSONObject info = json.getJSONObject("apps");
    assertEquals("incorrect number of elements", 1, info.length());
    JSONArray appInfo = info.getJSONArray("app");
    assertEquals("incorrect number of elements", 2, appInfo.length());
    String id = appInfo.getJSONObject(0).getString("id");
    if (id.matches(app.getAppId().toString())) {
        verifyNodeAppInfo(appInfo.getJSONObject(0), app, hash);
        verifyNodeAppInfo(appInfo.getJSONObject(1), app2, hash2);
    } else {
        verifyNodeAppInfo(appInfo.getJSONObject(0), app2, hash2);
        verifyNodeAppInfo(appInfo.getJSONObject(1), app, hash);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) WebResource(com.sun.jersey.api.client.WebResource) Application(org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application)

Example 57 with Application

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

the class TestNMWebServer method testNMWebApp.

@Test
public void testNMWebApp() throws IOException, YarnException {
    Configuration conf = new Configuration();
    Context nmContext = new NodeManager.NMContext(null, null, null, null, null, false, conf);
    ResourceView resourceView = new ResourceView() {

        @Override
        public long getVmemAllocatedForContainers() {
            return 0;
        }

        @Override
        public long getPmemAllocatedForContainers() {
            return 0;
        }

        @Override
        public long getVCoresAllocatedForContainers() {
            return 0;
        }

        @Override
        public boolean isVmemCheckEnabled() {
            return true;
        }

        @Override
        public boolean isPmemCheckEnabled() {
            return true;
        }
    };
    conf.set(YarnConfiguration.NM_LOCAL_DIRS, testRootDir.getAbsolutePath());
    conf.set(YarnConfiguration.NM_LOG_DIRS, testLogDir.getAbsolutePath());
    NodeHealthCheckerService healthChecker = createNodeHealthCheckerService(conf);
    healthChecker.init(conf);
    LocalDirsHandlerService dirsHandler = healthChecker.getDiskHandler();
    WebServer server = new WebServer(nmContext, resourceView, new ApplicationACLsManager(conf), dirsHandler);
    server.init(conf);
    server.start();
    // Add an application and the corresponding containers
    RecordFactory recordFactory = RecordFactoryProvider.getRecordFactory(conf);
    Dispatcher dispatcher = new AsyncDispatcher();
    String user = "nobody";
    long clusterTimeStamp = 1234;
    ApplicationId appId = BuilderUtils.newApplicationId(recordFactory, clusterTimeStamp, 1);
    Application app = mock(Application.class);
    when(app.getUser()).thenReturn(user);
    when(app.getAppId()).thenReturn(appId);
    nmContext.getApplications().put(appId, app);
    ApplicationAttemptId appAttemptId = BuilderUtils.newApplicationAttemptId(appId, 1);
    ContainerId container1 = BuilderUtils.newContainerId(recordFactory, appId, appAttemptId, 0);
    ContainerId container2 = BuilderUtils.newContainerId(recordFactory, appId, appAttemptId, 1);
    NodeManagerMetrics metrics = mock(NodeManagerMetrics.class);
    NMStateStoreService stateStore = new NMNullStateStoreService();
    for (ContainerId containerId : new ContainerId[] { container1, container2 }) {
        // TODO: Use builder utils
        ContainerLaunchContext launchContext = recordFactory.newRecordInstance(ContainerLaunchContext.class);
        long currentTime = System.currentTimeMillis();
        Token containerToken = BuilderUtils.newContainerToken(containerId, 0, "127.0.0.1", 1234, user, BuilderUtils.newResource(1024, 1), currentTime + 10000L, 123, "password".getBytes(), currentTime);
        Context context = mock(Context.class);
        Container container = new ContainerImpl(conf, dispatcher, launchContext, null, metrics, BuilderUtils.newContainerTokenIdentifier(containerToken), context) {

            @Override
            public ContainerState getContainerState() {
                return ContainerState.RUNNING;
            }

            ;
        };
        nmContext.getContainers().put(containerId, container);
        //TODO: Gross hack. Fix in code.
        ApplicationId applicationId = containerId.getApplicationAttemptId().getApplicationId();
        nmContext.getApplications().get(applicationId).getContainers().put(containerId, container);
        writeContainerLogs(nmContext, containerId, dirsHandler);
    }
// TODO: Pull logs and test contents.
//    Thread.sleep(1000000);
}
Also used : ContainerLaunchContext(org.apache.hadoop.yarn.api.records.ContainerLaunchContext) Context(org.apache.hadoop.yarn.server.nodemanager.Context) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) NodeHealthCheckerService(org.apache.hadoop.yarn.server.nodemanager.NodeHealthCheckerService) Token(org.apache.hadoop.yarn.api.records.Token) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) ContainerLaunchContext(org.apache.hadoop.yarn.api.records.ContainerLaunchContext) LocalDirsHandlerService(org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService) Dispatcher(org.apache.hadoop.yarn.event.Dispatcher) AsyncDispatcher(org.apache.hadoop.yarn.event.AsyncDispatcher) NMNullStateStoreService(org.apache.hadoop.yarn.server.nodemanager.recovery.NMNullStateStoreService) NMStateStoreService(org.apache.hadoop.yarn.server.nodemanager.recovery.NMStateStoreService) ResourceView(org.apache.hadoop.yarn.server.nodemanager.ResourceView) ApplicationACLsManager(org.apache.hadoop.yarn.server.security.ApplicationACLsManager) Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) RecordFactory(org.apache.hadoop.yarn.factories.RecordFactory) AsyncDispatcher(org.apache.hadoop.yarn.event.AsyncDispatcher) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ContainerImpl(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerImpl) NodeManagerMetrics(org.apache.hadoop.yarn.server.nodemanager.metrics.NodeManagerMetrics) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) Application(org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application) Test(org.junit.Test)

Example 58 with Application

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

the class TestContainerLogsPage method testLogFileWithDriveLetter.

@Test
public void testLogFileWithDriveLetter() throws Exception {
    ContainerImpl container = mock(ContainerImpl.class);
    ApplicationIdPBImpl appId = mock(ApplicationIdPBImpl.class);
    when(appId.toString()).thenReturn("appId");
    Application app = mock(Application.class);
    when(app.getAppId()).thenReturn(appId);
    ApplicationAttemptIdPBImpl appAttemptId = mock(ApplicationAttemptIdPBImpl.class);
    when(appAttemptId.getApplicationId()).thenReturn(appId);
    ConcurrentMap<ApplicationId, Application> applications = new ConcurrentHashMap<ApplicationId, Application>();
    applications.put(appId, app);
    ContainerId containerId = mock(ContainerIdPBImpl.class);
    when(containerId.toString()).thenReturn("containerId");
    when(containerId.getApplicationAttemptId()).thenReturn(appAttemptId);
    ConcurrentMap<ContainerId, Container> containers = new ConcurrentHashMap<ContainerId, Container>();
    containers.put(containerId, container);
    LocalDirsHandlerService localDirs = mock(LocalDirsHandlerService.class);
    when(localDirs.getLogPathToRead("appId" + Path.SEPARATOR + "containerId" + Path.SEPARATOR + "fileName")).thenReturn(new Path("F:/nmlogs/appId/containerId/fileName"));
    NMContext context = mock(NMContext.class);
    when(context.getLocalDirsHandler()).thenReturn(localDirs);
    when(context.getApplications()).thenReturn(applications);
    when(context.getContainers()).thenReturn(containers);
    File logFile = ContainerLogsUtils.getContainerLogFile(containerId, "fileName", null, context);
    Assert.assertTrue("logFile lost drive letter " + logFile, logFile.toString().indexOf("F:" + File.separator + "nmlogs") > -1);
}
Also used : Path(org.apache.hadoop.fs.Path) LocalDirsHandlerService(org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService) ApplicationIdPBImpl(org.apache.hadoop.yarn.api.records.impl.pb.ApplicationIdPBImpl) ApplicationAttemptIdPBImpl(org.apache.hadoop.yarn.api.records.impl.pb.ApplicationAttemptIdPBImpl) Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) NMContext(org.apache.hadoop.yarn.server.nodemanager.NodeManager.NMContext) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ContainerImpl(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerImpl) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) Application(org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application) File(java.io.File) Test(org.junit.Test)

Example 59 with Application

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

the class TestNMWebFilter method testRedirection.

@Test(timeout = 5000)
public void testRedirection() throws Exception {
    ApplicationId appId = ApplicationId.newInstance(System.currentTimeMillis(), 1);
    ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(appId, 1);
    ContainerId containerId = ContainerId.newContainerId(attemptId, 1);
    NMContext mockNMContext = mock(NMContext.class);
    ConcurrentMap<ApplicationId, Application> applications = new ConcurrentHashMap<>();
    when(mockNMContext.getApplications()).thenReturn(applications);
    LocalDirsHandlerService mockLocalDirsHandlerService = mock(LocalDirsHandlerService.class);
    Configuration conf = new Configuration();
    conf.setBoolean(YarnConfiguration.LOG_AGGREGATION_ENABLED, true);
    conf.set(YarnConfiguration.YARN_LOG_SERVER_URL, "http://" + LOG_SERVER_URI);
    when(mockLocalDirsHandlerService.getConfig()).thenReturn(conf);
    when(mockNMContext.getLocalDirsHandler()).thenReturn(mockLocalDirsHandlerService);
    NodeId nodeId = NodeId.newInstance("testNM", 9999);
    when(mockNMContext.getNodeId()).thenReturn(nodeId);
    Injector mockInjector = mock(Injector.class);
    NMWebAppFilter testFilter = new NMWebAppFilter(mockInjector, mockNMContext);
    HttpServletResponseForTest response = new HttpServletResponseForTest();
    // dummy filter
    FilterChain chain = new FilterChain() {

        @Override
        public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException {
        // Do Nothing
        }
    };
    String uri = "testNM:8042/node/containerlogs/" + containerId.toString() + "/" + USER;
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getRequestURI()).thenReturn(uri);
    testFilter.doFilter(request, response, chain);
    assertEquals(HttpServletResponse.SC_TEMPORARY_REDIRECT, response.status);
    String redirect = response.getHeader("Location");
    assertTrue(redirect.contains(LOG_SERVER_URI));
    assertTrue(redirect.contains(nodeId.toString()));
    assertTrue(redirect.contains(containerId.toString()));
    assertTrue(redirect.contains(USER));
    String logType = "syslog";
    uri = "testNM:8042/node/containerlogs/" + containerId.toString() + "/" + USER + "/" + logType + "/?start=10";
    HttpServletRequest request2 = mock(HttpServletRequest.class);
    when(request2.getRequestURI()).thenReturn(uri);
    when(request2.getQueryString()).thenReturn("start=10");
    testFilter.doFilter(request2, response, chain);
    assertEquals(HttpServletResponse.SC_TEMPORARY_REDIRECT, response.status);
    redirect = response.getHeader("Location");
    assertTrue(redirect.contains(LOG_SERVER_URI));
    assertTrue(redirect.contains(nodeId.toString()));
    assertTrue(redirect.contains(containerId.toString()));
    assertTrue(redirect.contains(USER));
    assertTrue(redirect.contains(logType));
    assertTrue(redirect.contains("start=10"));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) FilterChain(javax.servlet.FilterChain) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) LocalDirsHandlerService(org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService) HttpServletRequest(javax.servlet.http.HttpServletRequest) NMContext(org.apache.hadoop.yarn.server.nodemanager.NodeManager.NMContext) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) Injector(com.google.inject.Injector) NodeId(org.apache.hadoop.yarn.api.records.NodeId) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Application(org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application) Test(org.junit.Test)

Example 60 with Application

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

the class TestNMWebServicesApps method testNodeAppsUserNone.

@Test
public void testNodeAppsUserNone() throws JSONException, Exception {
    WebResource r = resource();
    Application app = new MockApp(1);
    nmContext.getApplications().put(app.getAppId(), app);
    addAppContainers(app);
    Application app2 = new MockApp("foo", 1234, 2);
    nmContext.getApplications().put(app2.getAppId(), app2);
    addAppContainers(app2);
    ClientResponse response = r.path("ws").path("v1").path("node").path("apps").queryParam("user", "george").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    JSONObject json = response.getEntity(JSONObject.class);
    assertEquals("apps is not empty", new JSONObject().toString(), json.get("apps").toString());
}
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) Test(org.junit.Test)

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