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


Java KeeperException类代码示例

本文整理汇总了Java中org.apache.zookeeper.KeeperException的典型用法代码示例。如果您正苦于以下问题:Java KeeperException类的具体用法?Java KeeperException怎么用?Java KeeperException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


KeeperException类属于org.apache.zookeeper包,在下文中一共展示了KeeperException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createPath

import org.apache.zookeeper.KeeperException; //导入依赖的package包/类
private boolean createPath(String path, CreateMode createMode) {
    boolean success;
    try {
        zkClient.create()
                .creatingParentsIfNeeded()
                .withMode(createMode)
                .forPath(path, "".getBytes());
        success = true;
        LOG.info("create path success, path={}", path);
    } catch (KeeperException.NodeExistsException ex1) {
        success = true;
        LOG.debug("node exist, path={}", path);
    } catch (Exception ex2) {
        success = false;
        LOG.debug("createPath exception:", ex2);
    }
    return success;
}
 
开发者ID:wenweihu86,项目名称:distmq,代码行数:19,代码来源:MetadataManager.java

示例2: processRegionInTransitionAndBlockUntilAssigned

import org.apache.zookeeper.KeeperException; //导入依赖的package包/类
/**
 * If region is up in zk in transition, then do fixup and block and wait until
 * the region is assigned and out of transition.  Used on startup for
 * catalog regions.
 * @param hri Region to look for.
 * @return True if we processed a region in transition else false if region
 * was not up in zk in transition.
 * @throws InterruptedException
 * @throws KeeperException
 * @throws IOException
 */
