Return-Path: Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: (qmail 13743 invoked from network); 13 Sep 2010 18:37:53 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 13 Sep 2010 18:37:53 -0000 Received: (qmail 4615 invoked by uid 500); 13 Sep 2010 18:37:53 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 4587 invoked by uid 500); 13 Sep 2010 18:37:52 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 4580 invoked by uid 99); 13 Sep 2010 18:37:52 -0000 Received: from Unknown (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Sep 2010 18:37:52 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Sep 2010 18:37:34 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 68C8323889E2; Mon, 13 Sep 2010 18:37:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r996633 - in /hbase/trunk: ./ src/main/java/org/apache/hadoop/hbase/master/ src/main/java/org/apache/hadoop/hbase/regionserver/ src/main/java/org/apache/hadoop/hbase/util/ src/test/java/org/apache/hadoop/hbase/master/ src/test/java/org/apac... Date: Mon, 13 Sep 2010 18:37:12 -0000 To: commits@hbase.apache.org From: todd@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100913183712.68C8323889E2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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 masterClass; - public HMasterCommandLine(Class 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 ]"); - 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 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 regionServerClass = (Class) 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 regionServerClass; + + private static final String USAGE = + "Usage: HRegionServer [-D conf.param=value] start"; + + public HRegionServerCommandLine(Class 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 run(). + */ + 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