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.monitoring;
20  
21  import java.io.IOException;
22  import java.io.PrintWriter;
23  import java.util.Map;
24  
25  import javax.servlet.http.HttpServlet;
26  import javax.servlet.http.HttpServletRequest;
27  
28  import org.apache.hadoop.hbase.classification.InterfaceAudience;
29  import org.apache.hadoop.conf.Configuration;
30  import org.apache.hadoop.hbase.executor.ExecutorService;
31  import org.apache.hadoop.hbase.executor.ExecutorService.ExecutorStatus;
32  import org.apache.hadoop.hbase.util.VersionInfo;
33  
34  @InterfaceAudience.Private
35  public abstract class StateDumpServlet extends HttpServlet {
36    static final long DEFAULT_TAIL_KB = 100;
37    private static final long serialVersionUID = 1L;
38  
39    protected void dumpVersionInfo(PrintWriter out) {
40      VersionInfo.writeTo(out);
41    
42      out.println("Hadoop " + org.apache.hadoop.util.VersionInfo.getVersion());
43      out.println("Subversion " + org.apache.hadoop.util.VersionInfo.getUrl() + " -r " +
44          org.apache.hadoop.util.VersionInfo.getRevision());
45      out.println("Compiled by " + org.apache.hadoop.util.VersionInfo.getUser() +
46          " on " + org.apache.hadoop.util.VersionInfo.getDate());
47    }
48  
49    protected boolean isShowQueueDump(Configuration conf){
50      return conf.getBoolean("hbase.regionserver.servlet.show.queuedump", true);
51    }
52  
53    protected long getTailKbParam(HttpServletRequest request) {
54      String param = request.getParameter("tailkb");
55      if (param == null) {
56        return DEFAULT_TAIL_KB;
57      }
58      return Long.parseLong(param);
59    }
60  
61    protected void dumpExecutors(ExecutorService service, PrintWriter out)
62        throws IOException {
63      if (service == null) {
64        out.println("ExecutorService is not initialized");
65        return;
66      }
67  
68      Map<String, ExecutorStatus> statuses = service.getAllExecutorStatuses();
69      for (ExecutorStatus status : statuses.values()) {
70        status.dumpTo(out, "  ");
71      }
72    }
73  }