List of usage examples for org.apache.zookeeper KeeperException getPath
public String getPath()
From source file:com.guang.eunormia.common.dislock.ZKClient.java
License:Open Source License
public void create(String path, byte[] bytes, boolean isPersistent) throws ZKException { path = ZKUtil.normalize(path);/*from w w w.ja v a 2 s . c o m*/ CreateMode createMode = isPersistent ? CreateMode.PERSISTENT : CreateMode.EPHEMERAL; try { zookeeper.create(path, bytes, ZooDefs.Ids.OPEN_ACL_UNSAFE, createMode); } catch (KeeperException e) { if (e instanceof KeeperException.NoNodeException) { throw new ZKException( "The node [" + e.getPath() + "]'s parent node doesn't exist,can't create it. ", e); } else if (e instanceof KeeperException.NodeExistsException) { this.setData(path, bytes); } else { throw new ZKException("Other error", e); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new ZKException(e); } catch (Throwable e) { throw new ZKException(e); } }
From source file:com.guang.eunormia.common.dislock.ZKClient.java
License:Open Source License
public void createPath(String path, boolean isPersistent) throws ZKException { CreateMode createMode = isPersistent ? CreateMode.PERSISTENT : CreateMode.EPHEMERAL; path = ZKUtil.normalize(path);//from w w w .j a v a 2s . com try { if (!this.exists(path)) { zookeeper.create(path, null, ZooDefs.Ids.OPEN_ACL_UNSAFE, createMode); } } catch (KeeperException e) { if (e instanceof KeeperException.NodeExistsException) { } else if (e instanceof KeeperException.NoNodeException) { throw new ZKException( "The node [" + e.getPath() + "]'s parent node doesn't exist,can't create it. ", e); } else { throw new ZKException("Other error", e); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new ZKException(e); } catch (Throwable e) { throw new ZKException(e); } }
From source file:com.guang.eunormia.common.dislock.ZKClient.java
License:Open Source License
public byte[] getData(String path, Watcher watcher) throws ZKException { path = ZKUtil.normalize(path);/* w w w.jav a 2 s . c o m*/ byte[] data = null; try { data = zookeeper.getData(path, watcher, null); } catch (KeeperException e) { if (e instanceof KeeperException.NoNodeException) { throw new ZKException("Node does not exist,path is [" + e.getPath() + "].", e); } else { throw new ZKException(e); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new ZKException(e); } return data; }
From source file:com.guang.eunormia.common.dislock.ZKClient.java
License:Open Source License
public List<String> getChildren(String path, Watcher watcher) throws ZKException { path = ZKUtil.normalize(path);//ww w.j av a2 s .c o m List<String> children = null; try { children = zookeeper.getChildren(path, watcher); } catch (KeeperException e) { if (e instanceof KeeperException.NoNodeException) { throw new ZKException("Node does not exist,path is [" + e.getPath() + "].", e); } else { throw new ZKException(e); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new ZKException(e); } return children; }
From source file:com.guang.eunormia.common.dislock.ZKClient.java
License:Open Source License
public void setData(String path, byte[] bytes, int version) throws ZKException { path = ZKUtil.normalize(path);//from w ww . j a v a 2 s . c o m try { zookeeper.setData(path, bytes, version); } catch (KeeperException e) { if (e instanceof KeeperException.NoNodeException) { this.rcreate(path, bytes); } else if (e instanceof KeeperException.BadVersionException) { throw new ZKException("Bad Version,path [" + e.getPath() + "] version [" + version + "],the given version does not match the node's version", e); } else { throw new ZKException("May be value(byte[]) is larger than 1MB.", e); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new ZKException(e); } }
From source file:com.navercorp.nbasearc.confmaster.repository.ZooKeeperHolder.java
License:Apache License
public List<OpResult> multi(Iterable<Op> ops) throws MgmtZooKeeperException { try {/*from w w w . ja v a 2 s. c o m*/ return zk.multi(ops); } catch (KeeperException e) { Logger.error("Multi operation fail. {}, {}", e.getPath(), ops, e); throw new MgmtZooKeeperException(e); } catch (InterruptedException e) { Logger.error("Multi operation fail. {}", ops, e); throw new MgmtZooKeeperException(e); } }
From source file:com.navercorp.nbasearc.confmaster.server.ZooKeeperHolder.java
License:Apache License
public List<OpResult> multi(Iterable<Op> ops) throws MgmtZooKeeperException { try {/*from w w w. j a va2s. c om*/ for (Op op : ops) { if (op.getType() == create || op.getType() == delete || op.getType() == setData) { ThreadLocalVariableHolder.checkPermission(op.getPath(), WRITE); } else if (op.getType() == getData || op.getType() == exists || op.getType() == getChildren) { ThreadLocalVariableHolder.checkPermission(op.getPath(), READ); } } return zk.multi(ops); } catch (KeeperException e) { Logger.error("Multi operation fail. {}, {}", e.getPath(), ops, e); throw new MgmtZooKeeperException(e); } catch (InterruptedException e) { Logger.error("Multi operation fail. {}", ops, e); throw new MgmtZooKeeperException(e); } }
From source file:com.taobao.common.tedis.dislock.ZKClient.java
License:Open Source License
public void create(String path, byte[] bytes, boolean isPersistent) throws ZKException { path = ZKUtil.normalize(path);/*from w w w . j a v a2 s .c o m*/ CreateMode createMode = isPersistent ? CreateMode.PERSISTENT : CreateMode.EPHEMERAL; try { zookeeper.create(path, bytes, Ids.OPEN_ACL_UNSAFE, createMode); } catch (KeeperException e) { if (e instanceof KeeperException.NoNodeException) { throw new ZKException( "The node [" + e.getPath() + "]'s parent node doesn't exist,can't create it. ", e); } else if (e instanceof KeeperException.NodeExistsException) { this.setData(path, bytes); } else { throw new ZKException("Other error", e); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new ZKException(e); } catch (Throwable e) { throw new ZKException(e); } }
From source file:com.taobao.common.tedis.dislock.ZKClient.java
License:Open Source License
public void createPath(String path, boolean isPersistent) throws ZKException { CreateMode createMode = isPersistent ? CreateMode.PERSISTENT : CreateMode.EPHEMERAL; path = ZKUtil.normalize(path);/* w ww . j a v a 2 s .c om*/ try { if (!this.exists(path)) { zookeeper.create(path, null, Ids.OPEN_ACL_UNSAFE, createMode); } } catch (KeeperException e) { if (e instanceof KeeperException.NodeExistsException) { } else if (e instanceof KeeperException.NoNodeException) { throw new ZKException( "The node [" + e.getPath() + "]'s parent node doesn't exist,can't create it. ", e); } else { throw new ZKException("Other error", e); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new ZKException(e); } catch (Throwable e) { throw new ZKException(e); } }
From source file:org.apache.hadoop.hbase.replication.ReplicationQueuesZKImpl.java
License:Apache License
/** * Delete all the replication queues for a given region server. * @param regionserverZnode The znode of the region server to delete. *///from w w w .j a v a 2 s . c o m private void deleteAnotherRSQueues(String regionserverZnode) { String fullpath = ZKUtil.joinZNode(this.queuesZNode, regionserverZnode); try { List<String> clusters = ZKUtil.listChildrenNoWatch(this.zookeeper, fullpath); for (String cluster : clusters) { // No need to delete, it will be deleted later. if (cluster.equals(RS_LOCK_ZNODE)) { continue; } String fullClusterPath = ZKUtil.joinZNode(fullpath, cluster); ZKUtil.deleteNodeRecursively(this.zookeeper, fullClusterPath); } // Finish cleaning up ZKUtil.deleteNodeRecursively(this.zookeeper, fullpath); } catch (KeeperException e) { if (e instanceof KeeperException.NoNodeException || e instanceof KeeperException.NotEmptyException) { // Testing a special case where another region server was able to // create a lock just after we deleted it, but then was also able to // delete the RS znode before us or its lock znode is still there. if (e.getPath().equals(fullpath)) { return; } } this.abortable.abort("Failed to delete replication queues for region server: " + regionserverZnode, e); } }