boolean processRegionInTransitionAndBlockUntilAssigned(final HRegionInfo hri)
    throws InterruptedException, KeeperException, IOException {
  String encodedRegionName = hri.getEncodedName();
  if (!processRegionInTransition(encodedRegionName, hri)) {
    return false; // The region is not in transition
  }
  LOG.debug("Waiting on " + HRegionInfo.prettyPrint(encodedRegionName));
  while (!this.server.isStopped() &&
      this.regionStates.isRegionInTransition(encodedRegionName)) {
    RegionState state = this.regionStates.getRegionTransitionState(encodedRegionName);
    if (state == null || !serverManager.isServerOnline(state.getServerName())) {
      // The region is not in transition, or not in transition on an online
      // server. Doesn't help to block here any more. Caller need to
      // verify the region is actually assigned.
      break;
    }
    this.regionStates.waitForUpdate(100);
  }
  return true;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:32,代码来源:AssignmentManager.java

示例3: processRequest

import org.apache.zookeeper.KeeperException; //导入依赖的package包/类
@Override
public void processRequest(Request request)
        throws RequestProcessorException {
    // Check if this is a local session and we are trying to create
    // an ephemeral node, in which case we upgrade the session
    Request upgradeRequest = null;
    try {
        upgradeRequest = lzks.checkUpgradeSession(request);
    } catch (KeeperException ke) {
        if (request.getHdr() != null) {
            LOG.debug("Updating header");
            request.getHdr().setType(OpCode.error);
            request.setTxn(new ErrorTxn(ke.code().intValue()));
        }
        request.setException(ke);
        LOG.info("Error creating upgrade request " + ke.getMessage());
    } catch (IOException ie) {
        LOG.error("Unexpected error in upgrade", ie);
    }
    if (upgradeRequest != null) {
        nextProcessor.processRequest(upgradeRequest);
    }

    nextProcessor.processRequest(request);
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:26,代码来源:LeaderRequestProcessor.java

示例4: verifyRegionState

import org.apache.zookeeper.KeeperException; //导入依赖的package包/类
/**
 * Verifies that the specified region is in the specified state in ZooKeeper.
 * <p>
 * Returns true if region is in transition and in the specified state in
 * ZooKeeper.  Returns false if the region does not exist in ZK or is in
 * a different state.
 * <p>
 * Method synchronizes() with ZK so will yield an up-to-date result but is
 * a slow read.
 * @param zkw
 * @param region
 * @param expectedState
 * @return true if region exists and is in expected state
 * @throws DeserializationException
 */
static boolean verifyRegionState(ZooKeeperWatcher zkw, HRegionInfo region, EventType expectedState)
throws KeeperException, DeserializationException {
  String encoded = region.getEncodedName();

  String node = ZKAssign.getNodeName(zkw, encoded);
  zkw.sync(node);

  // Read existing data of the node
  byte [] existingBytes = null;
  try {
    existingBytes = ZKUtil.getDataAndWatch(zkw, node);
  } catch (KeeperException.NoNodeException nne) {
    return false;
  } catch (KeeperException e) {
    throw e;
  }
  if (existingBytes == null) return false;
  RegionTransition rt = RegionTransition.parseFrom(existingBytes);
  return rt.getEventType().equals(expectedState);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:36,代码来源:Mocking.java

示例5: createAndWatch

import org.apache.zookeeper.KeeperException; //导入依赖的package包/类
/**
 * Creates the specified node with the specified data and watches it.
 *
 * <p>Throws an exception if the node already exists.
 *
 * <p>The node created is persistent and open access.
 *
 * <p>Returns the version number of the created node if successful.
 *
 * @param zkw zk reference
 * @param znode path of node to create
 * @param data data of node to create
 * @return version of node created
 * @throws KeeperException if unexpected zookeeper exception
 * @throws KeeperException.NodeExistsException if node already exists
 */
public static int createAndWatch(ZooKeeperWatcher zkw,
    String znode, byte [] data)
throws KeeperException, KeeperException.NodeExistsException {
  try {
    zkw.getRecoverableZooKeeper().create(znode, data, createACL(zkw, znode),
        CreateMode.PERSISTENT);
    Stat stat = zkw.getRecoverableZooKeeper().exists(znode, zkw);
    if (stat == null){
      // Likely a race condition. Someone deleted the znode.
      throw KeeperException.create(KeeperException.Code.SYSTEMERROR,
          "ZK.exists returned null (i.e.: znode does not exist) for znode=" + znode);
    }
   return stat.getVersion();
  } catch (InterruptedException e) {
    zkw.interruptedException(e);
    return -1;
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:35,代码来源:ZKUtil.java

示例6: createZNodeTree

import org.apache.zookeeper.KeeperException; //导入依赖的package包/类
private void createZNodeTree(String rootZNode) throws KeeperException,
    InterruptedException {
  List<Op> opList = new ArrayList<Op>();
  opList.add(Op.create(rootZNode, new byte[0], Ids.OPEN_ACL_UNSAFE,
      CreateMode.PERSISTENT));
  int level = 0;
  String parentZNode = rootZNode;
  while (level < 10) {
    // define parent node
    parentZNode = parentZNode + "/" + level;
    opList.add(Op.create(parentZNode, new byte[0], Ids.OPEN_ACL_UNSAFE,
        CreateMode.PERSISTENT));
    int elements = 0;
    // add elements to the parent node
    while (elements < level) {
      opList.add(Op.create(parentZNode + "/" + elements, new byte[0],
          Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT));
      elements++;
    }
    level++;
  }
  zkw.getRecoverableZooKeeper().multi(opList);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:24,代码来源:TestZKMulti.java

示例7: testReconfigEnabledWithAuthAndWrongACL

import org.apache.zookeeper.KeeperException; //导入依赖的package包/类
@Test(timeout = 10000)
public void testReconfigEnabledWithAuthAndWrongACL() throws InterruptedException {
    resetZKAdmin();

    try {
        zkAdmin.addAuthInfo("digest", "super:test".getBytes());
        // There is ACL however the permission is wrong - need WRITE permission at leaste.
        ArrayList<ACL> acls = new ArrayList<ACL>(
                Collections.singletonList(
                        new ACL(ZooDefs.Perms.READ,
                                new Id("digest", "user:tl+z3z0vO6PfPfEENfLF96E6pM0="/* password is test */))));
        zkAdmin.setACL(ZooDefs.CONFIG_NODE, acls, -1);
        resetZKAdmin();
        zkAdmin.addAuthInfo("digest", "user:test".getBytes());
        reconfigPort();
        Assert.fail("Reconfig should fail with an ACL that is read only!");
    } catch (KeeperException e) {
        Assert.assertTrue(e.code() == KeeperException.Code.NOAUTH);
    }
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:21,代码来源:ReconfigExceptionTest.java

示例8: testZNodeDeletes

import org.apache.zookeeper.KeeperException; //导入依赖的package包/类
/**
 * Create a bunch of znodes in a hierarchy, try deleting one that has childs (it will fail), then
 * delete it recursively, then delete the last znode
 * @throws Exception
 */
@Test
public void testZNodeDeletes() throws Exception {
  ZooKeeperWatcher zkw = new ZooKeeperWatcher(
    new Configuration(TEST_UTIL.getConfiguration()),
    TestZooKeeper.class.getName(), null);
  ZKUtil.createWithParents(zkw, "/l1/l2/l3/l4");
  try {
    ZKUtil.deleteNode(zkw, "/l1/l2");
    fail("We should not be able to delete if znode has childs");
  } catch (KeeperException ex) {
    assertNotNull(ZKUtil.getDataNoWatch(zkw, "/l1/l2/l3/l4", null));
  }
  ZKUtil.deleteNodeRecursively(zkw, "/l1/l2");
  // make sure it really is deleted
  assertNull(ZKUtil.getDataNoWatch(zkw, "/l1/l2/l3/l4", null));

  // do the same delete again and make sure it doesn't crash
  ZKUtil.deleteNodeRecursively(zkw, "/l1/l2");

  ZKUtil.deleteNode(zkw, "/l1");
  assertNull(ZKUtil.getDataNoWatch(zkw, "/l1/l2", null));
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:28,代码来源:TestZooKeeper.java

示例9: deleteRecoveringRegionZNodes

import org.apache.zookeeper.KeeperException; //导入依赖的package包/类
public static void deleteRecoveringRegionZNodes(ZooKeeperWatcher watcher, List<String> regions) {
  try {
    if (regions == null) {
      // remove all children under /home/recovering-regions
      LOG.debug("Garbage collecting all recovering region znodes");
      ZKUtil.deleteChildrenRecursively(watcher, watcher.recoveringRegionsZNode);
    } else {
      for (String curRegion : regions) {
        String nodePath = ZKUtil.joinZNode(watcher.recoveringRegionsZNode, curRegion);
        ZKUtil.deleteNodeRecursively(watcher, nodePath);
      }
    }
  } catch (KeeperException e) {
    LOG.warn("Cannot remove recovering regions from ZooKeeper", e);
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:17,代码来源:ZKSplitLog.java

示例10: deleteZNode

import org.apache.zookeeper.KeeperException; //导入依赖的package包/类
@DELETE
@Produces( { MediaType.APPLICATION_JSON, "application/javascript",
        MediaType.APPLICATION_XML, MediaType.APPLICATION_OCTET_STREAM })
public void deleteZNode(@PathParam("path") String path,
        @DefaultValue("-1") @QueryParam("version") String versionParam,
        @Context UriInfo ui) throws InterruptedException, KeeperException {
    ensurePathNotNull(path);

    int version;
    try {
        version = Integer.parseInt(versionParam);
    } catch (NumberFormatException e) {
        throw new WebApplicationException(Response.status(
                Response.Status.BAD_REQUEST).entity(
                new ZError(ui.getRequestUri().toString(), path
                        + " bad version " + versionParam)).build());
    }

    zk.delete(path, version);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:21,代码来源:ZNodeResource.java

示例11: testReconfigEnabledWithAuthAndACL

import org.apache.zookeeper.KeeperException; //导入依赖的package包/类
@Test(timeout = 10000)
public void testReconfigEnabledWithAuthAndACL() throws InterruptedException {
    resetZKAdmin();

    try {
        zkAdmin.addAuthInfo("digest", "super:test".getBytes());
        ArrayList<ACL> acls = new ArrayList<ACL>(
                Collections.singletonList(
                        new ACL(ZooDefs.Perms.WRITE,
                        new Id("digest", "user:tl+z3z0vO6PfPfEENfLF96E6pM0="/* password is test */))));
        zkAdmin.setACL(ZooDefs.CONFIG_NODE, acls, -1);
        resetZKAdmin();
        zkAdmin.addAuthInfo("digest", "user:test".getBytes());
        Assert.assertTrue(reconfigPort());
    } catch (KeeperException e) {
        Assert.fail("Reconfig should not fail, but failed with exception : " + e.getMessage());
    }
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:19,代码来源:ReconfigExceptionTest.java

示例12: checkZnodePermsRecursive

import org.apache.zookeeper.KeeperException; //导入依赖的package包/类
private void checkZnodePermsRecursive(ZooKeeperWatcher watcher,
    RecoverableZooKeeper zk, String znode) throws KeeperException, InterruptedException {

  boolean expectedWorldReadable = watcher.isClientReadable(znode);

  assertZnodePerms(zk, znode, expectedWorldReadable);

  try {
    List<String> children = zk.getChildren(znode, false);

    for (String child : children) {
      checkZnodePermsRecursive(watcher, zk, ZKUtil.joinZNode(znode, child));
    }
  } catch (KeeperException ke) {
    // if we are not authenticated for listChildren, it is fine.
    if (ke.code() != Code.NOAUTH) {
      throw ke;
    }
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:21,代码来源:IntegrationTestZKAndFSPermissions.java

示例13: setData

import org.apache.zookeeper.KeeperException; //导入依赖的package包/类
@Override
public Stat setData(String path, byte[] data, int version)
        throws KeeperException, InterruptedException {
    int count = 0;
    do {
        try {
            return super.setData(path, data, version);
        } catch (KeeperException.ConnectionLossException e) {
            LoggerFactory.getLogger().warn(
                    "ZooKeeper connection lost.  Trying to reconnect.");
            Stat s = exists(path, false);
            if (s != null) {
                if (getData(path, false, s) == data) {
                    return s;
                }
            } else {
                return null;
            }
        }
    } while (!closed && (limit == -1 || count++ < limit));
    return null;
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:23,代码来源:ZooKeeperRetry.java

示例14: testBlankPath

import org.apache.zookeeper.KeeperException; //导入依赖的package包/类
/**
 * Test verifies the multi calls with blank znode path
 */
@Test(timeout = 90000)
public void testBlankPath() throws Exception {
    List<Integer> expectedResultCodes = new ArrayList<Integer>();
    expectedResultCodes.add(KeeperException.Code.RUNTIMEINCONSISTENCY
                            .intValue());
    expectedResultCodes.add(KeeperException.Code.BADARGUMENTS.intValue());
    expectedResultCodes.add(KeeperException.Code.RUNTIMEINCONSISTENCY
                            .intValue());
    expectedResultCodes.add(KeeperException.Code.BADARGUMENTS.intValue());

    // delete
    String expectedErr = "Path cannot be null";
    List<Op> opList = Arrays.asList(Op.delete("/multi0", -1),
                                    Op.delete(null, 100),
                                    Op.delete("/multi2", 5),
                                    Op.delete("", -1));
    multiHavingErrors(zk, opList, expectedResultCodes, expectedErr);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:22,代码来源:MultiTransactionTest.java

示例15: testNodes3

import org.apache.zookeeper.KeeperException; //导入依赖的package包/类
@Test
public void testNodes3() throws IOException, InterruptedException,
    KeeperException {

  int testIterations = 3;
  final CountDownLatch latch = new CountDownLatch(testIterations);
  final AtomicInteger failureCounter = new AtomicInteger();

  for (int i = 0; i < testIterations; i++) {
    runElectionSupportThread(latch, failureCounter);
  }

  Assert.assertEquals(0, failureCounter.get());

  if (!latch.await(10, TimeUnit.SECONDS)) {
    logger
        .info(
            "Waited for all threads to start, but timed out. We had {} failures.",
            failureCounter);
  }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:22,代码来源:LeaderElectionSupportTest.java


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