001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.monitoring;
019
020import java.io.IOException;
021import java.io.PrintWriter;
022import java.util.Map;
023import javax.servlet.http.HttpServlet;
024import javax.servlet.http.HttpServletRequest;
025import org.apache.hadoop.conf.Configuration;
026import org.apache.hadoop.hbase.executor.ExecutorService;
027import org.apache.hadoop.hbase.executor.ExecutorService.ExecutorStatus;
028import org.apache.hadoop.hbase.util.VersionInfo;
029import org.apache.yetus.audience.InterfaceAudience;
030
031@InterfaceAudience.Private
032public abstract class StateDumpServlet extends HttpServlet {
033  static final long DEFAULT_TAIL_KB = 100;
034  private static final long serialVersionUID = 1L;
035
036  protected void dumpVersionInfo(PrintWriter out) {
037    VersionInfo.writeTo(out);
038
039    out.println("Hadoop " + org.apache.hadoop.util.VersionInfo.getVersion());
040    out.println("Source code repository " + org.apache.hadoop.util.VersionInfo.getUrl()
041      + " revision=" + org.apache.hadoop.util.VersionInfo.getRevision());
042    out.println("Compiled by " + org.apache.hadoop.util.VersionInfo.getUser() + " on "
043      + org.apache.hadoop.util.VersionInfo.getDate());
044  }
045
046  protected boolean isShowQueueDump(Configuration conf) {
047    return conf.getBoolean("hbase.regionserver.servlet.show.queuedump", true);
048  }
049
050  protected long getTailKbParam(HttpServletRequest request) {
051    String param = request.getParameter("tailkb");
052    if (param == null) {
053      return DEFAULT_TAIL_KB;
054    }
055    return Long.parseLong(param);
056  }
057
058  protected void dumpExecutors(ExecutorService service, PrintWriter out) throws IOException {
059    if (service == null) {
060      out.println("ExecutorService is not initialized");
061      return;
062    }
063
064    Map<String, ExecutorStatus> statuses = service.getAllExecutorStatuses();
065    for (ExecutorStatus status : statuses.values()) {
066      status.dumpTo(out, "  ");
067    }
068  }
069}