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