View Javadoc

1   package org.apache.hadoop.hbase.generated.master;
2   
3   import javax.servlet.*;
4   import javax.servlet.http.*;
5   import javax.servlet.jsp.*;
6   import static org.apache.commons.lang.StringEscapeUtils.escapeXml;
7   import java.util.TreeMap;
8   import java.util.List;
9   import java.util.Map;
10  import java.util.Set;
11  import java.util.Collection;
12  import org.owasp.esapi.ESAPI;
13  import org.apache.hadoop.conf.Configuration;
14  import org.apache.hadoop.hbase.client.HTable;
15  import org.apache.hadoop.hbase.client.Admin;
16  import org.apache.hadoop.hbase.client.RegionLocator;
17  import org.apache.hadoop.hbase.HRegionInfo;
18  import org.apache.hadoop.hbase.HRegionLocation;
19  import org.apache.hadoop.hbase.ServerName;
20  import org.apache.hadoop.hbase.ServerLoad;
21  import org.apache.hadoop.hbase.RegionLoad;
22  import org.apache.hadoop.hbase.HConstants;
23  import org.apache.hadoop.hbase.master.HMaster;
24  import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
25  import org.apache.hadoop.hbase.util.Bytes;
26  import org.apache.hadoop.hbase.util.FSUtils;
27  import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.GetRegionInfoResponse.CompactionState;
28  import org.apache.hadoop.hbase.TableName;
29  import org.apache.hadoop.hbase.HColumnDescriptor;
30  import org.apache.hadoop.hbase.client.RegionReplicaUtil;
31  import org.apache.hadoop.hbase.HBaseConfiguration;
32  import org.apache.hadoop.hbase.TableNotFoundException;
33  
34  public final class table_jsp extends org.apache.jasper.runtime.HttpJspBase
35      implements org.apache.jasper.runtime.JspSourceDependent {
36  
37    private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();
38  
39    private static java.util.Vector _jspx_dependants;
40  
41    private org.apache.jasper.runtime.ResourceInjector _jspx_resourceInjector;
42  
43    public Object getDependants() {
44      return _jspx_dependants;
45    }
46  
47    public void _jspService(HttpServletRequest request, HttpServletResponse response)
48          throws java.io.IOException, ServletException {
49  
50      PageContext pageContext = null;
51      HttpSession session = null;
52      ServletContext application = null;
53      ServletConfig config = null;
54      JspWriter out = null;
55      Object page = this;
56      JspWriter _jspx_out = null;
57      PageContext _jspx_page_context = null;
58  
59      try {
60        response.setContentType("text/html;charset=UTF-8");
61        pageContext = _jspxFactory.getPageContext(this, request, response,
62        			null, true, 8192, true);
63        _jspx_page_context = pageContext;
64        application = pageContext.getServletContext();
65        config = pageContext.getServletConfig();
66        session = pageContext.getSession();
67        out = pageContext.getOut();
68        _jspx_out = out;
69        _jspx_resourceInjector = (org.apache.jasper.runtime.ResourceInjector) application.getAttribute("com.sun.appserv.jsp.resource.injector");
70  
71        out.write('\n');
72        out.write('\n');
73  
74    HMaster master = (HMaster)getServletContext().getAttribute(HMaster.MASTER);
75    Configuration conf = master.getConfiguration();
76  
77    MetaTableLocator metaTableLocator = new MetaTableLocator();
78    String fqtn = request.getParameter("name");
79    HTable table = null;
80    String tableHeader;
81    boolean withReplica = false;
82    ServerName rl = metaTableLocator.getMetaRegionLocation(master.getZooKeeper());
83    boolean showFragmentation = conf.getBoolean("hbase.master.ui.fragmentation.enabled", false);
84    boolean readOnly = conf.getBoolean("hbase.master.ui.readonly", false);
85    int numMetaReplicas = conf.getInt(HConstants.META_REPLICAS_NUM,
86                          HConstants.DEFAULT_META_REPLICA_NUM);
87    Map<String, Integer> frags = null;
88    if (showFragmentation) {
89        frags = FSUtils.getTableFragmentation(master);
90    }
91    String action = request.getParameter("action");
92    String key = request.getParameter("key");
93  
94        out.write("\n<!--[if IE]>\n<!DOCTYPE html>\n<![endif]-->\n<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n  <head>\n    <meta charset=\"utf-8\">\n    ");
95   if ( !readOnly && action != null ) { 
96        out.write("\n        <title>HBase Master: ");
97        out.print( master.getServerName() );
98        out.write("</title>\n    ");
99   } else { 
100       out.write("\n        <title>Table: ");
101       out.print( ESAPI.encoder().encodeForHTML(fqtn) );
102       out.write("</title>\n    ");
103  } 
104       out.write("\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <meta name=\"description\" content=\"\">\n    <meta name=\"author\" content=\"\">\n\n\n      <link href=\"/static/css/bootstrap.min.css\" rel=\"stylesheet\">\n      <link href=\"/static/css/bootstrap-theme.min.css\" rel=\"stylesheet\">\n      <link href=\"/static/css/hbase.css\" rel=\"stylesheet\">\n      ");
105  if ( ( !readOnly && action != null ) || fqtn == null ) { 
106       out.write("\n\t  <script type=\"text/javascript\">\n      <!--\n\t\t  setTimeout(\"history.back()\",5000);\n\t  -->\n\t  </script>\n      ");
107  } else { 
108       out.write("\n      <!--[if lt IE 9]>\n          <script src=\"/static/js/html5shiv.js\"></script>\n      <![endif]-->\n      ");
109  } 
110       out.write("\n</head>\n<body>\n<div class=\"navbar  navbar-fixed-top navbar-default\">\n    <div class=\"container-fluid\">\n        <div class=\"navbar-header\">\n            <button type=\"button\" class=\"navbar-toggle\" data-toggle=\"collapse\" data-target=\".navbar-collapse\">\n                <span class=\"icon-bar\"></span>\n                <span class=\"icon-bar\"></span>\n                <span class=\"icon-bar\"></span>\n            </button>\n            <a class=\"navbar-brand\" href=\"/master-status\"><img src=\"/static/hbase_logo_small.png\" alt=\"HBase Logo\"/></a>\n        </div>\n        <div class=\"collapse navbar-collapse\">\n            <ul class=\"nav navbar-nav\">\n                <li><a href=\"/master-status\">Home</a></li>\n                <li><a href=\"/tablesDetailed.jsp\">Table Details</a></li>\n                <li><a href=\"/procedures.jsp\">Procedures</a></li>\n                <li><a href=\"/logs/\">Local Logs</a></li>\n                <li><a href=\"/logLevel\">Log Level</a></li>\n                <li><a href=\"/dump\">Debug Dump</a></li>\n                <li><a href=\"/jmx\">Metrics Dump</a></li>\n");
111       out.write("                ");
112  if (HBaseConfiguration.isShowConfInServlet()) { 
113       out.write("\n                <li><a href=\"/conf\">HBase Configuration</a></li>\n                ");
114  } 
115       out.write("\n            </ul>\n        </div><!--/.nav-collapse -->\n    </div>\n</div>\n");
116 
117 if ( fqtn != null ) {
118   try {
119   table = (HTable) master.getConnection().getTable(TableName.valueOf(fqtn));
120   if (table.getTableDescriptor().getRegionReplication() > 1) {
121     tableHeader = "<h2>Table Regions</h2><table class=\"table table-striped\" style=\"table-layout: fixed; word-wrap: break-word;\"><tr><th style=\"width:22%\">Name</th><th>Region Server</th><th style=\"width:22%\">Start Key</th><th style=\"width:22%\">End Key</th><th>Locality</th><th>Requests</th><th>ReplicaID</th></tr>";
122     withReplica = true;
123   } else {
124     tableHeader = "<h2>Table Regions</h2><table class=\"table table-striped\" style=\"table-layout: fixed; word-wrap: break-word;\"><tr><th style=\"width:22%\">Name</th><th>Region Server</th><th style=\"width:22%\">Start Key</th><th style=\"width:22%\">End Key</th><th>Locality</th><th>Requests</th></tr>";
125   }
126   if ( !readOnly && action != null ) {
127 
128       out.write("\n<div class=\"container-fluid content\">\n        <div class=\"row inner_header\">\n            <div class=\"page-header\">\n                <h1>Table action request accepted</h1>\n            </div>\n        </div>\n<p><hr><p>\n");
129 
130   try (Admin admin = master.getConnection().getAdmin()) {
131     if (action.equals("split")) {
132       if (key != null && key.length() > 0) {
133         admin.splitRegion(Bytes.toBytes(key));
134       } else {
135         admin.split(TableName.valueOf(fqtn));
136       }
137 
138     
139       out.write(" Split request accepted. ");
140 
141     } else if (action.equals("compact")) {
142       if (key != null && key.length() > 0) {
143         admin.compactRegion(Bytes.toBytes(key));
144       } else {
145         admin.compact(TableName.valueOf(fqtn));
146       }
147     
148       out.write(" Compact request accepted. ");
149 
150     }
151   }
152 
153       out.write("\n<p>Go <a href=\"javascript:history.back()\">Back</a>, or wait for the redirect.\n</div>\n");
154 
155   } else {
156 
157       out.write("\n<div class=\"container-fluid content\">\n    <div class=\"row inner_header\">\n        <div class=\"page-header\">\n            <h1>Table <small>");
158       out.print( ESAPI.encoder().encodeForHTML(fqtn) );
159       out.write("</small></h1>\n        </div>\n    </div>\n    <div class=\"row\">\n");
160 
161   if(fqtn.equals(TableName.META_TABLE_NAME.getNameAsString())) {
162 
163       out.write('\n');
164       out.print( tableHeader );
165       out.write('\n');
166 
167   // NOTE: Presumes meta with one or more replicas
168   for (int j = 0; j < numMetaReplicas; j++) {
169     HRegionInfo meta = RegionReplicaUtil.getRegionInfoForReplica(
170                             HRegionInfo.FIRST_META_REGIONINFO, j);
171     ServerName metaLocation = metaTableLocator.waitMetaRegionLocation(master.getZooKeeper(), j, 1);
172     for (int i = 0; i < 1; i++) {
173       String url = "//" + metaLocation.getHostname() + ":" +
174                    master.getRegionServerInfoPort(metaLocation) + "/";
175 
176       out.write("\n<tr>\n  <td>");
177       out.print( escapeXml(meta.getRegionNameAsString()) );
178       out.write("</td>\n    <td><a href=\"");
179       out.print( url );
180       out.write('"');
181       out.write('>');
182       out.print( metaLocation.getHostname().toString() + ":" + master.getRegionServerInfoPort(metaLocation) );
183       out.write("</a></td>\n    <td>");
184       out.print( escapeXml(Bytes.toString(meta.getStartKey())) );
185       out.write("</td>\n    <td>");
186       out.print( escapeXml(Bytes.toString(meta.getEndKey())) );
187       out.write("</td>\n    <td>-</td>\n    <td>-</td>\n</tr>\n");
188   } 
189       out.write('\n');
190 } 
191       out.write("\n</table>\n");
192 } else {
193   Admin admin = master.getConnection().getAdmin();
194   RegionLocator r = master.getClusterConnection().getRegionLocator(table.getName());
195   try { 
196       out.write("\n<h2>Table Attributes</h2>\n<table class=\"table table-striped\">\n  <tr>\n      <th>Attribute Name</th>\n      <th>Value</th>\n      <th>Description</th>\n  </tr>\n  <tr>\n      <td>Enabled</td>\n      <td>");
197       out.print( admin.isTableEnabled(table.getName()) );
198       out.write("</td>\n      <td>Is the table enabled</td>\n  </tr>\n  <tr>\n      <td>Compaction</td>\n      <td>\n");
199 
200   try {
201     CompactionState compactionState = admin.getCompactionState(table.getName());
202 
203       out.write('\n');
204       out.print( compactionState );
205       out.write('\n');
206 
207   } catch (Exception e) {
208   // Nothing really to do here
209     e.printStackTrace();
210 
211       out.write(" Unknown ");
212 
213   }
214 
215       out.write("\n      </td>\n      <td>Is the table compacting</td>\n  </tr>\n");
216   if (showFragmentation) { 
217       out.write("\n  <tr>\n      <td>Fragmentation</td>\n      <td>");
218       out.print( frags.get(fqtn) != null ? frags.get(fqtn).intValue() + "%" : "n/a" );
219       out.write("</td>\n      <td>How fragmented is the table. After a major compaction it is 0%.</td>\n  </tr>\n");
220   } 
221       out.write("\n</table>\n<h2>Table Schema</h2>\n<table class=\"table table-striped\">\n  <tr>\n      <th>Column Name</th>\n      <th></th>\n  </tr>\n  ");
222 
223     Collection<HColumnDescriptor> families = table.getTableDescriptor().getFamilies();
224     for (HColumnDescriptor family: families) {
225   
226       out.write("\n  <tr>\n    <td>");
227       out.print( family.getNameAsString() );
228       out.write("</td>\n    <td>\n    <table class=\"table table-striped\">\n      <tr>\n       <th>Property</th>\n       <th>Value</th>\n      </tr>\n    ");
229 
230     Map<Bytes, Bytes> familyValues = family.getValues();
231     for (Bytes familyKey: familyValues.keySet()) {
232     
233       out.write("\n      <tr>\n        <td>\n          ");
234       out.print( familyKey );
235       out.write("\n\t\t</td>\n        <td>\n          ");
236       out.print( familyValues.get(familyKey) );
237       out.write("\n        </td>\n      </tr>\n    ");
238  } 
239       out.write("\n    </table>\n    </td>\n  </tr>\n  ");
240  } 
241       out.write("\n</table>\n");
242 
243   Map<ServerName, Integer> regDistribution = new TreeMap<ServerName, Integer>();
244   Map<ServerName, Integer> primaryRegDistribution = new TreeMap<ServerName, Integer>();
245   List<HRegionLocation> regions = r.getAllRegionLocations();
246   if(regions != null && regions.size() > 0) { 
247       out.write('\n');
248       out.print(     tableHeader );
249       out.write('\n');
250 
251   for (HRegionLocation hriEntry : regions) {
252     HRegionInfo regionInfo = hriEntry.getRegionInfo();
253     ServerName addr = hriEntry.getServerName();
254     long req = 0;
255     float locality = 0.0f;
256     String urlRegionServer = null;
257 
258     if (addr != null) {
259       ServerLoad sl = master.getServerManager().getLoad(addr);
260       if (sl != null) {
261         Map<byte[], RegionLoad> map = sl.getRegionsLoad();
262         if (map.containsKey(regionInfo.getRegionName())) {
263           req = map.get(regionInfo.getRegionName()).getRequestsCount();
264           locality = map.get(regionInfo.getRegionName()).getDataLocality();
265         }
266         Integer i = regDistribution.get(addr);
267         if (null == i) i = Integer.valueOf(0);
268         regDistribution.put(addr, i + 1);
269         if (withReplica && RegionReplicaUtil.isDefaultReplica(regionInfo.getReplicaId())) {
270           i = primaryRegDistribution.get(addr);
271           if (null == i) i = Integer.valueOf(0);
272           primaryRegDistribution.put(addr, i+1);
273         }
274       }
275     }
276 
277       out.write("\n<tr>\n  <td>");
278       out.print( escapeXml(Bytes.toStringBinary(HRegionInfo.getRegionNameForDisplay(regionInfo,
279                     conf))) );
280       out.write("</td>\n  ");
281 
282   if (addr != null) {
283     String url = "//" + addr.getHostname() + ":" + master.getRegionServerInfoPort(addr) + "/rs-status";
284   
285       out.write("\n  <td>\n     <a href=\"");
286       out.print( url );
287       out.write('"');
288       out.write('>');
289       out.print( addr.getHostname().toString() + ":" + addr.getPort() );
290       out.write("</a>\n  </td>\n  ");
291 
292   } else {
293   
294       out.write("\n  <td class=\"undeployed-region\">not deployed</td>\n  ");
295 
296   }
297   
298       out.write("\n  <td>");
299       out.print( escapeXml(Bytes.toStringBinary(HRegionInfo.getStartKeyForDisplay(regionInfo,
300                     conf))) );
301       out.write("</td>\n  <td>");
302       out.print( escapeXml(Bytes.toStringBinary(HRegionInfo.getEndKeyForDisplay(regionInfo,
303                     conf))) );
304       out.write("</td>\n  <td>");
305       out.print( locality);
306       out.write("</td>\n  <td>");
307       out.print( req);
308       out.write("</td>\n  ");
309 
310   if (withReplica) {
311   
312       out.write("\n  <td>");
313       out.print( regionInfo.getReplicaId() );
314       out.write("</td>\n  ");
315 
316   }
317   
318       out.write("\n</tr>\n");
319  } 
320       out.write("\n</table>\n<h2>Regions by Region Server</h2>\n");
321 
322 if (withReplica) {
323 
324       out.write("\n<table class=\"table table-striped\"><tr><th>Region Server</th><th>Region Count</th><th>Primary Region Count</th></tr>\n");
325 
326 } else {
327 
328       out.write("\n<table class=\"table table-striped\"><tr><th>Region Server</th><th>Region Count</th></tr>\n");
329 
330 }
331 
332       out.write('\n');
333 
334   for (Map.Entry<ServerName, Integer> rdEntry : regDistribution.entrySet()) {
335      ServerName addr = rdEntry.getKey();
336      String url = "//" + addr.getHostname() + ":" + master.getRegionServerInfoPort(addr) + "/";
337 
338       out.write("\n<tr>\n  <td><a href=\"");
339       out.print( url );
340       out.write('"');
341       out.write('>');
342       out.print( addr.getHostname().toString() + ":" + addr.getPort() );
343       out.write("</a></td>\n  <td>");
344       out.print( rdEntry.getValue());
345       out.write("</td>\n");
346 
347 if (withReplica) {
348 
349       out.write("\n  <td>");
350       out.print( primaryRegDistribution.get(addr));
351       out.write("</td>\n");
352 
353 }
354 
355       out.write("\n</tr>\n");
356  } 
357       out.write("\n</table>\n");
358  }
359 } catch(Exception ex) {
360   ex.printStackTrace(System.err);
361 } finally {
362   admin.close();
363 }
364 } // end else
365 
366       out.write("\n\n\n");
367  if (!readOnly) { 
368       out.write("\n<p><hr/></p>\nActions:\n<p>\n<center>\n<table class=\"table\" width=\"95%\" >\n<tr>\n  <form method=\"get\">\n  <input type=\"hidden\" name=\"action\" value=\"compact\">\n  <input type=\"hidden\" name=\"name\" value=\"");
369       out.print( fqtn );
370       out.write("\">\n  <td style=\"border-style: none; text-align: center\">\n      <input style=\"font-size: 12pt; width: 10em\" type=\"submit\" value=\"Compact\" class=\"btn\"></td>\n  <td style=\"border-style: none\" width=\"5%\">&nbsp;</td>\n  <td style=\"border-style: none\">Region Key (optional):<input type=\"text\" name=\"key\" size=\"40\"></td>\n  <td style=\"border-style: none\">This action will force a compaction of all\n  regions of the table, or, if a key is supplied, only the region containing the\n  given key.</td>\n  </form>\n</tr>\n<tr><td style=\"border-style: none\" colspan=\"4\">&nbsp;</td></tr>\n<tr>\n  <form method=\"get\">\n  <input type=\"hidden\" name=\"action\" value=\"split\">\n  <input type=\"hidden\" name=\"name\" value=\"");
371       out.print( fqtn );
372       out.write("\">\n  <td style=\"border-style: none; text-align: center\">\n      <input style=\"font-size: 12pt; width: 10em\" type=\"submit\" value=\"Split\" class=\"btn\"></td>\n  <td style=\"border-style: none\" width=\"5%\">&nbsp;</td>\n  <td style=\"border-style: none\">Region Key (optional):<input type=\"text\" name=\"key\" size=\"40\"></td>\n  <td style=\"border-style: none\">This action will force a split of all eligible\n  regions of the table, or, if a key is supplied, only the region containing the\n  given key. An eligible region is one that does not contain any references to\n  other regions. Split requests for noneligible regions will be ignored.</td>\n  </form>\n</tr>\n</table>\n</center>\n</p>\n");
373  } 
374       out.write("\n</div>\n</div>\n");
375  }
376   } catch(TableNotFoundException e) { 
377       out.write("\n  <div class=\"container-fluid content\">\n    <div class=\"row inner_header\">\n      <div class=\"page-header\">\n        <h1>Table not found</h1>\n       </div>\n    </div>\n    <p><hr><p>\n    <p>Go <a href=\"javascript:history.back()\">Back</a>\n  </div> ");
378 
379   } catch(IllegalArgumentException e) { 
380       out.write("\n  <div class=\"container-fluid content\">\n    <div class=\"row inner_header\">\n      <div class=\"page-header\">\n        <h1>Table qualifier must not be empty</h1>\n      </div>\n    </div>\n    <p><hr><p>\n    <p>Go <a href=\"javascript:history.back()\">Back</a>\n  </div> ");
381 
382   }
383 }
384   else { // handle the case for fqtn is null with error message + redirect
385 
386       out.write("\n<div class=\"container-fluid content\">\n    <div class=\"row inner_header\">\n        <div class=\"page-header\">\n            <h1>Table not ready</h1>\n        </div>\n    </div>\n<p><hr><p>\n<p>Go <a href=\"javascript:history.back()\">Back</a>, or wait for the redirect.\n</div>\n");
387  } 
388       out.write("\n<script src=\"/static/js/jquery.min.js\" type=\"text/javascript\"></script>\n<script src=\"/static/js/bootstrap.min.js\" type=\"text/javascript\"></script>\n\n</body>\n</html>\n");
389     } catch (Throwable t) {
390       if (!(t instanceof SkipPageException)){
391         out = _jspx_out;
392         if (out != null && out.getBufferSize() != 0)
393           out.clearBuffer();
394         if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
395       }
396     } finally {
397       _jspxFactory.releasePageContext(_jspx_page_context);
398     }
399   }
400 }