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 org.apache.commons.logging.Log;
22  import org.apache.commons.logging.LogFactory;
23  
24  import org.apache.hadoop.classification.InterfaceAudience;
25  import org.apache.hadoop.conf.Configuration;
26  import org.apache.hadoop.hbase.HConstants;
27  import org.apache.hadoop.hbase.LocalHBaseCluster;
28  import org.apache.hadoop.hbase.util.ServerCommandLine;
29  
30  /**
31   * Class responsible for parsing the command line and starting the
32   * RegionServer.
33   */
34  @InterfaceAudience.Private
35  public class HRegionServerCommandLine extends ServerCommandLine {
36    private static final Log LOG = LogFactory.getLog(HRegionServerCommandLine.class);
37  
38    private final Class<? extends HRegionServer> regionServerClass;
39  
40    private static final String USAGE =
41      "Usage: HRegionServer [-D conf.param=value] start";
42  
43    public HRegionServerCommandLine(Class<? extends HRegionServer> clazz) {
44      this.regionServerClass = clazz;
45    }
46  
47    protected String getUsage() {
48      return USAGE;
49    }
50  
51    private int start() throws Exception {
52      Configuration conf = getConf();
53  
54      // If 'local', don't start a region server here. Defer to
55      // LocalHBaseCluster. It manages 'local' clusters.
56      if (LocalHBaseCluster.isLocal(conf)) {
57        LOG.warn("Not starting a distinct region server because "
58                 + HConstants.CLUSTER_DISTRIBUTED + " is false");
59      } else {
60        logJVMInfo();
61        HRegionServer hrs = HRegionServer.constructRegionServer(regionServerClass, conf);
62        HRegionServer.startRegionServer(hrs);
63      }
64      return 0;
65    }
66  
67    public int run(String args[]) throws Exception {
68      if (args.length != 1) {
69        usage(null);
70        return -1;
71      }
72  
73      String cmd = args[0];
74  
75      if ("start".equals(cmd)) {
76        return start();
77      } else if ("stop".equals(cmd)) {
78        System.err.println(
79          "To shutdown the regionserver run " +
80          "bin/hbase-daemon.sh stop regionserver or send a kill signal to" +
81          "the regionserver pid");
82        return -1;
83      } else {
84        usage("Unknown command: " + args[0]);
85        return -1;
86      }
87    }
88  }