org.apache.bookkeeper.util.LocalBookKeeper Java Examples

The following examples show how to use org.apache.bookkeeper.util.LocalBookKeeper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestBookKeeperConfiguration.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setupZooKeeper() throws Exception {
  // create a ZooKeeper server(dataDir, dataLogDir, port)
  LOG.info("Starting ZK server");
  ZkTmpDir = File.createTempFile("zookeeper", "test");
  ZkTmpDir.delete();
  ZkTmpDir.mkdir();

  try {
    zks = new ZooKeeperServer(ZkTmpDir, ZkTmpDir, ZooKeeperDefaultPort);
    serverFactory = new NIOServerCnxnFactory();
    serverFactory.configure(new InetSocketAddress(ZooKeeperDefaultPort), 10);
    serverFactory.startup(zks);
  } catch (Exception e) {
    LOG.error("Exception while instantiating ZooKeeper", e);
  }

  boolean b = LocalBookKeeper.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT);
  LOG.debug("ZooKeeper server up: " + b);
}
 
Example #2
Source File: BKJMUtil.java    From hadoop with Apache License 2.0 6 votes vote down vote up
BKJMUtil(final int numBookies) throws Exception {
  this.numBookies = numBookies;

  bkthread = new Thread() {
      public void run() {
        try {
          String[] args = new String[1];
          args[0] = String.valueOf(numBookies);
          LOG.info("Starting bk");
          LocalBookKeeper.main(args);
        } catch (InterruptedException e) {
          // go away quietly
        } catch (Exception e) {
          LOG.error("Error starting local bk", e);
        }
      }
    };
}
 
Example #3
Source File: TestCurrentInprogress.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setupZooKeeper() throws Exception {
  LOG.info("Starting ZK server");
  zkTmpDir = File.createTempFile("zookeeper", "test");
  zkTmpDir.delete();
  zkTmpDir.mkdir();
  try {
    zks = new ZooKeeperServer(zkTmpDir, zkTmpDir, ZooKeeperDefaultPort);
    serverFactory = new NIOServerCnxnFactory();
    serverFactory.configure(new InetSocketAddress(ZooKeeperDefaultPort), 10);
    serverFactory.startup(zks);
  } catch (Exception e) {
    LOG.error("Exception while instantiating ZooKeeper", e);
  }
  boolean b = LocalBookKeeper.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT);
  LOG.debug("ZooKeeper server up: " + b);
}
 
Example #4
Source File: TestCurrentInprogress.java    From big-c with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setupZooKeeper() throws Exception {
  LOG.info("Starting ZK server");
  zkTmpDir = File.createTempFile("zookeeper", "test");
  zkTmpDir.delete();
  zkTmpDir.mkdir();
  try {
    zks = new ZooKeeperServer(zkTmpDir, zkTmpDir, ZooKeeperDefaultPort);
    serverFactory = new NIOServerCnxnFactory();
    serverFactory.configure(new InetSocketAddress(ZooKeeperDefaultPort), 10);
    serverFactory.startup(zks);
  } catch (Exception e) {
    LOG.error("Exception while instantiating ZooKeeper", e);
  }
  boolean b = LocalBookKeeper.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT);
  LOG.debug("ZooKeeper server up: " + b);
}
 
Example #5
Source File: TestBookKeeperConfiguration.java    From big-c with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setupZooKeeper() throws Exception {
  // create a ZooKeeper server(dataDir, dataLogDir, port)
  LOG.info("Starting ZK server");
  ZkTmpDir = File.createTempFile("zookeeper", "test");
  ZkTmpDir.delete();
  ZkTmpDir.mkdir();

  try {
    zks = new ZooKeeperServer(ZkTmpDir, ZkTmpDir, ZooKeeperDefaultPort);
    serverFactory = new NIOServerCnxnFactory();
    serverFactory.configure(new InetSocketAddress(ZooKeeperDefaultPort), 10);
    serverFactory.startup(zks);
  } catch (Exception e) {
    LOG.error("Exception while instantiating ZooKeeper", e);
  }

  boolean b = LocalBookKeeper.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT);
  LOG.debug("ZooKeeper server up: " + b);
}
 
