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