private static void verifyAclStrict(CuratorFramework zk, List<ACL> strictAcl, String path, boolean fixUp) throws Exception { try { List<ACL> foundAcl = zk.getACL().forPath(path); if (!equivalent(foundAcl, strictAcl)) { if (fixUp) { LOG.warn("{} expected to have ACL {}, but has {}. Fixing...", path, strictAcl, foundAcl); zk.setACL().withACL(strictAcl).forPath(path); } else { throw new IllegalStateException(path + " did not have the correct ACL found " + foundAcl + " expected " + strictAcl); } } } catch (KeeperException.NoNodeException ne) { LOG.debug("{} removed in the middle of checking it", ne); } }
public static Integer getVersion(CuratorFramework zk, String path, boolean watch) throws Exception { String npath = normalizePath(path); Stat stat = null; if (existsNode(zk, npath, watch)) { if (watch) { stat = zk.checkExists().watched().forPath(npath); } else { stat = zk.checkExists().forPath(npath); } } return stat == null ? null : Integer.valueOf(stat.getVersion()); }
public static List<String> getChildren(CuratorFramework zk, String path, boolean watch) { try { String npath = normalizePath(path); if (watch) { return zk.getChildren().watched().forPath(npath); } else { return zk.getChildren().forPath(npath); } } catch (Exception e) { throw Utils.wrapInRuntime(e); } }
public static boolean existsNode(CuratorFramework zk, String path, boolean watch) { Stat stat = null; try { if (watch) { stat = zk.checkExists().watched().forPath(normalizePath(path)); } else { stat = zk.checkExists().forPath(normalizePath(path)); } } catch (Exception e) { throw Utils.wrapInRuntime(e); } return stat != null; }
public static byte[] getData(CuratorFramework zk, String path, boolean watch) { try { String npath = normalizePath(path); if (existsNode(zk, npath, watch)) { if (watch) { return zk.getData().watched().forPath(npath); } else { return zk.getData().forPath(npath); } } } catch (Exception e) { if (Utils.exceptionCauseIsInstanceOf(KeeperException.NoNodeException.class, e)) { // this is fine b/c we still have a watch from the successful exists call } else { throw Utils.wrapInRuntime(e); } } return null; }
private static void verifyAclStrict(CuratorFramework zk, List<ACL> strictAcl, String path, boolean fixUp) throws Exception { try { List<ACL> foundAcl = zk.getACL().forPath(path); if (!equivalent(foundAcl, strictAcl)) { if (fixUp) { LOG.warn("{} expected to have ACL {}, but has {}. Fixing...", path, strictAcl, foundAcl); zk.setACL().withACL(strictAcl).forPath(path); } else { throw new IllegalStateException(path + " did not have the correct ACL found " + foundAcl + " expected " + strictAcl); } } } catch (KeeperException.NoNodeException ne) { LOG.debug("{} removed in the middle of checking it", ne); } }
protected void initWatcher() throws Exception { // create base path if necessary Stat stat = this.client.checkExists().usingWatcher(this).forPath(this.name); if (stat == null) { String path = this.client.create().creatingParentsIfNeeded().forPath(this.name); LOG.info("Created: " + path); } }
@Override public void process(WatchedEvent we) { try { this.client.checkExists().usingWatcher(this).forPath(this.name); LOG.debug("Renewed watch for path {}", this.name); } catch (Exception ex) { LOG.error("Error renewing watch.", ex); } switch (we.getType()) { case NodeCreated: LOG.debug("Node created."); break; case NodeDataChanged: LOG.debug("Received signal."); try { this.listener.onSignal(this.client.getData().forPath(we.getPath())); } catch (Exception e) { LOG.warn("Unable to process signal.", e); } break; case NodeDeleted: LOG.debug("NodeDeleted"); break; } }
public static Integer getVersion(CuratorFramework zk, String path, boolean watch) throws Exception { String npath = normalizePath(path); Stat stat = null; if (existsNode(zk, npath, watch)) { if (watch) { stat = zk.checkExists().watched().forPath(npath); } else { stat = zk.checkExists().forPath(npath); } } return stat == null ? null : Integer.valueOf(stat.getVersion()); }
public static List<String> getChildren(CuratorFramework zk, String path, boolean watch) { try { String npath = normalizePath(path); if (watch) { return zk.getChildren().watched().forPath(npath); } else { return zk.getChildren().forPath(npath); } } catch (Exception e) { throw Utils.wrapInRuntime(e); } }
public static boolean existsNode(CuratorFramework zk, String path, boolean watch){ Stat stat = null; try { if (watch) { stat = zk.checkExists().watched().forPath(normalizePath(path)); } else { stat = zk.checkExists().forPath(normalizePath(path)); } } catch (Exception e) { throw Utils.wrapInRuntime(e); } return stat != null; }
public static byte[] getData(CuratorFramework zk, String path, boolean watch){ try { String npath = normalizePath(path); if (existsNode(zk, npath, watch)) { if (watch) { return zk.getData().watched().forPath(npath); } else { return zk.getData().forPath(npath); } } } catch (Exception e) { if (Utils.exceptionCauseIsInstanceOf(KeeperException.NoNodeException.class, e)) { // this is fine b/c we still have a watch from the successful exists call } else { throw Utils.wrapInRuntime(e); } } return null; }