Example #6
Source File: BKJMUtil.java    From big-c with Apache License 2.0 6 votes vote down vote up
BKJMUtil(final int numBookies) throws Exception {
  this.numBookies = numBookies;

  bkthread = new Thread() {
      public void run() {
        try {
          String[] args = new String[1];
          args[0] = String.valueOf(numBookies);
          LOG.info("Starting bk");
          LocalBookKeeper.main(args);
        } catch (InterruptedException e) {
          // go away quietly
        } catch (Exception e) {
          LOG.error("Error starting local bk", e);
        }
      }
    };
}
 
Example #7
Source File: LocalDLMEmulator.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
private LocalDLMEmulator(final int numBookies, final boolean shouldStartZK,
                         final String zkHost, final int zkPort, final int initialBookiePort,
                         final int zkTimeoutSec, final ServerConfiguration serverConf) throws Exception {
    this.numBookies = numBookies;
    this.zkHost = zkHost;
    this.zkPort = zkPort;
    this.zkEnsemble = zkHost + ":" + zkPort;
    this.uri = URI.create("distributedlog://" + zkEnsemble + DLOG_NAMESPACE);
    this.zkTimeoutSec = zkTimeoutSec;
    this.bkStartupThread = new Thread() {
        public void run() {
            try {
                LOG.info("Starting {} bookies : allowLoopback = {}", numBookies, serverConf.getAllowLoopback());
                LocalBookKeeper.startLocalBookies(zkHost, zkPort,
                        numBookies, shouldStartZK, initialBookiePort, serverConf);
                LOG.info("{} bookies are started.");
            } catch (InterruptedException e) {
                // go away quietly
            } catch (Exception e) {
                LOG.error("Error starting local bk", e);
            }
        }
    };
}
 
Example #8
Source File: LocalDLMEmulator.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
private LocalDLMEmulator(final int numBookies, final boolean shouldStartZK, final String zkHost, final int zkPort, final int initialBookiePort, final int zkTimeoutSec, final ServerConfiguration serverConf) throws Exception {
    this.numBookies = numBookies;
    this.zkHost = zkHost;
    this.zkPort = zkPort;
    this.zkEnsemble = zkHost + ":" + zkPort;
    this.uri = URI.create("distributedlog://" + zkEnsemble + DLOG_NAMESPACE);
    this.zkTimeoutSec = zkTimeoutSec;
    this.bkStartupThread = new Thread() {
        public void run() {
            try {
                LOG.info("Starting {} bookies : allowLoopback = {}", numBookies, serverConf.getAllowLoopback());
                LocalBookKeeper.startLocalBookies(zkHost, zkPort, numBookies, shouldStartZK, initialBookiePort, serverConf);
                LOG.info("{} bookies are started.");
            } catch (InterruptedException e) {
                // go away quietly
            } catch (Exception e) {
                LOG.error("Error starting local bk", e);
            }
        }
    };
}
 
Example #9
Source File: DistributedLogCluster.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
private DistributedLogCluster(DistributedLogConfiguration dlConf,
                              ServerConfiguration bkConf,
                              int numBookies,
                              boolean shouldStartZK,
                              String zkServers,
                              int zkPort,
                              boolean shouldStartProxy,
                              int proxyPort) throws Exception {
    this.dlConf = dlConf;
    if (shouldStartZK) {
        File zkTmpDir = IOUtils.createTempDir("zookeeper", "distrlog");
        tmpDirs.add(zkTmpDir);
        if (0 == zkPort) {
            Pair<ZooKeeperServerShim, Integer> serverAndPort = LocalDLMEmulator.runZookeeperOnAnyPort(zkTmpDir);
            this.zks = serverAndPort.getLeft();
            zkPort = serverAndPort.getRight();
        } else {
            this.zks = LocalBookKeeper.runZookeeper(1000, zkPort, zkTmpDir);
        }
    } else {
        this.zks = null;
    }
    this.dlmEmulator = LocalDLMEmulator.newBuilder()
            .numBookies(numBookies)
            .zkHost(zkServers)
            .zkPort(zkPort)
            .serverConf(bkConf)
            .shouldStartZK(false)
            .build();
    this.shouldStartProxy = shouldStartProxy;
    this.proxyPort = proxyPort;
}
 
