[120] | 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 | |
---|
| 42 | <html> |
---|
| 43 | |
---|
| 44 | <title></title> |
---|
| 45 | |
---|
| 46 | <body> |
---|
| 47 | <% |
---|
| 48 | NameNode nn = (NameNode)application.getAttribute("name.node"); |
---|
| 49 | redirectToRandomDataNode(nn, response); |
---|
| 50 | %> |
---|
| 51 | <hr> |
---|
| 52 | |
---|
| 53 | <h2>Local logs</h2> |
---|
| 54 | <a href="/logs/">Log</a> directory |
---|
| 55 | |
---|
| 56 | <% |
---|
| 57 | out.println(ServletUtil.htmlFooter()); |
---|
| 58 | %> |
---|