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();
}
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));
}
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);
}
}
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;
}
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;
}
}
}
Aggregations