Example #10
Source File: LocalDLMEmulator.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
/**
 * Try to start zookkeeper locally on any port beginning with some base port.
 * Dump some socket info when bind fails.
 */
public static Pair<ZooKeeperServerShim, Integer> runZookeeperOnAnyPort(int basePort, File zkDir) throws Exception {

    final int MAX_RETRIES = 20;
    final int MIN_PORT = 1025;
    final int MAX_PORT = 65535;
    ZooKeeperServerShim zks = null;
    int zkPort = basePort;
    boolean success = false;
    int retries = 0;

    while (!success) {
        try {
            LOG.info("zk trying to bind to port " + zkPort);
            zks = LocalBookKeeper.runZookeeper(1000, zkPort, zkDir);
            success = true;
        } catch (BindException be) {
            retries++;
            if (retries > MAX_RETRIES) {
                throw be;
            }
            zkPort++;
            if (zkPort > MAX_PORT) {
                zkPort = MIN_PORT;
            }
        }
    }

    return Pair.of(zks, zkPort);
}
 
Example #11
Source File: LocalDLMEmulator.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
public void start() throws Exception {
    bkStartupThread.start();
    if (!LocalBookKeeper.waitForServerUp(zkEnsemble, zkTimeoutSec*1000)) {
        throw new Exception("Error starting zookeeper/bookkeeper");
    }
    int bookiesUp = checkBookiesUp(numBookies, zkTimeoutSec);
    assert (numBookies == bookiesUp);
    // Provision "/messaging/distributedlog" namespace
    DLMetadata.create(new BKDLConfig(zkEnsemble, "/ledgers")).create(uri);
}
 
Example #12
Source File: LocalDLMEmulator.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
/**
 * Try to start zookkeeper locally on any port beginning with some base port.
 * Dump some socket info when bind fails.
 */
public static Pair<ZooKeeperServerShim, Integer> runZookeeperOnAnyPort(int basePort, File zkDir) throws Exception {

    final int maxRetries = 20;
    final int minPort = 1025;
    final int maxPort = 65535;
    ZooKeeperServerShim zks = null;
    int zkPort = basePort;
    boolean success = false;
    int retries = 0;

    while (!success) {
        try {
            LOG.info("zk trying to bind to port " + zkPort);
            zks = LocalBookKeeper.runZookeeper(1000, zkPort, zkDir);
            success = true;
        } catch (BindException be) {
            retries++;
            if (retries > maxRetries) {
                throw be;
            }
            zkPort++;
            if (zkPort > maxPort) {
                zkPort = minPort;
            }
        }
    }

    return Pair.of(zks, zkPort);
}
 
Example #13
Source File: LocalDLMEmulator.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
public void start() throws Exception {
    bkStartupThread.start();
    if (!LocalBookKeeper.waitForServerUp(zkEnsemble, zkTimeoutSec * 1000)) {
        throw new Exception("Error starting zookeeper/bookkeeper");
    }
    int bookiesUp = checkBookiesUp(numBookies, zkTimeoutSec);
    if (numBookies != bookiesUp) {
        LOG.info("Only {} bookies are up, expected {} bookies to be there.",
            bookiesUp, numBookies);
    }
    assert (numBookies == bookiesUp);
    // Provision "/messaging/distributedlog" namespace
    DLMetadata.create(new BKDLConfig(zkEnsemble, "/ledgers")).create(uri);
}
 
