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