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.namenode.*; |
---|
13 | import org.apache.hadoop.hdfs.server.datanode.*; |
---|
14 | import org.apache.hadoop.hdfs.server.common.Storage; |
---|
15 | import org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory; |
---|
16 | import org.apache.hadoop.hdfs.protocol.*; |
---|
17 | import org.apache.hadoop.util.*; |
---|
18 | import java.text.DateFormat; |
---|
19 | import java.lang.Math; |
---|
20 | import java.net.URLEncoder; |
---|
21 | |
---|
22 | public final class dfshealth_jsp extends org.apache.jasper.runtime.HttpJspBase |
---|
23 | implements org.apache.jasper.runtime.JspSourceDependent { |
---|
24 | |
---|
25 | |
---|
26 | JspHelper jspHelper = new JspHelper(); |
---|
27 | |
---|
28 | int rowNum = 0; |
---|
29 | int colNum = 0; |
---|
30 | |
---|
31 | String rowTxt() { colNum = 0; |
---|
32 | return "<tr class=\"" + (((rowNum++)%2 == 0)? "rowNormal" : "rowAlt") |
---|
33 | + "\"> "; } |
---|
34 | String colTxt() { return "<td id=\"col" + ++colNum + "\"> "; } |
---|
35 | void counterReset () { colNum = 0; rowNum = 0 ; } |
---|
36 | |
---|
37 | long diskBytes = 1024 * 1024 * 1024; |
---|
38 | String diskByteStr = "GB"; |
---|
39 | |
---|
40 | String sorterField = null; |
---|
41 | String sorterOrder = null; |
---|
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 | "'/dfshealth.jsp?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 | public void generateConfReport( JspWriter out, |
---|
130 | FSNamesystem fsn, |
---|
131 | HttpServletRequest request) |
---|
132 | throws IOException { |
---|
133 | long underReplicatedBlocks = fsn.getUnderReplicatedBlocks(); |
---|
134 | FSImage fsImage = fsn.getFSImage(); |
---|
135 | List<Storage.StorageDirectory> removedStorageDirs = fsImage.getRemovedStorageDirs(); |
---|
136 | String storageDirsSizeStr="", removedStorageDirsSizeStr="", storageDirsStr="", removedStorageDirsStr="", storageDirsDiv="", removedStorageDirsDiv=""; |
---|
137 | |
---|
138 | //FS Image storage configuration |
---|
139 | out.print("<h3> NameNode Storage: </h3>"); |
---|
140 | out.print("<div id=\"dfstable\"> <table border=1 cellpadding=10 cellspacing=0 title=\"NameNode Storage\">\n"+ |
---|
141 | "<thead><tr><td><b>Storage Directory</b></td><td><b>Type</b></td><td><b>State</b></td></tr></thead>"); |
---|
142 | |
---|
143 | StorageDirectory st =null; |
---|
144 | for (Iterator<StorageDirectory> it = fsImage.dirIterator(); it.hasNext();) { |
---|
145 | st = it.next(); |
---|
146 | String dir = "" + st.getRoot(); |
---|
147 | String type = "" + st.getStorageDirType(); |
---|
148 | out.print("<tr><td>"+dir+"</td><td>"+type+"</td><td>Active</td></tr>"); |
---|
149 | } |
---|
150 | |
---|
151 | long storageDirsSize = removedStorageDirs.size(); |
---|
152 | for(int i=0; i< storageDirsSize; i++){ |
---|
153 | st = removedStorageDirs.get(i); |
---|
154 | String dir = "" + st.getRoot(); |
---|
155 | String type = "" + st.getStorageDirType(); |
---|
156 | out.print("<tr><td>"+dir+"</td><td>"+type+"</td><td><font color=red>Failed</font></td></tr>"); |
---|
157 | } |
---|
158 | |
---|
159 | out.print("</table></div><br>\n"); |
---|
160 | } |
---|
161 | |
---|
162 | |
---|
163 | public void generateDFSHealthReport(JspWriter out, |
---|
164 | NameNode nn, |
---|
165 | HttpServletRequest request) |
---|
166 | throws IOException { |
---|
167 | FSNamesystem fsn = nn.getNamesystem(); |
---|
168 | ArrayList<DatanodeDescriptor> live = new ArrayList<DatanodeDescriptor>(); |
---|
169 | ArrayList<DatanodeDescriptor> dead = new ArrayList<DatanodeDescriptor>(); |
---|
170 | jspHelper.DFSNodesStatus(live, dead); |
---|
171 | |
---|
172 | sorterField = request.getParameter("sorter/field"); |
---|
173 | sorterOrder = request.getParameter("sorter/order"); |
---|
174 | if ( sorterField == null ) |
---|
175 | sorterField = "name"; |
---|
176 | if ( sorterOrder == null ) |
---|
177 | sorterOrder = "ASC"; |
---|
178 | |
---|
179 | // Find out common suffix. Should this be before or after the sort? |
---|
180 | String port_suffix = null; |
---|
181 | if ( live.size() > 0 ) { |
---|
182 | String name = live.get(0).getName(); |
---|
183 | int idx = name.indexOf(':'); |
---|
184 | if ( idx > 0 ) { |
---|
185 | port_suffix = name.substring( idx ); |
---|
186 | } |
---|
187 | |
---|
188 | for ( int i=1; port_suffix != null && i < live.size(); i++ ) { |
---|
189 | if ( live.get(i).getName().endsWith( port_suffix ) == false ) { |
---|
190 | port_suffix = null; |
---|
191 | break; |
---|
192 | } |
---|
193 | } |
---|
194 | } |
---|
195 | |
---|
196 | counterReset(); |
---|
197 | |
---|
198 | long total = fsn.getCapacityTotal(); |
---|
199 | long remaining = fsn.getCapacityRemaining(); |
---|
200 | long used = fsn.getCapacityUsed(); |
---|
201 | long nonDFS = fsn.getCapacityUsedNonDFS(); |
---|
202 | float percentUsed = fsn.getCapacityUsedPercent(); |
---|
203 | float percentRemaining = fsn.getCapacityRemainingPercent(); |
---|
204 | |
---|
205 | out.print( "<div id=\"dfstable\"> <table>\n" + |
---|
206 | rowTxt() + colTxt() + "Configured Capacity" + colTxt() + ":" + colTxt() + |
---|
207 | StringUtils.byteDesc( total ) + |
---|
208 | rowTxt() + colTxt() + "DFS Used" + colTxt() + ":" + colTxt() + |
---|
209 | StringUtils.byteDesc( used ) + |
---|
210 | rowTxt() + colTxt() + "Non DFS Used" + colTxt() + ":" + colTxt() + |
---|
211 | StringUtils.byteDesc( nonDFS ) + |
---|
212 | rowTxt() + colTxt() + "DFS Remaining" + colTxt() + ":" + colTxt() + |
---|
213 | StringUtils.byteDesc( remaining ) + |
---|
214 | rowTxt() + colTxt() + "DFS Used%" + colTxt() + ":" + colTxt() + |
---|
215 | StringUtils.limitDecimalTo2(percentUsed) + " %" + |
---|
216 | rowTxt() + colTxt() + "DFS Remaining%" + colTxt() + ":" + colTxt() + |
---|
217 | StringUtils.limitDecimalTo2(percentRemaining) + " %" + |
---|
218 | rowTxt() + colTxt() + |
---|
219 | "<a href=\"dfsnodelist.jsp?whatNodes=LIVE\">Live Nodes</a> " + |
---|
220 | colTxt() + ":" + colTxt() + live.size() + |
---|
221 | rowTxt() + colTxt() + |
---|
222 | "<a href=\"dfsnodelist.jsp?whatNodes=DEAD\">Dead Nodes</a> " + |
---|
223 | colTxt() + ":" + colTxt() + dead.size() + |
---|
224 | "</table></div><br>\n" ); |
---|
225 | |
---|
226 | if (live.isEmpty() && dead.isEmpty()) { |
---|
227 | out.print("There are no datanodes in the cluster"); |
---|
228 | } |
---|
229 | } |
---|
230 | private static java.util.List _jspx_dependants; |
---|
231 | |
---|
232 | public Object getDependants() { |
---|
233 | return _jspx_dependants; |
---|
234 | } |
---|
235 | |
---|
236 | public void _jspService(HttpServletRequest request, HttpServletResponse response) |
---|
237 | throws java.io.IOException, ServletException { |
---|
238 | |
---|
239 | JspFactory _jspxFactory = null; |
---|
240 | PageContext pageContext = null; |
---|
241 | HttpSession session = null; |
---|
242 | ServletContext application = null; |
---|
243 | ServletConfig config = null; |
---|
244 | JspWriter out = null; |
---|
245 | Object page = this; |
---|
246 | JspWriter _jspx_out = null; |
---|
247 | PageContext _jspx_page_context = null; |
---|
248 | |
---|
249 | |
---|
250 | try { |
---|
251 | _jspxFactory = JspFactory.getDefaultFactory(); |
---|
252 | response.setContentType("text/html; charset=UTF-8"); |
---|
253 | pageContext = _jspxFactory.getPageContext(this, request, response, |
---|
254 | null, true, 8192, true); |
---|
255 | _jspx_page_context = pageContext; |
---|
256 | application = pageContext.getServletContext(); |
---|
257 | config = pageContext.getServletConfig(); |
---|
258 | session = pageContext.getSession(); |
---|
259 | out = pageContext.getOut(); |
---|
260 | _jspx_out = out; |
---|
261 | |
---|
262 | out.write('\n'); |
---|
263 | out.write('\n'); |
---|
264 | out.write('\n'); |
---|
265 | |
---|
266 | NameNode nn = (NameNode)application.getAttribute("name.node"); |
---|
267 | FSNamesystem fsn = nn.getNamesystem(); |
---|
268 | String namenodeLabel = nn.getNameNodeAddress().getHostName() + ":" + nn.getNameNodeAddress().getPort(); |
---|
269 | |
---|
270 | out.write("\n\n<html>\n\n<link rel=\"stylesheet\" type=\"text/css\" href=\"/static/hadoop.css\">\n<title>Hadoop NameNode "); |
---|
271 | out.print(namenodeLabel); |
---|
272 | out.write("</title>\n \n<body>\n<h1>NameNode '"); |
---|
273 | out.print(namenodeLabel); |
---|
274 | out.write("'</h1>\n\n\n<div id=\"dfstable\"> <table>\t \n<tr> <td id=\"col1\"> Started: <td> "); |
---|
275 | out.print( fsn.getStartTime()); |
---|
276 | out.write("\n<tr> <td id=\"col1\"> Version: <td> "); |
---|
277 | out.print( VersionInfo.getVersion()); |
---|
278 | out.write(','); |
---|
279 | out.write(' '); |
---|
280 | out.write('r'); |
---|
281 | out.print( VersionInfo.getRevision()); |
---|
282 | out.write("\n<tr> <td id=\"col1\"> Compiled: <td> "); |
---|
283 | out.print( VersionInfo.getDate()); |
---|
284 | out.write(" by "); |
---|
285 | out.print( VersionInfo.getUser()); |
---|
286 | out.write("\n<tr> <td id=\"col1\"> Upgrades: <td> "); |
---|
287 | out.print( jspHelper.getUpgradeStatusText()); |
---|
288 | 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>\n\n<hr>\n<h3>Cluster Summary</h3>\n<b> "); |
---|
289 | out.print( jspHelper.getSafeModeText()); |
---|
290 | out.write(" </b>\n<b> "); |
---|
291 | out.print( jspHelper.getInodeLimitText()); |
---|
292 | out.write(" </b>\n<a class=\"warning\"> "); |
---|
293 | out.print( JspHelper.getWarningText(fsn)); |
---|
294 | out.write("</a>\n\n"); |
---|
295 | |
---|
296 | generateDFSHealthReport(out, nn, request); |
---|
297 | |
---|
298 | out.write("\n<hr>\n"); |
---|
299 | |
---|
300 | generateConfReport(out, fsn, request); |
---|
301 | |
---|
302 | out.write('\n'); |
---|
303 | |
---|
304 | out.println(ServletUtil.htmlFooter()); |
---|
305 | |
---|
306 | out.write('\n'); |
---|
307 | } catch (Throwable t) { |
---|
308 | if (!(t instanceof SkipPageException)){ |
---|
309 | out = _jspx_out; |
---|
310 | if (out != null && out.getBufferSize() != 0) |
---|
311 | out.clearBuffer(); |
---|
312 | if (_jspx_page_context != null) _jspx_page_context.handlePageException(t); |
---|
313 | } |
---|
314 | } finally { |
---|
315 | if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context); |
---|
316 | } |
---|
317 | } |
---|
318 | } |
---|