Search in sources :

Example 1 with HtmlBlock

use of org.apache.hadoop.yarn.webapp.view.HtmlBlock in project hadoop by apache.

the class TestAggregatedLogsBlock method testAggregatedLogsBlock.

/**
   * 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");
    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"));
}
Also used : HtmlBlockForTest(org.apache.hadoop.yarn.webapp.view.HtmlBlockForTest) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) AggregatedLogsBlockForTest(org.apache.hadoop.yarn.webapp.log.AggregatedLogsBlockForTest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HtmlBlock(org.apache.hadoop.yarn.webapp.view.HtmlBlock) File(java.io.File) PrintWriter(java.io.PrintWriter) AggregatedLogsBlockForTest(org.apache.hadoop.yarn.webapp.log.AggregatedLogsBlockForTest) BlockForTest(org.apache.hadoop.yarn.webapp.view.BlockForTest) HtmlBlockForTest(org.apache.hadoop.yarn.webapp.view.HtmlBlockForTest) AggregatedLogsBlockForTest(org.apache.hadoop.yarn.webapp.log.AggregatedLogsBlockForTest) BlockForTest(org.apache.hadoop.yarn.webapp.view.BlockForTest) HtmlBlockForTest(org.apache.hadoop.yarn.webapp.view.HtmlBlockForTest) Test(org.junit.Test)

Example 2 with HtmlBlock

use of org.apache.hadoop.yarn.webapp.view.HtmlBlock in project hadoop by apache.

the class TestAggregatedLogsBlock method testBlockContainsPortNumForUnavailableAppLog.

@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));
}
Also used : HtmlBlockForTest(org.apache.hadoop.yarn.webapp.view.HtmlBlockForTest) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) AggregatedLogsBlockForTest(org.apache.hadoop.yarn.webapp.log.AggregatedLogsBlockForTest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HtmlBlock(org.apache.hadoop.yarn.webapp.view.HtmlBlock) File(java.io.File) PrintWriter(java.io.PrintWriter) AggregatedLogsBlockForTest(org.apache.hadoop.yarn.webapp.log.AggregatedLogsBlockForTest) BlockForTest(org.apache.hadoop.yarn.webapp.view.BlockForTest) HtmlBlockForTest(org.apache.hadoop.yarn.webapp.view.HtmlBlockForTest) AggregatedLogsBlockForTest(org.apache.hadoop.yarn.webapp.log.AggregatedLogsBlockForTest) BlockForTest(org.apache.hadoop.yarn.webapp.view.BlockForTest) HtmlBlockForTest(org.apache.hadoop.yarn.webapp.view.HtmlBlockForTest) Test(org.junit.Test)

Example 3 with HtmlBlock

use of org.apache.hadoop.yarn.webapp.view.HtmlBlock in project hadoop by apache.

the class TestAggregatedLogsBlock method testAggregatedLogsBlockHar.

/**
   * Reading from logs should succeed (from a HAR archive) and they should be
   * shown in the AggregatedLogsBlock html.
   *
   * @throws Exception
   */
