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