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.regionserver;
20  
21  import java.io.IOException;
22  
23  import javax.servlet.ServletException;
24  import javax.servlet.http.HttpServlet;
25  import javax.servlet.http.HttpServletRequest;
26  import javax.servlet.http.HttpServletResponse;
27  import org.apache.hadoop.hbase.classification.InterfaceAudience;
28  
29  import org.apache.hadoop.hbase.tmpl.regionserver.RSStatusTmpl;
30  
31  @InterfaceAudience.Private
32  public class RSStatusServlet extends HttpServlet {
33    private static final long serialVersionUID = 1L;
34  
35    @Override
36    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
37        throws ServletException, IOException
38      {
39      HRegionServer hrs = (HRegionServer)getServletContext().getAttribute(
40          HRegionServer.REGIONSERVER);
41      assert hrs != null : "No RS in context!";
42  
43      resp.setContentType("text/html");
44  
45      if (!hrs.isOnline()) {
46        resp.getWriter().write("The RegionServer is initializing!");
47        resp.getWriter().close();
48        return;
49      }
50  
51      RSStatusTmpl tmpl = new RSStatusTmpl();
52      if (req.getParameter("format") != null)
53        tmpl.setFormat(req.getParameter("format"));
54      if (req.getParameter("filter") != null)
55        tmpl.setFilter(req.getParameter("filter"));
56      if (req.getParameter("bcn") != null)
57        tmpl.setBcn(req.getParameter("bcn"));
58      if (req.getParameter("bcv") != null)
59        tmpl.setBcv(req.getParameter("bcv"));
60      tmpl.render(resp.getWriter(), hrs);
61    }
62  }