View Javadoc

1   /**
2    * Copyright 2010 The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  package org.apache.hadoop.hbase.regionserver;
21  
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  
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  public class HRegionServerCommandLine extends ServerCommandLine {
35    private static final Log LOG = LogFactory.getLog(HRegionServerCommandLine.class);
36  
37    private final Class<? extends HRegionServer> regionServerClass;
38  
39    private static final String USAGE =
40      "Usage: HRegionServer [-D conf.param=value] start";
41  
42    public HRegionServerCommandLine(Class<? extends HRegionServer> clazz) {
43      this.regionServerClass = clazz;
44    }
45  
46    protected String getUsage() {
47      return USAGE;
48    }
49  
50    private int start() throws Exception {
51      Configuration conf = getConf();
52  
53      // If 'local', don't start a region server here. Defer to
54      // LocalHBaseCluster. It manages 'local' clusters.
55      if (LocalHBaseCluster.isLocal(conf)) {
56        LOG.warn("Not starting a distinct region server because "
57                 + HConstants.CLUSTER_DISTRIBUTED + " is false");
58      } else {
59        logJVMInfo();
60        HRegionServer hrs = HRegionServer.constructRegionServer(regionServerClass, conf);
61        HRegionServer.startRegionServer(hrs);
62      }
63      return 0;
64    }
65  
66    public int run(String args[]) throws Exception {
67      if (args.length != 1) {
68        usage(null);
69        return -1;
70      }
71  
72      String cmd = args[0];
73  
74      if ("start".equals(cmd)) {
75        return start();
76      } else if ("stop".equals(cmd)) {
77        System.err.println(
78          "To shutdown the regionserver run " +
79          "bin/hbase-daemon.sh stop regionserver or send a kill signal to" +
80          "the regionserver pid");
81        return -1;
82      } else {
83        usage("Unknown command: " + args[0]);
84        return -1;
85      }
86    }
87  }