session = pageContext.getSession();
out = pageContext.getOut();
_jspx_out = out;
HMaster master = (HMaster)getServletContext().getAttribute(HMaster.MASTER);
Configuration conf = master.getConfiguration();
HBaseAdmin hbadmin = new HBaseAdmin(conf);
String tableName = request.getParameter("name");
HTable table = new HTable(conf, tableName);
String tableHeader = "<h2>Table Regions</h2><table><tr><th>Name</th><th>Region Server</th><th>Start Key</th><th>End Key</th></tr>";
HServerAddress rootLocation = master.getRegionManager().getRootRegionLocation();
boolean showFragmentation = conf.getBoolean("hbase.master.ui.fragmentation.enabled", false);
Map<String, Integer> frags = null;
if (showFragmentation) {
frags = master.getTableFragmentation();
}
out.write("\n\n<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \n \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> \n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n\n");
String action = request.getParameter("action");
String key = request.getParameter("key");
if ( action != null ) {
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</head>\n<body>\n<a id=\"logo\" href=\"http://wiki.apache.org/lucene-hadoop/Hbase\"><img src=\"/static/hbase_logo_med.gif\" alt=\"HBase Logo\" title=\"HBase Logo\" /></a>\n<h1 id=\"page_title\">Table action request accepted</h1>\n<p><hr><p>\n");
if (action.equals("split")) {
if (key != null && key.length() > 0) {
Writable[] arr = new Writable[1];
arr[0] = new ImmutableBytesWritable(Bytes.toBytes(key));
master.modifyTable(Bytes.toBytes(tableName), HConstants.Modify.TABLE_SPLIT, arr);
} else {
master.modifyTable(Bytes.toBytes(tableName), HConstants.Modify.TABLE_SPLIT, null);
}
out.write(" Split request accepted. ");
} else if (action.equals("compact")) {
if (key != null && key.length() > 0) {
Writable[] arr = new Writable[1];
arr[0] = new ImmutableBytesWritable(Bytes.toBytes(key));
master.modifyTable(Bytes.toBytes(tableName), HConstants.Modify.TABLE_COMPACT, arr);
} else {
master.modifyTable(Bytes.toBytes(tableName), HConstants.Modify.TABLE_COMPACT, null);
}
out.write(" Compact request accepted. ");
}
out.write("\n<p>Reload.\n</body>\n");
} else {
out.write("\n<head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\"/>\n<title>Table: ");
out.print( tableName );
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_med.gif\" alt=\"HBase Logo\" title=\"HBase Logo\" /></a>\n<h1 id=\"page_title\">Table: ");
out.print( tableName );
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");
if(tableName.equals(Bytes.toString(HConstants.ROOT_TABLE_NAME))) {
out.write('\n');
out.print( tableHeader );
out.write('\n');
int infoPort = master.getServerManager().getHServerInfo(rootLocation).getInfoPort();
String url = "http://" + rootLocation.getHostname() + ":" + infoPort + "/";
out.write("\n<tr>\n <td>");
out.print( tableName );
out.write("</td>\n <td><a href=\"");
out.print( url );
out.write('"');
out.write('>');
out.print( rootLocation.getHostname() );
out.write(':');
out.print( rootLocation.getPort() );
out.write("</a></td>\n <td>-</td>\n <td></td>\n <td>-</td>\n</tr>\n</table>\n");
} else if(tableName.equals(Bytes.toString(HConstants.META_TABLE_NAME))) {
out.write('\n');
out.print( tableHeader );
out.write('\n');
Map<byte [], MetaRegion> onlineRegions = master.getRegionManager().getOnlineMetaRegions();
for (MetaRegion meta: onlineRegions.values()) {
int infoPort = master.getServerManager().getHServerInfo(meta.getServer()).getInfoPort();
String url = "http://" + meta.getServer().getHostname() + ":" + infoPort + "/";
out.write("\n<tr>\n <td>");
out.print( Bytes.toString(meta.getRegionName()) );
out.write("</td>\n <td><a href=\"");
out.print( url );
out.write('"');
out.write('>');
out.print( meta.getServer().getHostname().toString() + ":" + infoPort );
out.write("</a></td>\n <td>-</td><td>");
out.print( Bytes.toString(meta.getStartKey()) );
out.write("</td><td>");
out.print( Bytes.toString(meta.getEndKey()) );
out.write("</td>\n</tr>\n");
}
out.write("\n</table>\n");
} else {
try {
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>");
out.print( hbadmin.isTableEnabled(table.getTableName()) );
out.write("</td>\n <td>Is the table enabled</td>\n </tr>\n");
if (showFragmentation) {
out.write("\n <tr>\n <td>Fragmentation</td>\n <td>");
out.print( frags.get(tableName) != null ? frags.get(tableName).intValue() + "%" : "n/a" );
out.write("</td>\n <td>How fragmented is the table. After a major compaction it is 0%.</td>\n </tr>\n");
}
out.write("\n</table>\n");
Map<HRegionInfo, HServerAddress> regions = table.getRegionsInfo();
if(regions != null && regions.size() > 0) {
out.write('\n');
out.print( tableHeader );
out.write('\n');
for(Map.Entry<HRegionInfo, HServerAddress> hriEntry : regions.entrySet()) {
int infoPort = master.getServerManager().getHServerInfo(hriEntry.getValue()).getInfoPort();
String urlRegionServer =
"http://" + hriEntry.getValue().getHostname().toString() + ":" + infoPort + "/";
out.write("\n<tr>\n <td>");
out.print( Bytes.toStringBinary(hriEntry.getKey().getRegionName()));