bookkeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhai...@apache.org
Subject bookkeeper git commit: change BookieServer cmdline
Date Wed, 09 Nov 2016 08:23:26 GMT
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 <jia.zhai@emc.com>
Authored: Wed Nov 9 16:22:31 2016 +0800
Committer: jiazhai <jia.zhai@emc.com>
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 <bookie_port> <zk_servers> <journal_dir>
<ledger_dir [ledger_dir]>", 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) {


Mime
View raw message