1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.master;
21
22 import java.io.IOException;
23
24 import java.util.List;
25 import java.util.Map;
26 import java.util.Set;
27
28 import javax.servlet.http.HttpServlet;
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
31
32 import org.apache.commons.logging.Log;
33 import org.apache.commons.logging.LogFactory;
34 import org.apache.hadoop.conf.Configuration;
35 import org.apache.hadoop.hbase.ServerName;
36 import org.apache.hadoop.hbase.client.HBaseAdmin;
37 import org.apache.hadoop.hbase.util.FSUtils;
38 import org.apache.hadoop.hbase.tmpl.master.MasterStatusTmpl;
39
40
41
42
43
44 public class MasterStatusServlet extends HttpServlet {
45 private static final Log LOG = LogFactory.getLog(MasterStatusServlet.class);
46 private static final long serialVersionUID = 1L;
47
48 @Override
49 public void doGet(HttpServletRequest request, HttpServletResponse response)
50 throws IOException
51 {
52 HMaster master = (HMaster) getServletContext().getAttribute(HMaster.MASTER);
53 assert master != null : "No Master in context!";
54
55 Configuration conf = master.getConfiguration();
56 HBaseAdmin admin = new HBaseAdmin(conf);
57
58 Map<String, Integer> frags = getFragmentationInfo(master, conf);
59
60 ServerName rootLocation = getRootLocationOrNull(master);
61 ServerName metaLocation = master.getCatalogTracker().getMetaLocation();
62 List<ServerName> servers = master.getServerManager().getOnlineServersList();
63 Set<ServerName> deadServers = master.getServerManager().getDeadServers();
64
65 response.setContentType("text/html");
66 MasterStatusTmpl tmpl = new MasterStatusTmpl()
67 .setFrags(frags)
68 .setShowAppendWarning(shouldShowAppendWarning(conf))
69 .setRootLocation(rootLocation)
70 .setMetaLocation(metaLocation)
71 .setServers(servers)
72 .setDeadServers(deadServers);
73 if (request.getParameter("filter") != null)
74 tmpl.setFilter(request.getParameter("filter"));
75 if (request.getParameter("format") != null)
76 tmpl.setFormat(request.getParameter("format"));
77 tmpl.render(response.getWriter(),
78 master, admin);
79 }
80
81 private ServerName getRootLocationOrNull(HMaster master) {
82 try {
83 return master.getCatalogTracker().getRootLocation();
84 } catch (InterruptedException e) {
85 LOG.warn("Unable to get root location", e);
86 return null;
87 }
88 }
89
90 private Map<String, Integer> getFragmentationInfo(
91 HMaster master, Configuration conf) throws IOException {
92 boolean showFragmentation = conf.getBoolean(
93 "hbase.master.ui.fragmentation.enabled", false);
94 if (showFragmentation) {
95 return FSUtils.getTableFragmentation(master);
96 } else {
97 return null;
98 }
99 }
100
101 static boolean shouldShowAppendWarning(Configuration conf) {
102 try {
103 return !FSUtils.isAppendSupported(conf) && FSUtils.isHDFS(conf);
104 } catch (IOException e) {
105 LOG.warn("Unable to determine if append is supported", e);
106 return false;
107 }
108 }
109 }