dfsnodelist.jsp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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.fs.*"
  8. import="org.apache.hadoop.hdfs.*"
  9. import="org.apache.hadoop.hdfs.server.common.*"
  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.util.*"
  14. import="java.text.DateFormat"
  15. import="java.lang.Math"
  16. import="java.net.URLEncoder"
  17. %>
  18. <%!
  19. JspHelper jspHelper = new JspHelper();
  20. int rowNum = 0;
  21. int colNum = 0;
  22. String rowTxt() { colNum = 0;
  23. return "<tr class=\"" + (((rowNum++)%2 == 0)? "rowNormal" : "rowAlt")
  24. + "\"> "; }
  25. String colTxt() { return "<td id=\"col" + ++colNum + "\"> "; }
  26. void counterReset () { colNum = 0; rowNum = 0 ; }
  27. long diskBytes = 1024 * 1024 * 1024;
  28. String diskByteStr = "GB";
  29. String sorterField = null;
  30. String sorterOrder = null;
  31. String whatNodes = "LIVE";
  32. String NodeHeaderStr(String name) {
  33. String ret = "class=header";
  34. String order = "ASC";
  35. if ( name.equals( sorterField ) ) {
  36. ret += sorterOrder;
  37. if ( sorterOrder.equals("ASC") )
  38. order = "DSC";
  39. }
  40. ret += " onClick=\"window.document.location=" +
  41. "'/dfsnodelist.jsp?whatNodes="+whatNodes+"&sorter/field=" + name + "&sorter/order=" +
  42. order + "'\" title=\"sort on this column\"";
  43. return ret;
  44. }
  45. public void generateNodeData( JspWriter out, DatanodeDescriptor d,
  46. String suffix, boolean alive,
  47. int nnHttpPort )
  48. throws IOException {
  49. /* Say the datanode is dn1.hadoop.apache.org with ip 192.168.0.5
  50. we use:
  51. 1) d.getHostName():d.getPort() to display.
  52. Domain and port are stripped if they are common across the nodes.
  53. i.e. "dn1"
  54. 2) d.getHost():d.Port() for "title".
  55. i.e. "192.168.0.5:50010"
  56. 3) d.getHostName():d.getInfoPort() for url.
  57. i.e. "http://dn1.hadoop.apache.org:50075/..."
  58. Note that "d.getHost():d.getPort()" is what DFS clients use
  59. to interact with datanodes.
  60. */
  61. // from nn_browsedfscontent.jsp:
  62. String url = "http://" + d.getHostName() + ":" + d.getInfoPort() +
  63. "/browseDirectory.jsp?namenodeInfoPort=" +
  64. nnHttpPort + "&dir=" +
  65. URLEncoder.encode("/", "UTF-8");
  66. String name = d.getHostName() + ":" + d.getPort();
  67. if ( !name.matches( "\\d+\\.\\d+.\\d+\\.\\d+.*" ) )
  68. name = name.replaceAll( "\\.[^.:]*", "" );
  69. int idx = (suffix != null && name.endsWith( suffix )) ?
  70. name.indexOf( suffix ) : -1;
  71. out.print( rowTxt() + "<td class=\"name\"><a title=\""
  72. + d.getHost() + ":" + d.getPort() +
  73. "\" href=\"" + url + "\">" +
  74. (( idx > 0 ) ? name.substring(0, idx) : name) + "</a>" +
  75. (( alive ) ? "" : "\n") );
  76. if ( !alive )
  77. return;
  78. long c = d.getCapacity();
  79. long u = d.getDfsUsed();
  80. long nu = d.getNonDfsUsed();
  81. long r = d.getRemaining();
  82. String percentUsed = StringUtils.limitDecimalTo2(d.getDfsUsedPercent());
  83. String percentRemaining = StringUtils.limitDecimalTo2(d.getRemainingPercent());
  84. String adminState = (d.isDecommissioned() ? "Decommissioned" :
  85. (d.isDecommissionInProgress() ? "Decommission In Progress":
  86. "In Service"));
  87. long timestamp = d.getLastUpdate();
  88. long currentTime = System.currentTimeMillis();
  89. out.print("<td class=\"lastcontact\"> " +
  90. ((currentTime - timestamp)/1000) +
  91. "<td class=\"adminstate\">" +
  92. adminState +
  93. "<td align=\"right\" class=\"capacity\">" +
  94. StringUtils.limitDecimalTo2(c*1.0/diskBytes) +
  95. "<td align=\"right\" class=\"used\">" +
  96. StringUtils.limitDecimalTo2(u*1.0/diskBytes) +
  97. "<td align=\"right\" class=\"nondfsused\">" +
  98. StringUtils.limitDecimalTo2(nu*1.0/diskBytes) +
  99. "<td align=\"right\" class=\"remaining\">" +
  100. StringUtils.limitDecimalTo2(r*1.0/diskBytes) +
  101. "<td align=\"right\" class=\"pcused\">" + percentUsed +
  102. "<td class=\"pcused\">" +
  103. ServletUtil.percentageGraph( (int)Double.parseDouble(percentUsed) , 100) +
  104. "<td align=\"right\" class=\"pcremaining`\">" + percentRemaining +
  105. "<td title=" + "\"blocks scheduled : " + d.getBlocksScheduled() +
  106. "\" class=\"blocks\">" + d.numBlocks() + "\n");
  107. }
  108. public void generateDFSNodesList(JspWriter out,
  109. NameNode nn,
  110. HttpServletRequest request)
  111. throws IOException {
  112. ArrayList<DatanodeDescriptor> live = new ArrayList<DatanodeDescriptor>();
  113. ArrayList<DatanodeDescriptor> dead = new ArrayList<DatanodeDescriptor>();
  114. jspHelper.DFSNodesStatus(live, dead);
  115. whatNodes = request.getParameter("whatNodes"); // show only live or only dead nodes
  116. sorterField = request.getParameter("sorter/field");
  117. sorterOrder = request.getParameter("sorter/order");
  118. if ( sorterField == null )
  119. sorterField = "name";
  120. if ( sorterOrder == null )
  121. sorterOrder = "ASC";
  122. jspHelper.sortNodeList(live, sorterField, sorterOrder);
  123. jspHelper.sortNodeList(dead, "name", "ASC");
  124. // Find out common suffix. Should this be before or after the sort?
  125. String port_suffix = null;
  126. if ( live.size() > 0 ) {
  127. String name = live.get(0).getName();
  128. int idx = name.indexOf(':');
  129. if ( idx > 0 ) {
  130. port_suffix = name.substring( idx );
  131. }
  132. for ( int i=1; port_suffix != null && i < live.size(); i++ ) {
  133. if ( live.get(i).getName().endsWith( port_suffix ) == false ) {
  134. port_suffix = null;
  135. break;
  136. }
  137. }
  138. }
  139. counterReset();
  140. try {
  141. Thread.sleep(1000);
  142. } catch (InterruptedException e) {}
  143. if (live.isEmpty() && dead.isEmpty()) {
  144. out.print("There are no datanodes in the cluster");
  145. }
  146. else {
  147. int nnHttpPort = nn.getHttpAddress().getPort();
  148. out.print( "<div id=\"dfsnodetable\"> ");
  149. if(whatNodes.equals("LIVE")) {
  150. out.print(
  151. "<a name=\"LiveNodes\" id=\"title\">" +
  152. "Live Datanodes : " + live.size() + "</a>" +
  153. "<br><br>\n<table border=1 cellspacing=0>\n" );
  154. counterReset();
  155. if ( live.size() > 0 ) {
  156. if ( live.get(0).getCapacity() > 1024 * diskBytes ) {
  157. diskBytes *= 1024;
  158. diskByteStr = "TB";
  159. }
  160. out.print( "<tr class=\"headerRow\"> <th " +
  161. NodeHeaderStr("name") + "> Node <th " +
  162. NodeHeaderStr("lastcontact") + "> Last <br>Contact <th " +
  163. NodeHeaderStr("adminstate") + "> Admin State <th " +
  164. NodeHeaderStr("capacity") + "> Configured <br>Capacity (" +
  165. diskByteStr + ") <th " +
  166. NodeHeaderStr("used") + "> Used <br>(" +
  167. diskByteStr + ") <th " +
  168. NodeHeaderStr("nondfsused") + "> Non DFS <br>Used (" +
  169. diskByteStr + ") <th " +
  170. NodeHeaderStr("remaining") + "> Remaining <br>(" +
  171. diskByteStr + ") <th " +
  172. NodeHeaderStr("pcused") + "> Used <br>(%) <th " +
  173. NodeHeaderStr("pcused") + "> Used <br>(%) <th " +
  174. NodeHeaderStr("pcremaining") + "> Remaining <br>(%) <th " +
  175. NodeHeaderStr("blocks") + "> Blocks\n" );
  176. jspHelper.sortNodeList(live, sorterField, sorterOrder);
  177. for ( int i=0; i < live.size(); i++ ) {
  178. generateNodeData(out, live.get(i), port_suffix, true, nnHttpPort);
  179. }
  180. }
  181. out.print("</table>\n");
  182. } else {
  183. out.print("<br> <a name=\"DeadNodes\" id=\"title\"> " +
  184. " Dead Datanodes : " +dead.size() + "</a><br><br>\n");
  185. if ( dead.size() > 0 ) {
  186. out.print( "<table border=1 cellspacing=0> <tr id=\"row1\"> " +
  187. "<td> Node \n" );
  188. jspHelper.sortNodeList(dead, "name", "ASC");
  189. for ( int i=0; i < dead.size() ; i++ ) {
  190. generateNodeData(out, dead.get(i), port_suffix, false, nnHttpPort);
  191. }
  192. out.print("</table>\n");
  193. }
  194. }
  195. out.print("</div>");
  196. }
  197. }%>
  198. <%
  199. NameNode nn = (NameNode)application.getAttribute("name.node");
  200. FSNamesystem fsn = nn.getNamesystem();
  201. String namenodeLabel = nn.getNameNodeAddress().getHostName() + ":" + nn.getNameNodeAddress().getPort();
  202. %>
  203. <html>
  204. <link rel="stylesheet" type="text/css" href="/static/hadoop.css">
  205. <title>Hadoop NameNode <%=namenodeLabel%></title>
  206. <body>
  207. <h1>NameNode '<%=namenodeLabel%>'</h1>
  208. <div id="dfstable"> <table>
  209. <tr> <td id="col1"> Started: <td> <%= fsn.getStartTime()%>
  210. <tr> <td id="col1"> Version: <td> <%= VersionInfo.getVersion()%>, r<%= VersionInfo.getRevision()%>
  211. <tr> <td id="col1"> Compiled: <td> <%= VersionInfo.getDate()%> by <%= VersionInfo.getUser()%>
  212. <tr> <td id="col1"> Upgrades: <td> <%= jspHelper.getUpgradeStatusText()%>
  213. </table></div><br>
  214. <b><a href="/nn_browsedfscontent.jsp">Browse the filesystem</a></b><br>
  215. <b><a href="/logs/">Namenode Logs</a></b><br>
  216. <b><a href=/dfshealth.jsp> Go back to DFS home</a></b>
  217. <hr>
  218. <%
  219. generateDFSNodesList(out, nn, request);
  220. %>
  221. <%
  222. out.println(ServletUtil.htmlFooter());
  223. %>