org.apache.hadoop.yarn.webapp.MimeType Java Examples

The following examples show how to use org.apache.hadoop.yarn.webapp.MimeType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AMWebController.java    From tez with Apache License 2.0 6 votes vote down vote up
@Override
public void render() {
  response().setContentType(MimeType.HTML);
  PrintWriter pw = writer();
  pw.write("<html>");
  pw.write("<head>");
  pw.write("<meta charset=\"utf-8\">");
  pw.write("<title>Redirecting to Tez UI</title>");
  pw.write("</head>");
  pw.write("<body>");
  if (historyUrl == null || historyUrl.isEmpty()) {
    pw.write("<h1>Tez UI Url is not defined.</h1>" +
        "<p>To enable tracking url pointing to Tez UI, set the config <b>" +
        TezConfiguration.TEZ_HISTORY_URL_BASE + "</b> in the tez-site.xml.</p>");
  } else {
    pw.write("<h1>Redirecting to Tez UI</h1>. <p>If you are not redirected shortly, click " +
        "<a href='" + historyUrl + "'><b>here</b></a></p>"
    );
    pw.write("<script type='text/javascript'>setTimeout(function() { " +
      "window.location.replace('" + historyUrl + "');" +
      "}, 0); </script>");
  }
  pw.write("</body>");
  pw.write("</html>");
  pw.flush();
}
 
Example #2
Source File: TestAppController.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 *  Test method 'taskCounters'. Should print message about error or set CountersPage class for rendering
 */
@Test
public void testGetTaskCounters() {

  when(job.checkAccess(any(UserGroupInformation.class), any(JobACL.class)))
      .thenReturn(false);

  appController.taskCounters();
  verify(appController.response()).setContentType(MimeType.TEXT);
  assertEquals(
      "Access denied: User user does not have permission to view job job_01_01",
      appController.getData());

  when(job.checkAccess(any(UserGroupInformation.class), any(JobACL.class)))
      .thenReturn(true);

  appController.getProperty().remove(AMParams.TASK_ID);
  appController.taskCounters();
  assertEquals(
      "Access denied: User user does not have permission to view job job_01_01missing task ID",
      appController.getData());

  appController.getProperty().put(AMParams.TASK_ID, "task_01_01_m01_01");
  appController.taskCounters();
  assertEquals(CountersPage.class, appController.getClazz());
}
 
Example #3
Source File: TestAppController.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 *  Test method 'jobCounters'. Should print message about error or set CountersPage class for rendering
 */
@Test
public void testGetJobCounters() {

  when(job.checkAccess(any(UserGroupInformation.class), any(JobACL.class)))
      .thenReturn(false);

  appController.jobCounters();
  verify(appController.response()).setContentType(MimeType.TEXT);
  assertEquals(
      "Access denied: User user does not have permission to view job job_01_01",
      appController.getData());
  when(job.checkAccess(any(UserGroupInformation.class), any(JobACL.class)))
      .thenReturn(true);

  appController.getProperty().remove(AMParams.JOB_ID);
  appController.jobCounters();
  assertEquals(
      "Access denied: User user does not have permission to view job job_01_01Bad Request: Missing job ID",
      appController.getData());

  appController.getProperty().put(AMParams.JOB_ID, "job_01_01");
  appController.jobCounters();
  assertEquals(CountersPage.class, appController.getClazz());
}
 
Example #4
Source File: TestAppController.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 *  Test method 'job'. Should print message about error or set JobPage class for rendering
 */
@Test
public void testGetJob() {
  when(job.checkAccess(any(UserGroupInformation.class), any(JobACL.class)))
      .thenReturn(false);

  appController.job();
  verify(appController.response()).setContentType(MimeType.TEXT);
  assertEquals(
      "Access denied: User user does not have permission to view job job_01_01",
      appController.getData());
  when(job.checkAccess(any(UserGroupInformation.class), any(JobACL.class)))
      .thenReturn(true);

  appController.getProperty().remove(AMParams.JOB_ID);
  appController.job();
  assertEquals(
      "Access denied: User user does not have permission to view job job_01_01Bad Request: Missing job ID",
      appController.getData());

  appController.getProperty().put(AMParams.JOB_ID, "job_01_01");
  appController.job();
  assertEquals(JobPage.class, appController.getClazz());
}
 
Example #5
Source File: WebAppProxyServlet.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Warn the user that the link may not be safe!
 * @param resp the http response
 * @param link the link to point to
 * @param user the user that owns the link.
 * @throws IOException on any error.
 */
