@Test public void testMkNodesWhenNoNodesExist() throws Exception { assertDoesNotExist("/test/foo/bar"); ZkUtils.mkNodes(_zooKeeper, "test", "foo", "bar"); assertExists("/test/foo/bar"); }
public static void mkNodes(ZooKeeper zk, String... path) { if (path == null) { return; } for (int i = 0; i < path.length; i++) { StringBuilder builder = new StringBuilder(); for (int j = 0; j <= i; j++) { if (!path[j].isEmpty()) { builder.append('/'); builder.append(path[j]); } } String pathToCheck = removeDupSeps(builder.toString()); if (pathToCheck.isEmpty()) { continue; } try { if (zk.exists(pathToCheck, false) == null) { zk.create(pathToCheck, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); } } catch (NodeExistsException e) { } catch (KeeperException e) { LOG.error("error", e); throw new RuntimeException(e); } catch (InterruptedException e) { LOG.error("error", e); throw new RuntimeException(e); } } }
ZkUtils { public static void mkNodes(ZooKeeper zk, String... path) { if (path == null) { return; } for (int i = 0; i < path.length; i++) { StringBuilder builder = new StringBuilder(); for (int j = 0; j <= i; j++) { if (!path[j].isEmpty()) { builder.append('/'); builder.append(path[j]); } } String pathToCheck = removeDupSeps(builder.toString()); if (pathToCheck.isEmpty()) { continue; } try { if (zk.exists(pathToCheck, false) == null) { zk.create(pathToCheck, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); } } catch (NodeExistsException e) { } catch (KeeperException e) { LOG.error("error", e); throw new RuntimeException(e); } catch (InterruptedException e) { LOG.error("error", e); throw new RuntimeException(e); } } } }
ZkUtils { public static void mkNodes(ZooKeeper zk, String... path) { if (path == null) { return; } for (int i = 0; i < path.length; i++) { StringBuilder builder = new StringBuilder(); for (int j = 0; j <= i; j++) { if (!path[j].isEmpty()) { builder.append('/'); builder.append(path[j]); } } String pathToCheck = removeDupSeps(builder.toString()); if (pathToCheck.isEmpty()) { continue; } try { if (zk.exists(pathToCheck, false) == null) { zk.create(pathToCheck, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); } } catch (NodeExistsException e) { } catch (KeeperException e) { LOG.error("error", e); throw new RuntimeException(e); } catch (InterruptedException e) { LOG.error("error", e); throw new RuntimeException(e); } } }  }
ZkUtils { public static void mkNodes(ZooKeeper zk, String... path) { if (path == null) { return; } for (int i = 0; i < path.length; i++) { StringBuilder builder = new StringBuilder(); for (int j = 0; j <= i; j++) { if (!path[j].isEmpty()) { builder.append('/'); builder.append(path[j]); } } String pathToCheck = removeDupSeps(builder.toString()); if (pathToCheck.isEmpty()) { continue; } try { if (zk.exists(pathToCheck, false) == null) { zk.create(pathToCheck, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); } } catch (NodeExistsException e) { } catch (KeeperException e) { LOG.error("error", e); throw new RuntimeException(e); } catch (InterruptedException e) { LOG.error("error", e); throw new RuntimeException(e); } } }  static ZooKeeper newZooKeeper(String zkConnectionString); static void mkNodesStr(ZooKeeper zk, String path); static void mkNodes(ZooKeeper zk, String... path); static String getPath(String... parts); static boolean exists(ZooKeeper zk, String... path); static void deleteAnyVersion(ZooKeeper zk, String path); static void waitUntilExists(ZooKeeper zooKeeper, String path); }
ZkUtils { public static void mkNodes(ZooKeeper zk, String... path) { if (path == null) { return; } for (int i = 0; i < path.length; i++) { StringBuilder builder = new StringBuilder(); for (int j = 0; j <= i; j++) { if (!path[j].isEmpty()) { builder.append('/'); builder.append(path[j]); } } String pathToCheck = removeDupSeps(builder.toString()); if (pathToCheck.isEmpty()) { continue; } try { if (zk.exists(pathToCheck, false) == null) { zk.create(pathToCheck, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); } } catch (NodeExistsException e) { } catch (KeeperException e) { LOG.error("error", e); throw new RuntimeException(e); } catch (InterruptedException e) { LOG.error("error", e); throw new RuntimeException(e); } } }  static ZooKeeper newZooKeeper(String zkConnectionString); static void mkNodesStr(ZooKeeper zk, String path); static void mkNodes(ZooKeeper zk, String... path); static String getPath(String... parts); static boolean exists(ZooKeeper zk, String... path); static void deleteAnyVersion(ZooKeeper zk, String path); static void waitUntilExists(ZooKeeper zooKeeper, String path); static final int ANY_VERSION; static final int DEFAULT_ZK_SESSION_TIMEOUT; }