@Test
public void testAggregatedLogsBlockHar() throws Exception {
    FileUtil.fullyDelete(new File("target/logs"));
    Configuration configuration = getConfiguration();
    URL harUrl = ClassLoader.getSystemClassLoader().getResource("application_1440536969523_0001.har");
    assertNotNull(harUrl);
    String path = "target/logs/admin/logs/application_1440536969523_0001" + "/application_1440536969523_0001.har";
    FileUtils.copyDirectory(new File(harUrl.getPath()), new File(path));
    AggregatedLogsBlockForTest aggregatedBlock = getAggregatedLogsBlockForTest(configuration, "admin", "container_1440536969523_0001_01_000001", "host1:1111");
    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("Hello stderr"));
    assertTrue(out.contains("Hello stdout"));
    assertTrue(out.contains("Hello syslog"));
    aggregatedBlock = getAggregatedLogsBlockForTest(configuration, "admin", "container_1440536969523_0001_01_000002", "host2:2222");
    data = new ByteArrayOutputStream();
    printWriter = new PrintWriter(data);
    html = new HtmlBlockForTest();
    block = new BlockForTest(html, printWriter, 10, false);
    aggregatedBlock.render(block);
    block.getWriter().flush();
    out = data.toString();
    assertTrue(out.contains("Goodbye stderr"));
    assertTrue(out.contains("Goodbye stdout"));
    assertTrue(out.contains("Goodbye syslog"));
}
Also used : HtmlBlockForTest(org.apache.hadoop.yarn.webapp.view.HtmlBlockForTest) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) AggregatedLogsBlockForTest(org.apache.hadoop.yarn.webapp.log.AggregatedLogsBlockForTest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HtmlBlock(org.apache.hadoop.yarn.webapp.view.HtmlBlock) File(java.io.File) URL(java.net.URL) PrintWriter(java.io.PrintWriter) AggregatedLogsBlockForTest(org.apache.hadoop.yarn.webapp.log.AggregatedLogsBlockForTest) BlockForTest(org.apache.hadoop.yarn.webapp.view.BlockForTest) HtmlBlockForTest(org.apache.hadoop.yarn.webapp.view.HtmlBlockForTest) AggregatedLogsBlockForTest(org.apache.hadoop.yarn.webapp.log.AggregatedLogsBlockForTest) BlockForTest(org.apache.hadoop.yarn.webapp.view.BlockForTest) HtmlBlockForTest(org.apache.hadoop.yarn.webapp.view.HtmlBlockForTest) Test(org.junit.Test)

Example 4 with HtmlBlock

use of org.apache.hadoop.yarn.webapp.view.HtmlBlock in project hadoop by apache.

the class TestAggregatedLogsBlock method testAccessDenied.

/**
   * 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"));
}
Also used : HtmlBlockForTest(org.apache.hadoop.yarn.webapp.view.HtmlBlockForTest) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) AggregatedLogsBlockForTest(org.apache.hadoop.yarn.webapp.log.AggregatedLogsBlockForTest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HtmlBlock(org.apache.hadoop.yarn.webapp.view.HtmlBlock) File(java.io.File) PrintWriter(java.io.PrintWriter) AggregatedLogsBlockForTest(org.apache.hadoop.yarn.webapp.log.AggregatedLogsBlockForTest) BlockForTest(org.apache.hadoop.yarn.webapp.view.BlockForTest) HtmlBlockForTest(org.apache.hadoop.yarn.webapp.view.HtmlBlockForTest) AggregatedLogsBlockForTest(org.apache.hadoop.yarn.webapp.log.AggregatedLogsBlockForTest) BlockForTest(org.apache.hadoop.yarn.webapp.view.BlockForTest) HtmlBlockForTest(org.apache.hadoop.yarn.webapp.view.HtmlBlockForTest) Test(org.junit.Test)

Example 5 with HtmlBlock

use of org.apache.hadoop.yarn.webapp.view.HtmlBlock in project hadoop by apache.

the class TestAggregatedLogsBlock method testNoLogs.

/**
   * 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"));
}
Also used : HtmlBlockForTest(org.apache.hadoop.yarn.webapp.view.HtmlBlockForTest) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) AggregatedLogsBlockForTest(org.apache.hadoop.yarn.webapp.log.AggregatedLogsBlockForTest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HtmlBlock(org.apache.hadoop.yarn.webapp.view.HtmlBlock) File(java.io.File) PrintWriter(java.io.PrintWriter) AggregatedLogsBlockForTest(org.apache.hadoop.yarn.webapp.log.AggregatedLogsBlockForTest) BlockForTest(org.apache.hadoop.yarn.webapp.view.BlockForTest) HtmlBlockForTest(org.apache.hadoop.yarn.webapp.view.HtmlBlockForTest) AggregatedLogsBlockForTest(org.apache.hadoop.yarn.webapp.log.AggregatedLogsBlockForTest) BlockForTest(org.apache.hadoop.yarn.webapp.view.BlockForTest) HtmlBlockForTest(org.apache.hadoop.yarn.webapp.view.HtmlBlockForTest) Test(org.junit.Test)

Aggregations

PrintWriter (java.io.PrintWriter)7 BlockForTest (org.apache.hadoop.yarn.webapp.view.BlockForTest)7 HtmlBlock (org.apache.hadoop.yarn.webapp.view.HtmlBlock)7 HtmlBlockForTest (org.apache.hadoop.yarn.webapp.view.HtmlBlockForTest)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 File (java.io.File)6 Configuration (org.apache.hadoop.conf.Configuration)6 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)6 AggregatedLogsBlockForTest (org.apache.hadoop.yarn.webapp.log.AggregatedLogsBlockForTest)6 Test (org.junit.Test)6 URL (java.net.URL)1 SubView (org.apache.hadoop.yarn.webapp.SubView)1