nn_browsedfscontent.jsp
上传用户:quxuerui
上传日期:2018-01-08
资源大小:41811k
文件大小:2k
源码类别:

网格计算

开发平台:

Java

  1. <%@ page
  2.   contentType="text/html; charset=UTF-8"
  3.   import="javax.servlet.*"
  4.   import="javax.servlet.http.*"
  5.   import="java.io.*"
  6.   import="java.util.*"
  7.   import="org.apache.hadoop.hdfs.*"
  8.   import="org.apache.hadoop.hdfs.server.namenode.*"
  9.   import="org.apache.hadoop.hdfs.server.datanode.*"
  10.   import="org.apache.hadoop.hdfs.protocol.*"
  11.   import="org.apache.hadoop.util.*"
  12.   import="java.text.DateFormat"
  13.   import="java.net.InetAddress"
  14.   import="java.net.URLEncoder"
  15. %>
  16. <%!
  17.   public void redirectToRandomDataNode(
  18.                             NameNode nn, 
  19.                             HttpServletResponse resp) throws IOException {
  20.     FSNamesystem fsn = nn.getNamesystem();
  21.     String datanode = fsn.randomDataNode();
  22.     String redirectLocation;
  23.     String nodeToRedirect;
  24.     int redirectPort;
  25.     if (datanode != null) {
  26.       redirectPort = Integer.parseInt(datanode.substring(datanode.indexOf(':') + 1));
  27.       nodeToRedirect = datanode.substring(0, datanode.indexOf(':'));
  28.     }
  29.     else {
  30.       nodeToRedirect = nn.getHttpAddress().getHostName();
  31.       redirectPort = nn.getHttpAddress().getPort();
  32.     }
  33.     String fqdn = InetAddress.getByName(nodeToRedirect).getCanonicalHostName();
  34.     redirectLocation = "http://" + fqdn + ":" + redirectPort + 
  35.                        "/browseDirectory.jsp?namenodeInfoPort=" + 
  36.                        nn.getHttpAddress().getPort() +
  37.                        "&dir=" + URLEncoder.encode("/", "UTF-8");
  38.     resp.sendRedirect(redirectLocation);
  39.   }
  40. %>
  41. <html>
  42. <title></title>
  43. <body>
  44. <% 
  45.   NameNode nn = (NameNode)application.getAttribute("name.node");
  46.   redirectToRandomDataNode(nn, response); 
  47. %>
  48. <hr>
  49. <h2>Local logs</h2>
  50. <a href="/logs/">Log</a> directory
  51. <%
  52. out.println(ServletUtil.htmlFooter());
  53. %>