private static void warnUserPage(HttpServletResponse resp, String link, 
    String user, ApplicationId id) throws IOException {
  //Set the cookie when we warn which overrides the query parameter
  //This is so that if a user passes in the approved query parameter without
  //having first visited this page then this page will still be displayed 
  resp.addCookie(makeCheckCookie(id, false));
  resp.setContentType(MimeType.HTML);
  Page p = new Page(resp.getWriter());
  p.html().
    h1("WARNING: The following page may not be safe!").
    h3().
    _("click ").a(link, "here").
    _(" to continue to an Application Master web interface owned by ", user).
    _().
  _();
}
 
Example #6
Source File: TestAppController.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 *  Test method 'job'. Should print message about error or set JobPage class for rendering
 */
@Test
public void testGetJob() {
  when(job.checkAccess(any(UserGroupInformation.class), any(JobACL.class)))
      .thenReturn(false);

  appController.job();
  verify(appController.response()).setContentType(MimeType.TEXT);
  assertEquals(
      "Access denied: User user does not have permission to view job job_01_01",
      appController.getData());
  when(job.checkAccess(any(UserGroupInformation.class), any(JobACL.class)))
      .thenReturn(true);

  appController.getProperty().remove(AMParams.JOB_ID);
  appController.job();
  assertEquals(
      "Access denied: User user does not have permission to view job job_01_01Bad Request: Missing job ID",
      appController.getData());

  appController.getProperty().put(AMParams.JOB_ID, "job_01_01");
  appController.job();
  assertEquals(JobPage.class, appController.getClazz());
}
 
Example #7
Source File: TestAppController.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 *  Test method 'jobCounters'. Should print message about error or set CountersPage class for rendering
 */
@Test
public void testGetJobCounters() {

  when(job.checkAccess(any(UserGroupInformation.class), any(JobACL.class)))
      .thenReturn(false);

  appController.jobCounters();
  verify(appController.response()).setContentType(MimeType.TEXT);
  assertEquals(
      "Access denied: User user does not have permission to view job job_01_01",
      appController.getData());
  when(job.checkAccess(any(UserGroupInformation.class), any(JobACL.class)))
      .thenReturn(true);

  appController.getProperty().remove(AMParams.JOB_ID);
  appController.jobCounters();
  assertEquals(
      "Access denied: User user does not have permission to view job job_01_01Bad Request: Missing job ID",
      appController.getData());

  appController.getProperty().put(AMParams.JOB_ID, "job_01_01");
  appController.jobCounters();
  assertEquals(CountersPage.class, appController.getClazz());
}
 
Example #8
Source File: TestAppController.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 *  Test method 'taskCounters'. Should print message about error or set CountersPage class for rendering
 */
@Test
public void testGetTaskCounters() {

  when(job.checkAccess(any(UserGroupInformation.class), any(JobACL.class)))
      .thenReturn(false);

  appController.taskCounters();
  verify(appController.response()).setContentType(MimeType.TEXT);
  assertEquals(
      "Access denied: User user does not have permission to view job job_01_01",
      appController.getData());

  when(job.checkAccess(any(UserGroupInformation.class), any(JobACL.class)))
      .thenReturn(true);

  appController.getProperty().remove(AMParams.TASK_ID);
  appController.taskCounters();
  assertEquals(
      "Access denied: User user does not have permission to view job job_01_01missing task ID",
      appController.getData());

  appController.getProperty().put(AMParams.TASK_ID, "task_01_01_m01_01");
  appController.taskCounters();
  assertEquals(CountersPage.class, appController.getClazz());
}
 
Example #9
Source File: WebAppProxyServlet.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Warn the user that the link may not be safe!
 * @param resp the http response
 * @param link the link to point to
 * @param user the user that owns the link.
 * @throws IOException on any error.
 */
private static void warnUserPage(HttpServletResponse resp, String link, 
    String user, ApplicationId id) throws IOException {
  //Set the cookie when we warn which overrides the query parameter
  //This is so that if a user passes in the approved query parameter without
  //having first visited this page then this page will still be displayed 
  resp.addCookie(makeCheckCookie(id, false));
  resp.setContentType(MimeType.HTML);
  Page p = new Page(resp.getWriter());
  p.html().
    h1("WARNING: The following page may not be safe!").
    h3().
    _("click ").a(link, "here").
    _(" to continue to an Application Master web interface owned by ", user).
    _().
  _();
}
 
Example #10
Source File: HtmlPage.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void render() {
  puts(DOCTYPE);
  render(page().html().meta_http("X-UA-Compatible", "IE=8")
      .meta_http("Content-type", MimeType.HTML));
  if (page().nestLevel() != 0) {
    throw new WebAppException("Error rendering page: nestLevel="+
                              page().nestLevel());
  }
}
 
