@Test public void testChildChildrenChanged() { WatchedEvent event = new WatchedEvent(EventType.NodeChildrenChanged, null, baseNode + "/2"); AuthenticationKey key1 = new AuthenticationKey(1, 0L, 10000L, keyGen.generateKey()), key2 = new AuthenticationKey(2, key1.getExpirationDate(), 20000L, keyGen.generateKey()); secretManager.addKey(key1); secretManager.addKey(key2); assertEquals(2, secretManager.getKeys().size()); replay(zk); keyWatcher.process(event); verify(zk); assertEquals(2, secretManager.getKeys().size()); assertEquals(key1, secretManager.getKeys().get(key1.getKeyId())); assertEquals(key2, secretManager.getKeys().get(key2.getKeyId())); assertEquals(key2, secretManager.getCurrentKey()); }
@Override public void process(WatchedEvent event) { if (event.getType() == EventType.None) { switch (event.getState()) { case Disconnected: case Expired: log.debug("ZooKeeper connection disconnected, clearing secret manager"); secretManager.removeAllKeys(); break; case SyncConnected: log.debug("ZooKeeper reconnected, updating secret manager"); try { updateAuthKeys(); } catch (KeeperException | InterruptedException e) { log.error("Failed to update secret manager after ZooKeeper reconnect"); } break; default: log.warn("Unhandled: {}", event); } return; } String path = event.getPath(); if (path == null) { return; } if (!path.startsWith(baseNode)) { log.info("Ignoring event for path: {}", path); return; } try { if (path.equals(baseNode)) { processBaseNode(event); } else { processChildNode(event); } } catch (KeeperException | InterruptedException e) { log.error("Failed to communicate with ZooKeeper", e); } }
ZooAuthenticationKeyWatcher implements Watcher { @Override public void process(WatchedEvent event) { if (event.getType() == EventType.None) { switch (event.getState()) { case Disconnected: case Expired: log.debug("ZooKeeper connection disconnected, clearing secret manager"); secretManager.removeAllKeys(); break; case SyncConnected: log.debug("ZooKeeper reconnected, updating secret manager"); try { updateAuthKeys(); } catch (KeeperException | InterruptedException e) { log.error("Failed to update secret manager after ZooKeeper reconnect"); } break; default: log.warn("Unhandled: {}", event); } return; } String path = event.getPath(); if (path == null) { return; } if (!path.startsWith(baseNode)) { log.info("Ignoring event for path: {}", path); return; } try { if (path.equals(baseNode)) { processBaseNode(event); } else { processChildNode(event); } } catch (KeeperException | InterruptedException e) { log.error("Failed to communicate with ZooKeeper", e); } } }
ZooAuthenticationKeyWatcher implements Watcher { @Override public void process(WatchedEvent event) { if (event.getType() == EventType.None) { switch (event.getState()) { case Disconnected: case Expired: log.debug("ZooKeeper connection disconnected, clearing secret manager"); secretManager.removeAllKeys(); break; case SyncConnected: log.debug("ZooKeeper reconnected, updating secret manager"); try { updateAuthKeys(); } catch (KeeperException | InterruptedException e) { log.error("Failed to update secret manager after ZooKeeper reconnect"); } break; default: log.warn("Unhandled: {}", event); } return; } String path = event.getPath(); if (path == null) { return; } if (!path.startsWith(baseNode)) { log.info("Ignoring event for path: {}", path); return; } try { if (path.equals(baseNode)) { processBaseNode(event); } else { processChildNode(event); } } catch (KeeperException | InterruptedException e) { log.error("Failed to communicate with ZooKeeper", e); } } ZooAuthenticationKeyWatcher(AuthenticationTokenSecretManager secretManager, ZooReader zk,
      String baseNode); }
ZooAuthenticationKeyWatcher implements Watcher { @Override public void process(WatchedEvent event) { if (event.getType() == EventType.None) { switch (event.getState()) { case Disconnected: case Expired: log.debug("ZooKeeper connection disconnected, clearing secret manager"); secretManager.removeAllKeys(); break; case SyncConnected: log.debug("ZooKeeper reconnected, updating secret manager"); try { updateAuthKeys(); } catch (KeeperException | InterruptedException e) { log.error("Failed to update secret manager after ZooKeeper reconnect"); } break; default: log.warn("Unhandled: {}", event); } return; } String path = event.getPath(); if (path == null) { return; } if (!path.startsWith(baseNode)) { log.info("Ignoring event for path: {}", path); return; } try { if (path.equals(baseNode)) { processBaseNode(event); } else { processChildNode(event); } } catch (KeeperException | InterruptedException e) { log.error("Failed to communicate with ZooKeeper", e); } } ZooAuthenticationKeyWatcher(AuthenticationTokenSecretManager secretManager, ZooReader zk,
      String baseNode); @Override void process(WatchedEvent event); void updateAuthKeys(); }
ZooAuthenticationKeyWatcher implements Watcher { @Override public void process(WatchedEvent event) { if (event.getType() == EventType.None) { switch (event.getState()) { case Disconnected: case Expired: log.debug("ZooKeeper connection disconnected, clearing secret manager"); secretManager.removeAllKeys(); break; case SyncConnected: log.debug("ZooKeeper reconnected, updating secret manager"); try { updateAuthKeys(); } catch (KeeperException | InterruptedException e) { log.error("Failed to update secret manager after ZooKeeper reconnect"); } break; default: log.warn("Unhandled: {}", event); } return; } String path = event.getPath(); if (path == null) { return; } if (!path.startsWith(baseNode)) { log.info("Ignoring event for path: {}", path); return; } try { if (path.equals(baseNode)) { processBaseNode(event); } else { processChildNode(event); } } catch (KeeperException | InterruptedException e) { log.error("Failed to communicate with ZooKeeper", e); } } ZooAuthenticationKeyWatcher(AuthenticationTokenSecretManager secretManager, ZooReader zk,
      String baseNode); @Override void process(WatchedEvent event); void updateAuthKeys();  }