当前位置: 首页>>代码示例>>Java>>正文


Java KeeperException.NodeExistsException方法代码示例

本文整理汇总了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);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:23,代码来源:EditLogLedgerMetadata.java

示例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);
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:14,代码来源:ClusterStatusTracker.java

示例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();
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:36,代码来源:ZKDelegationTokenSecretManager.java

示例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();
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:33,代码来源:CliWrapperException.java

示例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);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:54,代码来源:TestZKMulti.java

示例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;
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:56,代码来源:DataTreeV1.java

示例7: testWideSerialize

import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
@Test
public void testWideSerialize()
        throws InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
    serializeTree(2, 10000, 20);
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:6,代码来源:SerializationPerfTest.java

示例8: testSingleDeserialize

import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
@Test
public void testSingleDeserialize() throws
        InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
    deserializeTree(1, 0, 20);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:6,代码来源:DeserializationPerfTest.java

示例9: testWideDeserialize

import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
@Test
public void testWideDeserialize() throws
        InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
    deserializeTree(2, 10000, 20);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:6,代码来源:DeserializationPerfTest.java

示例10: test40Wide4DeepSerialize

import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
@Test
public void test40Wide4DeepSerialize()
        throws InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
    serializeTree(4, 40, 20);
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:6,代码来源:SerializationPerfTest.java

示例11: test10Wide5DeepDeserialize

import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
@Test
public void test10Wide5DeepDeserialize() throws
        InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
    deserializeTree(5, 10, 20);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:6,代码来源:DeserializationPerfTest.java

示例12: test15Wide5DeepDeserialize

import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
@Test
public void test15Wide5DeepDeserialize() throws
        InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
    deserializeTree(5, 15, 20);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:6,代码来源:DeserializationPerfTest.java

示例13: test25Wide4DeepDeserialize

import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
@Test
public void test25Wide4DeepDeserialize() throws
        InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
    deserializeTree(4, 25, 20);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:6,代码来源:DeserializationPerfTest.java

示例14: test40Wide4DeepDeserialize

import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
@Test
public void test40Wide4DeepDeserialize() throws
        InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
    deserializeTree(4, 40, 20);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:6,代码来源:DeserializationPerfTest.java

示例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());
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:34,代码来源:ZKAssign.java


注:本文中的org.apache.zookeeper.KeeperException.NodeExistsException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。