Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id BAF6F200BB7 for ; Wed, 9 Nov 2016 09:23:28 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id B9A81160AEE; Wed, 9 Nov 2016 08:23:28 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id DB536160AFD for ; Wed, 9 Nov 2016 09:23:27 +0100 (CET) Received: (qmail 93591 invoked by uid 500); 9 Nov 2016 08:23:27 -0000 Mailing-List: contact commits-help@bookkeeper.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: bookkeeper-dev@bookkeeper.apache.org Delivered-To: mailing list commits@bookkeeper.apache.org Received: (qmail 93575 invoked by uid 99); 9 Nov 2016 08:23:27 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 09 Nov 2016 08:23:27 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D93A9E07EF; Wed, 9 Nov 2016 08:23:26 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: zhaijia@apache.org To: commits@bookkeeper.apache.org Message-Id: <38e093184fe84501a1cafc7a4b27f165@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: bookkeeper git commit: change BookieServer cmdline Date: Wed, 9 Nov 2016 08:23:26 +0000 (UTC) archived-at: Wed, 09 Nov 2016 08:23:28 -0000 Repository: bookkeeper Updated Branches: refs/heads/BOOKKEEPER-966 [created] e5c494256 change BookieServer cmdline Project: http://git-wip-us.apache.org/repos/asf/bookkeeper/repo Commit: http://git-wip-us.apache.org/repos/asf/bookkeeper/commit/e5c49425 Tree: http://git-wip-us.apache.org/repos/asf/bookkeeper/tree/e5c49425 Diff: http://git-wip-us.apache.org/repos/asf/bookkeeper/diff/e5c49425 Branch: refs/heads/BOOKKEEPER-966 Commit: e5c49425656287cb99e51226ea03b231c05729ee Parents: 8f0bed9 Author: jiazhai Authored: Wed Nov 9 16:22:31 2016 +0800 Committer: jiazhai Committed: Wed Nov 9 16:22:31 2016 +0800 ---------------------------------------------------------------------- .../apache/bookkeeper/proto/BookieServer.java | 65 +++++++++++++++----- 1 file changed, 50 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/e5c49425/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieServer.java ---------------------------------------------------------------------- diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieServer.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieServer.java index 637587f..be8ed07 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieServer.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieServer.java @@ -24,6 +24,7 @@ import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.UnknownHostException; +import java.lang.Integer; import org.apache.bookkeeper.bookie.Bookie; import org.apache.bookkeeper.bookie.ReadOnlyBookie; @@ -45,6 +46,7 @@ import org.apache.commons.cli.BasicParser; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Options; +import org.apache.commons.cli.Option; import org.apache.commons.cli.ParseException; import org.apache.commons.configuration.ConfigurationException; import org.apache.zookeeper.KeeperException; @@ -270,6 +272,13 @@ public class BookieServer { "Start Autorecovery service Bookie server"); bkOpts.addOption("readOnly", false, "Force Start a ReadOnly Bookie server"); + bkOpts.addOption("z", "zkserver", true, "Zookeeper Server"); + bkOpts.addOption("m", "zkledgerpath", true, "Zookeeper ledgers root path"); + bkOpts.addOption("p", "bookieport", true, "bookie port exported"); + bkOpts.addOption("j", "journal", true, "bookie journal directory"); + Option ledgerDirs = new Option ("l", "ledgerdirs", true, "bookie ledgers directories"); + ledgerDirs.setArgs(10); + bkOpts.addOption(ledgerDirs); bkOpts.addOption("h", "help", false, "Print help message"); } @@ -278,8 +287,14 @@ public class BookieServer { */ private static void printUsage() { HelpFormatter hf = new HelpFormatter(); - hf.printHelp("BookieServer [options]\n\tor\n" - + "BookieServer ", bkOpts); + String header = "\n" + + "BookieServer provide an interface to start a bookie with configuration file and/or arguments." + + "The settings in configuration file will be overwrite by provided arguments.\n" + + "Options including:\n"; + String footer = "Here is an example:\n" + + "\tBookieServer -c bookie.conf -z localhost:2181 -m /bookkeeper/ledgers " + + "-p 3181 -j /mnt/journal -l \"/mnt/ledger1 /mnt/ledger2 /mnt/ledger3\"\n"; + hf.printHelp("BookieServer [options]\n", header, bkOpts, footer, true); } private static void loadConfFile(ServerConfiguration conf, String confFile) @@ -311,12 +326,8 @@ public class BookieServer { String[] leftArgs = cmdLine.getArgs(); if (cmdLine.hasOption('c')) { - if (null != leftArgs && leftArgs.length > 0) { - throw new IllegalArgumentException(); - } String confFile = cmdLine.getOptionValue("c"); loadConfFile(conf, confFile); - return conf; } if (cmdLine.hasOption("withAutoRecovery")) { @@ -327,17 +338,41 @@ public class BookieServer { conf.setForceReadOnlyBookie(true); } - if (leftArgs.length < 4) { - throw new IllegalArgumentException(); - } // command line arguments overwrite settings in configuration file - conf.setBookiePort(Integer.parseInt(leftArgs[0])); - conf.setZkServers(leftArgs[1]); - conf.setJournalDirName(leftArgs[2]); - String[] ledgerDirNames = new String[leftArgs.length - 3]; - System.arraycopy(leftArgs, 3, ledgerDirNames, 0, ledgerDirNames.length); - conf.setLedgerDirNames(ledgerDirNames); + if (cmdLine.hasOption('z')) { + String sZK = cmdLine.getOptionValue('z'); + LOG.info("Get cmdline zookeeper instance: " + sZK); + conf.setZkServers(sZK); + } + + if (cmdLine.hasOption('m')) { + String sZkLedgersRootPath = cmdLine.getOptionValue('m'); + LOG.info("Get cmdline zookeeper ledger path: " + sZkLedgersRootPath); + conf.setZkLedgersRootPath(sZkLedgersRootPath); + } + + if (cmdLine.hasOption('p')) { + String sPort = cmdLine.getOptionValue('p'); + LOG.info("Get cmdline bookie port: " + sPort); + Integer iPort = Integer.parseInt(sPort); + conf.setBookiePort(iPort.intValue()); + } + + if (cmdLine.hasOption('j')) { + String sJournalDir = cmdLine.getOptionValue('j'); + LOG.info("Get cmdline journal dir: " + sJournalDir); + conf.setJournalDirName(sJournalDir); + } + + if (cmdLine.hasOption('l')) { + String[] sLedgerDirs = cmdLine.getOptionValues('l'); + LOG.info("Get cmdline ledger dirs: "); + for(String ledger : sLedgerDirs) { + LOG.info("ledgerdir : " + ledger); + } + conf.setLedgerDirNames(sLedgerDirs); + } return conf; } catch (ParseException e) {