List of usage examples for org.apache.zookeeper CreateMode EPHEMERAL
CreateMode EPHEMERAL
To view the source code for org.apache.zookeeper CreateMode EPHEMERAL.
Click Source Link
From source file:ZookeeperBackedAdoptionLogicImpl.java
License:Open Source License
public void advertisePartitionForAdoption(Partition partitionToGiveOut) throws Exception { //clear any previous ads by this broker List<String> prevAds = Utils.getAdoptionAds(client); String localBrokerId = "" + Utils.getLocalBrokerId(); for (String prevAd : prevAds) { if (prevAd.startsWith(localBrokerId)) { logger.debug("Deleting previous Ad posting {}", prevAd); client.delete().forPath(ADOPTION_ADS_ROOT_ZNODE + "/" + prevAd); }// w ww . j av a2 s. co m } String adZNode = ADOPTION_ADS_ROOT_ZNODE + "/" + partitionToGiveOut.getPartitionFullNameWithBrokerId(); logger.debug("Posting Ad for {}", adZNode); //create an ephemeral ad post client.create().withMode(CreateMode.EPHEMERAL).forPath(adZNode, AD_POSTING_TEXT.getBytes()); long adPostTime = System.currentTimeMillis(); logger.debug("Ad {} created at {}", adZNode, adPostTime); while (new String(client.getData().forPath(adZNode)).equals(AD_POSTING_TEXT) && System.currentTimeMillis() - adPostTime < AD_EXPIRY_MS) { logger.debug("Ad {} is active. Sleeping 1 min", adZNode); Thread.sleep(60000); } if (!new String(client.getData().forPath(adZNode)).equals(AD_POSTING_TEXT)) { logger.debug("Partition {} got adopted", adZNode); } else { logger.debug("Expired the Ad for {}", adZNode); } //Someone has adopted this partition, or the Ad needs to expire. Delete the Ad logger.debug("Deleting Ad node {}", adZNode); client.delete().forPath(adZNode); }
From source file:ai.grakn.engine.backgroundtasks.distributed.TaskRunner.java
License:Open Source License
private void registerAsRunning() throws Exception { if (zkStorage.connection().checkExists().forPath(RUNNERS_WATCH + "/" + engineID) == null) { zkStorage.connection().create().creatingParentContainersIfNeeded().withMode(CreateMode.EPHEMERAL) .forPath(RUNNERS_WATCH + "/" + engineID); }// w ww.j a v a 2 s. c o m if (zkStorage.connection().checkExists().forPath(RUNNERS_STATE + "/" + engineID) == null) { zkStorage.connection().create().creatingParentContainersIfNeeded() .forPath(RUNNERS_STATE + "/" + engineID); } LOG.debug("Registered TaskRunner"); }
From source file:ai.grakn.engine.tasks.manager.multiqueue.MultiQueueTaskRunner.java
License:Open Source License
private void registerAsRunning() { try {/*from w w w . j av a 2 s .c o m*/ if (connection.connection().checkExists() .forPath(format(SINGLE_ENGINE_WATCH_PATH, engineId.value())) == null) { connection.connection().create().creatingParentContainersIfNeeded().withMode(CreateMode.EPHEMERAL) .forPath(format(SINGLE_ENGINE_WATCH_PATH, engineId.value())); } } catch (RuntimeException e) { throw e; } catch (Exception exception) { throw new RuntimeException("Could not create Zookeeper paths in TaskRunner"); } LOG.debug("Registered TaskRunner"); }
From source file:ai.grakn.engine.tasks.manager.singlequeue.SingleQueueTaskManager.java
License:Open Source License
/** * Register this instance of Engine in Zookeeper to monitor its status * * @param engineId identifier of this instance of engine, which will be registered in Zookeeper * @param zookeeper connection to zookeeper * @throws Exception when there is an issue contacting or writing to zookeeper *///w ww . j a v a2 s . c om private void registerSelfForFailover(EngineID engineId, ZookeeperConnection zookeeper) throws Exception { zookeeper.connection().create().creatingParentContainersIfNeeded().withMode(CreateMode.EPHEMERAL) .forPath(format(SINGLE_ENGINE_WATCH_PATH, engineId.value())); }
From source file:ai.grakn.test.engine.tasks.manager.multiqueue.TaskFailoverTest.java
License:Open Source License
private void registerFakeEngine(EngineID id) throws Exception { if (connection.connection().checkExists().forPath(format(SINGLE_ENGINE_WATCH_PATH, id.value())) == null) { connection.connection().create().creatingParentContainersIfNeeded().withMode(CreateMode.EPHEMERAL) .forPath(format(SINGLE_ENGINE_WATCH_PATH, id.value())); }/*from w ww .j a v a2s . c o m*/ assertNotNull(connection.connection().checkExists().forPath(format(SINGLE_ENGINE_WATCH_PATH, id.value()))); }
From source file:alluxio.master.PrimarySelectorClient.java
License:Apache License
@Override public void takeLeadership(CuratorFramework client) throws Exception { setState(State.PRIMARY);/*from www . ja va2 s .c o m*/ if (client.checkExists().forPath(mLeaderFolder + mName) != null) { LOG.info("Deleting zk path: {}{}", mLeaderFolder, mName); client.delete().forPath(mLeaderFolder + mName); } LOG.info("Creating zk path: {}{}", mLeaderFolder, mName); client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath(mLeaderFolder + mName); LOG.info("{} is now the leader.", mName); try { waitForState(State.SECONDARY); } finally { LOG.warn("{} relinquishing leadership.", mName); LOG.info("The current leader is {}", mLeaderSelector.getLeader().getId()); LOG.info("All participants: {}", mLeaderSelector.getParticipants()); client.delete().forPath(mLeaderFolder + mName); } }
From source file:blazingcache.zookeeper.ZKClusterManager.java
License:Apache License
/** * Let cache server compete for cluster leadership. */// w w w . j a v a 2s. co m public void requestLeadership() { zk.create(leaderpath, localhostdata, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL, masterCreateCallback, null); }
From source file:br.unb.cic.bionimbuz.services.RepositoryService.java
/** * @param resource//from ww w . j av a 2s.c o m * Resource to be added */ public void addPeerToZookeeper(PluginInfo resource) { this.cms.createZNode(CreateMode.PERSISTENT, Path.NODE_PEER.getFullPath(resource.getId()), resource.toString()); this.cms.createZNode(CreateMode.EPHEMERAL, Path.STATUS.getFullPath(resource.getId()), null); this.cms.createZNode(CreateMode.PERSISTENT, Path.SCHED.getFullPath(resource.getId()), null); this.cms.createZNode(CreateMode.PERSISTENT, Path.TASKS.getFullPath(resource.getId()), null); }
From source file:ch.ethz.globis.distindex.orchestration.ZKClusterService.java
License:Open Source License
private void initSizeCounter(String hostId) throws Exception { if (sizes.containsKey(hostId)) { throw new IllegalStateException("Host size should not be initialized"); }//ww w. ja v a2 s . c om int value = 0; sizes.put(hostId, value); String path = sizePath(hostId); client.create().withMode(CreateMode.EPHEMERAL).forPath(path, intToByte(value)); }
From source file:ch.usi.da.paxos.old.Proposer.java
License:Open Source License
private void init() throws IOException { setLeader(true); // initially everybody is a leader // register the leader selection watcher try {/* w w w . ja v a 2 s .c om*/ if (zoo.exists(path, false) == null) { zoo.create(path, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); } zoo.getChildren(path, true); // start watching zoo.create(path + "/" + this.getID(), null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); } catch (Exception e) { //e.printStackTrace(); System.out.println("Running without zookeeper. So no leader election!"); } }