Example #11
Source File: TestAppController.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 *   Test method 'conf'. Should set AttemptsPage class for rendering or print information about error
 */
@Test
public void testAttempts() {

  appController.getProperty().remove(AMParams.TASK_TYPE);

  when(job.checkAccess(any(UserGroupInformation.class), any(JobACL.class)))
      .thenReturn(false);

  appController.attempts();
  verify(appController.response()).setContentType(MimeType.TEXT);
  assertEquals(
      "Access denied: User user does not have permission to view job job_01_01",
      appController.getData());

  when(job.checkAccess(any(UserGroupInformation.class), any(JobACL.class)))
      .thenReturn(true);

  appController.getProperty().remove(AMParams.TASK_ID);
  appController.attempts();
  assertEquals(
      "Access denied: User user does not have permission to view job job_01_01",
      appController.getData());

  appController.getProperty().put(AMParams.TASK_ID, "task_01_01_m01_01");
  appController.attempts();
  assertEquals("Bad request: missing task-type.", appController.getProperty()
      .get("title"));
  appController.getProperty().put(AMParams.TASK_TYPE, "m");

  appController.attempts();
  assertEquals("Bad request: missing attempt-state.", appController
      .getProperty().get("title"));
  appController.getProperty().put(AMParams.ATTEMPT_STATE, "State");

  appController.attempts();

  assertEquals(AttemptsPage.class, appController.getClazz());
}
 
Example #12
Source File: ProxyUtils.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Output 404 with appropriate message.
 * @param resp the http response.
 * @param message the message to include on the page.
 * @throws IOException on any error.
 */
public static void notFound(HttpServletResponse resp, String message)
    throws IOException {
  resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
  resp.setContentType(MimeType.HTML);
  Page p = new Page(resp.getWriter());
  p.html().
      h1(message).
       _();
}
 
Example #13
Source File: ProxyUtils.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Handle redirects with a status code that can in future support verbs other
 * than GET, thus supporting full REST functionality.
 * <p>
 * The target URL is included in the redirect text returned
 * <p>
 * At the end of this method, the output stream is closed.
 * 
 * @param request request (hence: the verb and any other information
 * relevant to a redirect)
 * @param response the response
 * @param target the target URL -unencoded
 *
 */
public static void sendRedirect(HttpServletRequest request,
    HttpServletResponse response,
    String target)
    throws IOException {
  if (LOG.isDebugEnabled()) {
    LOG.debug("Redirecting {} {} to {}",
        request.getMethod(), 
        request.getRequestURI(),
        target);
  }
  String location = response.encodeRedirectURL(target);
  response.setStatus(HttpServletResponse.SC_FOUND);
  response.setHeader(LOCATION, location);
  response.setContentType(MimeType.HTML);
  PrintWriter writer = response.getWriter();
  Page p = new Page(writer);
  p.html()
      .head().title("Moved")._()
      .body()
      .h1("Moved")
      .div()
        ._("Content has moved ")
        .a(location, "here")._()
      ._()._();
  writer.close();
}
 
Example #14
Source File: TestHtmlPage.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test public void testUsual() {
  Injector injector = WebAppTests.testPage(TestView.class);
  PrintWriter out = injector.getInstance(PrintWriter.class);

  // Verify the HTML page has correct meta tags in the header
  verify(out).print(" http-equiv=\"X-UA-Compatible\"");
  verify(out).print(" content=\"IE=8\"");
  verify(out).print(" http-equiv=\"Content-type\"");
  verify(out).print(String.format(" content=\"%s\"", MimeType.HTML));

  verify(out).print("test");
  verify(out).print(" id=\"testid\"");
  verify(out).print("test note");
}
 
Example #15
Source File: HtmlPage.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void render() {
  puts(DOCTYPE);
  render(page().html().meta_http("X-UA-Compatible", "IE=8")
      .meta_http("Content-type", MimeType.HTML));
  if (page().nestLevel() != 0) {
    throw new WebAppException("Error rendering page: nestLevel="+
                              page().nestLevel());
  }
}
 
Example #16
Source File: TestAppController.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 *   Test method 'conf'. Should set AttemptsPage class for rendering or print information about error
 */
