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