bookkeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From si...@apache.org
Subject bookkeeper git commit: BOOKKEEPER-966: change bookieServer cmdline to make conf-file and option co-exist
Date Sat, 17 Dec 2016 01:45:14 GMT
Repository: bookkeeper
Updated Branches:
  refs/heads/master 669ab4ac3 -> 73edd4a99


BOOKKEEPER-966: change bookieServer cmdline to make conf-file and option co-exist

Currently, when using bookieServer cmdline to start a bookie, you will either give it a cofiguration
file by "-c booke.conf"; or add some options like "<bookie_port> <zk_servers>
<journal_dir> <ledger_dir [ledger_dir]>" in a fix sequential.
It may not satisfy some of the requirement. So changed it to be co-exist for configuration
file and options.

By this change, it will first use settings in configuration file; and then use options to
overwrite some of the settings, if there are some options provided.

Here is an example after this change:
```
BookieServer -c bookie.conf -z localhost:2181 -m /bookkeeper/ledgers -p 3181 -j /mnt/journal
-l "/mnt/ledger1 /mnt/ledger2 /mnt/ledger3”
```
Here, in this command:
-z is for “Zookeeper client instance”;
-m is for "Zookeeper ledgers root path for bookies";
-p is for "bookie service port exported";
-j is for "bookie journal directory";
-l is for "bookie ledgers directories".

Author: jiazhai <jia.zhai@emc.com>
Author: jiazhai <jiazhai@users.noreply.github.com>

Reviewers: Enrico Olivelli <eolivelli@gmail.com>, Sijie Guo <sijie@apache.org>

Closes #75 from jiazhai/BOOKKEEPER-966


Project: http://git-wip-us.apache.org/repos/asf/bookkeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/bookkeeper/commit/73edd4a9
Tree: http://git-wip-us.apache.org/repos/asf/bookkeeper/tree/73edd4a9
Diff: http://git-wip-us.apache.org/repos/asf/bookkeeper/diff/73edd4a9

Branch: refs/heads/master
Commit: 73edd4a99191d3c710b24a85eed3e2dbcd0a93bc
Parents: 669ab4a
Author: jiazhai <jia.zhai@emc.com>
Authored: Fri Dec 16 17:45:11 2016 -0800
Committer: Sijie Guo <sijie@apache.org>
Committed: Fri Dec 16 17:45:11 2016 -0800

----------------------------------------------------------------------
 .../apache/bookkeeper/proto/BookieServer.java   | 77 ++++++++++++++++----
 1 file changed, 62 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/73edd4a9/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..461f347 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,16 @@ 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 indexDirs = new Option ("i", "indexdirs", true, "bookie index directories");
+        indexDirs.setArgs(10);
+        bkOpts.addOption(indexDirs);
+        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 +290,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 -i \"/mnt/index1 /mnt/index2\" -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 +329,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 +341,50 @@ 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('i')) {
+                String[] sIndexDirs = cmdLine.getOptionValues('i');
+                LOG.info("Get cmdline index dirs: ");
+                for(String index : sIndexDirs) {
+                    LOG.info("indexDir : " + index);
+                }
+                conf.setIndexDirName(sIndexDirs);
+            }
+
+            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