@Test
public void testAttempts() {

  appController.getProperty().remove(AMParams.TASK_TYPE);

  when(job.checkAccess(any(UserGroupInformation.class), any(JobACL.class)))
      .thenReturn(false);

  appController.attempts();
  verify(appController.response()).setContentType(MimeType.TEXT);
  assertEquals(
      "Access denied: User user does not have permission to view job job_01_01",
      appController.getData());

  when(job.checkAccess(any(UserGroupInformation.class), any(JobACL.class)))
      .thenReturn(true);

  appController.getProperty().remove(AMParams.TASK_ID);
  appController.attempts();
  assertEquals(
      "Access denied: User user does not have permission to view job job_01_01",
      appController.getData());

  appController.getProperty().put(AMParams.TASK_ID, "task_01_01_m01_01");
  appController.attempts();
  assertEquals("Bad request: missing task-type.", appController.getProperty()
      .get("title"));
  appController.getProperty().put(AMParams.TASK_TYPE, "m");

  appController.attempts();
  assertEquals("Bad request: missing attempt-state.", appController
      .getProperty().get("title"));
  appController.getProperty().put(AMParams.ATTEMPT_STATE, "State");

  appController.attempts();

  assertEquals(AttemptsPage.class, appController.getClazz());
}
 
Example #17
Source File: ProxyUtils.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Output 404 with appropriate message.
 * @param resp the http response.
 * @param message the message to include on the page.
 * @throws IOException on any error.
 */
public static void notFound(HttpServletResponse resp, String message)
    throws IOException {
  resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
  resp.setContentType(MimeType.HTML);
  Page p = new Page(resp.getWriter());
  p.html().
      h1(message).
       _();
}
 
Example #18
Source File: ProxyUtils.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Handle redirects with a status code that can in future support verbs other
 * than GET, thus supporting full REST functionality.
 * <p>
 * The target URL is included in the redirect text returned
 * <p>
 * At the end of this method, the output stream is closed.
 * 
 * @param request request (hence: the verb and any other information
 * relevant to a redirect)
 * @param response the response
 * @param target the target URL -unencoded
 *
 */
public static void sendRedirect(HttpServletRequest request,
    HttpServletResponse response,
    String target)
    throws IOException {
  if (LOG.isDebugEnabled()) {
    LOG.debug("Redirecting {} {} to {}",
        request.getMethod(), 
        request.getRequestURI(),
        target);
  }
  String location = response.encodeRedirectURL(target);
  response.setStatus(HttpServletResponse.SC_FOUND);
  response.setHeader(LOCATION, location);
  response.setContentType(MimeType.HTML);
  PrintWriter writer = response.getWriter();
  Page p = new Page(writer);
  p.html()
      .head().title("Moved")._()
      .body()
      .h1("Moved")
      .div()
        ._("Content has moved ")
        .a(location, "here")._()
      ._()._();
  writer.close();
}
 
Example #19
Source File: TestHtmlPage.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test public void testUsual() {
  Injector injector = WebAppTests.testPage(TestView.class);
  PrintWriter out = injector.getInstance(PrintWriter.class);

  // Verify the HTML page has correct meta tags in the header
  verify(out).print(" http-equiv=\"X-UA-Compatible\"");
  verify(out).print(" content=\"IE=8\"");
  verify(out).print(" http-equiv=\"Content-type\"");
  verify(out).print(String.format(" content=\"%s\"", MimeType.HTML));

  verify(out).print("test");
  verify(out).print(" id=\"testid\"");
  verify(out).print("test note");
}
 
Example #20
Source File: TextPage.java    From big-c with Apache License 2.0 4 votes vote down vote up
protected TextPage() {
  super(null, MimeType.TEXT);
}
 
Example #21
Source File: TextPage.java    From big-c with Apache License 2.0 4 votes vote down vote up
protected TextPage(ViewContext ctx) {
  super(ctx, MimeType.TEXT);
}
 
Example #22
Source File: HtmlBlock.java    From big-c with Apache License 2.0 4 votes vote down vote up
protected HtmlBlock(ViewContext ctx) {
  super(ctx, MimeType.HTML);
}
 
Example #23
Source File: HtmlPage.java    From big-c with Apache License 2.0 4 votes vote down vote up
protected HtmlPage(ViewContext ctx) {
  super(ctx, MimeType.HTML);
}
 
Example #24
Source File: HtmlBlock.java    From hadoop with Apache License 2.0 4 votes vote down vote up
protected HtmlBlock(ViewContext ctx) {
  super(ctx, MimeType.HTML);
}
 
Example #25
Source File: TextPage.java    From hadoop with Apache License 2.0 4 votes vote down vote up
protected TextPage(ViewContext ctx) {
  super(ctx, MimeType.TEXT);
}
 
Example #26
Source File: TextPage.java    From hadoop with Apache License 2.0 4 votes vote down vote up
protected TextPage() {
  super(null, MimeType.TEXT);
}
 
Example #27
Source File: HtmlPage.java    From hadoop with Apache License 2.0 4 votes vote down vote up
protected HtmlPage(ViewContext ctx) {
  super(ctx, MimeType.HTML);
}