use of org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService in project hadoop by apache.
the class TestNMWebServer method createNodeHealthCheckerService.
private NodeHealthCheckerService createNodeHealthCheckerService(Configuration conf) {
NodeHealthScriptRunner scriptRunner = NodeManager.getNodeHealthScriptRunner(conf);
LocalDirsHandlerService dirsHandler = new LocalDirsHandlerService();
return new NodeHealthCheckerService(scriptRunner, dirsHandler);
}
use of org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService in project hadoop by apache.
the class TestContainerLogsPage method createNodeHealthCheckerService.
private NodeHealthCheckerService createNodeHealthCheckerService(Configuration conf) {
NodeHealthScriptRunner scriptRunner = NodeManager.getNodeHealthScriptRunner(conf);
LocalDirsHandlerService dirsHandler = new LocalDirsHandlerService();
return new NodeHealthCheckerService(scriptRunner, dirsHandler);
}
use of org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService 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);
}
use of org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService 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"));
}
use of org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService in project hadoop by apache.
the class TestNMWebServer method startNMWebAppServer.
private int startNMWebAppServer(String webAddr) {
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();
conf.set(YarnConfiguration.NM_WEBAPP_ADDRESS, webAddr);
WebServer server = new WebServer(nmContext, resourceView, new ApplicationACLsManager(conf), dirsHandler);
try {
server.init(conf);
server.start();
return server.getPort();
} finally {
server.stop();
healthChecker.stop();
}
}
Aggregations