private AggregatedLogsBlockForTest getAggregatedLogsBlockForTest( Configuration configuration, String user, String containerId) { return getAggregatedLogsBlockForTest(configuration, user, containerId, "localhost:1234"); }
private void writeLogs(String dirName) throws Exception { File f = new File(dirName + File.separator + "log1"); if (!f.getParentFile().exists()) { assertTrue(f.getParentFile().mkdirs()); } writeLog(dirName + File.separator + "log1", "test log1"); writeLog(dirName + File.separator + "log2", "test log2"); writeLog(dirName + File.separator + "log3", "test log3"); }
/** * Bad user. User 'owner' is trying to read logs without access */ @Test public void testAccessDenied() throws Exception { FileUtil.fullyDelete(new File("target/logs")); Configuration configuration = getConfiguration(); writeLogs("target/logs/logs/application_0_0001/container_0_0001_01_000001"); writeLog(configuration, "owner"); AggregatedLogsBlockForTest aggregatedBlock = getAggregatedLogsBlockForTest( configuration, "owner", "container_0_0001_01_000001"); ByteArrayOutputStream data = new ByteArrayOutputStream(); PrintWriter printWriter = new PrintWriter(data); HtmlBlock html = new HtmlBlockForTest(); HtmlBlock.Block block = new BlockForTest(html, printWriter, 10, false); aggregatedBlock.render(block); block.getWriter().flush(); String out = data.toString(); assertTrue(out .contains("User [owner] is not authorized to view the logs for entity")); }
/** * Bad user. User 'owner' is trying to read logs without access */ @Test public void testAccessDenied() throws Exception { FileUtil.fullyDelete(new File("target/logs")); Configuration configuration = getConfiguration(); writeLogs("target/logs/logs/application_0_0001/container_0_0001_01_000001"); writeLog(configuration, "owner"); ByteArrayOutputStream data = new ByteArrayOutputStream(); PrintWriter printWriter = new PrintWriter(data); HtmlBlock html = new HtmlBlockForTest(); HtmlBlock.Block block = new BlockForTest(html, printWriter, 10, false); TFileAggregatedLogsBlockForTest aggregatedBlock = getTFileAggregatedLogsBlockForTest(configuration, "owner", "container_0_0001_01_000001", "localhost:1234"); aggregatedBlock.render(block); block.getWriter().flush(); String out = data.toString(); assertTrue(out .contains("User [owner] is not authorized to view the logs for entity")); }
/** * Log files was deleted. * @throws Exception */ @Test public void testNoLogs() throws Exception { FileUtil.fullyDelete(new File("target/logs")); Configuration configuration = getConfiguration(); File f = new File("target/logs/logs/application_0_0001/container_0_0001_01_000001"); if (!f.exists()) { assertTrue(f.mkdirs()); } writeLog(configuration, "admin"); AggregatedLogsBlockForTest aggregatedBlock = getAggregatedLogsBlockForTest( configuration, "admin", "container_0_0001_01_000001"); ByteArrayOutputStream data = new ByteArrayOutputStream(); PrintWriter printWriter = new PrintWriter(data); HtmlBlock html = new HtmlBlockForTest(); HtmlBlock.Block block = new BlockForTest(html, printWriter, 10, false); aggregatedBlock.render(block); block.getWriter().flush(); String out = data.toString(); assertTrue(out.contains("No logs available for container container_0_0001_01_000001")); }
/** * Log files was deleted. * @throws Exception */ @Test public void testNoLogs() throws Exception { FileUtil.fullyDelete(new File("target/logs")); Configuration configuration = getConfiguration(); File f = new File("target/logs/logs/application_0_0001/container_0_0001_01_000001"); if (!f.exists()) { assertTrue(f.mkdirs()); } writeLog(configuration, "admin"); ByteArrayOutputStream data = new ByteArrayOutputStream(); PrintWriter printWriter = new PrintWriter(data); HtmlBlock html = new HtmlBlockForTest(); HtmlBlock.Block block = new BlockForTest(html, printWriter, 10, false); TFileAggregatedLogsBlockForTest aggregatedBlock = getTFileAggregatedLogsBlockForTest(configuration, "admin", "container_0_0001_01_000001", "localhost:1234"); aggregatedBlock.render(block); block.getWriter().flush(); String out = data.toString(); assertTrue(out.contains("No logs available for container container_0_0001_01_000001")); }
@Test public void testBlockContainsPortNumForUnavailableAppLog() { FileUtil.fullyDelete(new File("target/logs")); Configuration configuration = getConfiguration(); String nodeName = configuration.get(YarnConfiguration.NM_WEBAPP_ADDRESS, YarnConfiguration.DEFAULT_NM_WEBAPP_ADDRESS); AggregatedLogsBlockForTest aggregatedBlock = getAggregatedLogsBlockForTest( configuration, "admin", "container_0_0001_01_000001", nodeName); ByteArrayOutputStream data = new ByteArrayOutputStream(); PrintWriter printWriter = new PrintWriter(data); HtmlBlock html = new HtmlBlockForTest(); HtmlBlock.Block block = new BlockForTest(html, printWriter, 10, false); aggregatedBlock.render(block); block.getWriter().flush(); String out = data.toString(); assertTrue(out.contains(nodeName)); }
public void testAggregatedLogsBlockHar() throws Exception { FileUtil.fullyDelete(new File("target/logs")); Configuration configuration = getConfiguration(); HtmlBlock.Block block = new BlockForTest(html, printWriter, 10, false); TFileAggregatedLogsBlockForTest aggregatedBlock = getTFileAggregatedLogsBlockForTest(configuration, "admin", "container_1440536969523_0001_01_000001", "host1:1111"); aggregatedBlock.render(block); assertTrue(out.contains("Hello syslog")); aggregatedBlock = getTFileAggregatedLogsBlockForTest( configuration, "admin", "container_1440536969523_0001_01_000002", "host2:2222");
/** * Bad user. User 'owner' is trying to read logs without access */ @Test public void testAccessDenied() throws Exception { FileUtil.fullyDelete(new File("target/logs")); Configuration configuration = getConfiguration(); writeLogs("target/logs/logs/application_0_0001/container_0_0001_01_000001"); writeLog(configuration, "owner"); AggregatedLogsBlockForTest aggregatedBlock = getAggregatedLogsBlockForTest( configuration, "owner", "container_0_0001_01_000001"); ByteArrayOutputStream data = new ByteArrayOutputStream(); PrintWriter printWriter = new PrintWriter(data); HtmlBlock html = new HtmlBlockForTest(); HtmlBlock.Block block = new BlockForTest(html, printWriter, 10, false); aggregatedBlock.render(block); block.getWriter().flush(); String out = data.toString(); assertTrue(out .contains("User [owner] is not authorized to view the logs for entity")); }
/** * Reading from logs should succeed and they should be shown in the * AggregatedLogsBlock html. * * @throws Exception */ @Test public void testAggregatedLogsBlock() throws Exception { FileUtil.fullyDelete(new File("target/logs")); Configuration configuration = getConfiguration(); writeLogs("target/logs/logs/application_0_0001/container_0_0001_01_000001"); writeLog(configuration, "admin"); ByteArrayOutputStream data = new ByteArrayOutputStream(); PrintWriter printWriter = new PrintWriter(data); HtmlBlock html = new HtmlBlockForTest(); HtmlBlock.Block block = new BlockForTest(html, printWriter, 10, false); TFileAggregatedLogsBlockForTest aggregatedBlock = getTFileAggregatedLogsBlockForTest(configuration, "admin", "container_0_0001_01_000001", "localhost:1234"); aggregatedBlock.render(block); block.getWriter().flush(); String out = data.toString(); assertTrue(out.contains("test log1")); assertTrue(out.contains("test log2")); assertTrue(out.contains("test log3")); }
/** * Log files was deleted. * @throws Exception */ @Test public void testNoLogs() throws Exception { FileUtil.fullyDelete(new File("target/logs")); Configuration configuration = getConfiguration(); File f = new File("target/logs/logs/application_0_0001/container_0_0001_01_000001"); if (!f.exists()) { assertTrue(f.mkdirs()); } writeLog(configuration, "admin"); AggregatedLogsBlockForTest aggregatedBlock = getAggregatedLogsBlockForTest( configuration, "admin", "container_0_0001_01_000001"); ByteArrayOutputStream data = new ByteArrayOutputStream(); PrintWriter printWriter = new PrintWriter(data); HtmlBlock html = new HtmlBlockForTest(); HtmlBlock.Block block = new BlockForTest(html, printWriter, 10, false); aggregatedBlock.render(block); block.getWriter().flush(); String out = data.toString(); assertTrue(out.contains("No logs available for container container_0_0001_01_000001")); }
public void testAggregatedLogsBlockHar() throws Exception { FileUtil.fullyDelete(new File("target/logs")); Configuration configuration = getConfiguration(); FileUtils.copyDirectory(new File(harUrl.getPath()), new File(path)); AggregatedLogsBlockForTest aggregatedBlock = getAggregatedLogsBlockForTest( configuration, "admin", "container_1440536969523_0001_01_000001", "host1:1111"); assertTrue(out.contains("Hello syslog")); aggregatedBlock = getAggregatedLogsBlockForTest( configuration, "admin", "container_1440536969523_0001_01_000002", "host2:2222");
/** * try to read bad logs * * @throws Exception */ @Test public void testBadLogs() throws Exception { FileUtil.fullyDelete(new File("target/logs")); Configuration configuration = getConfiguration(); writeLogs("target/logs/logs/application_0_0001/container_0_0001_01_000001"); writeLog(configuration, "owner"); AggregatedLogsBlockForTest aggregatedBlock = getAggregatedLogsBlockForTest( configuration, "admin", "container_0_0001_01_000001"); ByteArrayOutputStream data = new ByteArrayOutputStream(); PrintWriter printWriter = new PrintWriter(data); HtmlBlock html = new HtmlBlockForTest(); HtmlBlock.Block block = new BlockForTest(html, printWriter, 10, false); aggregatedBlock.render(block); block.getWriter().flush(); String out = data.toString(); assertTrue(out .contains("Logs not available for entity. Aggregation may not be complete, Check back later or try the nodemanager at localhost:1234")); }
private void writeLogs(String dirName) throws Exception { File f = new File(dirName + File.separator + "log1"); if (!f.getParentFile().exists()) { assertTrue(f.getParentFile().mkdirs()); } writeLog(dirName + File.separator + "log1", "test log1"); writeLog(dirName + File.separator + "log2", "test log2"); writeLog(dirName + File.separator + "log3", "test log3"); }
private AggregatedLogsBlockForTest getAggregatedLogsBlockForTest( Configuration configuration, String user, String containerId) { return getAggregatedLogsBlockForTest(configuration, user, containerId, "localhost:1234"); }
/** * try to read bad logs * * @throws Exception */ @Test public void testBadLogs() throws Exception { FileUtil.fullyDelete(new File("target/logs")); Configuration configuration = getConfiguration(); writeLogs("target/logs/logs/application_0_0001/container_0_0001_01_000001"); writeLog(configuration, "owner"); AggregatedLogsBlockForTest aggregatedBlock = getAggregatedLogsBlockForTest( configuration, "admin", "container_0_0001_01_000001"); ByteArrayOutputStream data = new ByteArrayOutputStream(); PrintWriter printWriter = new PrintWriter(data); HtmlBlock html = new HtmlBlockForTest(); HtmlBlock.Block block = new BlockForTest(html, printWriter, 10, false); aggregatedBlock.render(block); block.getWriter().flush(); String out = data.toString(); assertTrue(out .contains("Logs not available for entity. Aggregation may not be complete, Check back later or try the nodemanager at localhost:1234")); }
private void writeLogs(String dirName) throws Exception { File f = new File(dirName + File.separator + "log1"); if (!f.getParentFile().exists()) { assertTrue(f.getParentFile().mkdirs()); } writeLog(dirName + File.separator + "log1", "test log1"); writeLog(dirName + File.separator + "log2", "test log2"); writeLog(dirName + File.separator + "log3", "test log3"); }
/** * try to read bad logs * * @throws Exception */ @Test public void testBadLogs() throws Exception { FileUtil.fullyDelete(new File("target/logs")); Configuration configuration = getConfiguration(); writeLogs("target/logs/logs/application_0_0001/container_0_0001_01_000001"); writeLog(configuration, "owner"); AggregatedLogsBlockForTest aggregatedBlock = getAggregatedLogsBlockForTest( configuration, "admin", "container_0_0001_01_000001"); ByteArrayOutputStream data = new ByteArrayOutputStream(); PrintWriter printWriter = new PrintWriter(data); HtmlBlock html = new HtmlBlockForTest(); HtmlBlock.Block block = new BlockForTest(html, printWriter, 10, false); aggregatedBlock.render(block); block.getWriter().flush(); String out = data.toString(); assertTrue(out .contains("Logs not available for entity. Aggregation may not be complete, Check back later or try the nodemanager at localhost:1234")); }
/** * Reading from logs should succeed and they should be shown in the * AggregatedLogsBlock html. * * @throws Exception */ @Test public void testAggregatedLogsBlock() throws Exception { FileUtil.fullyDelete(new File("target/logs")); Configuration configuration = getConfiguration(); String user = UserGroupInformation.getCurrentUser().getShortUserName(); writeLogs("target/logs/logs/" + user + "/application_0_0001/container_0_0001_01_000001"); writeLog(configuration, "admin"); AggregatedLogsBlockForTest aggregatedBlock = getAggregatedLogsBlockForTest( configuration, "admin", "container_0_0001_01_000001"); ByteArrayOutputStream data = new ByteArrayOutputStream(); PrintWriter printWriter = new PrintWriter(data); HtmlBlock html = new HtmlBlockForTest(); HtmlBlock.Block block = new BlockForTest(html, printWriter, 10, false); aggregatedBlock.render(block); block.getWriter().flush(); String out = data.toString(); assertTrue(out.contains("test log1")); assertTrue(out.contains("test log2")); assertTrue(out.contains("test log3")); }
/** * All ok and the AggregatedLogsBlockFor should aggregate logs and show it. * * @throws Exception */ @Test public void testAggregatedLogsBlock() throws Exception { FileUtil.fullyDelete(new File("target/logs")); Configuration configuration = getConfiguration(); writeLogs("target/logs/logs/application_0_0001/container_0_0001_01_000001"); writeLog(configuration, "admin"); AggregatedLogsBlockForTest aggregatedBlock = getAggregatedLogsBlockForTest( configuration, "admin", "container_0_0001_01_000001"); ByteArrayOutputStream data = new ByteArrayOutputStream(); PrintWriter printWriter = new PrintWriter(data); HtmlBlock html = new HtmlBlockForTest(); HtmlBlock.Block block = new BlockForTest(html, printWriter, 10, false); aggregatedBlock.render(block); block.getWriter().flush(); String out = data.toString(); assertTrue(out.contains("test log1")); assertTrue(out.contains("test log2")); assertTrue(out.contains("test log3")); } /**