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