/** * Get the data in a ZNode. * @param path Path of the ZNode. * @param stat * @return The data in the ZNode. * @throws Exception If it cannot contact Zookeeper. */ public byte[] getData(final String path, Stat stat) throws Exception { return curator.getData().storingStatIn(stat).forPath(path); }
@Override public Node getNode(final String path) throws KeeperException { assertClusterIdFlagTrue(); final Stat stat = new Stat(); try { final byte[] bytes = client.getData().storingStatIn(stat).forPath(path); return new Node(path, bytes, stat); } catch (Exception e) { throwIfInstanceOf(e, KeeperException.class); throw new RuntimeException(e); } }
@Override public byte[] readData(String path, Stat stat, boolean watch) throws KeeperException, InterruptedException { try { if ( stat != null ) { return watch ? curator.getData().storingStatIn(stat).watched().forPath(path) : curator.getData().storingStatIn(stat).forPath(path); } else { return watch ? curator.getData().watched().forPath(path) : curator.getData().forPath(path); } } catch ( Exception e ) { adjustException(e); } return null; // will never execute }
byte[] bytes = context.getExhibitor().getLocalConnection().getData().storingStatIn(stat).forPath(key);
bldr.storingStatIn(stat.get());
@Override public boolean replace(String key, String oldValue, String newValue) { Assert.notNull(key, "'key' must not be null."); Assert.notNull(oldValue, "'oldValue' must not be null."); Assert.notNull(newValue, "'newValue' must not be null."); synchronized (this.updateMap) { Stat currentStat = new Stat(); try { byte[] bytes = this.client.getData().storingStatIn(currentStat).forPath(getPath(key)); if (oldValue.equals(IntegrationUtils.bytesToString(bytes, this.encoding))) { updateNode(key, newValue, currentStat.getVersion()); } return true; } catch (KeeperException.NoNodeException e) { // ignore, the node doesn't exist there's nothing to replace return false; } catch (KeeperException.BadVersionException e) { // ignore return false; } catch (Exception e) { throw new ZookeeperMetadataStoreException("Cannot replace value"); } } }
@Override public WatchPathable<byte[]> storingStatIn(Stat stat) { return new WatchPathableDecorator<>(inner.storingStatIn(stat)); }
public static long getDeliveryTag(String experimentID, CuratorFramework curatorClient, String experimentNode, String pickedChild) throws Exception { String deliveryTagPath = experimentNode + File.separator + pickedChild + File.separator + experimentID + DELIVERY_TAG_POSTFIX; Stat exists = curatorClient.checkExists().forPath(deliveryTagPath); if(exists==null) { logger.error("Cannot find delivery Tag in path:" + deliveryTagPath + " for this experiment"); return -1; } return bytesToLong(curatorClient.getData().storingStatIn(exists).forPath(deliveryTagPath)); } public static byte[] longToBytes(long x) {
public String get(String path, Stat stat) throws Exception { if (exists(path, false)) { byte[] bytes = zookeeperClient.getData().storingStatIn(stat).forPath(path); String value = new String(bytes, CHARSET); LOGGER.debug("get value of node " + path + ", value " + value); return value; } else { LOGGER.debug("node " + path + " does not exist"); return null; } }
public static long getCancelDeliveryTagIfExist(String experimentId, CuratorFramework curatorClient, String experimentNode, String pickedChild) throws Exception { String cancelDeliveryTagPath = experimentNode + File.separator + pickedChild + File.separator + experimentId + AiravataZKUtils.CANCEL_DELIVERY_TAG_POSTFIX; Stat exists = curatorClient.checkExists().forPath(cancelDeliveryTagPath); if (exists == null) { return -1; // no cancel deliverytag found } else { return bytesToLong(curatorClient.getData().storingStatIn(exists).forPath(cancelDeliveryTagPath)); } } }
public static String getExpState(CuratorFramework curatorClient, String expId) throws Exception { Stat exists = curatorClient.checkExists().forPath(getExpStatePath(expId)); if (exists != null) { return new String(curatorClient.getData().storingStatIn(exists).forPath(getExpStatePath(expId))); } return null; }
private void internalRebuildNode(String fullPath) throws Exception { try { Stat stat = new Stat(); byte[] bytes = client.getData().storingStatIn(stat).forPath(fullPath); currentData.put(fullPath, new ChildData<T>(fullPath, stat, bytes, decode(bytes))); } catch (KeeperException.NoNodeException ignore) { // node no longer exists - remove it currentData.remove(fullPath); } }
@Override public StateMachineContext<S, E> read(Stat stat) throws Exception { return deserialize(curatorClient.getData().storingStatIn(stat).forPath(path)); }
private void internalRebuildNode(String fullPath) throws Exception { try { Stat stat = new Stat(); byte[] bytes = client.getData().storingStatIn(stat).forPath(fullPath); currentData.put(fullPath, new ChildData<T>(fullPath, stat, bytes, decode(bytes))); } catch (KeeperException.NoNodeException ignore) { // node no longer exists - remove it currentData.remove(fullPath); } }
private static void copyChildren(CuratorFramework curatorClient, String oldPath, String newPath, int depth) throws Exception { for (String childNode : curatorClient.getChildren().forPath(oldPath)) { String oldChildPath = oldPath + File.separator + childNode; Stat stat = curatorClient.checkExists().forPath(oldChildPath); // no need to check exists String newChildPath = newPath + File.separator + childNode; log.info("Creating new znode: " + newChildPath); curatorClient.create().withMode(CreateMode.PERSISTENT).withACL(OPEN_ACL_UNSAFE) .forPath(newChildPath, curatorClient.getData().storingStatIn(stat).forPath(oldChildPath)); if (--depth > 0) { copyChildren(curatorClient, oldChildPath, newChildPath, depth); } } }
@Override public Node getNode(final String path) throws KeeperException { assertClusterIdFlagTrue(); final Stat stat = new Stat(); try { byte[] bytes = client.getData().storingStatIn(stat).forPath(path); return new Node(path, bytes, stat); } catch (Exception e) { propagateIfInstanceOf(e, KeeperException.class); throw propagate(e); } }
private void internalRebuild() throws Exception { try { Stat stat = new Stat(); byte[] bytes = dataIsCompressed ? client.getData().decompressed().storingStatIn(stat).forPath(path) : client.getData().storingStatIn(stat).forPath(path); data.set(new ChildData(path, stat, bytes)); } catch ( KeeperException.NoNodeException e ) { data.set(null); } }
void getDataAndStat(final String fullPath) throws Exception { Stat stat = new Stat(); byte[] data = client.getData().storingStatIn(stat).usingWatcher(dataWatcher).forPath(fullPath); applyNewData(fullPath, KeeperException.Code.OK.intValue(), stat, data); }
private void readValue() throws Exception { Stat localStat = new Stat(); byte[] bytes = client.getData().storingStatIn(localStat).usingWatcher(watcher).forPath(path); updateValue(localStat.getVersion(), bytes); }
void getDataAndStat(final String fullPath) throws Exception { Stat stat = new Stat(); byte[] data = client.getData().storingStatIn(stat).usingWatcher(dataWatcher).forPath(fullPath); applyNewData(fullPath, KeeperException.Code.OK.intValue(), stat, data); }