/** Process the {@link WatchedEvent} for a node which represents an {@link AuthenticationKey} */ void processChildNode(WatchedEvent event) throws KeeperException, InterruptedException { final String path = event.getPath(); switch (event.getType()) { case NodeDeleted: // Key expired if (null == path) { log.error("Got null path for NodeDeleted event"); return; } // Pull off the base ZK path and the '/' separator String childName = path.substring(baseNode.length() + 1); secretManager.removeKey(Integer.parseInt(childName)); break; case None: // Not connected, don't care. We'll update when we're reconnected break; case NodeCreated: // New key created if (null == path) { log.error("Got null path for NodeCreated event"); return; } // Get the data and reset the watcher AuthenticationKey key = deserializeKey(zk.getData(path, this, null)); log.debug("Adding AuthenticationKey with keyId {}", key.getKeyId()); secretManager.addKey(key); break; case NodeDataChanged: // Key changed, could happen on restart after not running Accumulo. if (null == path) { log.error("Got null path for NodeDataChanged event"); return; } // Get the data and reset the watcher AuthenticationKey newKey = deserializeKey(zk.getData(path, this, null)); // Will overwrite the old key if one exists secretManager.addKey(newKey); break; case NodeChildrenChanged: // no children for the children.. log.warn("Unexpected NodeChildrenChanged event for authentication key node {}", path); break; default: log.warn("Unsupported event type: {}", event.getType()); break; } }
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; }