public List<String> list(String path) { path = "/" + path; try { List<String> children; if (_curator.checkExists().forPath(path) == null) { children = new ArrayList<>(); } else { children = _curator.getChildren().forPath(path); } LOG.debug("List [path = {}], [children = {}]", path, children); return children; } catch (Exception e) { throw new RuntimeException(e); } }
public Object getData(String path) { path = "/" + path; try { Object data; if (_curator.checkExists().forPath(path) != null) { // Use parseWithException instead of parse so we can capture deserialization errors in the log. // They are likely to be bugs in the spout code. try { data = JSONValue.parseWithException(new String(_curator.getData().forPath(path), "UTF-8")); } catch (ParseException e) { LOG.warn("Failed to deserialize zookeeper data for path {}", path, e); data = null; } } else { data = null; } LOG.debug("Get. [path = {}] => [data = {}]", path, data); return data; } catch (Exception e) { throw new RuntimeException(e); } }
public void setData(String path, Object obj) { path = "/" + path; byte[] ser; try { ser = JSONValue.toJSONString(obj).getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } try { if (_curator.checkExists().forPath(path) != null) { _curator.setData().forPath(path, ser); } else { TransactionalState.createNode(_curator, path, ser, _zkAcls, CreateMode.PERSISTENT); } } catch (KeeperException.NodeExistsException nne) { LOG.warn("Node {} already created.", path); } catch (Exception e) { throw new RuntimeException(e); } }
public synchronized boolean checkForBlobOrDownload(String key) throws KeyNotFoundException { boolean checkBlobDownload = false; try { List<String> keyList = BlobStoreUtils.getKeyListFromBlobStore(this); if (!keyList.contains(key)) { if (zkClient.checkExists().forPath(BLOBSTORE_SUBTREE + key) != null) { Set<NimbusInfo> nimbusSet = BlobStoreUtils.getNimbodesWithLatestSequenceNumberOfBlob(zkClient, key); nimbusSet.remove(this.nimbusInfo); if (BlobStoreUtils.downloadMissingBlob(conf, this, key, nimbusSet)) { LOG.debug("Updating blobs state"); BlobStoreUtils.createStateInZookeeper(conf, key, nimbusInfo); checkBlobDownload = true; } } } } catch (KeyNotFoundException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } return checkBlobDownload; }
private static void verifyParentWithTopoChildren(CuratorFramework zk, ACL superUserAcl, String path, Map<String, Id> topoToZkCreds, boolean fixUp, int perms) throws Exception { if (zk.checkExists().forPath(path) != null) { verifyAclStrict(zk, Arrays.asList(superUserAcl), path, fixUp); for (String topoId : zk.getChildren().forPath(path)) { String childPath = path + ClusterUtils.ZK_SEPERATOR + topoId; List<ACL> rwAcl = getTopoAcl(path, topoId, topoToZkCreds, superUserAcl, fixUp, perms); verifyAclStrictRecursive(zk, rwAcl, childPath, fixUp); } } }
if (zkClient.checkExists().forPath(BLOBSTORE_SUBTREE + "/" + key) == null) { return;
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()); }
private static void verifyParentWithTopoChildrenDeleteDead(CuratorFramework zk, ACL superUserAcl, String path, Map<String, Id> topoToZkCreds, boolean fixUp, int perms) throws Exception { if (zk.checkExists().forPath(path) != null) { verifyAclStrict(zk, Arrays.asList(superUserAcl), path, fixUp); Set<String> possiblyBadIds = new HashSet<>(); for (String topoId : zk.getChildren().forPath(path)) { String childPath = path + ClusterUtils.ZK_SEPERATOR + topoId; if (!topoToZkCreds.containsKey(topoId)) { //Save it to try again later... possiblyBadIds.add(topoId); } else { List<ACL> rwAcl = getTopoAcl(path, topoId, topoToZkCreds, superUserAcl, fixUp, perms); verifyAclStrictRecursive(zk, rwAcl, childPath, fixUp); } } if (!possiblyBadIds.isEmpty()) { //Lets reread the children in STORMS as the source of truth and see if a new one was created in the background possiblyBadIds.removeAll(zk.getChildren().forPath(ClusterUtils.STORMS_SUBTREE)); for (String topoId : possiblyBadIds) { //Now we know for sure that this is a bad id String childPath = path + ClusterUtils.ZK_SEPERATOR + topoId; zk.delete().deletingChildrenIfNeeded().forPath(childPath); } } } }
@Override public int getBlobReplication(String key, Subject who) throws Exception { int replicationCount = 0; validateKey(key); SettableBlobMeta meta = getStoredBlobMeta(key); _aclHandler.hasPermissions(meta.get_acl(), READ, who, key); if (zkClient.checkExists().forPath(BLOBSTORE_SUBTREE + key) == null) { return 0; } try { replicationCount = zkClient.getChildren().forPath(BLOBSTORE_SUBTREE + key).size(); } catch (KeeperException.NoNodeException e) { //Race with delete //If it is not here the replication is 0 } return replicationCount; }
try { if (zkClient.checkExists().forPath(BlobStoreUtils.getBlobStoreSubtree() + "/" + key) == null) { zkClient.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT) .withACL(ZooDefs.Ids.OPEN_ACL_UNSAFE).forPath(BLOBSTORE_MAX_KEY_SEQUENCE_SUBTREE + "/" + key);
if (zk.checkExists().forPath(stormRoot) != null) { if (zk.checkExists().forPath(ClusterUtils.BLOBSTORE_SUBTREE) != null) { verifyAclStrictRecursive(zk, superAcl, ClusterUtils.BLOBSTORE_SUBTREE, fixUp); if (zk.checkExists().forPath(ClusterUtils.BLOBSTORE_MAX_KEY_SEQUENCE_NUMBER_SUBTREE) != null) { verifyAclStrict(zk, superAcl, ClusterUtils.BLOBSTORE_MAX_KEY_SEQUENCE_NUMBER_SUBTREE, fixUp); if (zk.checkExists().forPath(ClusterUtils.STORMS_SUBTREE) != null) { topoIds.addAll(zk.getChildren().forPath(ClusterUtils.STORMS_SUBTREE)); if (zk.checkExists().forPath(ClusterUtils.ERRORS_SUBTREE) != null) { if (zk.checkExists().forPath(path) == null) { LOG.warn("Creating missing errors location {}", path); zk.create().withACL(getTopoReadWrite(path, topoId, topoToZkCreds, superUserAcl, fixUp)).forPath(path); if (zk.checkExists().forPath(ClusterUtils.SECRET_KEYS_SUBTREE) != null) { verifyAclStrict(zk, superAcl, ClusterUtils.SECRET_KEYS_SUBTREE, fixUp); verifyAclStrictRecursive(zk, superAcl, ClusterUtils.secretKeysPath(WorkerTokenServiceType.NIMBUS), fixUp); if (zk.checkExists().forPath(ClusterUtils.NIMBUSES_SUBTREE) != null) { verifyAclStrictRecursive(zk, superAcl, ClusterUtils.NIMBUSES_SUBTREE, fixUp); if (zk.checkExists().forPath("/leader-lock") != null) { verifyAclStrictRecursive(zk, superAcl, "/leader-lock", fixUp); if (zk.checkExists().forPath(ClusterUtils.PROFILERCONFIG_SUBTREE) != null) { verifyAclStrictRecursive(zk, superAcl, ClusterUtils.PROFILERCONFIG_SUBTREE, fixUp);
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 List<String> list(String path) { path = "/" + path; try { if(_curator.checkExists().forPath(path)==null) { return new ArrayList<String>(); } else { return _curator.getChildren().forPath(path); } } catch(Exception e) { throw new RuntimeException(e); } }
public Object getData(String path) { path = "/" + path; try { if(_curator.checkExists().forPath(path)!=null) { return _des.deserializeObject(_curator.getData().forPath(path)); } else { return null; } } catch(Exception e) { throw new RuntimeException(e); } }
public void send(String toPath, byte[] signal) throws Exception { Stat stat = this.client.checkExists().forPath(toPath); if (stat == null) { String path = this.client.create().creatingParentsIfNeeded().forPath(toPath); LOG.info("Created: " + path); } this.client.setData().forPath(toPath, signal); } }
private static void verifyParentWithTopoChildren(CuratorFramework zk, ACL superUserAcl, String path, Map<String, Id> topoToZkCreds, boolean fixUp, int perms) throws Exception { if (zk.checkExists().forPath(path) != null) { verifyAclStrict(zk, Arrays.asList(superUserAcl), path, fixUp); for (String topoId : zk.getChildren().forPath(path)) { String childPath = path + ClusterUtils.ZK_SEPERATOR + topoId; List<ACL> rwAcl = getTopoAcl(path, topoId, topoToZkCreds, superUserAcl, fixUp, perms); verifyAclStrictRecursive(zk, rwAcl, childPath, fixUp); } } }
public void send(byte[] signal) throws Exception { Stat stat = this.client.checkExists().forPath(this.name); if (stat == null) { String path = this.client.create().creatingParentsIfNeeded().forPath(this.name); LOG.info("Created: " + path); } this.client.setData().forPath(this.name, signal); }
@Override public int getBlobReplication(String key, Subject who) throws Exception { int replicationCount = 0; validateKey(key); SettableBlobMeta meta = getStoredBlobMeta(key); _aclHandler.hasPermissions(meta.get_acl(), READ, who, key); if (zkClient.checkExists().forPath(BLOBSTORE_SUBTREE + key) == null) { return 0; } replicationCount = zkClient.getChildren().forPath(BLOBSTORE_SUBTREE + key).size(); return replicationCount; }
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 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; }