@Override public List<String> listData(String path, Watcher watcher) throws NoSuchElementException, IOException, KeeperException, InterruptedException { try { return zkClient.getChildren(path, watcher, true); } catch (KeeperException.NoNodeException e) { throw new NoSuchElementException(path); } catch (InterruptedException e) { throw e; } }
public List<String> listConfigs() throws IOException { try { return zkClient.getChildren(ZkConfigManager.CONFIGS_ZKNODE, null, true); } catch (KeeperException.NoNodeException e) { return Collections.emptyList(); } catch (KeeperException | InterruptedException e) { throw new IOException("Error listing configs", SolrZkClient.checkInterrupted(e)); } } }
public List<String> listConfigs() throws IOException { try { return zkClient.getChildren(ZkConfigManager.CONFIGS_ZKNODE, null, true); } catch (KeeperException.NoNodeException e) { return Collections.emptyList(); } catch (KeeperException | InterruptedException e) { throw new IOException("Error listing configs", SolrZkClient.checkInterrupted(e)); } }
private void downloadFromZK(String zkPath, Path dir) throws IOException { try { List<String> files = zkClient.getChildren(zkPath, null, true); Files.createDirectories(dir); for (String file : files) { List<String> children = zkClient.getChildren(zkPath + "/" + file, null, true); if (children.size() == 0) { byte[] data = zkClient.getData(zkPath + "/" + file, null, null, true); Path filename = dir.resolve(file); logger.info("Writing file {}", filename); Files.write(filename, data); } else { downloadFromZK(zkPath + "/" + file, dir.resolve(file)); } } } catch (KeeperException | InterruptedException e) { throw new IOException("Error downloading files from zookeeper path " + zkPath + " to " + dir.toString(), SolrZkClient.checkInterrupted(e)); } }
for (String node : zkClient.getChildren(root, null, true)) { if (node.equals("zookeeper") == false) { sb.append(node).append(System.lineSeparator());
private void copyConfigDirFromZk(String fromZkPath, String toZkPath, Set<String> copiedToZkPaths) throws IOException { try { List<String> files = zkClient.getChildren(fromZkPath, null, true); for (String file : files) { List<String> children = zkClient.getChildren(fromZkPath + "/" + file, null, true); if (children.size() == 0) { final String toZkFilePath = toZkPath + "/" + file; log.info("Copying zk node {} to {}", fromZkPath + "/" + file, toZkFilePath); byte[] data = zkClient.getData(fromZkPath + "/" + file, null, null, true); zkClient.makePath(toZkFilePath, data, true); if (copiedToZkPaths != null) copiedToZkPaths.add(toZkFilePath); } else { copyConfigDirFromZk(fromZkPath + "/" + file, toZkPath + "/" + file, copiedToZkPaths); } } } catch (KeeperException | InterruptedException e) { throw new IOException("Error copying nodes from zookeeper path " + fromZkPath + " to " + toZkPath, SolrZkClient.checkInterrupted(e)); } }
private void updateClusterState(boolean onlyLiveNodes) throws KeeperException, InterruptedException { // build immutable CloudInfo synchronized (getUpdateLock()) { List<String> liveNodes = zkClient.getChildren(LIVE_NODES_ZKNODE, null, true); Set<String> liveNodesSet = new HashSet<>(liveNodes); if (!onlyLiveNodes) { log.debug("Updating cloud state from ZooKeeper... "); clusterState = constructState(liveNodesSet, null); } else { log.debug("Updating live nodes from ZooKeeper... ({})", liveNodesSet.size()); clusterState = this.clusterState; clusterState.setLiveNodes(liveNodesSet); } } }
private Set<String> getStateFormat2CollectionNames() throws KeeperException, InterruptedException { List<String> children = null; try { children = zkClient.getChildren(COLLECTIONS_ZKNODE, null, true); } catch (KeeperException.NoNodeException e) { log.warn("Error fetching collection names"); return new HashSet<>(); } if (children == null || children.isEmpty()) return new HashSet<>(); HashSet<String> result = new HashSet<>(children.size(), 1.0f); for (String c : children) { try { // this exists call is necessary because we only want to return // those collections which have their own state.json. // The getCollectionPath() calls returns the complete path to the // collection's state.json if (zkClient.exists(getCollectionPath(c), true)) { result.add(c); } } catch (Exception e) { log.warn("Error reading collections nodes", e); } } return result; }
throws KeeperException, InterruptedException { byte[] data = getData(path, null, null, true); List<String> children = getChildren(path, null, true); StringBuilder dent = new StringBuilder(); for (int i = 0; i < indent; i++) {
private void waitForAllNodes(int numServers, int timeout) throws IOException, InterruptedException { try (SolrZkClient zkClient = new SolrZkClient(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT)) { int numliveNodes = 0; int retries = timeout; String liveNodesPath = "/solr/live_nodes"; // Wait up to {timeout} seconds for number of live_nodes to match up number of servers do { if (zkClient.exists(liveNodesPath, true)) { numliveNodes = zkClient.getChildren(liveNodesPath, null, true).size(); if (numliveNodes == numServers) { break; } } retries--; if (retries == 0) { throw new IllegalStateException("Solr servers failed to register with ZK." + " Current count: " + numliveNodes + "; Expected count: " + numServers); } Thread.sleep(1000); } while (numliveNodes != numServers); } catch (KeeperException e) { throw new IOException("Error communicating with zookeeper", e); } }
throws KeeperException, InterruptedException { byte[] data = getData(path, null, null, true); List<String> children = getChildren(path, null, true); StringBuilder dent = new StringBuilder(); for (int i = 0; i < indent; i++) {
SortedSet<String> newLiveNodes; try { List<String> nodeList = zkClient.getChildren(LIVE_NODES_ZKNODE, watcher, true); newLiveNodes = new TreeSet<>(nodeList); } catch (KeeperException.NoNodeException e) {
List<String> children = null; try { children = zkClient.getChildren(COLLECTIONS_ZKNODE, watcher, true); } catch (KeeperException.NoNodeException e) { log.warn("Error fetching collection names: [{}]", e.getMessage());
public static void downloadFromZK(SolrZkClient zkClient, String zkPath, Path file) throws IOException { try { List<String> children = zkClient.getChildren(zkPath, null, true);
private static void checkAllZnodesThere(SolrZkClient zkClient, String src, String dst) throws KeeperException, InterruptedException, SolrServerException { for (String node : zkClient.getChildren(src, null, true)) { if (zkClient.exists(dst + "/" + node, true) == false) { throw new SolrServerException("mv command did not move node " + dst + "/" + node + " source left intact"); } checkAllZnodesThere(zkClient, src + "/" + node, dst + "/" + node); } }
public void clean(String path) throws InterruptedException, KeeperException { List<String> children; try { children = getChildren(path, null, true); } catch (NoNodeException r) { return; } for (String string : children) { // we can't clean the built-in zookeeper node if (path.equals("/") && string.equals("zookeeper")) continue; if (path.equals("/")) { clean(path + string); } else { clean(path + "/" + string); } } try { if (!path.equals("/")) { try { delete(path, -1, true); } catch (NotEmptyException e) { clean(path); } } } catch (NoNodeException r) { return; } }
List<String> liveNodes = zkClient.getChildren( LIVE_NODES_ZKNODE, this, true); log.debug("Updating live nodes... ({})", liveNodes.size());
children = zkClient.getChildren(path, null, true); } catch (KeeperException.NoNodeException r) { return;
if (zkClient.getChildren(src, null, true).size() != 0) { throw new SolrServerException("Zookeeper node " + src + " has children and recurse is false"); if (zkClient.getChildren(src, null, true).size() > 0) { downloadFromZK(zkClient, src, Paths.get(dst)); return;
public static void moveZnode(SolrZkClient zkClient, String src, String dst) throws SolrServerException, KeeperException, InterruptedException { String destName = normalizeDest(src, dst, true, true); // Special handling if the source has no children, i.e. copying just a single file. if (zkClient.getChildren(src, null, true).size() == 0) { zkClient.makePath(destName, false, true); zkClient.setData(destName, zkClient.getData(src, null, null, true), true); } else { traverseZkTree(zkClient, src, VISIT_ORDER.VISIT_PRE, new ZkCopier(zkClient, src, destName)); } // Insure all source znodes are present in dest before deleting the source. // throws error if not all there so the source is left intact. Throws error if source and dest don't match. checkAllZnodesThere(zkClient, src, destName); clean(zkClient, src); }