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 List<String> getChildren(CuratorFramework zk, String path, boolean watch) throws Exception { String npath = PathUtils.normalize_path(path); if (watch) { return zk.getChildren().watched().forPath(npath); } else { return zk.getChildren().forPath(npath); } }
@VisibleForTesting protected List<String> getChildrenForEntering() throws Exception { return client.getChildren().forPath(barrierPath); }
protected List<String> getChildren() throws Exception { return client.getChildren().forPath(queuePath); }
public static List<String> getSortedChildren(CuratorFramework client, String basePath, final String lockName, final LockInternalsSorter sorter) throws Exception { List<String> children = client.getChildren().forPath(basePath); List<String> sortedList = Lists.newArrayList(children); Collections.sort ( sortedList, new Comparator<String>() { @Override public int compare(String lhs, String rhs) { return sorter.fixForSorting(lhs, lockName).compareTo(sorter.fixForSorting(rhs, lockName)); } } ); return sortedList; }
private int getNumPartitions() { try { String topicBrokersPath = partitionPath(); List<String> children = _curator.getChildren().forPath(topicBrokersPath); return children.size(); } catch (Exception e) { throw new RuntimeException(e); } }
public List<String> getChildren(String path) { try { if (!exists(path)) return null; return m_curator.getChildren().forPath(path); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
/** * Return a list of all current nodes participating in the semaphore * * @return list of nodes * @throws Exception ZK errors, interruptions, etc. */ public Collection<String> getParticipantNodes() throws Exception { return client.getChildren().forPath(ZKPaths.makePath(leasesPath, LEASE_BASE_NAME)); }
public List<KafkaTopic> listTopics(String zookeeperUri) { List<KafkaTopic> kafkaTopics = null; // Get the updated status for the cluster from zookeeper CuratorFramework curatorClient = getCuratorClient(zookeeperUri); if (curatorClient != null) { try { kafkaTopics = new ArrayList<KafkaTopic>(); for (String topic : curatorClient.getChildren().forPath("/brokers/topics")) { KafkaTopic kafkaTopic = new KafkaTopic(); kafkaTopic.setName(topic); kafkaTopics.add(kafkaTopic); } } catch (Exception ex) { ex.printStackTrace(); } } return kafkaTopics; }
private void getInitialQueues() throws Exception { List<String> children = client.getChildren().forPath(queuePath); for ( String child : children ) { String queuePath = ZKPaths.makePath(this.queuePath, child); addNewQueueIfNeeded(queuePath); } if ( children.size() == 0 ) { addNewQueueIfNeeded(null); } }
@Override public Map<String, Map<HostConfiguration, NodeState>> getNodeDatas() { Map<String, Map<HostConfiguration, NodeState>> states = new HashMap<String, Map<HostConfiguration, NodeState>>(); try { List<String> children = this.curator.getChildren().forPath(NODE_STATES_PATH); for (String path : children) { byte[] nodeData = this.curator.getData().forPath(PathUtils.toPath(NODE_STATES_PATH, path)); if (nodeData != null && nodeData.length > 0) { states.put(path, this.jsonBinder.toNodeState(nodeData)); } } } catch (Exception e) { log.error("Error trying to access node datas", e); throw new ZooKeeperException(e); } return states; }
kafkaBrokers = new ArrayList<KafkaBroker>(); for (String brokerId : curatorClient.getChildren().forPath("/brokers/ids")) { byte[] brokerData = curatorClient.getData().forPath("/brokers/ids/" + brokerId);
try children = client.getChildren().forPath(barrierPath);
private void doWork() { try { List<String> children = client.getChildren().forPath(path); for ( String name : children ) { String thisPath = ZKPaths.makePath(path, name); Stat stat = client.checkExists().forPath(thisPath); if ( (stat != null) && (stat.getNumChildren() == 0) ) { reaper.addPath(thisPath, mode); } } } catch ( Exception e ) { log.error("Could not get children for path: " + path, e); } } }
/** * NOTE: this is a BLOCKING method. Completely rebuild the internal cache by querying * for all needed data WITHOUT generating any events to send to listeners. * * @throws Exception errors */ public void rebuild() throws Exception { Preconditions.checkState(!executorService.isShutdown(), "cache has been closed"); ensurePath.ensure(client.getZookeeperClient()); clear(); List<String> children = client.getChildren().forPath(path); for ( String child : children ) { String fullPath = ZKPaths.makePath(path, child); internalRebuildNode(fullPath); if ( rebuildTestExchanger != null ) { rebuildTestExchanger.exchange(new Object()); } } // this is necessary so that any updates that occurred while rebuilding are taken offerOperation(new RefreshOperation(this, RefreshMode.FORCE_GET_DATA_AND_STAT)); }
List<String> children = client.getChildren().forPath(queuePath); for ( String child : children )
try nodes = (watcher != null) ? client.getChildren().usingWatcher(watcher).forPath(path) : client.getChildren().forPath(path);