List of usage examples for org.apache.zookeeper WatchedEvent getType
public EventType getType()
From source file:blazingcache.zookeeper.ZKCacheServerLocator.java
License:Apache License
@Override protected ServerHostData getServer() { String leaderPath = basePath + "/leader"; try {//from w w w . j a v a 2 s .co m byte[] data; if (ownedZk) { CountDownLatch connection = new CountDownLatch(1); try { LOGGER.finest("creating temp ZK client for discovery"); ZooKeeper client = new ZooKeeper(zkAddress, zkSessiontimeout, new Watcher() { @Override public void process(WatchedEvent event) { if (event.getState() == Event.KeeperState.SyncConnected || event.getState() == Event.KeeperState.ConnectedReadOnly) { connection.countDown(); } LOGGER.severe("process ZK event " + event.getState() + " " + event.getType() + " " + event.getPath()); } }); try { connection.await(connectTimeout, TimeUnit.MILLISECONDS); LOGGER.finest("ZK client is " + client); // se la connessione non sar stabilita in tempo o c' qualche problem troveremo un ConnectionLoss ad esempio data = client.getData(leaderPath, false, null); } finally { client.close(); } } catch (IOException err) { LOGGER.log(Level.SEVERE, "zookeeper client not available: " + err); return null; } } else { ZooKeeper client = zkSupplier.get(); if (client == null) { LOGGER.log(Level.SEVERE, "zookeeper client available"); return null; } data = client.getData(leaderPath, false, null); } lastKnownServer = ServerHostData.parseHostdata(data); return lastKnownServer; } catch (KeeperException.NoNodeException nobroker) { LOGGER.log(Level.SEVERE, "zookeeper client error", nobroker); return null; } catch (KeeperException | InterruptedException err) { LOGGER.log(Level.SEVERE, "zookeeper client error", err); return null; } }
From source file:br.unb.cic.bionimbuz.controller.slacontroller.SlaController.java
@Override public void event(WatchedEvent eventType) { LOGGER.info("DISPARADOOOOOOOOOOOOOOOOOOOOOO"); switch (eventType.getType()) { case NodeChildrenChanged: if (eventType.getPath().equals(Path.USERS_INFO.getFullPath())) { LOGGER.info("Imprimir"); // for (User u : MonitoringService.getZkUsers()) { // LOGGER.info("User: " + u.toString()); // for (Workflow work : u.getWorkflows()) { // LOGGER.info("Workflow: " + work.toString()); // }//from w w w.ja v a 2s. c o m // } } break; case NodeDeleted: break; case NodeCreated: break; case NodeDataChanged: break; case None: break; default: break; } }
From source file:br.unb.cic.bionimbuz.services.monitor.MonitoringService.java
License:Open Source License
@Override public void event(WatchedEvent eventType) { final String path = eventType.getPath(); try {//from w ww. ja v a2 s .co m switch (eventType.getType()) { case NodeCreated: LOGGER.info(path + "= NodeCreated"); break; case NodeChildrenChanged: if (eventType.getPath().equals(Path.PEERS.toString())) { if (this.plugins.size() < this.getPeers().size()) { this.verifyPlugins(); } } LOGGER.info(path + "= NodeChildrenChanged"); break; case NodeDeleted: final String peerPath = path.subSequence(0, path.indexOf("STATUS") - 1).toString(); if (path.contains(Path.STATUSWAITING.toString())) { this.deletePeer(peerPath); } break; } } catch (final KeeperException ex) { java.util.logging.Logger.getLogger(MonitoringService.class.getName()).log(Level.SEVERE, null, ex); } catch (final InterruptedException ex) { java.util.logging.Logger.getLogger(MonitoringService.class.getName()).log(Level.SEVERE, null, ex); } catch (final Exception ex) { java.util.logging.Logger.getLogger(MonitoringService.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:br.unb.cic.bionimbuz.services.RepositoryService.java
@Override public void event(WatchedEvent eventType) { switch (eventType.getType()) { case NodeChildrenChanged: if (eventType.getPath().equals(Path.USERS_INFO.getFullPath())) { LOGGER.info("Imprimir"); }/*from w w w . j ava2 s .co m*/ break; case NodeDeleted: break; } }
From source file:br.unb.cic.bionimbuz.services.sched.SchedService.java
License:Open Source License
/** * Trata os watchers enviados pelas mudanas realizadas no zookeeper. * * @param eventType//from w ww. ja v a 2 s .co m * evento recebido do zookeeper */ @Override public void event(WatchedEvent eventType) { try { switch (eventType.getType()) { case NodeChildrenChanged: String datas; // reconhece um alerta de um novo pipeline if (eventType.getPath().contains(Path.PIPELINES.toString()) && !this.isClient) { LOGGER.info("[SchedService] Recebimento de um alerta para um pipeline, NodeChildrenChanged"); // checking moved to checkTasks in order to solve racing condition // updatePipelines(); } else if (eventType.getPath().contains(Path.SCHED.toString() + Path.TASKS)) { LOGGER.info("[SchedService] Recebimento de um alerta para uma TAREFA"); // verifica qual foi o job colocado para ser executado final PluginTask pluginTask = this.getNewTask(eventType.getPath()); // verifica se um existe algum novo pluginTask if (pluginTask != null) { if (pluginTask.getState() == PluginTaskState.PENDING) { this.executeTasks(pluginTask); } } else if (!this.waitingTask.isEmpty()) { this.checkStatusTask(); } } else if (eventType.getPath().contains(Path.FILES.toString())) { this.checkFilesPlugin(); } else if (eventType.getPath().equals(Path.PEERS.toString())) { if (this.cloudMap.size() < this.getPeers().size()) { this.verifyPlugins(); } } break; case NodeDataChanged: // reconhece o alerta como uma mudana na poltica de escalonamento // if (eventType.getPath().contains(JOBS.getCodigo()) && !eventType.getPath().contains(PREFIX_JOB.toString())) { // setPolicy(); // reconhece a mudana no estado da tarefa // } else if (this.cms.getZNodeExist(eventType.getPath(), null)) { datas = this.cms.getData(eventType.getPath(), null); final PluginTask pluginTask = (PluginTask) this.convertString(PluginTask.class, datas); // retirar depois testes, exibi a tarefa que est em execuo if (pluginTask.getState() == PluginTaskState.RUNNING) { LOGGER.info("Task est rodando: " + Path.NODE_TASK.getFullPath(pluginTask.getPluginExec(), pluginTask.getId())); } if (pluginTask.getState() == PluginTaskState.DONE) { this.finalizeTask(pluginTask); } } break; case NodeDeleted: // Trata o evento de quando o zNode status for apagado, ou seja, quando um peer estiver off-line, deve recuperar os jobs // que haviam sido escalonados para esse peer if (eventType.getPath().contains(Path.STATUS.toString())) { // cloudMap.clear(); // cloudMap.putAll(getPeers()); // schedPolicy.setCloudMap(cloudMap); this.repairTask(eventType.getPath().subSequence(0, eventType.getPath().indexOf("STATUS") - 1) .toString()); } break; } } catch (final KeeperException ex) { java.util.logging.Logger.getLogger(SchedService.class.getName()).log(Level.SEVERE, null, ex); } catch (final InterruptedException ex) { java.util.logging.Logger.getLogger(SchedService.class.getName()).log(Level.SEVERE, null, ex); } catch (final Exception ex) { java.util.logging.Logger.getLogger(SchedService.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:br.unb.cic.bionimbuz.services.storage.StorageService.java
License:Open Source License
/** * Mtodo que recebe um evento do zookeeper caso os znodes setados nessa * classe sofra alguma alterao, criado, deletado, modificado, trata os * eventos de acordo com o tipo do mesmo * * @param eventType//from w w w.j a v a 2s . c o m */ @Override public void event(WatchedEvent eventType) { final String path = eventType.getPath(); switch (eventType.getType()) { case NodeChildrenChanged: if (eventType.getPath().equals(Path.PEERS.toString())) { if (this.cloudMap.size() < this.getPeers().size()) { this.verifyPlugins(); } } else if (eventType.getPath().equals(Path.PENDING_SAVE.toString())) { // chamada para checar a pending_save apenas quando uma alerta para ela for lanado // try{ // checkingPendingSave(); // } // catch (IOException ex) { // Logger.getLogger(StorageService.class.getName()).log(Level.SEVERE, null, ex); // } } break; case NodeDeleted: if (eventType.getPath().contains(Path.STATUS.toString())) { LOGGER.info("Erased ZNode Status"); final String peerId = path.substring(12, path.indexOf("/STATUS")); if (this.getPeers().values().size() != 1) { try { if (!this.cms.getZNodeExist(Path.STATUSWAITING.getFullPath(peerId), null)) { this.cms.createZNode(CreateMode.PERSISTENT, Path.STATUSWAITING.getFullPath(peerId), ""); } final StringBuilder info = new StringBuilder( this.cms.getData(Path.STATUSWAITING.getFullPath(peerId), null)); // verifica se recurso j foi recuperado ou est sendo recuperado por outro recurso if (!info.toString().contains("S") /* && !info.toString().contains("L") */) { // bloqueio para recuperar tarefas sem que outros recursos realizem a mesma operao // cms.setData(Path.STATUSWAITING.getFullPath(peerId), info.append("L").toString()); // Verificar pluginid para gravar for (final PluginFile fileExcluded : this.getFilesPeer(peerId)) { String idPluginExcluded = null; for (final String idPlugin : fileExcluded.getPluginId()) { if (peerId.equals(idPlugin) && !idPlugin.equals(BioNimbusConfig.get().getId())) { idPluginExcluded = idPlugin; break; } } if (fileExcluded.getPluginId().size() > 1) { fileExcluded.getPluginId().remove(idPluginExcluded); } this.setPendingFile(fileExcluded); fileExcluded.setService("storagePeerDown"); this.fileUploaded(fileExcluded); } // retira bloqueio de uso e adiciona marcao de recuperao // info.deleteCharAt(info.indexOf("L")); info.append("S"); this.cms.setData(Path.STATUSWAITING.getFullPath(peerId), info.toString()); // nao necessrio chamar esse mtodo aqui, ele ser chamado se for necessrio ao receber um alerta de watcher // checkingPendingSave(); } } catch (final AvroRemoteException ex) { LOGGER.error("[AvroRemoteException] - " + ex.getMessage()); } catch (final KeeperException ex) { LOGGER.error("[KeeperException] - " + ex.getMessage()); } catch (final InterruptedException ex) { LOGGER.error("[InterruptedException] - " + ex.getMessage()); } catch (final IOException ex) { LOGGER.error("[IOException] - " + ex.getMessage()); } catch (final NoSuchAlgorithmException ex) { LOGGER.error("[NoSuchAlgorithmException] - " + ex.getMessage()); } catch (final SftpException ex) { LOGGER.error("[SftpException] - " + ex.getMessage()); } } break; } default: break; } }
From source file:br.unb.cic.bionimbuz.services.UpdatePeerData.java
License:Open Source License
/** * Recebe as notificaes de evento do zookeeper. * * @param event evento que identifica a mudana realizada no zookeeper *///from w w w . jav a 2s . c o m @Override public void process(WatchedEvent event) { //chamada para alertar servico que adicionou o watcher, tratar evento na service // System.out.println("[UpdatePeerData] event: " + event.toString()); if (service != null) service.event(event); if (controler != null) controler.event(event); //Realiza a solicitao para um novo observer switch (event.getType()) { case NodeChildrenChanged: if (cms.getZNodeExist(event.getPath(), null)) cms.getChildren(event.getPath(), this); break; case NodeDataChanged: if (cms.getZNodeExist(event.getPath(), null)) cms.getData(event.getPath(), this); break; } }
From source file:cc.alessandro.zookeeper.example.SyncPrimitive.java
License:Open Source License
@Override public synchronized void process(WatchedEvent event) { synchronized (mutex) { LOG.info("Process: {}", event.getType()); mutex.notify();/*from w w w. j av a2 s. c o m*/ } }
From source file:ch.usi.da.paxos.old.Proposer.java
License:Open Source License
@Override public void process(WatchedEvent event) { int max = -1; try {/* w ww .j a v a2 s. co m*/ if (event.getType() == EventType.NodeChildrenChanged) { List<String> l = zoo.getChildren(path, true); for (String s : l) { int i = Integer.parseInt(s); if (i > max) { max = i; } } if (max == this.getID()) { System.out.println("I'm the new leader :-)!"); setLeader(true); } else { System.out.println("I'm a dumb follower :-(!"); setLeader(false); } } } catch (KeeperException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:ch.usi.da.paxos.ring.RingManager.java
License:Open Source License
@Override public void process(WatchedEvent event) { int old_coordinator = coordinator; super.process(event); // ls nodes to form the ring try {/*from w ww . ja va 2 s. c o m*/ if (event.getType() == EventType.NodeChildrenChanged) { if (event.getPath().startsWith(path + "/" + id_path)) { nodes.clear(); List<String> l = zoo.getChildren(path + "/" + id_path, true); for (String s : l) { nodes.add(Integer.valueOf(s)); } Collections.sort(nodes); notifyRingChanged(); } else if (event.getPath().startsWith(path + "/" + acceptor_path)) { List<String> l = zoo.getChildren(path + "/" + acceptor_path, true); int min = nodeID + 1; int max = 0; for (String s : l) { int i = Integer.valueOf(s); if (i < min) { min = i; } if (i > max) { max = i; } } last_acceptor = max; coordinator = min; if (nodeID == min && old_coordinator != coordinator) { notifyNewCoordinator(); } } } } catch (KeeperException e) { logger.error(e); } catch (InterruptedException e) { } }