/** * @return True if cluster has an active master. */ public boolean isActiveMaster() { try { if (ZKUtil.checkExists(watcher, watcher.getMasterAddressZNode()) >= 0) { return true; } } catch (KeeperException ke) { LOG.info("Received an unexpected KeeperException when checking " + "isActiveMaster : " + ke); } return false; }
/** * Checks if the baseznode set as per the property 'zookeeper.znode.parent' * exists. * @return true if baseznode exists. false if doesnot exists. */ public boolean checkIfBaseNodeAvailable() { try { if (ZKUtil.checkExists(watcher, watcher.baseZNode) == -1) { return false; } } catch (KeeperException e) { abortable.abort("Exception while checking if basenode (" + watcher.baseZNode + ") exists in ZooKeeper.", e); } return true; } }
/** * Get the version of the specified znode * @param zkw zk reference * @param entityGroup entityGroup's info * @return the version of the znode, -1 if it doesn't exist * @throws org.apache.zookeeper.KeeperException */ public static int getVersion(ZooKeeperWatcher zkw, EntityGroupInfo entityGroup) throws KeeperException { String znode = getNodeName(zkw, entityGroup.getEncodedName()); return ZKUtil.checkExists(zkw, znode); }
private void checkIfBaseNodeAvailable(ZooKeeperWatcher zkw) throws MasterNotRunningException { String errorMsg; try { if (ZKUtil.checkExists(zkw, zkw.baseZNode) == -1) { errorMsg = "The node " + zkw.baseZNode + " is not in ZooKeeper. " + "It should have been written by the master. " + "Check the value configured in 'zookeeper.znode.parent'. " + "There could be a mismatch with the one configured in the master."; LOG.error(errorMsg); throw new MasterNotRunningException(errorMsg); } } catch (KeeperException e) { errorMsg = "Can't get connection to ZooKeeper: " + e.getMessage(); LOG.error(errorMsg); throw new MasterNotRunningException(errorMsg, e); } }
/** * Set data into node creating node if it doesn't yet exist. Does not set * watch. * * @param zkw * zk reference * @param znode * path of node * @param data * data to set for node * @throws org.apache.zookeeper.KeeperException */ public static void createSetData(final ZooKeeperWatcher zkw, final String znode, final byte[] data) throws KeeperException { if (checkExists(zkw, znode) == -1) { ZKUtil.createWithParents(zkw, znode); } ZKUtil.setData(zkw, znode, data); }
public static ClusterId readClusterIdZNode(ZooKeeperWatcher watcher) throws KeeperException { if (ZKUtil.checkExists(watcher, watcher.clusterIdZNode) != -1) { byte[] data = ZKUtil.getData(watcher, watcher.clusterIdZNode); if (data != null) { try { return ClusterId.parseFrom(data); } catch (DeserializationException e) { throw ZKUtil.convert(e); } } } return null; }
if (!nodeExistsChecked) { try { nodeExistsChecked = (ZKUtil.checkExists(watcher, node) != -1); } catch (KeeperException e) { LOG.warn(
private void setTableState(final String tableName, final ZooKeeperProtos.Table.State state) throws KeeperException { String znode = ZKUtil.joinZNode(this.watcher.tableZNode, tableName); if (ZKUtil.checkExists(this.watcher, znode) == -1) { ZKUtil.createAndFailSilent(this.watcher, znode); } synchronized (this.cache) { ZooKeeperProtos.Table.Builder builder = ZooKeeperProtos.Table .newBuilder(); builder.setState(state); byte[] data = builder.build().toByteArray(); ZKUtil.setData(this.watcher, znode, data); this.cache.put(tableName, state); } }
if (ZKUtil.checkExists(this.watcher, backupZNode) != -1) { LOG.info("Deleting ZNode for " + backupZNode + " from backup master directory");
String node = getNodeName(zkw, entityGroup.getEncodedName()); zkw.sync(node); int version = ZKUtil.checkExists(zkw, node); if (version == -1) { return ZKUtil.createAndWatch(zkw, node, data);
.get(0).getEntityGroupInfo().getEncodedName()); if (nodeCreated) { assertFalse(ZKUtil.checkExists(fserver.getZooKeeper(), node) == -1); } else { assertTrue(ZKUtil.checkExists(fserver.getZooKeeper(), node) == -1); assertTrue(ZKUtil.checkExists(fserver.getZooKeeper(), node) == -1);