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 java.util.HashMap;
7   import org.apache.hadoop.io.Writable;
8   import org.apache.hadoop.conf.Configuration;
9   import org.apache.hadoop.hbase.client.HTable;
10  import org.apache.hadoop.hbase.client.HBaseAdmin;
11  import org.apache.hadoop.hbase.client.HConnectionManager;
12  import org.apache.hadoop.hbase.HRegionInfo;
13  import org.apache.hadoop.hbase.ServerName;
14  import org.apache.hadoop.hbase.HServerAddress;
15  import org.apache.hadoop.hbase.ServerName;
16  import org.apache.hadoop.hbase.HServerInfo;
17  import org.apache.hadoop.hbase.HServerLoad;
18  import org.apache.hadoop.hbase.HServerLoad.RegionLoad;
19  import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
20  import org.apache.hadoop.hbase.master.HMaster;
21  import org.apache.hadoop.hbase.util.Bytes;
22  import org.apache.hadoop.hbase.util.FSUtils;
23  import java.util.Map;
24  import org.apache.hadoop.hbase.HConstants;
25  
26  public final class table_jsp extends org.apache.jasper.runtime.HttpJspBase
27      implements org.apache.jasper.runtime.JspSourceDependent {
28  
29    private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();
30  
31    private static java.util.Vector _jspx_dependants;
32  
33    private org.apache.jasper.runtime.ResourceInjector _jspx_resourceInjector;
34  
35    public Object getDependants() {
36      return _jspx_dependants;
37    }
38  
39    public void _jspService(HttpServletRequest request, HttpServletResponse response)
40          throws java.io.IOException, ServletException {
41  
42      PageContext pageContext = null;
43      HttpSession session = null;
44      ServletContext application = null;
45      ServletConfig config = null;
46      JspWriter out = null;
47      Object page = this;
48      JspWriter _jspx_out = null;
49      PageContext _jspx_page_context = null;
50  
51      try {
52        response.setContentType("text/html;charset=UTF-8");
53        pageContext = _jspxFactory.getPageContext(this, request, response,
54        			null, true, 8192, true);
55        _jspx_page_context = pageContext;
56        application = pageContext.getServletContext();
57        config = pageContext.getServletConfig();
58        session = pageContext.getSession();
59        out = pageContext.getOut();
60        _jspx_out = out;
61        _jspx_resourceInjector = (org.apache.jasper.runtime.ResourceInjector) application.getAttribute("com.sun.appserv.jsp.resource.injector");
62  
63        out.write('\n');
64  
65    HMaster master = (HMaster)getServletContext().getAttribute(HMaster.MASTER);
66    Configuration conf = master.getConfiguration();
67    HBaseAdmin hbadmin = new HBaseAdmin(conf);
68    String tableName = request.getParameter("name");
69    HTable table = new HTable(conf, tableName);
70    String tableHeader = "<h2>Table Regions</h2><table><tr><th>Name</th><th>Region Server</th><th>Start Key</th><th>End Key</th><th>Requests</th></tr>";
71    ServerName rl = master.getCatalogTracker().getRootLocation();
72    boolean showFragmentation = conf.getBoolean("hbase.master.ui.fragmentation.enabled", false);
73    boolean readOnly = conf.getBoolean("hbase.master.ui.readonly", false);
74    Map<String, Integer> frags = null;
75    if (showFragmentation) {
76        frags = FSUtils.getTableFragmentation(master);
77    }
78    // HARDCODED FOR NOW TODO: FIX GET FROM ZK
79    // This port might be wrong if RS actually ended up using something else.
80    int infoPort = conf.getInt("hbase.regionserver.info.port", 60030);
81  
82        out.write("\n\n<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<!-- Commenting out DOCTYPE so our blue outline shows on hadoop 0.20.205.0, etc.\n     See tail of HBASE-2110 for explaination.\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \n  \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> \n-->\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n\n");
83  
84    String action = request.getParameter("action");
85    String key = request.getParameter("key");
86    if ( !readOnly && action != null ) {
87  
88        out.write("\n<head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\"/>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"/static/hbase.css\" />\n<meta http-equiv=\"refresh\" content=\"5,javascript:history.back()\" />\n</head>\n<body>\n<a id=\"logo\" href=\"http://wiki.apache.org/lucene-hadoop/Hbase\"><img src=\"/static/hbase_logo.png\" alt=\"HBase Logo\" title=\"HBase Logo\" /></a>\n<h1 id=\"page_title\">Table action request accepted</h1>\n<p><hr><p>\n");
89  
90    if (action.equals("split")) {
91      if (key != null && key.length() > 0) {
92        hbadmin.split(key);
93      } else {
94        hbadmin.split(tableName);
95      }
96      
97      
98        out.write(" Split request accepted. ");
99  
100   } else if (action.equals("compact")) {
101     if (key != null && key.length() > 0) {
102       hbadmin.compact(key);
103     } else {
104       hbadmin.compact(tableName);
105     }
106     
107       out.write(" Compact request accepted. ");
108 
109   }
110 
111       out.write("\n<p>Go <a href=\"javascript:history.back()\">Back</a>, or wait for the redirect.\n\n</body>\n");
112 
113 } else {
114 
115       out.write("\n<head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\"/>\n<title>Table: ");
116       out.print( tableName );
117       out.write("</title>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"/static/hbase.css\" />\n</head>\n<body>\n<a id=\"logo\" href=\"http://wiki.apache.org/lucene-hadoop/Hbase\"><img src=\"/static/hbase_logo.png\" alt=\"HBase Logo\" title=\"HBase Logo\" /></a>\n<h1 id=\"page_title\">Table: ");
118       out.print( tableName );
119       out.write("</h1>\n<p id=\"links_menu\"><a href=\"/master.jsp\">Master</a>, <a href=\"/logs/\">Local logs</a>, <a href=\"/stacks\">Thread Dump</a>, <a href=\"/logLevel\">Log Level</a></p>\n<hr id=\"head_rule\" />\n");
120 
121   if(tableName.equals(Bytes.toString(HConstants.ROOT_TABLE_NAME))) {
122 
123       out.write('\n');
124       out.print( tableHeader );
125       out.write('\n');
126 
127   String url = "http://" + rl.getHostname() + ":" + infoPort + "/";
128 
129       out.write("\n<tr>\n  <td>");
130       out.print( tableName );
131       out.write("</td>\n  <td><a href=\"");
132       out.print( url );
133       out.write('"');
134       out.write('>');
135       out.print( rl.getHostname() );
136       out.write(':');
137       out.print( rl.getPort() );
138       out.write("</a></td>\n  <td>-</td>\n  <td></td>\n  <td>-</td>\n</tr>\n</table>\n");
139 
140   } else if(tableName.equals(Bytes.toString(HConstants.META_TABLE_NAME))) {
141 
142       out.write('\n');
143       out.print( tableHeader );
144       out.write('\n');
145 
146   // NOTE: Presumes one meta region only.
147   HRegionInfo meta = HRegionInfo.FIRST_META_REGIONINFO;
148   ServerName metaLocation = master.getCatalogTracker().waitForMeta(1);
149   for (int i = 0; i < 1; i++) {
150     String url = "http://" + metaLocation.getHostname() + ":" + infoPort + "/";
151 
152       out.write("\n<tr>\n  <td>");
153       out.print( meta.getRegionNameAsString() );
154       out.write("</td>\n    <td><a href=\"");
155       out.print( url );
156       out.write('"');
157       out.write('>');
158       out.print( metaLocation.getHostname().toString() + ":" + infoPort );
159       out.write("</a></td>\n    <td>-</td><td>");
160       out.print( Bytes.toString(meta.getStartKey()) );
161       out.write("</td><td>");
162       out.print( Bytes.toString(meta.getEndKey()) );
163       out.write("</td>\n</tr>\n");
164   } 
165       out.write("\n</table>\n");
166 } else {
167   try { 
168       out.write("\n<h2>Table Attributes</h2>\n<table>\n  <tr>\n      <th>Attribute Name</th>\n      <th>Value</th>\n      <th>Description</th></tr>\n  <tr>\n      <td>Enabled</td>\n      <td>");
169       out.print( hbadmin.isTableEnabled(table.getTableName()) );
170       out.write("</td>\n      <td>Is the table enabled</td>\n  </tr>\n  <tr>\n      <td>Compaction</td>\n      <td>");
171       out.print( hbadmin.getCompactionState(table.getTableName()) );
172       out.write("</td>\n      <td>Is the table compacting</td>\n  </tr>\n");
173   if (showFragmentation) { 
174       out.write("\n  <tr>\n      <td>Fragmentation</td>\n      <td>");
175       out.print( frags.get(tableName) != null ? frags.get(tableName).intValue() + "%" : "n/a" );
176       out.write("</td>\n      <td>How fragmented is the table. After a major compaction it is 0%.</td>\n  </tr>\n");
177   } 
178       out.write("\n</table>\n");
179 
180   Map<String, Integer> regDistribution = new HashMap<String, Integer>();
181   Map<HRegionInfo, ServerName> regions = table.getRegionLocations();
182   if(regions != null && regions.size() > 0) { 
183       out.write('\n');
184       out.print(     tableHeader );
185       out.write('\n');
186 
187   for (Map.Entry<HRegionInfo, ServerName> hriEntry : regions.entrySet()) {
188     HRegionInfo regionInfo = hriEntry.getKey();
189     ServerName addr = hriEntry.getValue();
190     long req = 0;
191 
192     String urlRegionServer = null;
193 
194     if (addr != null) {
195       HServerLoad sl = master.getServerManager().getLoad(addr);
196       if (sl != null) {
197         Map<byte[], RegionLoad> map = sl.getRegionsLoad();
198         if (map.containsKey(regionInfo.getRegionName())) {
199           req = map.get(regionInfo.getRegionName()).getRequestsCount();
200         }
201         // This port might be wrong if RS actually ended up using something else.
202         urlRegionServer =
203             "http://" + addr.getHostname().toString() + ":" + infoPort + "/";
204         Integer i = regDistribution.get(urlRegionServer);
205         if (null == i) i = new Integer(0);
206         regDistribution.put(urlRegionServer, i+1);
207       }
208     }
209 
210       out.write("\n<tr>\n  <td>");
211       out.print( Bytes.toStringBinary(regionInfo.getRegionName()));
212       out.write("</td>\n  ");
213 
214   if (urlRegionServer != null) {
215   
216       out.write("\n  <td>\n    <a href=\"");
217       out.print( urlRegionServer );
218       out.write('"');
219       out.write('>');
220       out.print( addr.getHostname().toString() + ":" + infoPort );
221       out.write("</a>\n  </td>\n  ");
222 
223   } else {
224   
225       out.write("\n  <td class=\"undeployed-region\">not deployed</td>\n  ");
226 
227   }
228   
229       out.write("\n  <td>");
230       out.print( Bytes.toStringBinary(regionInfo.getStartKey()));
231       out.write("</td>\n  <td>");
232       out.print( Bytes.toStringBinary(regionInfo.getEndKey()));
233       out.write("</td>\n  <td>");
234       out.print( req);
235       out.write("</td>\n</tr>\n");
236  } 
237       out.write("\n</table>\n<h2>Regions by Region Server</h2>\n<table><tr><th>Region Server</th><th>Region Count</th></tr>\n");
238 
239   for (Map.Entry<String, Integer> rdEntry : regDistribution.entrySet()) {
240 
241       out.write("\n<tr>\n  <td>");
242       out.print( rdEntry.getKey());
243       out.write("</td>\n  <td>");
244       out.print( rdEntry.getValue());
245       out.write("</td>\n</tr>\n");
246  } 
247       out.write("\n</table>\n");
248  }
249 } catch(Exception ex) {
250   ex.printStackTrace(System.err);
251 }
252 } // end else
253 
254 HConnectionManager.deleteConnection(hbadmin.getConfiguration());
255 
256       out.write("\n\n\n");
257  if (!readOnly) { 
258       out.write("\n<p><hr><p>\nActions:\n<p>\n<center>\n<table style=\"border-style: none\" width=\"90%\">\n<tr>\n  <form method=\"get\">\n  <input type=\"hidden\" name=\"action\" value=\"compact\">\n  <input type=\"hidden\" name=\"name\" value=\"");
259       out.print( tableName );
260       out.write("\">\n  <td style=\"border-style: none; text-align: center\">\n      <input style=\"font-size: 12pt; width: 10em\" type=\"submit\" value=\"Compact\"></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=\"");
261       out.print( tableName );
262       out.write("\">\n  <td style=\"border-style: none; text-align: center\">\n      <input style=\"font-size: 12pt; width: 10em\" type=\"submit\" value=\"Split\"></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");
263  } 
264       out.write('\n');
265 
266 }
267 
268       out.write("\n\n</body>\n</html>\n");
269     } catch (Throwable t) {
270       if (!(t instanceof SkipPageException)){
271         out = _jspx_out;
272         if (out != null && out.getBufferSize() != 0)
273           out.clearBuffer();
274         if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
275       }
276     } finally {
277       _jspxFactory.releasePageContext(_jspx_page_context);
278     }
279   }
280 }