private static TreeSet<UUID> getInstanceIDs(ZooReader zk, boolean printErrors) { TreeSet<UUID> ts = new TreeSet<>(); try { List<String> children = zk.getChildren(Constants.ZROOT); for (String iid : children) { if (iid.equals("instances")) continue; try { ts.add(UUID.fromString(iid)); } catch (Exception e) { log.error("Exception: ", e); } } } catch (Exception e) { handleException(e, printErrors); } return ts; }
private static void recurse(ZooReader zoo, String root, Visitor v) { try { v.visit(zoo, root); for (String child : zoo.getChildren(root)) { recurse(zoo, root + "/" + child, v); } } catch (Exception ex) { throw new RuntimeException(ex); } }
private static TreeMap<String,UUID> getInstanceNames(ZooReader zk, boolean printErrors) { String instancesPath = Constants.ZROOT + Constants.ZINSTANCES; TreeMap<String,UUID> tm = new TreeMap<>(); List<String> names; try { names = zk.getChildren(instancesPath); } catch (Exception e) { handleException(e, printErrors); return tm; } for (String name : names) { String instanceNamePath = Constants.ZROOT + Constants.ZINSTANCES + "/" + name; try { UUID iid = UUID.fromString(new String(zk.getData(instanceNamePath, null), UTF_8)); tm.put(name, iid); } catch (Exception e) { handleException(e, printErrors); tm.put(name, null); } } return tm; }
private int updateAuthKeys(String path) throws KeeperException, InterruptedException { int keysAdded = 0; for (String child : zk.getChildren(path, this)) { String childPath = path + "/" + child; try { // Get the node data and reset the watcher AuthenticationKey key = deserializeKey(zk.getData(childPath, this, null)); secretManager.addKey(key); keysAdded++; } catch (NoNodeException e) { // The master expired(deleted) the key between when we saw it in getChildren() and when we // went to add it to our secret manager. log.trace("{} was deleted when we tried to access it", childPath); } } return keysAdded; }
protected void updateHostsFromZooKeeper() throws KeeperException, InterruptedException { if (pathExists || zoo.exists(path)) { pathExists = true; updateHosts(path, zoo.getChildren(path, this)); } else { zoo.exists(path, this); } }
private static TreeSet<UUID> getInstanceIDs(ZooReader zk, boolean printErrors) { TreeSet<UUID> ts = new TreeSet<>(); try { List<String> children = zk.getChildren(Constants.ZROOT); for (String iid : children) { if (iid.equals("instances")) continue; try { ts.add(UUID.fromString(iid)); } catch (Exception e) { log.error("Exception: " + e); } } } catch (Exception e) { handleException(e, printErrors); } return ts; }
private static TreeSet<UUID> getInstanceIDs(ZooReader zk) { TreeSet<UUID> ts = new TreeSet<UUID>(); try { List<String> children = zk.getChildren(Constants.ZROOT); for (String iid : children) { if (iid.equals("instances")) continue; try { ts.add(UUID.fromString(iid)); } catch (Exception e) { log.error("Exception: " + e); } } } catch (Exception e) { handleException(e); } return ts; }
private static void recurse(ZooReader zoo, String root, Visitor v) { try { v.visit(zoo, root); for (String child : zoo.getChildren(root)) { recurse(zoo, root + "/" + child, v); } } catch (Exception ex) { throw new RuntimeException(ex); } }
private static void recurse(ZooReader zoo, String root, Visitor v) { try { v.visit(zoo, root); for (String child : zoo.getChildren(root)) { recurse(zoo, root + "/" + child, v); } } catch (Exception ex) { throw new RuntimeException(ex); } }
private static TreeMap<String,UUID> getInstanceNames(ZooReader zk) { String instancesPath = Constants.ZROOT + Constants.ZINSTANCES; TreeMap<String,UUID> tm = new TreeMap<String,UUID>(); List<String> names; try { names = zk.getChildren(instancesPath); } catch (Exception e) { handleException(e); return tm; } for (String name : names) { String instanceNamePath = Constants.ZROOT + Constants.ZINSTANCES + "/" + name; try { UUID iid = UUID.fromString(new String(zk.getData(instanceNamePath, null), UTF_8)); tm.put(name, iid); } catch (Exception e) { handleException(e); tm.put(name, null); } } return tm; }
private static TreeMap<String,UUID> getInstanceNames(ZooReader zk, boolean printErrors) { String instancesPath = Constants.ZROOT + Constants.ZINSTANCES; TreeMap<String,UUID> tm = new TreeMap<>(); List<String> names; try { names = zk.getChildren(instancesPath); } catch (Exception e) { handleException(e, printErrors); return tm; } for (String name : names) { String instanceNamePath = Constants.ZROOT + Constants.ZINSTANCES + "/" + name; try { UUID iid = UUID.fromString(new String(zk.getData(instanceNamePath, null), UTF_8)); tm.put(name, iid); } catch (Exception e) { handleException(e, printErrors); tm.put(name, null); } } return tm; }
Set<TServerInstance> getTServers(Instance instance) throws KeeperException, InterruptedException { Set<TServerInstance> result = new HashSet<>(); ZooReader rdr = new ZooReader(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut()); String base = ZooUtil.getRoot(instance) + Constants.ZTSERVERS; for (String child : rdr.getChildren(base)) { try { List<String> children = rdr.getChildren(base + "/" + child); if (children.size() > 0) { Collections.sort(children); Stat stat = new Stat(); byte[] data = rdr.getData(base + "/" + child + "/" + children.get(0), stat); if (!"master".equals(new String(data, UTF_8))) { result.add(new TServerInstance(AddressUtil.parseAddress(child, false), stat.getEphemeralOwner())); } } } catch (KeeperException.NoNodeException ex) { // someone beat us too it } } return result; }
private int updateAuthKeys(String path) throws KeeperException, InterruptedException { int keysAdded = 0; for (String child : zk.getChildren(path, this)) { String childPath = path + "/" + child; try { // Get the node data and reset the watcher AuthenticationKey key = deserializeKey(zk.getData(childPath, this, null)); secretManager.addKey(key); keysAdded++; } catch (NoNodeException e) { // The master expired(deleted) the key between when we saw it in getChildren() and when we // went to add it to our secret manager. log.trace("{} was deleted when we tried to access it", childPath); } } return keysAdded; }
protected void updateHostsFromZooKeeper() throws KeeperException, InterruptedException { if (pathExists || zoo.exists(path)) { pathExists = true; updateHosts(path, zoo.getChildren(path, this)); } else { zoo.exists(path, this); } }
@Test public void tserverReplicationServicePortsAreAdvertised() throws Exception { // Wait for the cluster to be up Connector conn = getConnector(); Instance inst = conn.getInstance(); // Wait for a tserver to come up to fulfill this request conn.tableOperations().create("foo"); Scanner s = conn.createScanner("foo", Authorizations.EMPTY); Assert.assertEquals(0, Iterables.size(s)); ZooReader zreader = new ZooReader(inst.getZooKeepers(), inst.getZooKeepersSessionTimeOut()); Set<String> tserverHost = new HashSet<>(); tserverHost.addAll(zreader.getChildren(ZooUtil.getRoot(inst) + Constants.ZTSERVERS)); Set<HostAndPort> replicationServices = new HashSet<>(); for (String tserver : tserverHost) { try { byte[] portData = zreader.getData( ZooUtil.getRoot(inst) + ReplicationConstants.ZOO_TSERVERS + "/" + tserver, null); HostAndPort replAddress = HostAndPort.fromString(new String(portData, UTF_8)); replicationServices.add(replAddress); } catch (Exception e) { log.error("Could not find port for {}", tserver, e); Assert.fail("Did not find replication port advertisement for " + tserver); } } // Each tserver should also have equial replicaiton services running internally Assert.assertEquals("Expected an equal number of replication servicers and tservers", tserverHost.size(), replicationServices.size()); }