nn_browsedfscontent.jsp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <%@ page
  2. contentType="text/html; charset=UTF-8"
  3. import="java.io.*"
  4. import="java.security.PrivilegedExceptionAction"
  5. import="java.util.*"
  6. import="javax.servlet.*"
  7. import="javax.servlet.http.*"
  8. import="org.apache.hadoop.conf.Configuration"
  9. import="org.apache.hadoop.hdfs.*"
  10. import="org.apache.hadoop.hdfs.server.namenode.*"
  11. import="org.apache.hadoop.hdfs.server.datanode.*"
  12. import="org.apache.hadoop.hdfs.protocol.*"
  13. import="org.apache.hadoop.hdfs.security.token.delegation.*"
  14. import="org.apache.hadoop.io.Text"
  15. import="org.apache.hadoop.security.UserGroupInformation"
  16. import="org.apache.hadoop.security.token.Token"
  17. import="org.apache.hadoop.util.*"
  18. import="java.text.DateFormat"
  19. import="java.net.InetAddress"
  20. import="java.net.URLEncoder"
  21. %>
  22. <%!
  23. static String getDelegationToken(final NameNode nn,
  24. final UserGroupInformation ugi,
  25. HttpServletRequest request, Configuration conf)
  26. throws IOException, InterruptedException {
  27. Token<DelegationTokenIdentifier> token =
  28. ugi.doAs(
  29. new PrivilegedExceptionAction<Token<DelegationTokenIdentifier>>()
  30. {
  31. public Token<DelegationTokenIdentifier> run() throws IOException {
  32. return nn.getDelegationToken(new Text(ugi.getUserName()));
  33. }
  34. });
  35. return token.encodeToUrlString();
  36. }
  37. public void redirectToRandomDataNode(
  38. ServletContext context,
  39. HttpServletRequest request,
  40. HttpServletResponse resp
  41. ) throws IOException, InterruptedException {
  42. Configuration conf = (Configuration) context.getAttribute(JspHelper.CURRENT_CONF);
  43. NameNode nn = (NameNode)context.getAttribute("name.node");
  44. final UserGroupInformation ugi = JspHelper.getUGI(context, request, conf);
  45. String tokenString = null;
  46. if (UserGroupInformation.isSecurityEnabled()) {
  47. tokenString = getDelegationToken(nn, ugi, request, conf);
  48. }
  49. FSNamesystem fsn = nn.getNamesystem();
  50. String datanode = fsn.randomDataNode();
  51. String redirectLocation;
  52. String nodeToRedirect;
  53. int redirectPort;
  54. if (datanode != null) {
  55. redirectPort = Integer.parseInt(datanode.substring(datanode.indexOf(':')
  56. + 1));
  57. nodeToRedirect = datanode.substring(0, datanode.indexOf(':'));
  58. }
  59. else {
  60. nodeToRedirect = nn.getHttpAddress().getHostName();
  61. redirectPort = nn.getHttpAddress().getPort();
  62. }
  63. String fqdn = InetAddress.getByName(nodeToRedirect).getCanonicalHostName();
  64. redirectLocation = "http://" + fqdn + ":" + redirectPort +
  65. "/browseDirectory.jsp?namenodeInfoPort=" +
  66. nn.getHttpAddress().getPort() +
  67. "&dir=/" +
  68. (tokenString == null ? "" :
  69. JspHelper.getDelegationTokenUrlParam(tokenString));
  70. resp.sendRedirect(redirectLocation);
  71. }
  72. %>
  73. <html>
  74. <title></title>
  75. <body>
  76. <%
  77. redirectToRandomDataNode(application, request, response);
  78. %>
  79. <hr>
  80. <h2>Local logs</h2>
  81. <a href="/logs/">Log</a> directory
  82. <%
  83. out.println(ServletUtil.htmlFooter());
  84. %>