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      HRegionServer hrs = (HRegionServer)getServletContext().getAttribute(HRegionServer.REGIONSERVER);
39      assert hrs != null : "No RS in context!";
40  
41      resp.setContentType("text/html");
42  
43      if (!hrs.isOnline()) {
44        resp.getWriter().write("The RegionServer is initializing!");
45        resp.getWriter().close();
46        return;
47      }
48  
49      RSStatusTmpl tmpl = new RSStatusTmpl();
50      if (req.getParameter("format") != null)
51        tmpl.setFormat(req.getParameter("format"));
52      if (req.getParameter("filter") != null)
53        tmpl.setFilter(req.getParameter("filter"));
54      if (req.getParameter("bcn") != null)
55        tmpl.setBcn(req.getParameter("bcn"));
56      if (req.getParameter("bcv") != null)
57        tmpl.setBcv(req.getParameter("bcv"));
58      tmpl.render(resp.getWriter(), hrs);
59    }
60  }