View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  package org.apache.hadoop.hbase.master;
20  
21  import java.io.IOException;
22  import java.io.OutputStream;
23  import java.io.PrintWriter;
24  import java.util.Date;
25  import java.util.Map;
26  
27  import javax.servlet.http.HttpServletRequest;
28  import javax.servlet.http.HttpServletResponse;
29  
30  import org.apache.hadoop.classification.InterfaceAudience;
31  import org.apache.hadoop.conf.Configuration;
32  import org.apache.hadoop.hbase.ServerLoad;
33  import org.apache.hadoop.hbase.ServerName;
34  import org.apache.hadoop.hbase.monitoring.LogMonitoring;
35  import org.apache.hadoop.hbase.monitoring.StateDumpServlet;
36  import org.apache.hadoop.hbase.monitoring.TaskMonitor;
37  import org.apache.hadoop.util.ReflectionUtils;
38  
39  @InterfaceAudience.Private
40  public class MasterDumpServlet extends StateDumpServlet {
41    private static final long serialVersionUID = 1L;
42    private static final String LINE =
43      "===========================================================";
44    
45    @Override
46    public void doGet(HttpServletRequest request, HttpServletResponse response)
47        throws IOException {
48      HMaster master = (HMaster) getServletContext().getAttribute(HMaster.MASTER);
49      assert master != null : "No Master in context!";
50  
51      response.setContentType("text/plain");
52      OutputStream os = response.getOutputStream();
53      PrintWriter out = new PrintWriter(os);
54      
55      out.println("Master status for " + master.getServerName()
56          + " as of " + new Date());
57      
58      out.println("\n\nVersion Info:");
59      out.println(LINE);
60      dumpVersionInfo(out);
61  
62      out.println("\n\nTasks:");
63      out.println(LINE);
64      TaskMonitor.get().dumpAsText(out);
65      
66      out.println("\n\nServers:");
67      out.println(LINE);
68      dumpServers(master, out);
69      
70      out.println("\n\nRegions-in-transition:");
71      out.println(LINE);
72      dumpRIT(master, out);
73      
74      out.println("\n\nExecutors:");
75      out.println(LINE);
76      dumpExecutors(master.getExecutorService(), out);
77      
78      out.println("\n\nStacks:");
79      out.println(LINE);
80      ReflectionUtils.printThreadInfo(out, "");
81      
82      out.println("\n\nMaster configuration:");
83      out.println(LINE);
84      Configuration conf = master.getConfiguration();
85      out.flush();
86      conf.writeXml(os);
87      os.flush();
88      
89      out.println("\n\nRecent regionserver aborts:");
90      out.println(LINE);
91      master.getRegionServerFatalLogBuffer().dumpTo(out);
92      
93      out.println("\n\nLogs");
94      out.println(LINE);
95      long tailKb = getTailKbParam(request);
96      LogMonitoring.dumpTailOfLogs(out, tailKb);
97      
98      out.flush();
99    }
100   
101 
102   private void dumpRIT(HMaster master, PrintWriter out) {
103     AssignmentManager am = master.getAssignmentManager();
104     if (am == null) {
105       out.println("AssignmentManager is not initialized");
106       return;
107     }
108 
109     Map<String, RegionState> regionsInTransition =
110       am.getRegionStates().getRegionsInTransition();
111     for (Map.Entry<String, RegionState> e : regionsInTransition.entrySet()) {
112       String rid = e.getKey();
113       RegionState rs = e.getValue();
114       out.println("Region " + rid + ": " + rs.toDescriptiveString());
115     }
116   }
117 
118   private void dumpServers(HMaster master, PrintWriter out) {
119     ServerManager sm = master.getServerManager();
120     if (sm == null) {
121       out.println("ServerManager is not initialized");
122       return;
123     }
124 
125     Map<ServerName, ServerLoad> servers = sm.getOnlineServers();
126     for (Map.Entry<ServerName, ServerLoad> e : servers.entrySet()) {
127       out.println(e.getKey() + ": " + e.getValue());
128     }
129   }
130 }