List of usage examples for org.apache.zookeeper KeeperException create
public static KeeperException create(Code code)
From source file:org.apache.niolex.zookeeper.core.ZKConnectorExceTest.java
License:Apache License
@Test @Order(9)//from w w w. jav a2 s . com public void testUpdateNodeDataE() throws Exception { ZKC.zk = mock(ZooKeeper.class); KeeperException ke = KeeperException.create(KeeperException.Code.NONODE); byte[] data = "not".getBytes(); String path = "/lex/zkc/bbc"; doThrow(ke).when(ZKC.zk).setData(path, data, -1); try { ZKC.updateNodeData(path, data); assertFalse(true); } catch (ZKException e) { assertEquals(e.getCode(), ZKException.Code.NO_NODE); } }
From source file:org.apache.niolex.zookeeper.core.ZKExceptionTest.java
License:Apache License
@Test public void testGetCode2() throws Exception { ZKException zk = ZKException.makeInstance("NODE_EXISTS", KeeperException.create(KeeperException.Code.NODEEXISTS)); assertEquals(zk.getCode(), ZKException.Code.NODE_EXISTS); System.out.println(zk.getMessage()); }
From source file:org.apache.niolex.zookeeper.core.ZKExceptionTest.java
License:Apache License
@Test public void testGetCode3() throws Exception { ZKException zk = ZKException.makeInstance("SYSTEM_ERROR", KeeperException.create(KeeperException.Code.SYSTEMERROR)); assertEquals(zk.getCode(), ZKException.Code.SYSTEM_ERROR); System.out.println(zk.getMessage()); }
From source file:org.apache.niolex.zookeeper.core.ZKExceptionTest.java
License:Apache License
@Test public void testGetCode4() throws Exception { ZKException zk = ZKException.makeInstance("DISCONNECTED", KeeperException.create(KeeperException.Code.CONNECTIONLOSS)); assertEquals(zk.getCode(), ZKException.Code.DISCONNECTED); System.out.println(zk.getMessage()); }
From source file:org.apache.niolex.zookeeper.core.ZKExceptionTest.java
License:Apache License
@Test public void testGetCode5() throws Exception { ZKException zk = ZKException.makeInstance("DISCONNECTED", KeeperException.create(KeeperException.Code.NONODE)); assertEquals(zk.getCode(), ZKException.Code.NO_NODE); System.out.println(zk.getMessage()); }
From source file:org.apache.niolex.zookeeper.core.ZKExceptionTest.java
License:Apache License
@Test public void testGetMessage() throws Exception { ZKException zk = ZKException.makeInstance("not yet implemented", KeeperException.create(KeeperException.Code.NOAUTH)); assertEquals(zk.getCode(), ZKException.Code.NO_AUTH); }
From source file:org.apache.niolex.zookeeper.core.ZKExceptionTest.java
License:Apache License
@Test public void testGetMessage2() throws Exception { ZKException zk = ZKException.makeInstance("not yet implemented", KeeperException.create(KeeperException.Code.AUTHFAILED)); assertEquals(zk.getCode(), ZKException.Code.NO_AUTH); }
From source file:org.apache.niolex.zookeeper.core.ZKExceptionTest.java
License:Apache License
@Test public void testGetMessage3() throws Exception { ZKException zk = ZKException.makeInstance("not yet implemented", KeeperException.create(KeeperException.Code.APIERROR)); assertEquals(zk.getCode(), ZKException.Code.SYSTEM_ERROR); }
From source file:org.apache.pulsar.broker.namespace.NamespaceService.java
License:Apache License
/** * 1. split the given bundle into two bundles 2. assign ownership of both the bundles to current broker 3. update * policies with newly created bundles into LocalZK 4. disable original bundle and refresh the cache * * @param bundle//from w w w. ja va 2 s . co m * @return * @throws Exception */ public CompletableFuture<Void> splitAndOwnBundle(NamespaceBundle bundle) throws Exception { final CompletableFuture<Void> future = new CompletableFuture<>(); Pair<NamespaceBundles, List<NamespaceBundle>> splittedBundles = bundleFactory.splitBundles(bundle, 2 /* by default split into 2 */); if (splittedBundles != null) { checkNotNull(splittedBundles.getLeft()); checkNotNull(splittedBundles.getRight()); checkArgument(splittedBundles.getRight().size() == 2, "bundle has to be split in two bundles"); NamespaceName nsname = bundle.getNamespaceObject(); try { // take ownership of newly split bundles for (NamespaceBundle sBundle : splittedBundles.getRight()) { checkNotNull(ownershipCache.tryAcquiringOwnership(sBundle)); } updateNamespaceBundles(nsname, splittedBundles.getLeft(), (rc, path, zkCtx, stat) -> pulsar.getOrderedExecutor().submit(safeRun(() -> { if (rc == KeeperException.Code.OK.intValue()) { // disable old bundle try { ownershipCache.disableOwnership(bundle); // invalidate cache as zookeeper has new split // namespace bundle bundleFactory.invalidateBundleCache(nsname); // update bundled_topic cache for load-report-generation pulsar.getBrokerService().refreshTopicToStatsMaps(bundle); loadManager.get().setLoadReportForceUpdateFlag(); future.complete(null); } catch (Exception e) { String msg1 = format( "failed to disable bundle %s under namespace [%s] with error %s", nsname.toString(), bundle.toString(), e.getMessage()); LOG.warn(msg1, e); future.completeExceptionally(new ServiceUnitNotReadyException(msg1)); } } else { String msg2 = format("failed to update namespace [%s] policies due to %s", nsname.toString(), KeeperException.create(KeeperException.Code.get(rc)).getMessage()); LOG.warn(msg2); future.completeExceptionally(new ServiceUnitNotReadyException(msg2)); } }))); } catch (Exception e) { String msg = format("failed to aquire ownership of split bundle for namespace [%s], %s", nsname.toString(), e.getMessage()); LOG.warn(msg, e); future.completeExceptionally(new ServiceUnitNotReadyException(msg)); } } else { String msg = format("bundle %s not found under namespace", bundle.toString()); future.completeExceptionally(new ServiceUnitNotReadyException(msg)); } return future; }
From source file:org.apache.pulsar.broker.namespace.OwnershipCache.java
License:Apache License
/** * Method to remove the ownership of local broker on the <code>NamespaceBundle</code>, if owned * *//*from w w w . ja v a2 s .co m*/ public CompletableFuture<Void> removeOwnership(NamespaceBundle bundle) { CompletableFuture<Void> result = new CompletableFuture<>(); String key = ServiceUnitZkUtils.path(bundle); localZkCache.getZooKeeper().delete(key, -1, (rc, path, ctx) -> { if (rc == KeeperException.Code.OK.intValue() || rc == KeeperException.Code.NONODE.intValue()) { LOG.info("[{}] Removed zk lock for service unit: {}", key, KeeperException.Code.get(rc)); ownedBundlesCache.synchronous().invalidate(key); ownershipReadOnlyCache.invalidate(key); result.complete(null); } else { LOG.warn("[{}] Failed to delete the namespace ephemeral node. key={}", key, KeeperException.Code.get(rc)); result.completeExceptionally(KeeperException.create(rc)); } }, null); return result; }