Search in sources :

Example 56 with ZooKeeper

use of org.apache.zookeeper.ZooKeeper in project bookkeeper by apache.

the class AuditorBookieTest method tearDown.

@Override
public void tearDown() throws Exception {
    stopAuditorElectors();
    for (ZooKeeper zk : zkClients) {
        zk.close();
    }
    zkClients.clear();
    super.tearDown();
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper)

Example 57 with ZooKeeper

use of org.apache.zookeeper.ZooKeeper in project bookkeeper by apache.

the class TestZkUtils method testAsyncCreateAndDeleteFullPathOptimistic.

@Test
public void testAsyncCreateAndDeleteFullPathOptimistic() throws IOException, KeeperException, InterruptedException {
    ZooKeeper zkc = new ZooKeeper(zkUtil.getZooKeeperConnectString(), 10000, null);
    /*
         * "/ledgers/available" is already created in ZooKeeperUtil.startServer
         */
    String ledgerZnodePath = "/ledgers/000/000/000/001";
    ZkUtils.createFullPathOptimistic(zkc, ledgerZnodePath, "data".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    assertTrue(ledgerZnodePath + " zNode should exist", null != zkc.exists(ledgerZnodePath, false));
    ledgerZnodePath = "/ledgers/000/000/000/002";
    ZkUtils.createFullPathOptimistic(zkc, ledgerZnodePath, "data".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    assertTrue(ledgerZnodePath + " zNode should exist", null != zkc.exists(ledgerZnodePath, false));
    ZkUtils.deleteFullPathOptimistic(zkc, ledgerZnodePath, -1);
    assertTrue(ledgerZnodePath + " zNode should not exist, since it is deleted", null == zkc.exists(ledgerZnodePath, false));
    ledgerZnodePath = "/ledgers/000/000/000/001";
    assertTrue(ledgerZnodePath + " zNode should exist", null != zkc.exists(ledgerZnodePath, false));
    ZkUtils.deleteFullPathOptimistic(zkc, ledgerZnodePath, -1);
    assertTrue(ledgerZnodePath + " zNode should not exist, since it is deleted", null == zkc.exists(ledgerZnodePath, false));
    assertTrue("/ledgers/000" + " zNode should not exist, since it should be deleted recursively", null == zkc.exists(ledgerZnodePath, false));
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) Test(org.junit.Test)

Example 58 with ZooKeeper

use of org.apache.zookeeper.ZooKeeper in project bookkeeper by apache.

the class BookKeeperClusterUtils method legacyMetadataFormat.

public static void legacyMetadataFormat(DockerClient docker) throws Exception {
    try (ZooKeeper zk = BookKeeperClusterUtils.zookeeperClient(docker)) {
        zk.create("/ledgers", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        zk.create("/ledgers/available", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    }
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper)

Example 59 with ZooKeeper

use of org.apache.zookeeper.ZooKeeper in project bookkeeper by apache.

the class BookKeeperClusterUtils method waitBookieState.

private static boolean waitBookieState(DockerClient docker, String containerId, int timeout, TimeUnit timeoutUnit, boolean upOrDown) {
    long timeoutMillis = timeoutUnit.toMillis(timeout);
    long pollMillis = 1000;
    String bookieId = DockerUtils.getContainerIP(docker, containerId) + ":3181";
    try (ZooKeeper zk = BookKeeperClusterUtils.zookeeperClient(docker)) {
        String path = "/ledgers/available/" + bookieId;
        while (timeoutMillis > 0) {
            if ((zk.exists(path, false) != null) == upOrDown) {
                return true;
            }
            Thread.sleep(pollMillis);
            timeoutMillis -= pollMillis;
        }
    } catch (Exception e) {
        LOG.error("Exception checking for bookie state", e);
        return false;
    }
    LOG.warn("Bookie {} didn't go {} after {} seconds", containerId, upOrDown ? "up" : "down", timeoutUnit.toSeconds(timeout));
    return false;
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) IOException(java.io.IOException)

Example 60 with ZooKeeper

use of org.apache.zookeeper.ZooKeeper in project bookkeeper by apache.

the class BookKeeperClusterUtils method metadataFormatIfNeeded.

public static boolean metadataFormatIfNeeded(DockerClient docker, String version) throws Exception {
    try (ZooKeeper zk = BookKeeperClusterUtils.zookeeperClient(docker)) {
        if (zk.exists("/ledgers", false) == null) {
            String bookkeeper = "/opt/bookkeeper/" + version + "/bin/bookkeeper";
            runOnAnyBookie(docker, bookkeeper, "shell", "metaformat", "-nonInteractive");
            return true;
        } else {
            return false;
        }
    }
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper)

Aggregations

ZooKeeper (org.apache.zookeeper.ZooKeeper)605 Test (org.junit.jupiter.api.Test)190 KeeperException (org.apache.zookeeper.KeeperException)153 Test (org.junit.Test)100 Stat (org.apache.zookeeper.data.Stat)86 IOException (java.io.IOException)83 CountDownLatch (java.util.concurrent.CountDownLatch)80 WatchedEvent (org.apache.zookeeper.WatchedEvent)70 Watcher (org.apache.zookeeper.Watcher)59 ArrayList (java.util.ArrayList)47 CountdownWatcher (org.apache.zookeeper.test.ClientBase.CountdownWatcher)41 TestableZooKeeper (org.apache.zookeeper.TestableZooKeeper)38 Timeout (org.junit.jupiter.api.Timeout)32 ZooKeeperServer (org.apache.zookeeper.server.ZooKeeperServer)31 File (java.io.File)28 HashMap (java.util.HashMap)26 CompletableFuture (java.util.concurrent.CompletableFuture)22 Test (org.testng.annotations.Test)21 AsyncCallback (org.apache.zookeeper.AsyncCallback)19 ACL (org.apache.zookeeper.data.ACL)19