List of usage examples for org.apache.zookeeper WatchedEvent getType
public EventType getType()
From source file:org.apache.accumulo.server.logger.LogService.java
License:Apache License
@Override public void process(WatchedEvent event) { LOG.debug("event " + event.getPath() + " " + event.getType() + " " + event.getState()); if (event.getState() == KeeperState.Expired) { LOG.warn("Logger lost zookeeper registration at " + event.getPath()); service.stop();//from w w w. j a v a 2s .c o m } else if (event.getType() == EventType.NodeDeleted) { LOG.info("Logger zookeeper entry lost " + event.getPath()); String[] path = event.getPath().split("/"); if (path[path.length - 1].equals(Constants.ZLOGGERS) && this.shutdownState == ShutdownState.REGISTERED) { LOG.fatal("Stopping server, zookeeper entry lost " + event.getPath()); service.stop(); } } }
From source file:org.apache.accumulo.server.master.Master.java
License:Apache License
public void run() throws IOException, InterruptedException, KeeperException { final String zroot = ZooUtil.getRoot(instance); getMasterLock(zroot + Constants.ZMASTER_LOCK); recoveryManager = new RecoveryManager(this); TableManager.getInstance().addObserver(this); StatusThread statusThread = new StatusThread(); statusThread.start();//from w w w . ja va2s . co m MigrationCleanupThread migrationCleanupThread = new MigrationCleanupThread(); migrationCleanupThread.start(); tserverSet.startListeningForTabletServerChanges(); // TODO: add shutdown for fate object - ACCUMULO-1307 try { final AgeOffStore<Master> store = new AgeOffStore<Master>( new org.apache.accumulo.fate.ZooStore<Master>(ZooUtil.getRoot(instance) + Constants.ZFATE, ZooReaderWriter.getRetryingInstance()), 1000 * 60 * 60 * 8); int threads = this.getConfiguration().getConfiguration().getCount(Property.MASTER_FATE_THREADPOOL_SIZE); fate = new Fate<Master>(this, store, threads); SimpleTimer.getInstance().schedule(new Runnable() { @Override public void run() { store.ageOff(); } }, 63000, 63000); } catch (KeeperException e) { throw new IOException(e); } catch (InterruptedException e) { throw new IOException(e); } ZooReaderWriter.getInstance().getChildren(zroot + Constants.ZRECOVERY, new Watcher() { @Override public void process(WatchedEvent event) { nextEvent.event("Noticed recovery changes", event.getType()); try { // watcher only fires once, add it back ZooReaderWriter.getInstance().getChildren(zroot + Constants.ZRECOVERY, this); } catch (Exception e) { log.error("Failed to add log recovery watcher back", e); } } }); Credentials systemCreds = SystemCredentials.get(); watchers.add(new TabletGroupWatcher(this, new MetaDataStateStore(instance, systemCreds, this), null)); watchers.add(new TabletGroupWatcher(this, new RootTabletStateStore(instance, systemCreds, this), watchers.get(0))); watchers.add(new TabletGroupWatcher(this, new ZooTabletStateStore(new ZooStore(zroot)), watchers.get(1))); for (TabletGroupWatcher watcher : watchers) { watcher.start(); } Processor<Iface> processor = new Processor<Iface>(TraceWrap.service(new MasterClientServiceHandler())); ServerAddress sa = TServerUtils.startServer(getSystemConfiguration(), hostname, Property.MASTER_CLIENTPORT, processor, "Master", "Master Client Service Handler", null, Property.MASTER_MINTHREADS, Property.MASTER_THREADCHECK, Property.GENERAL_MAX_MESSAGE_SIZE); clientService = sa.server; String address = sa.address.toString(); log.info("Setting master lock data to " + address); masterLock.replaceLockData(address.getBytes()); while (!clientService.isServing()) { UtilWaitThread.sleep(100); } while (clientService.isServing()) { UtilWaitThread.sleep(500); } final long deadline = System.currentTimeMillis() + MAX_CLEANUP_WAIT_TIME; statusThread.join(remaining(deadline)); // quit, even if the tablet servers somehow jam up and the watchers // don't stop for (TabletGroupWatcher watcher : watchers) { watcher.join(remaining(deadline)); } log.info("exiting"); }
From source file:org.apache.accumulo.server.security.delegation.ZooAuthenticationKeyWatcher.java
License:Apache License
@Override public void process(WatchedEvent event) { if (EventType.None == event.getType()) { switch (event.getState()) { case Disconnected: // Intentional fall through of case case Expired: // ZooReader is handling the Expiration of the original ZooKeeper object for us log.debug("ZooKeeper connection disconnected, clearing secret manager"); secretManager.removeAllKeys(); break; case SyncConnected: log.debug("ZooKeeper reconnected, updating secret manager"); try { updateAuthKeys();/*from w w w . j a v a 2s. c o m*/ } catch (KeeperException | InterruptedException e) { log.error("Failed to update secret manager after ZooKeeper reconnect"); } break; default: log.warn("Unhandled: " + event); } // Nothing more to do for EventType.None return; } String path = event.getPath(); if (null == path) { 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); } }
From source file:org.apache.accumulo.server.security.delegation.ZooAuthenticationKeyWatcher.java
License:Apache License
/** * Process the {@link WatchedEvent} for the base znode that the {@link AuthenticationKey}s are stored in. *//* w w w .j a va 2 s . c o m*/ void processBaseNode(WatchedEvent event) throws KeeperException, InterruptedException { switch (event.getType()) { case NodeDeleted: // The parent node was deleted, no children are possible, remove all keys log.debug("Parent ZNode was deleted, removing all AuthenticationKeys"); secretManager.removeAllKeys(); break; case None: // Not connected, don't care break; case NodeCreated: // intentional fall-through to NodeChildrenChanged case NodeChildrenChanged: // Process each child, and reset the watcher on the parent node. We know that the node exists updateAuthKeys(event.getPath()); break; case NodeDataChanged: // The data on the parent changed. We aren't storing anything there so it's a noop break; default: log.warn("Unsupported event type: {}", event.getType()); break; } }
From source file:org.apache.accumulo.server.security.delegation.ZooAuthenticationKeyWatcher.java
License:Apache License
/** * Process the {@link WatchedEvent} for a node which represents an {@link AuthenticationKey} *///from w w w . jav a2 s.c o m 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; } }
From source file:org.apache.accumulo.server.trace.TraceServer.java
License:Apache License
@Override public void process(WatchedEvent event) { log.debug("event " + event.getPath() + " " + event.getType() + " " + event.getState()); if (event.getState() == KeeperState.Expired) { log.warn("Trace server lost zookeeper registration at " + event.getPath()); server.stop();/*from w w w. j av a 2s . c o m*/ } else if (event.getType() == EventType.NodeDeleted) { log.warn("Trace server zookeeper entry lost " + event.getPath()); server.stop(); } if (event.getPath() != null) { try { if (ZooReaderWriter.getInstance().exists(event.getPath(), this)) return; } catch (Exception ex) { log.error(ex, ex); } log.warn("Trace server unable to reset watch on zookeeper registration"); server.stop(); } }
From source file:org.apache.accumulo.server.zookeeper.DistributedWorkQueue.java
License:Apache License
public void startProcessing(final Processor processor, ThreadPoolExecutor executorService) throws KeeperException, InterruptedException { threadPool = executorService;/*from w w w. j a v a2 s . c om*/ zoo.mkdirs(path); zoo.mkdirs(path + "/" + LOCKS_NODE); List<String> children = zoo.getChildren(path, new Watcher() { @Override public void process(WatchedEvent event) { switch (event.getType()) { case NodeChildrenChanged: if (event.getPath().equals(path)) try { lookForWork(processor, zoo.getChildren(path, this)); } catch (KeeperException e) { log.error("Failed to look for work", e); } catch (InterruptedException e) { log.info("Interrupted looking for work", e); } else log.info("Unexpected path for NodeChildrenChanged event " + event.getPath()); break; case NodeCreated: case NodeDataChanged: case NodeDeleted: case None: log.info("Got unexpected zookeeper event: " + event.getType() + " for " + path); break; } } }); lookForWork(processor, children); // Add a little jitter to avoid all the tservers slamming zookeeper at once SimpleTimer.getInstance(config).schedule(new Runnable() { @Override public void run() { log.debug("Looking for work in " + path); try { lookForWork(processor, zoo.getChildren(path)); } catch (KeeperException e) { log.error("Failed to look for work", e); } catch (InterruptedException e) { log.info("Interrupted looking for work", e); } } }, timerInitialDelay, timerPeriod); }
From source file:org.apache.accumulo.server.zookeeper.DistributedWorkQueue.java
License:Apache License
public void waitUntilDone(Set<String> workIDs) throws KeeperException, InterruptedException { final Object condVar = new Object(); Watcher watcher = new Watcher() { @Override/*from w w w. j a v a 2 s. c om*/ public void process(WatchedEvent event) { switch (event.getType()) { case NodeChildrenChanged: synchronized (condVar) { condVar.notify(); } break; case NodeCreated: case NodeDataChanged: case NodeDeleted: case None: log.info("Got unexpected zookeeper event: " + event.getType() + " for " + path); break; } } }; List<String> children = zoo.getChildren(path, watcher); while (!Collections.disjoint(children, workIDs)) { synchronized (condVar) { condVar.wait(10000); } children = zoo.getChildren(path, watcher); } }
From source file:org.apache.accumulo.tracer.TraceServer.java
License:Apache License
@Override public void process(WatchedEvent event) { log.debug("event " + event.getPath() + " " + event.getType() + " " + event.getState()); if (event.getState() == KeeperState.Expired) { log.warn("Trace server lost zookeeper registration at " + event.getPath()); server.stop();//from ww w . jav a2 s.c o m } else if (event.getType() == EventType.NodeDeleted) { log.warn("Trace server zookeeper entry lost " + event.getPath()); server.stop(); } if (event.getPath() != null) { try { if (ZooReaderWriter.getInstance().exists(event.getPath(), this)) return; } catch (Exception ex) { log.error("{}", ex.getMessage(), ex); } log.warn("Trace server unable to reset watch on zookeeper registration"); server.stop(); } }
From source file:org.apache.airavata.gfac.core.cpi.BetterGfacImpl.java
License:Apache License
public void process(WatchedEvent watchedEvent) { if (Event.EventType.NodeDataChanged.equals(watchedEvent.getType())) { // node data is changed, this means node is cancelled. log.info("Experiment is cancelled with this path:" + watchedEvent.getPath()); this.cancelled = true; }/*from ww w.j a v a 2 s . co m*/ }