本文整理匯總了Java中org.apache.zookeeper.KeeperException.NodeExistsException方法的典型用法代碼示例。如果您正苦於以下問題:Java KeeperException.NodeExistsException方法的具體用法?Java KeeperException.NodeExistsException怎麽用?Java KeeperException.NodeExistsException使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.zookeeper.KeeperException
的用法示例。
在下文中一共展示了KeeperException.NodeExistsException方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: write
import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
void write(ZooKeeper zkc, String path)
throws IOException, KeeperException.NodeExistsException {
this.zkPath = path;
EditLogLedgerProto.Builder builder = EditLogLedgerProto.newBuilder();
builder.setDataLayoutVersion(dataLayoutVersion)
.setLedgerId(ledgerId).setFirstTxId(firstTxId);
if (!inprogress) {
builder.setLastTxId(lastTxId);
}
try {
zkc.create(path, TextFormat.printToString(builder.build()).getBytes(UTF_8),
Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
} catch (KeeperException.NodeExistsException nee) {
throw nee;
} catch (KeeperException e) {
throw new IOException("Error creating ledger znode", e);
} catch (InterruptedException ie) {
throw new IOException("Interrupted creating ledger znode", ie);
}
}
示例2: setClusterUp
import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
/**
* Sets the cluster as up.
* @throws KeeperException unexpected zk exception
*/
public void setClusterUp()
throws KeeperException {
byte [] upData = toByteArray();
try {
ZKUtil.createAndWatch(watcher, watcher.clusterStateZNode, upData);
} catch(KeeperException.NodeExistsException nee) {
ZKUtil.setData(watcher, watcher.clusterStateZNode, upData);
}
}
示例3: addOrUpdateDelegationKey
import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
private void addOrUpdateDelegationKey(DelegationKey key, boolean isUpdate)
throws IOException {
String nodeCreatePath =
getNodePath(ZK_DTSM_MASTER_KEY_ROOT,
DELEGATION_KEY_PREFIX + key.getKeyId());
ByteArrayOutputStream os = new ByteArrayOutputStream();
DataOutputStream fsOut = new DataOutputStream(os);
if (LOG.isDebugEnabled()) {
LOG.debug("Storing ZKDTSMDelegationKey_" + key.getKeyId());
}
key.write(fsOut);
try {
if (zkClient.checkExists().forPath(nodeCreatePath) != null) {
zkClient.setData().forPath(nodeCreatePath, os.toByteArray())
.setVersion(-1);
if (!isUpdate) {
LOG.debug("Key with path [" + nodeCreatePath
+ "] already exists.. Updating !!");
}
} else {
zkClient.create().withMode(CreateMode.PERSISTENT)
.forPath(nodeCreatePath, os.toByteArray());
if (isUpdate) {
LOG.debug("Updating non existent Key path [" + nodeCreatePath
+ "].. Adding new !!");
}
}
} catch (KeeperException.NodeExistsException ne) {
LOG.debug(nodeCreatePath + " znode already exists !!");
} catch (Exception ex) {
throw new IOException(ex);
} finally {
os.close();
}
}
示例4: getMessage
import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
private static String getMessage(Throwable cause) {
if (cause instanceof KeeperException) {
KeeperException keeperException = (KeeperException) cause;
if (keeperException instanceof KeeperException.NoNodeException) {
return "Node does not exist: " + keeperException.getPath();
} else if (keeperException instanceof KeeperException.NoChildrenForEphemeralsException) {
return "Ephemerals cannot have children: " + keeperException.getPath();
} else if (keeperException instanceof KeeperException.NodeExistsException) {
return "Node already exists: " + keeperException.getPath();
} else if (keeperException instanceof KeeperException.NotEmptyException) {
return "Node not empty: " + keeperException.getPath();
} else if (keeperException instanceof KeeperException.NotReadOnlyException) {
return "Not a read-only call: " + keeperException.getPath();
} else if (keeperException instanceof KeeperException.InvalidACLException) {
return "Acl is not valid : " + keeperException.getPath();
} else if (keeperException instanceof KeeperException.NoAuthException) {
return "Authentication is not valid : " + keeperException.getPath();
} else if (keeperException instanceof KeeperException.BadArgumentsException) {
return "Arguments are not valid : " + keeperException.getPath();
} else if (keeperException instanceof KeeperException.BadVersionException) {
return "version No is not valid : " + keeperException.getPath();
} else if (keeperException instanceof KeeperException.ReconfigInProgress) {
return "Another reconfiguration is in progress -- concurrent " +
"reconfigs not supported (yet)";
} else if (keeperException instanceof KeeperException.NewConfigNoQuorum) {
return "No quorum of new config is connected and " +
"up-to-date with the leader of last commmitted config - try invoking reconfiguration after " +
"new servers are connected and synced";
}
}
return cause.getMessage();
}
示例5: testMultiFailure
import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
@Test (timeout=60000)
public void testMultiFailure() throws Exception {
String pathX = ZKUtil.joinZNode(zkw.baseZNode, "testMultiFailureX");
String pathY = ZKUtil.joinZNode(zkw.baseZNode, "testMultiFailureY");
String pathZ = ZKUtil.joinZNode(zkw.baseZNode, "testMultiFailureZ");
// create X that we will use to fail create later
LinkedList<ZKUtilOp> ops = new LinkedList<ZKUtilOp>();
ops.add(ZKUtilOp.createAndFailSilent(pathX, Bytes.toBytes(pathX)));
ZKUtil.multiOrSequential(zkw, ops, false);
// fail one of each create ,setData, delete
String pathV = ZKUtil.joinZNode(zkw.baseZNode, "testMultiFailureV");
String pathW = ZKUtil.joinZNode(zkw.baseZNode, "testMultiFailureW");
ops = new LinkedList<ZKUtilOp>();
ops.add(ZKUtilOp.createAndFailSilent(pathX, Bytes.toBytes(pathX))); // fail -- already exists
ops.add(ZKUtilOp.setData(pathY, Bytes.toBytes(pathY))); // fail -- doesn't exist
ops.add(ZKUtilOp.deleteNodeFailSilent(pathZ)); // fail -- doesn't exist
ops.add(ZKUtilOp.createAndFailSilent(pathX, Bytes.toBytes(pathV))); // pass
ops.add(ZKUtilOp.createAndFailSilent(pathX, Bytes.toBytes(pathW))); // pass
boolean caughtNodeExists = false;
try {
ZKUtil.multiOrSequential(zkw, ops, false);
} catch (KeeperException.NodeExistsException nee) {
// check first operation that fails throws exception
caughtNodeExists = true;
}
assertTrue(caughtNodeExists);
// check that no modifications were made
assertFalse(ZKUtil.checkExists(zkw, pathX) == -1);
assertTrue(ZKUtil.checkExists(zkw, pathY) == -1);
assertTrue(ZKUtil.checkExists(zkw, pathZ) == -1);
assertTrue(ZKUtil.checkExists(zkw, pathW) == -1);
assertTrue(ZKUtil.checkExists(zkw, pathV) == -1);
// test that with multiple failures, throws an exception corresponding to first failure in list
ops = new LinkedList<ZKUtilOp>();
ops.add(ZKUtilOp.setData(pathY, Bytes.toBytes(pathY))); // fail -- doesn't exist
ops.add(ZKUtilOp.createAndFailSilent(pathX, Bytes.toBytes(pathX))); // fail -- exists
boolean caughtNoNode = false;
try {
ZKUtil.multiOrSequential(zkw, ops, false);
} catch (KeeperException.NoNodeException nne) {
// check first operation that fails throws exception
caughtNoNode = true;
}
assertTrue(caughtNoNode);
// check that no modifications were made
assertFalse(ZKUtil.checkExists(zkw, pathX) == -1);
assertTrue(ZKUtil.checkExists(zkw, pathY) == -1);
assertTrue(ZKUtil.checkExists(zkw, pathZ) == -1);
assertTrue(ZKUtil.checkExists(zkw, pathW) == -1);
assertTrue(ZKUtil.checkExists(zkw, pathV) == -1);
}
示例6: createNode
import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
/**
* @param path
* @param data
* @param acl
* @param ephemeralOwner
* the session id that owns this node. -1 indicates this is
* not an ephemeral node.
* @param zxid
* @param time
* @return the patch of the created node
* @throws KeeperException
*/
public String createNode(String path, byte data[], List<ACL> acl,
long ephemeralOwner, long zxid, long time)
throws KeeperException.NoNodeException, KeeperException.NodeExistsException {
int lastSlash = path.lastIndexOf('/');
String parentName = path.substring(0, lastSlash);
String childName = path.substring(lastSlash + 1);
StatPersistedV1 stat = new StatPersistedV1();
stat.setCtime(time);
stat.setMtime(time);
stat.setCzxid(zxid);
stat.setMzxid(zxid);
stat.setVersion(0);
stat.setAversion(0);
stat.setEphemeralOwner(ephemeralOwner);
DataNodeV1 parent = nodes.get(parentName);
if (parent == null) {
throw new KeeperException.NoNodeException();
}
synchronized (parent) {
if (parent.children.contains(childName)) {
throw new KeeperException.NodeExistsException();
}
int cver = parent.stat.getCversion();
cver++;
parent.stat.setCversion(cver);
DataNodeV1 child = new DataNodeV1(parent, data, acl, stat);
parent.children.add(childName);
nodes.put(path, child);
if (ephemeralOwner != 0) {
HashSet<String> list = ephemerals.get(ephemeralOwner);
if (list == null) {
list = new HashSet<String>();
ephemerals.put(ephemeralOwner, list);
}
synchronized(list) {
list.add(path);
}
}
}
dataWatches.triggerWatch(path, Event.EventType.NodeCreated);
childWatches.triggerWatch(parentName.equals("")?"/":parentName, Event.EventType.NodeChildrenChanged);
return path;
}
示例7: testWideSerialize
import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
@Test
public void testWideSerialize()
throws InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
serializeTree(2, 10000, 20);
}
示例8: testSingleDeserialize
import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
@Test
public void testSingleDeserialize() throws
InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
deserializeTree(1, 0, 20);
}
示例9: testWideDeserialize
import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
@Test
public void testWideDeserialize() throws
InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
deserializeTree(2, 10000, 20);
}
示例10: test40Wide4DeepSerialize
import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
@Test
public void test40Wide4DeepSerialize()
throws InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
serializeTree(4, 40, 20);
}
示例11: test10Wide5DeepDeserialize
import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
@Test
public void test10Wide5DeepDeserialize() throws
InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
deserializeTree(5, 10, 20);
}
示例12: test15Wide5DeepDeserialize
import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
@Test
public void test15Wide5DeepDeserialize() throws
InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
deserializeTree(5, 15, 20);
}
示例13: test25Wide4DeepDeserialize
import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
@Test
public void test25Wide4DeepDeserialize() throws
InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
deserializeTree(4, 25, 20);
}
示例14: test40Wide4DeepDeserialize
import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
@Test
public void test40Wide4DeepDeserialize() throws
InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
deserializeTree(4, 40, 20);
}
示例15: createNodeClosing
import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
/**
* Creates a new unassigned node in the CLOSING state for the specified
* region.
*
* <p>Does not transition nodes from any states. If a node already exists
* for this region, a {@link org.apache.zookeeper.KeeperException.NodeExistsException}
* will be thrown.
*
* <p>If creation is successful, returns the version number of the CLOSING
* node created.
*
* <p>Set a watch.
*
* <p>This method should only be used by a Master when initiating a
* close of a region before sending a close request to the region server.
*
* @param zkw zk reference
* @param region region to be created as closing
* @param serverName server transition will happen on
* @return version of node after transition, -1 if unsuccessful transition
* @throws KeeperException if unexpected zookeeper exception
* @throws KeeperException.NodeExistsException if node already exists
*/
public static int createNodeClosing(ZooKeeperWatcher zkw, HRegionInfo region,
ServerName serverName)
throws KeeperException, KeeperException.NodeExistsException {
LOG.debug(zkw.prefix("Creating unassigned node " +
region.getEncodedName() + " in a CLOSING state"));
RegionTransition rt = RegionTransition.createRegionTransition(EventType.M_ZK_REGION_CLOSING,
region.getRegionName(), serverName, HConstants.EMPTY_BYTE_ARRAY);
String node = getNodeName(zkw, region.getEncodedName());
return ZKUtil.createAndWatch(zkw, node, rt.toByteArray());
}