bookkeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mme...@apache.org
Subject bookkeeper git commit: BOOKKEEPER-910: In LocalBookkeeper, Zookeeper server and client use different host addresses
Date Tue, 05 Apr 2016 19:54:36 GMT
Repository: bookkeeper
Updated Branches:
  refs/heads/master e5939ed58 -> 19a5efe21


BOOKKEEPER-910: In LocalBookkeeper, Zookeeper server and client use different host addresses

Author: Arun M. Krishnakumar <akrishnakumar@salesforce.com>

Reviewers: Matteo Merli <mmerli@apache.org>


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

Branch: refs/heads/master
Commit: 19a5efe21ca0b33156a405f1084ddaa9ba4b28f5
Parents: e5939ed
Author: Arun M. Krishnakumar <akrishnakumar@salesforce.com>
Authored: Tue Apr 5 12:52:16 2016 -0700
Committer: Matteo Merli <mmerli@apache.org>
Committed: Tue Apr 5 12:53:42 2016 -0700

----------------------------------------------------------------------
 .../apache/bookkeeper/util/LocalBookKeeper.java   | 18 ++++++++++--------
 .../org/apache/bookkeeper/test/ZooKeeperUtil.java |  7 ++++---
 2 files changed, 14 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/19a5efe2/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/LocalBookKeeper.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/LocalBookKeeper.java
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/LocalBookKeeper.java
index 7d88c0b..80e8c7a 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/LocalBookKeeper.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/LocalBookKeeper.java
@@ -62,7 +62,6 @@ public class LocalBookKeeper {
         LOG.info("Running " + this.numberOfBookies + " bookie(s).");
     }
 
-    private final String HOSTPORT = "127.0.0.1:2181";
     NIOServerCnxnFactory serverFactory;
     ZooKeeperServer zks;
     ZooKeeper zkc;
@@ -87,26 +86,28 @@ public class LocalBookKeeper {
         //ClientBase.setupTestEnv();
         ZkTmpDir = IOUtils.createTempDir("zookeeper", "localbookkeeper");
 
+        InetAddress loopbackIP = InetAddress.getLoopbackAddress();
         try {
             zks = new ZooKeeperServer(ZkTmpDir, ZkTmpDir, ZooKeeperServer.DEFAULT_TICK_TIME);
             serverFactory =  new NIOServerCnxnFactory();
-            serverFactory.configure(new InetSocketAddress(ZooKeeperDefaultPort), maxCC);
+            LOG.info("Starting Zookeeper server at " + loopbackIP.getHostAddress() + " port:"
+ ZooKeeperDefaultPort);
+            serverFactory.configure(new InetSocketAddress(loopbackIP, ZooKeeperDefaultPort),
maxCC);
             serverFactory.startup(zks);
         } catch (Exception e) {
             // TODO Auto-generated catch block
             LOG.error("Exception while instantiating ZooKeeper", e);
         }
 
-        boolean b = waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT);
+        boolean b = waitForServerUp(loopbackIP.getHostAddress() + ":" + ZooKeeperDefaultPort,
CONNECTION_TIMEOUT);
         LOG.debug("ZooKeeper server up: {}", b);
     }
 
-    private void initializeZookeper() throws IOException {
+    private void initializeZookeeper() throws IOException {
         LOG.info("Instantiate ZK Client");
         //initialize the zk client with values
         try {
             zkc = ZooKeeperClient.newBuilder()
-                    .connectString(HOSTPORT)
+                    .connectString(InetAddress.getLoopbackAddress() + ":" + ZooKeeperDefaultPort)
                     .sessionTimeoutMs(zkSessionTimeOut)
                     .build();
             zkc.create("/ledgers", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
@@ -166,6 +167,7 @@ public class LocalBookKeeper {
         bs = new BookieServer[numberOfBookies];
         bsConfs = new ServerConfiguration[numberOfBookies];
 
+        String loopbackIPAddr = InetAddress.getLoopbackAddress().getHostAddress();
         for(int i = 0; i < numberOfBookies; i++) {
             tmpDirs[i] = File.createTempFile("bookie" + Integer.toString(i), "test");
             if (!tmpDirs[i].delete() || !tmpDirs[i].mkdir()) {
@@ -175,8 +177,8 @@ public class LocalBookKeeper {
             bsConfs[i] = new ServerConfiguration(baseConf);
             // override settings
             bsConfs[i].setBookiePort(initialPort + i);
-            bsConfs[i].setZkServers(InetAddress.getLocalHost().getHostAddress() + ":"
-                                  + ZooKeeperDefaultPort);
+            LOG.info("Connecting to Zookeeper at " + loopbackIPAddr + " port:" + ZooKeeperDefaultPort);
+            bsConfs[i].setZkServers(loopbackIPAddr + ":" + ZooKeeperDefaultPort);
             bsConfs[i].setJournalDirName(tmpDirs[i].getPath());
             bsConfs[i].setLedgerDirNames(new String[] { tmpDirs[i].getPath() });
             bsConfs[i].setAllowLoopback(true);
@@ -208,7 +210,7 @@ public class LocalBookKeeper {
         }
 
         lb.runZookeeper(1000);
-        lb.initializeZookeper();
+        lb.initializeZookeeper();
         List<File> tmpDirs = lb.runBookies(conf, "test");
         try {
             while (true) {

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/19a5efe2/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/ZooKeeperUtil.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/ZooKeeperUtil.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/ZooKeeperUtil.java
index 930e42a..481b647 100644
--- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/ZooKeeperUtil.java
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/ZooKeeperUtil.java
@@ -23,7 +23,7 @@ package org.apache.bookkeeper.test;
 
 import java.io.File;
 import java.io.IOException;
-
+import java.net.InetAddress;
 import java.net.InetSocketAddress;
 
 import org.apache.bookkeeper.util.IOUtils;
@@ -61,8 +61,9 @@ public class ZooKeeperUtil {
     private final String connectString;
 
     public ZooKeeperUtil() {
-        zkaddr = new InetSocketAddress(zooKeeperPort);
-        connectString= "localhost:" + zooKeeperPort;
+        String loopbackIPAddr = InetAddress.getLoopbackAddress().getHostAddress();
+        zkaddr = new InetSocketAddress(loopbackIPAddr, zooKeeperPort);
+        connectString = loopbackIPAddr + ":" + zooKeeperPort;
     }
 
     public ZooKeeper getZooKeeperClient() {


Mime
View raw message