-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HBASE-2980. Refactor region server command line to a new class
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@996633 13f79535-47bb-0310-9956-ffa450edef68
- Loading branch information
1 parent
d48a3d0
commit 02cd4a9
Showing
8 changed files
with
187 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServerCommandLine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/** | ||
* Copyright 2010 The Apache Software Foundation | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.hadoop.hbase.regionserver; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.hbase.HConstants; | ||
import org.apache.hadoop.hbase.LocalHBaseCluster; | ||
import org.apache.hadoop.hbase.util.ServerCommandLine; | ||
|
||
/** | ||
* Class responsible for parsing the command line and starting the | ||
* RegionServer. | ||
*/ | ||
public class HRegionServerCommandLine extends ServerCommandLine { | ||
private static final Log LOG = LogFactory.getLog(HRegionServerCommandLine.class); | ||
|
||
private final Class<? extends HRegionServer> regionServerClass; | ||
|
||
private static final String USAGE = | ||
"Usage: HRegionServer [-D conf.param=value] start"; | ||
|
||
public HRegionServerCommandLine(Class<? extends HRegionServer> clazz) { | ||
this.regionServerClass = clazz; | ||
} | ||
|
||
protected String getUsage() { | ||
return USAGE; | ||
} | ||
|
||
private int start() throws Exception { | ||
Configuration conf = getConf(); | ||
|
||
// If 'local', don't start a region server here. Defer to | ||
// LocalHBaseCluster. It manages 'local' clusters. | ||
if (LocalHBaseCluster.isLocal(conf)) { | ||
LOG.warn("Not starting a distinct region server because " | ||
+ HConstants.CLUSTER_DISTRIBUTED + " is false"); | ||
} else { | ||
logJVMInfo(); | ||
HRegionServer hrs = HRegionServer.constructRegionServer(regionServerClass, conf); | ||
HRegionServer.startRegionServer(hrs); | ||
} | ||
return 0; | ||
} | ||
|
||
public int run(String args[]) throws Exception { | ||
if (args.length != 1) { | ||
usage(null); | ||
return -1; | ||
} | ||
|
||
String cmd = args[0]; | ||
|
||
if ("start".equals(cmd)) { | ||
return start(); | ||
} else if ("stop".equals(cmd)) { | ||
System.err.println( | ||
"To shutdown the regionserver run " + | ||
"bin/hbase-daemon.sh stop regionserver or send a kill signal to" + | ||
"the regionserver pid"); | ||
return -1; | ||
} else { | ||
usage("Unknown command: " + args[0]); | ||
return -1; | ||
} | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
src/main/java/org/apache/hadoop/hbase/util/ServerCommandLine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* Copyright 2010 The Apache Software Foundation | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.hadoop.hbase.util; | ||
|
||
import java.lang.management.RuntimeMXBean; | ||
import java.lang.management.ManagementFactory; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.conf.Configured; | ||
import org.apache.hadoop.hbase.HBaseConfiguration; | ||
import org.apache.hadoop.util.Tool; | ||
import org.apache.hadoop.util.ToolRunner; | ||
|
||
/** | ||
* Base class for command lines that start up various HBase daemons. | ||
*/ | ||
public abstract class ServerCommandLine extends Configured implements Tool { | ||
private static final Log LOG = LogFactory.getLog(ServerCommandLine.class); | ||
|
||
/** | ||
* Implementing subclasses should return a usage string to print out. | ||
*/ | ||
protected abstract String getUsage(); | ||
|
||
/** | ||
* Print usage information for this command line. | ||
* | ||
* @param message if not null, print this message before the usage info. | ||
*/ | ||
protected void usage(String message) { | ||
if (message != null) { | ||
System.err.println(message); | ||
System.err.println(""); | ||
} | ||
|
||
System.err.println(getUsage()); | ||
} | ||
|
||
/** | ||
* Log information about the currently running JVM. | ||
*/ | ||
public static void logJVMInfo() { | ||
// Print out vm stats before starting up. | ||
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); | ||
if (runtime != null) { | ||
LOG.info("vmName=" + runtime.getVmName() + ", vmVendor=" + | ||
runtime.getVmVendor() + ", vmVersion=" + runtime.getVmVersion()); | ||
LOG.info("vmInputArguments=" + runtime.getInputArguments()); | ||
} | ||
} | ||
|
||
/** | ||
* Parse and run the given command line. This may exit the JVM if | ||
* a nonzero exit code is returned from <code>run()</code>. | ||
*/ | ||
public void doMain(String args[]) throws Exception { | ||
int ret = ToolRunner.run( | ||
HBaseConfiguration.create(), this, args); | ||
if (ret != 0) { | ||
System.exit(ret); | ||
} | ||
} | ||
} |
Oops, something went wrong.