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 com.google.protobuf.ByteString;
8   import java.util.ArrayList;
9   import java.util.TreeMap;
10  import java.util.List;
11  import java.util.LinkedHashMap;
12  import java.util.Map;
13  import java.util.Set;
14  import java.util.Collection;
15  import java.util.Collections;
16  import java.util.Comparator;
17  import org.owasp.esapi.ESAPI;
18  import org.apache.hadoop.conf.Configuration;
19  import org.apache.hadoop.util.StringUtils;
20  import org.apache.hadoop.hbase.HRegionInfo;
21  import org.apache.hadoop.hbase.HRegionLocation;
22  import org.apache.hadoop.hbase.ServerName;
23  import org.apache.hadoop.hbase.ServerLoad;
24  import org.apache.hadoop.hbase.RegionLoad;
25  import org.apache.hadoop.hbase.HConstants;
26  import org.apache.hadoop.hbase.master.HMaster;
27  import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
28  import org.apache.hadoop.hbase.util.Bytes;
29  import org.apache.hadoop.hbase.util.FSUtils;
30  import org.apache.hadoop.hbase.protobuf.generated.ClusterStatusProtos;
31  import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos;
32  import org.apache.hadoop.hbase.TableName;
33  import org.apache.hadoop.hbase.HColumnDescriptor;
34  import org.apache.hadoop.hbase.HBaseConfiguration;
35  import org.apache.hadoop.hbase.TableNotFoundException;
36  import org.apache.hadoop.hbase.client.*;
37
38  public final class table_jsp extends org.apache.jasper.runtime.HttpJspBase
39      implements org.apache.jasper.runtime.JspSourceDependent {
40
41    private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();
42
43    private static java.util.Vector _jspx_dependants;
44
45    private org.apache.jasper.runtime.ResourceInjector _jspx_resourceInjector;
46  
47    public Object getDependants() {
48      return _jspx_dependants;
49    }
50
51    public void _jspService(HttpServletRequest request, HttpServletResponse response)
52          throws java.io.IOException, ServletException {
53
54      PageContext pageContext = null;
55      HttpSession session = null;
56      ServletContext application = null;
57      ServletConfig config = null;
58      JspWriter out = null;
59      Object page = this;
60      JspWriter _jspx_out = null;
61      PageContext _jspx_page_context = null;
62
63      try {
64        response.setContentType("text/html;charset=UTF-8");
65        pageContext = _jspxFactory.getPageContext(this, request, response,
66        			null, true, 8192, true);
67        _jspx_page_context = pageContext;
68        application = pageContext.getServletContext();
69        config = pageContext.getServletConfig();
70        session = pageContext.getSession();
71        out = pageContext.getOut();
72        _jspx_out = out;
73        _jspx_resourceInjector = (org.apache.jasper.runtime.ResourceInjector) application.getAttribute("com.sun.appserv.jsp.resource.injector");
74
75        out.write("\n\n\n");
76
77    HMaster master = (HMaster)getServletContext().getAttribute(HMaster.MASTER);
78    Configuration conf = master.getConfiguration();
79
80    MetaTableLocator metaTableLocator = new MetaTableLocator();
81    String fqtn = request.getParameter("name");
82    String sortKey = request.getParameter("sort");
83    String reverse = request.getParameter("reverse");
84    final boolean reverseOrder = (reverse==null||!reverse.equals("false"));
85    String showWholeKey = request.getParameter("showwhole");
86    final boolean showWhole = (showWholeKey!=null && showWholeKey.equals("true"));
87    Table table;
88    String tableHeader;
89    boolean withReplica = false;
90    ServerName rl = metaTableLocator.getMetaRegionLocation(master.getZooKeeper());
91    boolean showFragmentation = conf.getBoolean("hbase.master.ui.fragmentation.enabled", false);
92    boolean readOnly = conf.getBoolean("hbase.master.ui.readonly", false);
93    int numMetaReplicas = conf.getInt(HConstants.META_REPLICAS_NUM,
94                          HConstants.DEFAULT_META_REPLICA_NUM);
95    Map<String, Integer> frags = null;
96    if (showFragmentation) {
97        frags = FSUtils.getTableFragmentation(master);
98    }
99    String action = request.getParameter("action");
100   String key = request.getParameter("key");
101
102       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    ");
103  if ( !readOnly && action != null ) {
104       out.write("\n        <title>HBase Master: ");
105       out.print( master.getServerName() );
106       out.write("</title>\n    ");
107  } else {
108       out.write("\n        <title>Table: ");
109       out.print( ESAPI.encoder().encodeForHTML(fqtn) );
110       out.write("</title>\n    ");
111  }
112       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      ");
113  if ( ( !readOnly && action != null ) || fqtn == null ) {
114       out.write("\n\t  <script type=\"text/javascript\">\n      <!--\n\t\t  setTimeout(\"history.back()\",5000);\n\t  -->\n\t  </script>\n      ");
115  } else {
116       out.write("\n      <!--[if lt IE 9]>\n          <script src=\"/static/js/html5shiv.js\"></script>\n      <![endif]-->\n      ");
117  }
118       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");
119       out.write("                ");
120  if (HBaseConfiguration.isShowConfInServlet()) {
121       out.write("\n                <li><a href=\"/conf\">HBase Configuration</a></li>\n                ");
122  }
123       out.write("\n            </ul>\n        </div><!--/.nav-collapse -->\n    </div>\n</div>\n");
124
125 if ( fqtn != null ) {
126   try {
127   table = master.getConnection().getTable(TableName.valueOf(fqtn));
128   if (table.getTableDescriptor().getRegionReplication() > 1) {
129     tableHeader = "<h2>Table Regions</h2><table class=\"table table-striped\" style=\"table-layout: fixed; word-wrap: break-word;\"><tr><th>Name</th><th>Region Server</th><th>ReadRequests</th><th>WriteRequests</th><th>StorefileSize</th><th>Num.Storefiles</th><th>MemSize</th><th>Locality</th><th>Start Key</th><th>End Key</th><th>ReplicaID</th></tr>";
130     withReplica = true;
131   } else {
132     tableHeader = "<h2>Table Regions</h2><table class=\"table table-striped\" style=\"table-layout: fixed; word-wrap: break-word;\"><tr><th>Name</th><th>Region Server</th><th>ReadRequests</th><th>WriteRequests</th><th>StorefileSize</th><th>Num.Storefiles</th><th>MemSize</th><th>Locality</th><th>Start Key</th><th>End Key</th></tr>";
133   }
134   if ( !readOnly && action != null ) {
135
136       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");
137
138   try (Admin admin = master.getConnection().getAdmin()) {
139     if (action.equals("split")) {
140       if (key != null && key.length() > 0) {
141         admin.splitRegion(Bytes.toBytes(key));
142       } else {
143         admin.split(TableName.valueOf(fqtn));
144       }
145
146
147       out.write(" Split request accepted. ");
148
149     } else if (action.equals("compact")) {
150       if (key != null && key.length() > 0) {
151         admin.compactRegion(Bytes.toBytes(key));
152       } else {
153         admin.compact(TableName.valueOf(fqtn));
154       }
155
156       out.write(" Compact request accepted. ");
157
158     }
159   }
160
161       out.write("\n<p>Go <a href=\"javascript:history.back()\">Back</a>, or wait for the redirect.\n</div>\n");
162 
163   } else {
164
165       out.write("\n<div class=\"container-fluid content\">\n    <div class=\"row inner_header\">\n        <div class=\"page-header\">\n            <h1>Table <small>");
166       out.print( ESAPI.encoder().encodeForHTML(fqtn) );
167       out.write("</small></h1>\n        </div>\n    </div>\n    <div class=\"row\">\n");
168
169   if(fqtn.equals(TableName.META_TABLE_NAME.getNameAsString())) {
170
171       out.write('\n');
172       out.print( tableHeader );
173       out.write('\n');
174
175   // NOTE: Presumes meta with one or more replicas
176   for (int j = 0; j < numMetaReplicas; j++) {
177     HRegionInfo meta = RegionReplicaUtil.getRegionInfoForReplica(
178                             HRegionInfo.FIRST_META_REGIONINFO, j);
179     ServerName metaLocation = metaTableLocator.waitMetaRegionLocation(master.getZooKeeper(), j, 1);
180     for (int i = 0; i < 1; i++) {
181       String url = "";
182       String readReq = "N/A";
183       String writeReq = "N/A";
184       String fileSize = "N/A";
185       String fileCount = "N/A";
186       String memSize = "N/A";
187       float locality = 0.0f;
188
189       if (metaLocation != null) {
190         ServerLoad sl = master.getServerManager().getLoad(metaLocation);
191         url = "//" + metaLocation.getHostname() + ":" + master.getRegionServerInfoPort(metaLocation) + "/";
192         if (sl != null) {
193           Map<byte[], RegionLoad> map = sl.getRegionsLoad();
194           if (map.containsKey(meta.getRegionName())) {
195             RegionLoad load = map.get(meta.getRegionName());
196             readReq = String.format("%,1d", load.getReadRequestsCount());
197             writeReq = String.format("%,1d", load.getWriteRequestsCount());
198             fileSize = StringUtils.byteDesc(load.getStorefileSizeMB()*1024l*1024);
199             fileCount = String.format("%,1d", load.getStorefiles());
200             memSize = StringUtils.byteDesc(load.getMemStoreSizeMB()*1024l*1024);
201             locality = load.getDataLocality();
202           }
203         }
204       }
205
206       out.write("\n<tr>\n  <td>");
207       out.print( escapeXml(meta.getRegionNameAsString()) );
208       out.write("</td>\n    <td><a href=\"");
209       out.print( url );
210       out.write('"');
211       out.write('>');
212       out.print( metaLocation.getHostname().toString() + ":" + master.getRegionServerInfoPort(metaLocation) );
213       out.write("</a></td>\n    <td>");
214       out.print( readReq);
215       out.write("</td>\n    <td>");
216       out.print( writeReq);
217       out.write("</td>\n    <td>");
218       out.print( fileSize);
219       out.write("</td>\n    <td>");
220       out.print( fileCount);
221       out.write("</td>\n    <td>");
222       out.print( memSize);
223       out.write("</td>\n    <td>");
224       out.print( locality);
225       out.write("</td>\n    <td>");
226       out.print( escapeXml(Bytes.toString(meta.getStartKey())) );
227       out.write("</td>\n    <td>");
228       out.print( escapeXml(Bytes.toString(meta.getEndKey())) );
229       out.write("</td>\n</tr>\n");
230   }
231       out.write('\n');
232 }
233       out.write("\n</table>\n");
234 } else {
235   Admin admin = master.getConnection().getAdmin();
236   RegionLocator r = master.getClusterConnection().getRegionLocator(table.getName());
237   try {
238       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>");
239       out.print( admin.isTableEnabled(table.getName()) );
240       out.write("</td>\n      <td>Is the table enabled</td>\n  </tr>\n  <tr>\n      <td>Compaction</td>\n      <td>\n");
241
242   try {
243     CompactionState compactionState = admin.getCompactionState(table.getName());
244
245       out.write('\n');
246       out.print( compactionState );
247       out.write('\n');
248
249   } catch (Exception e) {
250   // Nothing really to do here
251     e.printStackTrace();
252
253       out.write(" Unknown ");
254
255   }
256
257       out.write("\n      </td>\n      <td>Is the table compacting</td>\n  </tr>\n");
258   if (showFragmentation) {
259       out.write("\n  <tr>\n      <td>Fragmentation</td>\n      <td>");
260       out.print( frags.get(fqtn) != null ? frags.get(fqtn).intValue() + "%" : "n/a" );
261       out.write("</td>\n      <td>How fragmented is the table. After a major compaction it is 0%.</td>\n  </tr>\n");
262   }
263       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  ");
264
265     Collection<HColumnDescriptor> families = table.getTableDescriptor().getFamilies();
266     for (HColumnDescriptor family: families) {
267
268       out.write("\n  <tr>\n    <td>");
269       out.print( family.getNameAsString() );
270       out.write("</td>\n    <td>\n    <table class=\"table table-striped\">\n      <tr>\n       <th>Property</th>\n       <th>Value</th>\n      </tr>\n    ");
271
272     Map<Bytes, Bytes> familyValues = family.getValues();
273     for (Bytes familyKey: familyValues.keySet()) {
274
275       out.write("\n      <tr>\n        <td>\n          ");
276       out.print( familyKey );
277       out.write("\n\t\t</td>\n        <td>\n          ");
278       out.print( familyValues.get(familyKey) );
279       out.write("\n        </td>\n      </tr>\n    ");
280  }
281       out.write("\n    </table>\n    </td>\n  </tr>\n  ");
282  }
283       out.write("\n</table>\n");
284
285   long totalReadReq = 0;
286   long totalWriteReq = 0;
287   long totalSize = 0;
288   long totalStoreFileCount = 0;
289   long totalMemSize = 0;
290   String urlRegionServer = null;
291   Map<ServerName, Integer> regDistribution = new TreeMap<ServerName, Integer>();
292   Map<ServerName, Integer> primaryRegDistribution = new TreeMap<ServerName, Integer>();
293   List<HRegionLocation> regions = r.getAllRegionLocations();
294   Map<HRegionInfo, RegionLoad> regionsToLoad = new LinkedHashMap<HRegionInfo, RegionLoad>();
295   Map<HRegionInfo, ServerName> regionsToServer = new LinkedHashMap<HRegionInfo, ServerName>();
296   for (HRegionLocation hriEntry : regions) {
297     HRegionInfo regionInfo = hriEntry.getRegionInfo();
298     ServerName addr = hriEntry.getServerName();
299     regionsToServer.put(regionInfo, addr);
300
301     if (addr != null) {
302       ServerLoad sl = master.getServerManager().getLoad(addr);
303       if (sl != null) {
304         Map<byte[], RegionLoad> map = sl.getRegionsLoad();
305         RegionLoad regionload = map.get(regionInfo.getRegionName());
306         regionsToLoad.put(regionInfo, regionload);
307         if(regionload != null) {
308           totalReadReq += regionload.getReadRequestsCount();
309           totalWriteReq += regionload.getWriteRequestsCount();
310           totalSize += regionload.getStorefileSizeMB();
311           totalStoreFileCount += regionload.getStorefiles();
312           totalMemSize += regionload.getMemStoreSizeMB();
313         } else {
314           RegionLoad load0 = new RegionLoad(ClusterStatusProtos.RegionLoad.newBuilder().setRegionSpecifier(HBaseProtos.RegionSpecifier.newBuilder().setValue(ByteString.copyFrom(regionInfo.getRegionName())).build()).build());
315           regionsToLoad.put(regionInfo, load0);
316         }
317       }else{
318         RegionLoad load0 = new RegionLoad(ClusterStatusProtos.RegionLoad.newBuilder().setRegionSpecifier(HBaseProtos.RegionSpecifier.newBuilder().setValue(ByteString.copyFrom(regionInfo.getRegionName())).build()).build());
319         regionsToLoad.put(regionInfo, load0);
320       }
321     }else{
322       RegionLoad load0 = new RegionLoad(ClusterStatusProtos.RegionLoad.newBuilder().setRegionSpecifier(HBaseProtos.RegionSpecifier.newBuilder().setValue(ByteString.copyFrom(regionInfo.getRegionName())).build()).build());
323       regionsToLoad.put(regionInfo, load0);
324     }
325   }
326
327   if(regions != null && regions.size() > 0) {
328       out.write("\n<h2>Table Regions</h2>\nSort As\n<select id=\"sel\" style=\"margin-right: 10px\">\n<option value=\"regionName\">RegionName</option>\n<option value=\"readrequest\">ReadRequest</option>\n<option value=\"writerequest\">WriteRequest</option>\n<option value=\"size\">StorefileSize</option>\n<option value=\"filecount\">Num.Storefiles</option>\n<option value=\"memstore\">MemstoreSize</option>\n<option value=\"locality\">Locality</option>\n</select>\nAscending<input type=\"checkbox\" id=\"ascending\" value=\"Ascending\" style=\"margin-right:10px\">\nShowDetailName&Start/End Key<input type=\"checkbox\" id=\"showWhole\" style=\"margin-right:10px\">\n<input type=\"button\" id=\"submit\" value=\"Reorder\" onClick=\"reloadAsSort()\" style=\"font-size: 12pt; width: 5em; margin-bottom: 5px\" class=\"btn\">\n<p>\n\n<table class=\"table table-striped\">\n<tr>\n<th>Name(");
329       out.print( String.format("%,1d", regions.size()));
330       out.write(")</th>\n<th>Region Server</th>\n<th>ReadRequests<br>(");
331       out.print( String.format("%,1d", totalReadReq));
332       out.write(")</th>\n<th>WriteRequests<br>(");
333       out.print( String.format("%,1d", totalWriteReq));
334       out.write(")</th>\n<th>StorefileSize<br>(");
335       out.print( StringUtils.byteDesc(totalSize*1024l*1024));
336       out.write(")</th>\n<th>Num.Storefiles<br>(");
337       out.print( String.format("%,1d", totalStoreFileCount));
338       out.write(")</th>\n<th>MemSize<br>(");
339       out.print( StringUtils.byteDesc(totalMemSize*1024l*1024));
340       out.write(")</th>\n<th>Locality</th>\n<th>Start Key</th>\n<th>End Key</th>\n");
341
342   if (withReplica) {
343
344       out.write("\n<th>ReplicaID</th>\n");
345
346   }
347
348       out.write("\n</tr>\n\n");
349
350   List<Map.Entry<HRegionInfo, RegionLoad>> entryList = new ArrayList<Map.Entry<HRegionInfo, RegionLoad>>(regionsToLoad.entrySet());
351   if(sortKey != null) {
352     if (sortKey.equals("readrequest")) {
353       Collections.sort(entryList,
354           new Comparator<Map.Entry<HRegionInfo, RegionLoad>>() {
355             public int compare(
356                 Map.Entry<HRegionInfo, RegionLoad> entry1,
357                 Map.Entry<HRegionInfo, RegionLoad> entry2) {
358               if (entry1 == null || entry1.getValue() == null) {
359                 return -1;
360               } else if (entry2 == null || entry2.getValue() == null) {
361                 return 1;
362               }
363               int result = 0;
364               if (entry1.getValue().getReadRequestsCount() < entry2.getValue().getReadRequestsCount()) {
365                 result = -1;
366               } else if (entry1.getValue().getReadRequestsCount() > entry2.getValue().getReadRequestsCount()) {
367                 result = 1;
368               }
369               if (reverseOrder) {
370                 result = -1 * result;
371               }
372               return result;
373             }
374           });
375     } else if (sortKey.equals("writerequest")) {
376       Collections.sort(entryList,
377           new Comparator<Map.Entry<HRegionInfo, RegionLoad>>() {
378             public int compare(
379                 Map.Entry<HRegionInfo, RegionLoad> entry1,
380                 Map.Entry<HRegionInfo, RegionLoad> entry2) {
381               if (entry1 == null || entry1.getValue() == null) {
382                 return -1;
383               } else if (entry2 == null || entry2.getValue() == null) {
384                 return 1;
385               }
386               int result = 0;
387               if (entry1.getValue().getWriteRequestsCount() < entry2.getValue()
388                   .getWriteRequestsCount()) {
389                 result = -1;
390               } else if (entry1.getValue().getWriteRequestsCount() > entry2.getValue()
391                   .getWriteRequestsCount()) {
392                 result = 1;
393               }
394               if (reverseOrder) {
395                 result = -1 * result;
396               }
397               return result;
398             }
399           });
400     } else if (sortKey.equals("size")) {
401       Collections.sort(entryList,
402           new Comparator<Map.Entry<HRegionInfo, RegionLoad>>() {
403             public int compare(
404                 Map.Entry<HRegionInfo, RegionLoad> entry1,
405                 Map.Entry<HRegionInfo, RegionLoad> entry2) {
406               if (entry1 == null || entry1.getValue() == null) {
407                 return -1;
408               } else if (entry2 == null || entry2.getValue() == null) {
409                 return 1;
410               }
411               int result = 0;
412               if (entry1.getValue().getStorefileSizeMB() < entry2.getValue()
413                   .getStorefileSizeMB()) {
414                 result = -1;
415               } else if (entry1.getValue().getStorefileSizeMB() > entry2
416                   .getValue().getStorefileSizeMB()) {
417                 result = 1;
418               }
419               if (reverseOrder) {
420                 result = -1 * result;
421               }
422               return result;
423             }
424           });
425     } else if (sortKey.equals("filecount")) {
426       Collections.sort(entryList,
427           new Comparator<Map.Entry<HRegionInfo, RegionLoad>>() {
428             public int compare(
429                 Map.Entry<HRegionInfo, RegionLoad> entry1,
430                 Map.Entry<HRegionInfo, RegionLoad> entry2) {
431               if (entry1 == null || entry1.getValue() == null) {
432                 return -1;
433               } else if (entry2 == null || entry2.getValue() == null) {
434                 return 1;
435               }
436               int result = 0;
437               if (entry1.getValue().getStorefiles() < entry2.getValue()
438                   .getStorefiles()) {
439                 result = -1;
440               } else if (entry1.getValue().getStorefiles() > entry2.getValue()
441                   .getStorefiles()) {
442                 result = 1;
443               }
444               if (reverseOrder) {
445                 result = -1 * result;
446               }
447               return result;
448             }
449           });
450     } else if (sortKey.equals("memstore")) {
451       Collections.sort(entryList,
452           new Comparator<Map.Entry<HRegionInfo, RegionLoad>>() {
453             public int compare(
454                 Map.Entry<HRegionInfo, RegionLoad> entry1,
455                 Map.Entry<HRegionInfo, RegionLoad> entry2) {
456               if (entry1 == null || entry1.getValue()==null) {
457                 return -1;
458               } else if (entry2 == null || entry2.getValue()==null) {
459                 return 1;
460               }
461               int result = 0;
462               if (entry1.getValue().getMemStoreSizeMB() < entry2.getValue()
463                   .getMemStoreSizeMB()) {
464                 result = -1;
465               } else if (entry1.getValue().getMemStoreSizeMB() > entry2
466                   .getValue().getMemStoreSizeMB()) {
467                 result = 1;
468               }
469               if (reverseOrder) {
470                 result = -1 * result;
471               }
472               return result;
473             }
474           });
475     } else if (sortKey.equals("locality")) {
476       Collections.sort(entryList,
477           new Comparator<Map.Entry<HRegionInfo, RegionLoad>>() {
478             public int compare(
479                 Map.Entry<HRegionInfo, RegionLoad> entry1,
480                 Map.Entry<HRegionInfo, RegionLoad> entry2) {
481               if (entry1 == null || entry1.getValue()==null) {
482                 return -1;
483               } else if (entry2 == null || entry2.getValue()==null) {
484                 return 1;
485               }
486               int result = 0;
487               if (entry1.getValue().getDataLocality() < entry2.getValue()
488                   .getDataLocality()) {
489                 result = -1;
490               } else if (entry1.getValue().getDataLocality() > entry2
491                   .getValue().getDataLocality()) {
492                 result = 1;
493               }
494               if (reverseOrder) {
495                 result = -1 * result;
496               }
497               return result;
498             }
499           });
500     }
501   }
502
503   for (Map.Entry<HRegionInfo, RegionLoad> hriEntry : entryList) {
504     HRegionInfo regionInfo = hriEntry.getKey();
505     ServerName addr = regionsToServer.get(regionInfo);
506     RegionLoad load = hriEntry.getValue();
507     String readReq = "N/A";
508     String writeReq = "N/A";
509     String regionSize = "N/A";
510     String fileCount = "N/A";
511     String memSize = "N/A";
512     float locality = 0.0f;
513     if(load != null) {
514       readReq = String.format("%,1d", load.getReadRequestsCount());
515       writeReq = String.format("%,1d", load.getWriteRequestsCount());
516       regionSize = StringUtils.byteDesc(load.getStorefileSizeMB()*1024l*1024);
517       fileCount = String.format("%,1d", load.getStorefiles());
518       memSize = StringUtils.byteDesc(load.getMemStoreSizeMB()*1024l*1024);
519       locality = load.getDataLocality();
520     }
521
522     if (addr != null) {
523       ServerLoad sl = master.getServerManager().getLoad(addr);
524       // This port might be wrong if RS actually ended up using something else.
525       urlRegionServer =
526           "//" + addr.getHostname() + ":" + master.getRegionServerInfoPort(addr) + "/";
527       if(sl != null) {
528         Integer i = regDistribution.get(addr);
529         if (null == i) i = Integer.valueOf(0);
530         regDistribution.put(addr, i + 1);
531         if (withReplica && RegionReplicaUtil.isDefaultReplica(regionInfo.getReplicaId())) {
532           i = primaryRegDistribution.get(addr);
533           if (null == i) i = Integer.valueOf(0);
534           primaryRegDistribution.put(addr, i+1);
535         }
536       }
537     }
538
539       out.write("\n<tr>\n  <td>");
540       out.print( escapeXml(showWhole?Bytes.toStringBinary(regionInfo.getRegionName()):regionInfo.getEncodedName()) );
541       out.write("</td>\n  ");
542
543   if (urlRegionServer != null) {
544
545       out.write("\n  <td>\n     <a href=\"");
546       out.print( urlRegionServer );
547       out.write('"');
548       out.write('>');
549       out.print( addr.getHostname().toString() + ":" + master.getRegionServerInfoPort(addr) );
550       out.write("</a>\n  </td>\n  ");
551
552   } else {
553
554       out.write("\n  <td class=\"undeployed-region\">not deployed</td>\n  ");
555
556   }
557
558       out.write("\n  <td>");
559       out.print( readReq);
560       out.write("</td>\n  <td>");
561       out.print( writeReq);
562       out.write("</td>\n  <td>");
563       out.print( regionSize);
564       out.write("</td>\n  <td>");
565       out.print( fileCount);
566       out.write("</td>\n  <td>");
567       out.print( memSize);
568       out.write("</td>\n  <td>");
569       out.print( locality);
570       out.write("</td>\n  <td>");
571       out.print( escapeXml(showWhole?Bytes.toStringBinary(regionInfo.getStartKey()):"-"));
572       out.write("</td>\n  <td>");
573       out.print( escapeXml(showWhole?Bytes.toStringBinary(regionInfo.getEndKey()):"-"));
574       out.write("</td>\n  ");
575
576   if (withReplica) {
577
578       out.write("\n  <td>");
579       out.print( regionInfo.getReplicaId() );
580       out.write("</td>\n  ");
581
582   }
583
584       out.write("\n</tr>\n");
585  }
586       out.write("\n</table>\n<h2>Regions by Region Server</h2>\n");
587
588 if (withReplica) {
589
590       out.write("\n<table class=\"table table-striped\"><tr><th>Region Server</th><th>Region Count</th><th>Primary Region Count</th></tr>\n");
591
592 } else {
593
594       out.write("\n<table class=\"table table-striped\"><tr><th>Region Server</th><th>Region Count</th></tr>\n");
595
596 }
597
598       out.write('\n');
599
600   for (Map.Entry<ServerName, Integer> rdEntry : regDistribution.entrySet()) {
601      ServerName addr = rdEntry.getKey();
602      String url = "//" + addr.getHostname() + ":" + master.getRegionServerInfoPort(addr) + "/";
603
604       out.write("\n<tr>\n  <td><a href=\"");
605       out.print( url );
606       out.write('"');
607       out.write('>');
608       out.print( addr.getHostname().toString() + ":" + master.getRegionServerInfoPort(addr) );
609       out.write("</a></td>\n  <td>");
610       out.print( rdEntry.getValue());
611       out.write("</td>\n");
612
613 if (withReplica) {
614
615       out.write("\n  <td>");
616       out.print( primaryRegDistribution.get(addr));
617       out.write("</td>\n");
618
619 }
620
621       out.write("\n</tr>\n");
622  }
623       out.write("\n</table>\n");
624  }
625 } catch(Exception ex) {
626   ex.printStackTrace(System.err);
627 } finally {
628   admin.close();
629 }
630 } // end else
631
632       out.write("\n\n\n");
633  if (!readOnly) {
634       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=\"");
635       out.print( fqtn );
636       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=\"");
637       out.print( fqtn );
638       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");
639  }
640       out.write("\n</div>\n</div>\n");
641  }
642   } catch(TableNotFoundException e) {
643       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> ");
644
645   } catch(IllegalArgumentException e) {
646       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> ");
647
648   }
649 }
650   else { // handle the case for fqtn is null with error message + redirect
651
652       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");
653  }
654       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\n<script>\nvar index=0;\nvar sortKeyValue='");
655       out.print( sortKey );
656       out.write("';\nif(sortKeyValue==\"readrequest\")index=1;\nelse if(sortKeyValue==\"writerequest\")index=2;\nelse if(sortKeyValue==\"size\")index=3;\nelse if(sortKeyValue==\"filecount\")index=4;\nelse if(sortKeyValue==\"memstore\")index=5;\nelse if(sortKeyValue==\"locality\")index=6;\ndocument.getElementById(\"sel\").selectedIndex=index;\n\nvar reverse='");
657       out.print( reverseOrder );
658       out.write("';\nif(reverse=='false')document.getElementById(\"ascending\").checked=true;\n\nvar showWhole='");
659       out.print( showWhole );
660       out.write("';\nif(showWhole=='true')document.getElementById(\"showWhole\").checked=true;\n\nfunction reloadAsSort(){\n  var url=\"?name=\"+'");
661       out.print( fqtn );
662       out.write("';\n  if(document.getElementById(\"sel\").selectedIndex>0){\n    url=url+\"&sort=\"+document.getElementById(\"sel\").value;\n  }\n  if(document.getElementById(\"ascending\").checked){\n    url=url+\"&reverse=false\";\n  }\n  if(document.getElementById(\"showWhole\").checked){\n    url=url+\"&showwhole=true\";\n  }\n  location.href=url;\n}\n</script>\n");
663     } catch (Throwable t) {
664       if (!(t instanceof SkipPageException)){
665         out = _jspx_out;
666         if (out != null && out.getBufferSize() != 0)
667           out.clearBuffer();
668         if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
669       }
670     } finally {
671       _jspxFactory.releasePageContext(_jspx_page_context);
672     }
673   }
674 }