Java Code Examples for org.apache.bookkeeper.util.LocalBookKeeper#waitForServerUp()

The following examples show how to use org.apache.bookkeeper.util.LocalBookKeeper#waitForServerUp() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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);
    }
}