Example #14
Source File: DistributedLogCluster.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
private DistributedLogCluster(DistributedLogConfiguration dlConf,
                              ServerConfiguration bkConf,
                              int numBookies,
                              boolean shouldStartZK,
                              String zkServers,
                              int zkPort,
                              boolean shouldStartProxy,
                              int proxyPort,
                              boolean thriftmux) throws Exception {
    this.dlConf = dlConf;
    if (shouldStartZK) {
        File zkTmpDir = IOUtils.createTempDir("zookeeper", "distrlog");
        tmpDirs.add(zkTmpDir);
        if (0 == zkPort) {
            Pair<ZooKeeperServerShim, Integer> serverAndPort = LocalDLMEmulator.runZookeeperOnAnyPort(zkTmpDir);
            this.zks = serverAndPort.getLeft();
            zkPort = serverAndPort.getRight();
        } else {
            this.zks = LocalBookKeeper.runZookeeper(1000, zkPort, zkTmpDir);
        }
    } else {
        this.zks = null;
    }
    this.dlmEmulator = LocalDLMEmulator.newBuilder()
            .numBookies(numBookies)
            .zkHost(zkServers)
            .zkPort(zkPort)
            .serverConf(bkConf)
            .shouldStartZK(false)
            .build();
    this.shouldStartProxy = shouldStartProxy;
    this.proxyPort = proxyPort;
    this.thriftmux = thriftmux;
}
 
Example #15
Source File: BKJMUtil.java    From big-c with Apache License 2.0 5 votes vote down vote up
void start() throws Exception {
  bkthread.start();
  if (!LocalBookKeeper.waitForServerUp(zkEnsemble, 10000)) {
    throw new Exception("Error starting zookeeper/bookkeeper");
  }
  assertEquals("Not all bookies started",
               numBookies, checkBookiesUp(numBookies, 10));
}
 
Example #16
Source File: BKJMUtil.java    From hadoop with Apache License 2.0 5 votes vote down vote up
void start() throws Exception {
  bkthread.start();
  if (!LocalBookKeeper.waitForServerUp(zkEnsemble, 10000)) {
    throw new Exception("Error starting zookeeper/bookkeeper");
  }
  assertEquals("Not all bookies started",
               numBookies, checkBookiesUp(numBookies, 10));
}
 
Example #17
Source File: ZooKeeperServiceRunner.java    From pravega with Apache License 2.0 3 votes vote down vote up
/**
 * Blocks the current thread and awaits ZooKeeper to start running locally on the given port.
 *
 * @param zkPort The ZooKeeper Port.
 * @param secureZk Flag to notify whether the ZK is secure.
 * @param trustStore Location of the trust store.
 * @param keyStore Location of the key store.
 * @param keyStorePasswordPath Location of password path for key store.
 *                             Empty string if `secureZk` is false or a password does not exist.
 * @param trustStore Location of the trust store.
 * @param trustStorePasswordPath Location of password path for trust store.
 *                               Empty string if `secureZk` is false or a password does not exist.
 * @return True if ZooKeeper started within a specified timeout, false otherwise.
 */
private static boolean waitForServerUp(int zkPort, boolean secureZk, String keyStore, String keyStorePasswordPath,
                                      String trustStore, String trustStorePasswordPath) {
    val address = LOOPBACK_ADDRESS + ":" + zkPort;
    if (secureZk) {
        return waitForSSLServerUp(address, LocalBookKeeper.CONNECTION_TIMEOUT, keyStore, keyStorePasswordPath,
                trustStore, trustStorePasswordPath);
    } else {
        return LocalBookKeeper.waitForServerUp(address, LocalBookKeeper.CONNECTION_TIMEOUT);
    }
}