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