[120] | 1 | package org.apache.hadoop.hdfs.server.namenode; |
---|
| 2 | |
---|
| 3 | import javax.servlet.*; |
---|
| 4 | import javax.servlet.http.*; |
---|
| 5 | import javax.servlet.jsp.*; |
---|
| 6 | import javax.servlet.*; |
---|
| 7 | import javax.servlet.http.*; |
---|
| 8 | import java.io.*; |
---|
| 9 | import java.util.*; |
---|
| 10 | import org.apache.hadoop.fs.*; |
---|
| 11 | import org.apache.hadoop.hdfs.*; |
---|
| 12 | import org.apache.hadoop.hdfs.server.common.*; |
---|
| 13 | import org.apache.hadoop.hdfs.server.namenode.*; |
---|
| 14 | import org.apache.hadoop.hdfs.server.datanode.*; |
---|
| 15 | import org.apache.hadoop.hdfs.protocol.*; |
---|
| 16 | import org.apache.hadoop.util.*; |
---|
| 17 | import java.text.DateFormat; |
---|
| 18 | import java.lang.Math; |
---|
| 19 | import java.net.URLEncoder; |
---|
| 20 | |
---|
| 21 | public final class dfsnodelist_jsp extends org.apache.jasper.runtime.HttpJspBase |
---|
| 22 | implements org.apache.jasper.runtime.JspSourceDependent { |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | JspHelper jspHelper = new JspHelper(); |
---|
| 26 | |
---|
| 27 | int rowNum = 0; |
---|
| 28 | int colNum = 0; |
---|
| 29 | |
---|
| 30 | String rowTxt() { colNum = 0; |
---|
| 31 | return "<tr class=\"" + (((rowNum++)%2 == 0)? "rowNormal" : "rowAlt") |
---|
| 32 | + "\"> "; } |
---|
| 33 | String colTxt() { return "<td id=\"col" + ++colNum + "\"> "; } |
---|
| 34 | void counterReset () { colNum = 0; rowNum = 0 ; } |
---|
| 35 | |
---|
| 36 | long diskBytes = 1024 * 1024 * 1024; |
---|
| 37 | String diskByteStr = "GB"; |
---|
| 38 | |
---|
| 39 | String sorterField = null; |
---|
| 40 | String sorterOrder = null; |
---|
| 41 | String whatNodes = "LIVE"; |
---|
| 42 | |
---|
| 43 | String NodeHeaderStr(String name) { |
---|
| 44 | String ret = "class=header"; |
---|
| 45 | String order = "ASC"; |
---|
| 46 | if ( name.equals( sorterField ) ) { |
---|
| 47 | ret += sorterOrder; |
---|
| 48 | if ( sorterOrder.equals("ASC") ) |
---|
| 49 | order = "DSC"; |
---|
| 50 | } |
---|
| 51 | ret += " onClick=\"window.document.location=" + |
---|
| 52 | "'/dfsnodelist.jsp?whatNodes="+whatNodes+"&sorter/field=" + name + "&sorter/order=" + |
---|
| 53 | order + "'\" title=\"sort on this column\""; |
---|
| 54 | |
---|
| 55 | return ret; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | public void generateNodeData( JspWriter out, DatanodeDescriptor d, |
---|
| 59 | String suffix, boolean alive, |
---|
| 60 | int nnHttpPort ) |
---|
| 61 | throws IOException { |
---|
| 62 | |
---|
| 63 | /* Say the datanode is dn1.hadoop.apache.org with ip 192.168.0.5 |
---|
| 64 | we use: |
---|
| 65 | 1) d.getHostName():d.getPort() to display. |
---|
| 66 | Domain and port are stripped if they are common across the nodes. |
---|
| 67 | i.e. "dn1" |
---|
| 68 | 2) d.getHost():d.Port() for "title". |
---|
| 69 | i.e. "192.168.0.5:50010" |
---|
| 70 | 3) d.getHostName():d.getInfoPort() for url. |
---|
| 71 | i.e. "http://dn1.hadoop.apache.org:50075/..." |
---|
| 72 | Note that "d.getHost():d.getPort()" is what DFS clients use |
---|
| 73 | to interact with datanodes. |
---|
| 74 | */ |
---|
| 75 | // from nn_browsedfscontent.jsp: |
---|
| 76 | String url = "http://" + d.getHostName() + ":" + d.getInfoPort() + |
---|
| 77 | "/browseDirectory.jsp?namenodeInfoPort=" + |
---|
| 78 | nnHttpPort + "&dir=" + |
---|
| 79 | URLEncoder.encode("/", "UTF-8"); |
---|
| 80 | |
---|
| 81 | String name = d.getHostName() + ":" + d.getPort(); |
---|
| 82 | if ( !name.matches( "\\d+\\.\\d+.\\d+\\.\\d+.*" ) ) |
---|
| 83 | name = name.replaceAll( "\\.[^.:]*", "" ); |
---|
| 84 | int idx = (suffix != null && name.endsWith( suffix )) ? |
---|
| 85 | name.indexOf( suffix ) : -1; |
---|
| 86 | |
---|
| 87 | out.print( rowTxt() + "<td class=\"name\"><a title=\"" |
---|
| 88 | + d.getHost() + ":" + d.getPort() + |
---|
| 89 | "\" href=\"" + url + "\">" + |
---|
| 90 | (( idx > 0 ) ? name.substring(0, idx) : name) + "</a>" + |
---|
| 91 | (( alive ) ? "" : "\n") ); |
---|
| 92 | if ( !alive ) |
---|
| 93 | return; |
---|
| 94 | |
---|
| 95 | long c = d.getCapacity(); |
---|
| 96 | long u = d.getDfsUsed(); |
---|
| 97 | long nu = d.getNonDfsUsed(); |
---|
| 98 | long r = d.getRemaining(); |
---|
| 99 | String percentUsed = StringUtils.limitDecimalTo2(d.getDfsUsedPercent()); |
---|
| 100 | String percentRemaining = StringUtils.limitDecimalTo2(d.getRemainingPercent()); |
---|
| 101 | |
---|
| 102 | String adminState = (d.isDecommissioned() ? "Decommissioned" : |
---|
| 103 | (d.isDecommissionInProgress() ? "Decommission In Progress": |
---|
| 104 | "In Service")); |
---|
| 105 | |
---|
| 106 | long timestamp = d.getLastUpdate(); |
---|
| 107 | long currentTime = System.currentTimeMillis(); |
---|
| 108 | out.print("<td class=\"lastcontact\"> " + |
---|
| 109 | ((currentTime - timestamp)/1000) + |
---|
| 110 | "<td class=\"adminstate\">" + |
---|
| 111 | adminState + |
---|
| 112 | "<td align=\"right\" class=\"capacity\">" + |
---|
| 113 | StringUtils.limitDecimalTo2(c*1.0/diskBytes) + |
---|
| 114 | "<td align=\"right\" class=\"used\">" + |
---|
| 115 | StringUtils.limitDecimalTo2(u*1.0/diskBytes) + |
---|
| 116 | "<td align=\"right\" class=\"nondfsused\">" + |
---|
| 117 | StringUtils.limitDecimalTo2(nu*1.0/diskBytes) + |
---|
| 118 | "<td align=\"right\" class=\"remaining\">" + |
---|
| 119 | StringUtils.limitDecimalTo2(r*1.0/diskBytes) + |
---|
| 120 | "<td align=\"right\" class=\"pcused\">" + percentUsed + |
---|
| 121 | "<td class=\"pcused\">" + |
---|
| 122 | ServletUtil.percentageGraph( (int)Double.parseDouble(percentUsed) , 100) + |
---|
| 123 | "<td align=\"right\" class=\"pcremaining`\">" + percentRemaining + |
---|
| 124 | "<td title=" + "\"blocks scheduled : " + d.getBlocksScheduled() + |
---|
| 125 | "\" class=\"blocks\">" + d.numBlocks() + "\n"); |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | public void generateDFSNodesList(JspWriter out, |
---|
| 131 | NameNode nn, |
---|
| 132 | HttpServletRequest request) |
---|
| 133 | throws IOException { |
---|
| 134 | ArrayList<DatanodeDescriptor> live = new ArrayList<DatanodeDescriptor>(); |
---|
| 135 | ArrayList<DatanodeDescriptor> dead = new ArrayList<DatanodeDescriptor>(); |
---|
| 136 | jspHelper.DFSNodesStatus(live, dead); |
---|
| 137 | |
---|
| 138 | whatNodes = request.getParameter("whatNodes"); // show only live or only dead nodes |
---|
| 139 | sorterField = request.getParameter("sorter/field"); |
---|
| 140 | sorterOrder = request.getParameter("sorter/order"); |
---|
| 141 | if ( sorterField == null ) |
---|
| 142 | sorterField = "name"; |
---|
| 143 | if ( sorterOrder == null ) |
---|
| 144 | sorterOrder = "ASC"; |
---|
| 145 | |
---|
| 146 | jspHelper.sortNodeList(live, sorterField, sorterOrder); |
---|
| 147 | jspHelper.sortNodeList(dead, "name", "ASC"); |
---|
| 148 | |
---|
| 149 | // Find out common suffix. Should this be before or after the sort? |
---|
| 150 | String port_suffix = null; |
---|
| 151 | if ( live.size() > 0 ) { |
---|
| 152 | String name = live.get(0).getName(); |
---|
| 153 | int idx = name.indexOf(':'); |
---|
| 154 | if ( idx > 0 ) { |
---|
| 155 | port_suffix = name.substring( idx ); |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | for ( int i=1; port_suffix != null && i < live.size(); i++ ) { |
---|
| 159 | if ( live.get(i).getName().endsWith( port_suffix ) == false ) { |
---|
| 160 | port_suffix = null; |
---|
| 161 | break; |
---|
| 162 | } |
---|
| 163 | } |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | counterReset(); |
---|
| 167 | |
---|
| 168 | try { |
---|
| 169 | Thread.sleep(1000); |
---|
| 170 | } catch (InterruptedException e) {} |
---|
| 171 | |
---|
| 172 | if (live.isEmpty() && dead.isEmpty()) { |
---|
| 173 | out.print("There are no datanodes in the cluster"); |
---|
| 174 | } |
---|
| 175 | else { |
---|
| 176 | |
---|
| 177 | int nnHttpPort = nn.getHttpAddress().getPort(); |
---|
| 178 | out.print( "<div id=\"dfsnodetable\"> "); |
---|
| 179 | if(whatNodes.equals("LIVE")) { |
---|
| 180 | |
---|
| 181 | out.print( |
---|
| 182 | "<a name=\"LiveNodes\" id=\"title\">" + |
---|
| 183 | "Live Datanodes : " + live.size() + "</a>" + |
---|
| 184 | "<br><br>\n<table border=1 cellspacing=0>\n" ); |
---|
| 185 | |
---|
| 186 | counterReset(); |
---|
| 187 | |
---|
| 188 | if ( live.size() > 0 ) { |
---|
| 189 | |
---|
| 190 | if ( live.get(0).getCapacity() > 1024 * diskBytes ) { |
---|
| 191 | diskBytes *= 1024; |
---|
| 192 | diskByteStr = "TB"; |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | out.print( "<tr class=\"headerRow\"> <th " + |
---|
| 196 | NodeHeaderStr("name") + "> Node <th " + |
---|
| 197 | NodeHeaderStr("lastcontact") + "> Last <br>Contact <th " + |
---|
| 198 | NodeHeaderStr("adminstate") + "> Admin State <th " + |
---|
| 199 | NodeHeaderStr("capacity") + "> Configured <br>Capacity (" + |
---|
| 200 | diskByteStr + ") <th " + |
---|
| 201 | NodeHeaderStr("used") + "> Used <br>(" + |
---|
| 202 | diskByteStr + ") <th " + |
---|
| 203 | NodeHeaderStr("nondfsused") + "> Non DFS <br>Used (" + |
---|
| 204 | diskByteStr + ") <th " + |
---|
| 205 | NodeHeaderStr("remaining") + "> Remaining <br>(" + |
---|
| 206 | diskByteStr + ") <th " + |
---|
| 207 | NodeHeaderStr("pcused") + "> Used <br>(%) <th " + |
---|
| 208 | NodeHeaderStr("pcused") + "> Used <br>(%) <th " + |
---|
| 209 | NodeHeaderStr("pcremaining") + "> Remaining <br>(%) <th " + |
---|
| 210 | NodeHeaderStr("blocks") + "> Blocks\n" ); |
---|
| 211 | |
---|
| 212 | jspHelper.sortNodeList(live, sorterField, sorterOrder); |
---|
| 213 | for ( int i=0; i < live.size(); i++ ) { |
---|
| 214 | generateNodeData(out, live.get(i), port_suffix, true, nnHttpPort); |
---|
| 215 | } |
---|
| 216 | } |
---|
| 217 | out.print("</table>\n"); |
---|
| 218 | } else { |
---|
| 219 | |
---|
| 220 | out.print("<br> <a name=\"DeadNodes\" id=\"title\"> " + |
---|
| 221 | " Dead Datanodes : " +dead.size() + "</a><br><br>\n"); |
---|
| 222 | |
---|
| 223 | if ( dead.size() > 0 ) { |
---|
| 224 | out.print( "<table border=1 cellspacing=0> <tr id=\"row1\"> " + |
---|
| 225 | "<td> Node \n" ); |
---|
| 226 | |
---|
| 227 | jspHelper.sortNodeList(dead, "name", "ASC"); |
---|
| 228 | for ( int i=0; i < dead.size() ; i++ ) { |
---|
| 229 | generateNodeData(out, dead.get(i), port_suffix, false, nnHttpPort); |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | out.print("</table>\n"); |
---|
| 233 | } |
---|
| 234 | } |
---|
| 235 | out.print("</div>"); |
---|
| 236 | } |
---|
| 237 | } |
---|
| 238 | private static java.util.List _jspx_dependants; |
---|
| 239 | |
---|
| 240 | public Object getDependants() { |
---|
| 241 | return _jspx_dependants; |
---|
| 242 | } |
---|
| 243 | |
---|
| 244 | public void _jspService(HttpServletRequest request, HttpServletResponse response) |
---|
| 245 | throws java.io.IOException, ServletException { |
---|
| 246 | |
---|
| 247 | JspFactory _jspxFactory = null; |
---|
| 248 | PageContext pageContext = null; |
---|
| 249 | HttpSession session = null; |
---|
| 250 | ServletContext application = null; |
---|
| 251 | ServletConfig config = null; |
---|
| 252 | JspWriter out = null; |
---|
| 253 | Object page = this; |
---|
| 254 | JspWriter _jspx_out = null; |
---|
| 255 | PageContext _jspx_page_context = null; |
---|
| 256 | |
---|
| 257 | |
---|
| 258 | try { |
---|
| 259 | _jspxFactory = JspFactory.getDefaultFactory(); |
---|
| 260 | response.setContentType("text/html; charset=UTF-8"); |
---|
| 261 | pageContext = _jspxFactory.getPageContext(this, request, response, |
---|
| 262 | null, true, 8192, true); |
---|
| 263 | _jspx_page_context = pageContext; |
---|
| 264 | application = pageContext.getServletContext(); |
---|
| 265 | config = pageContext.getServletConfig(); |
---|
| 266 | session = pageContext.getSession(); |
---|
| 267 | out = pageContext.getOut(); |
---|
| 268 | _jspx_out = out; |
---|
| 269 | |
---|
| 270 | out.write('\n'); |
---|
| 271 | out.write('\n'); |
---|
| 272 | out.write('\n'); |
---|
| 273 | |
---|
| 274 | NameNode nn = (NameNode)application.getAttribute("name.node"); |
---|
| 275 | FSNamesystem fsn = nn.getNamesystem(); |
---|
| 276 | String namenodeLabel = nn.getNameNodeAddress().getHostName() + ":" + nn.getNameNodeAddress().getPort(); |
---|
| 277 | |
---|
| 278 | out.write("\n\n<html>\n\n<link rel=\"stylesheet\" type=\"text/css\" href=\"/static/hadoop.css\">\n<title>Hadoop NameNode "); |
---|
| 279 | out.print(namenodeLabel); |
---|
| 280 | out.write("</title>\n \n<body>\n<h1>NameNode '"); |
---|
| 281 | out.print(namenodeLabel); |
---|
| 282 | out.write("'</h1>\n\n\n<div id=\"dfstable\"> <table>\t \n<tr> <td id=\"col1\"> Started: <td> "); |
---|
| 283 | out.print( fsn.getStartTime()); |
---|
| 284 | out.write("\n<tr> <td id=\"col1\"> Version: <td> "); |
---|
| 285 | out.print( VersionInfo.getVersion()); |
---|
| 286 | out.write(','); |
---|
| 287 | out.write(' '); |
---|
| 288 | out.write('r'); |
---|
| 289 | out.print( VersionInfo.getRevision()); |
---|
| 290 | out.write("\n<tr> <td id=\"col1\"> Compiled: <td> "); |
---|
| 291 | out.print( VersionInfo.getDate()); |
---|
| 292 | out.write(" by "); |
---|
| 293 | out.print( VersionInfo.getUser()); |
---|
| 294 | out.write("\n<tr> <td id=\"col1\"> Upgrades: <td> "); |
---|
| 295 | out.print( jspHelper.getUpgradeStatusText()); |
---|
| 296 | out.write("\n</table></div><br>\t\t\t\t \n\n<b><a href=\"/nn_browsedfscontent.jsp\">Browse the filesystem</a></b><br>\n<b><a href=\"/logs/\">Namenode Logs</a></b><br>\n<b><a href=/dfshealth.jsp> Go back to DFS home</a></b>\n<hr>\n"); |
---|
| 297 | |
---|
| 298 | generateDFSNodesList(out, nn, request); |
---|
| 299 | |
---|
| 300 | out.write('\n'); |
---|
| 301 | out.write('\n'); |
---|
| 302 | |
---|
| 303 | out.println(ServletUtil.htmlFooter()); |
---|
| 304 | |
---|
| 305 | out.write('\n'); |
---|
| 306 | } catch (Throwable t) { |
---|
| 307 | if (!(t instanceof SkipPageException)){ |
---|
| 308 | out = _jspx_out; |
---|
| 309 | if (out != null && out.getBufferSize() != 0) |
---|
| 310 | out.clearBuffer(); |
---|
| 311 | if (_jspx_page_context != null) _jspx_page_context.handlePageException(t); |
---|
| 312 | } |
---|
| 313 | } finally { |
---|
| 314 | if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context); |
---|
| 315 | } |
---|
| 316 | } |
---|
| 317 | } |
---|