Search in sources :

Example 11 with NMContext

use of org.apache.hadoop.yarn.server.nodemanager.NodeManager.NMContext in project hadoop by apache.

the class TestResourceLocalizationService method createSpyService.

private ResourceLocalizationService createSpyService(DrainDispatcher dispatcher, LocalDirsHandlerService dirsHandler, NMStateStoreService stateStore) {
    ContainerExecutor exec = mock(ContainerExecutor.class);
    LocalizerTracker mockLocalizerTracker = mock(LocalizerTracker.class);
    DeletionService delService = mock(DeletionService.class);
    NMContext nmContext = new NMContext(new NMContainerTokenSecretManager(conf), new NMTokenSecretManagerInNM(), null, new ApplicationACLsManager(conf), stateStore, false, conf);
    ResourceLocalizationService rawService = new ResourceLocalizationService(dispatcher, exec, delService, dirsHandler, nmContext);
    ResourceLocalizationService spyService = spy(rawService);
    doReturn(mockServer).when(spyService).createServer();
    doReturn(mockLocalizerTracker).when(spyService).createLocalizerTracker(isA(Configuration.class));
    doReturn(lfs).when(spyService).getLocalFileContext(isA(Configuration.class));
    return spyService;
}
Also used : ContainerExecutor(org.apache.hadoop.yarn.server.nodemanager.ContainerExecutor) DefaultContainerExecutor(org.apache.hadoop.yarn.server.nodemanager.DefaultContainerExecutor) ApplicationACLsManager(org.apache.hadoop.yarn.server.security.ApplicationACLsManager) NMContext(org.apache.hadoop.yarn.server.nodemanager.NodeManager.NMContext) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) LocalizerTracker(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.ResourceLocalizationService.LocalizerTracker) NMContainerTokenSecretManager(org.apache.hadoop.yarn.server.nodemanager.security.NMContainerTokenSecretManager) DeletionService(org.apache.hadoop.yarn.server.nodemanager.DeletionService) NMTokenSecretManagerInNM(org.apache.hadoop.yarn.server.nodemanager.security.NMTokenSecretManagerInNM)

Example 12 with NMContext

use of org.apache.hadoop.yarn.server.nodemanager.NodeManager.NMContext in project hadoop by apache.

the class TestLocalCacheDirectoryManager method testMinimumPerDirectoryFileLimit.

@Test
public void testMinimumPerDirectoryFileLimit() {
    YarnConfiguration conf = new YarnConfiguration();
    conf.set(YarnConfiguration.NM_LOCAL_CACHE_MAX_FILES_PER_DIRECTORY, "1");
    Exception e = null;
    NMContext nmContext = new NMContext(new NMContainerTokenSecretManager(conf), new NMTokenSecretManagerInNM(), null, new ApplicationACLsManager(conf), new NMNullStateStoreService(), false, conf);
    ResourceLocalizationService service = new ResourceLocalizationService(null, null, null, null, nmContext);
    try {
        service.init(conf);
    } catch (Exception e1) {
        e = e1;
    }
    Assert.assertNotNull(e);
    Assert.assertEquals(YarnRuntimeException.class, e.getClass());
    Assert.assertEquals(e.getMessage(), YarnConfiguration.NM_LOCAL_CACHE_MAX_FILES_PER_DIRECTORY + " parameter is configured with a value less than 37.");
}
Also used : ApplicationACLsManager(org.apache.hadoop.yarn.server.security.ApplicationACLsManager) NMContext(org.apache.hadoop.yarn.server.nodemanager.NodeManager.NMContext) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) NMContainerTokenSecretManager(org.apache.hadoop.yarn.server.nodemanager.security.NMContainerTokenSecretManager) NMTokenSecretManagerInNM(org.apache.hadoop.yarn.server.nodemanager.security.NMTokenSecretManagerInNM) NMNullStateStoreService(org.apache.hadoop.yarn.server.nodemanager.recovery.NMNullStateStoreService) YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) Test(org.junit.Test)

Example 13 with NMContext

use of org.apache.hadoop.yarn.server.nodemanager.NodeManager.NMContext 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 14 with NMContext

use of org.apache.hadoop.yarn.server.nodemanager.NodeManager.NMContext in project hadoop by apache.

the class TestNMAppsPage method testNMAppsPage.

@Test
public void testNMAppsPage() {
    Configuration conf = new Configuration();
    final NMContext nmcontext = new NMContext(new NMContainerTokenSecretManager(conf), new NMTokenSecretManagerInNM(), null, new ApplicationACLsManager(conf), new NMNullStateStoreService(), false, conf);
    Injector injector = WebAppTests.createMockInjector(NMContext.class, nmcontext, new Module() {

        @Override
        public void configure(Binder binder) {
            NodeManager nm = TestNMAppsPage.mocknm(nmcontext);
            binder.bind(NodeManager.class).toInstance(nm);
            binder.bind(Context.class).toInstance(nmcontext);
        }
    });
    ApplicationBlock instance = injector.getInstance(ApplicationBlock.class);
    instance.set(YarnWebParams.APPLICATION_ID, applicationid);
    instance.render();
}
Also used : Binder(com.google.inject.Binder) NodeManager(org.apache.hadoop.yarn.server.nodemanager.NodeManager) ApplicationACLsManager(org.apache.hadoop.yarn.server.security.ApplicationACLsManager) Configuration(org.apache.hadoop.conf.Configuration) NMContext(org.apache.hadoop.yarn.server.nodemanager.NodeManager.NMContext) Injector(com.google.inject.Injector) NMContainerTokenSecretManager(org.apache.hadoop.yarn.server.nodemanager.security.NMContainerTokenSecretManager) NMTokenSecretManagerInNM(org.apache.hadoop.yarn.server.nodemanager.security.NMTokenSecretManagerInNM) Module(com.google.inject.Module) NMNullStateStoreService(org.apache.hadoop.yarn.server.nodemanager.recovery.NMNullStateStoreService) ApplicationBlock(org.apache.hadoop.yarn.server.nodemanager.webapp.ApplicationPage.ApplicationBlock) Test(org.junit.Test)

Example 15 with NMContext

use of org.apache.hadoop.yarn.server.nodemanager.NodeManager.NMContext 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)

Aggregations

NMContext (org.apache.hadoop.yarn.server.nodemanager.NodeManager.NMContext)15 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)9 Test (org.junit.Test)9 Configuration (org.apache.hadoop.conf.Configuration)8 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)7 NMContainerTokenSecretManager (org.apache.hadoop.yarn.server.nodemanager.security.NMContainerTokenSecretManager)7 NMTokenSecretManagerInNM (org.apache.hadoop.yarn.server.nodemanager.security.NMTokenSecretManagerInNM)7 ApplicationACLsManager (org.apache.hadoop.yarn.server.security.ApplicationACLsManager)7 Path (org.apache.hadoop.fs.Path)6 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)6 LocalDirsHandlerService (org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService)6 Application (org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application)6 NMNullStateStoreService (org.apache.hadoop.yarn.server.nodemanager.recovery.NMNullStateStoreService)6 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 ContainerLaunchContext (org.apache.hadoop.yarn.api.records.ContainerLaunchContext)3 AsyncDispatcher (org.apache.hadoop.yarn.event.AsyncDispatcher)3 Dispatcher (org.apache.hadoop.yarn.event.Dispatcher)3 Injector (com.google.inject.Injector)2