Author: todd
Date: Mon Sep 13 18:37:11 2010
New Revision: 996633
URL: http://svn.apache.org/viewvc?rev=996633&view=rev
Log:
HBASE-2980. Refactor region server command line to a new class
Added:
hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServerCommandLine.java
hbase/trunk/src/main/java/org/apache/hadoop/hbase/util/ServerCommandLine.java
Modified:
hbase/trunk/CHANGES.txt
hbase/trunk/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
hbase/trunk/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java
hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/OOMEHMaster.java
hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/OOMERegionServer.java
Modified: hbase/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hbase/trunk/CHANGES.txt?rev=996633&r1=996632&r2=996633&view=diff
==============================================================================
--- hbase/trunk/CHANGES.txt (original)
+++ hbase/trunk/CHANGES.txt Mon Sep 13 18:37:11 2010
@@ -905,6 +905,7 @@ Release 0.21.0 - Unreleased
HBASE-2976 Running HFile tool passing fully-qualified filename I get
'IllegalArgumentException: Wrong FS'
HBASE-2977 Refactor master command line to a new class
+ HBASE-2980 Refactor region server command line to a new class
NEW FEATURES
HBASE-1961 HBase EC2 scripts
Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
URL:
http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/master/HMaster.java?rev=996633&r1=996632&r2=996633&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
(original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/master/HMaster.java Mon
Sep 13 18:37:11 2010
@@ -865,24 +865,11 @@ implements HMasterInterface, HMasterRegi
}
}
- protected static void doMain(String [] args,
- Class<? extends HMaster> masterClass) throws Exception {
- int ret = ToolRunner.run(
- HBaseConfiguration.create(),
- new HMasterCommandLine(masterClass),
- args);
- if (ret != 0) {
- System.exit(ret);
- }
- // Otherwise exit gracefully so other threads clean up
- }
/**
- * Main program
- * @param args
- * @throws IOException
+ * @see org.apache.hadoop.hbase.master.HMasterCommandLine
*/
public static void main(String [] args) throws Exception {
- doMain(args, HMaster.class);
+ new HMasterCommandLine(HMaster.class).doMain(args);
}
}
Modified:
hbase/trunk/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java
URL:
http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java?rev=996633&r1=996632&r2=996633&view=diff
==============================================================================
---
hbase/trunk/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java
(original)
+++
hbase/trunk/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java
Mon Sep 13 18:37:11 2010
@@ -21,8 +21,6 @@ package org.apache.hadoop.hbase.master;
import java.io.IOException;
import java.io.File;
-import java.lang.management.RuntimeMXBean;
-import java.lang.management.ManagementFactory;
import java.util.List;
import org.apache.commons.cli.CommandLine;
@@ -32,8 +30,6 @@ import org.apache.commons.cli.ParseExcep
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.util.Tool;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HConstants;
@@ -41,10 +37,11 @@ import org.apache.hadoop.hbase.LocalHBas
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.regionserver.HRegionServer;
+import org.apache.hadoop.hbase.util.ServerCommandLine;
import org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster;
import org.apache.zookeeper.KeeperException;
-public class HMasterCommandLine extends Configured implements Tool {
+public class HMasterCommandLine extends ServerCommandLine {
private static final Log LOG = LogFactory.getLog(HMasterCommandLine.class);
private static final String USAGE =
@@ -57,30 +54,15 @@ public class HMasterCommandLine extends
private final Class<? extends HMaster> masterClass;
-
public HMasterCommandLine(Class<? extends HMaster> masterClass) {
this.masterClass = masterClass;
}
- private void usage(String message) {
- if (message != null) {
- System.err.println(message);
- System.err.println("\n");
- }
-
- System.err.println(USAGE);
- }
-
- private 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());
- }
+ protected String getUsage() {
+ return USAGE;
}
+
public int run(String args[]) throws Exception {
Options opt = new Options();
opt.addOption("minServers", true, "Minimum RegionServers needed to host
user tables");
Modified:
hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
URL:
http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java?rev=996633&r1=996632&r2=996633&view=diff
==============================================================================
---
hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
(original)
+++
hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
Mon Sep 13 18:37:11 2010
@@ -49,10 +49,6 @@ import java.util.concurrent.atomic.Atomi
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantReadWriteLock;
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.GnuParser;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
@@ -1939,6 +1935,10 @@ public class HRegionServer implements HR
return sortedset;
}
+ public int getNumberOfOnlineRegions() {
+ return onlineRegions.size();
+ }
+
/**
* For tests and web ui.
* This method will only work if HRegionServer is in the same JVM as client;
@@ -2321,18 +2321,6 @@ public class HRegionServer implements HR
return t;
}
- private static void printUsageAndExit() {
- printUsageAndExit(null);
- }
-
- private static void printUsageAndExit(final String message) {
- if (message != null) {
- System.err.println(message);
- }
- System.err.println("Usage: java org.apache.hbase.HRegionServer start|stop
[-D <conf.param=value>]");
- System.exit(0);
- }
-
/**
* Utility for constructing an instance of the passed HRegionServer class.
*
@@ -2360,80 +2348,17 @@ public class HRegionServer implements HR
this.replicationHandler.replicateLogEntries(entries);
}
- /**
- * Do class main.
- *
- * @param args
- * @param regionServerClass
- * HRegionServer to instantiate.
- */
- protected static void doMain(final String[] args,
- final Class<? extends HRegionServer> regionServerClass) {
- Configuration conf = HBaseConfiguration.create();
-
- Options opt = new Options();
- opt.addOption("D", true, "Override HBase Configuration Settings");
- try {
- CommandLine cmd = new GnuParser().parse(opt, args);
-
- if (cmd.hasOption("D")) {
- for (String confOpt : cmd.getOptionValues("D")) {
- String[] kv = confOpt.split("=", 2);
- if (kv.length == 2) {
- conf.set(kv[0], kv[1]);
- LOG.debug("-D configuration override: " + kv[0] + "=" + kv[1]);
- } else {
- throw new ParseException("-D option format invalid: " + confOpt);
- }
- }
- }
-
- if (cmd.getArgList().contains("start")) {
- try {
- // 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 {
- RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
- if (runtime != null) {
- LOG.info("vmInputArguments=" + runtime.getInputArguments());
- }
- HRegionServer hrs = constructRegionServer(regionServerClass, conf);
- startRegionServer(hrs);
- }
- } catch (Throwable t) {
- LOG.error( "Can not start region server because "+
- StringUtils.stringifyException(t) );
- System.exit(-1);
- }
- } else if (cmd.getArgList().contains("stop")) {
- throw new ParseException("To shutdown the regionserver run " +
- "bin/hbase-daemon.sh stop regionserver or send a kill signal to" +
- "the regionserver pid");
- } else {
- throw new ParseException("Unknown argument(s): " +
- org.apache.commons.lang.StringUtils.join(cmd.getArgs(), " "));
- }
- } catch (ParseException e) {
- LOG.error("Could not parse", e);
- printUsageAndExit();
- }
- }
/**
- * @param args
+ * @see org.apache.hadoop.hbase.regionserver.HRegionServerCommandLine
*/
- public static void main(String[] args) {
+ public static void main(String[] args) throws Exception {
Configuration conf = HBaseConfiguration.create();
@SuppressWarnings("unchecked")
Class<? extends HRegionServer> regionServerClass = (Class<? extends
HRegionServer>) conf
.getClass(HConstants.REGION_SERVER_IMPL, HRegionServer.class);
- doMain(args, regionServerClass);
- }
- public int getNumberOfOnlineRegions() {
- return onlineRegions.size();
+ new HRegionServerCommandLine(regionServerClass).doMain(args);
}
+
}
Added:
hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServerCommandLine.java
URL:
http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServerCommandLine.java?rev=996633&view=auto
==============================================================================
---
hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServerCommandLine.java
(added)
+++
hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServerCommandLine.java
Mon Sep 13 18:37:11 2010
@@ -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;
+ }
+ }
+}
\ No newline at end of file
Added:
hbase/trunk/src/main/java/org/apache/hadoop/hbase/util/ServerCommandLine.java
URL:
http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/util/ServerCommandLine.java?rev=996633&view=auto
==============================================================================
---
hbase/trunk/src/main/java/org/apache/hadoop/hbase/util/ServerCommandLine.java
(added)
+++
hbase/trunk/src/main/java/org/apache/hadoop/hbase/util/ServerCommandLine.java
Mon Sep 13 18:37:11 2010
@@ -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);
+ }
+ }
+}
Modified:
hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/OOMEHMaster.java
URL:
http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/OOMEHMaster.java?rev=996633&r1=996632&r2=996633&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/OOMEHMaster.java
(original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/OOMEHMaster.java
Mon Sep 13 18:37:11 2010
@@ -52,11 +52,7 @@ public class OOMEHMaster extends HMaster
return super.regionServerReport(serverInfo, msgs, mostLoadedRegions);
}
- /**
- * @param args
- * @throws IOException
- */
public static void main(String[] args) throws Exception {
- doMain(args, OOMEHMaster.class);
+ new HMasterCommandLine(OOMEHMaster.class).doMain(args);
}
}
Modified:
hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/OOMERegionServer.java
URL:
http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/OOMERegionServer.java?rev=996633&r1=996632&r2=996633&view=diff
==============================================================================
---
hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/OOMERegionServer.java
(original)
+++
hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/OOMERegionServer.java
Mon Sep 13 18:37:11 2010
@@ -49,7 +49,7 @@ public class OOMERegionServer extends HR
}
}
- public static void main(String[] args) {
- HRegionServer.doMain(args, OOMERegionServer.class);
+ public static void main(String[] args) throws Exception {
+ new HRegionServerCommandLine(OOMERegionServer.class).doMain(args);
}
}
\ No newline at end of file