public boolean isZkNoNodeException() { Throwable cause = getCause(); if (cause != null && cause instanceof KeeperException) { return KeeperException.Code.NONODE != ((KeeperException) cause).code(); } return false; }
public boolean isZkNodeExistsException() { Throwable cause = getCause(); if (cause != null && cause instanceof KeeperException) { return KeeperException.Code.NODEEXISTS != ((KeeperException) cause).code(); } return false; } }
public boolean isZkNodeExistsException() { Throwable cause = getCause(); if (cause != null && cause instanceof KeeperException) { return KeeperException.Code.NODEEXISTS != ((KeeperException) cause).code(); } return false; } }
public boolean isZkNoNodeException() { Throwable cause = getCause(); if (cause != null && cause instanceof KeeperException) { return KeeperException.Code.NONODE != ((KeeperException) cause).code(); } return false; }
private boolean isAccumuloView(SchemaTableName tableName) { try { String path = getTablePath(tableName); return curator.checkExists().forPath(path) != null && isAccumuloView(curator.getData().forPath(path)); } catch (Exception e) { // Capture race condition between checkExists and getData if (e instanceof KeeperException && ((KeeperException) e).code() == NONODE) { return false; } throw new PrestoException(ZOOKEEPER_ERROR, "Error checking if path is an AccumuloView object", e); } }
private boolean isAccumuloTable(SchemaTableName tableName) { try { String path = getTablePath(tableName); return curator.checkExists().forPath(path) != null && isAccumuloTable(curator.getData().forPath(path)); } catch (Exception e) { // Capture race condition between checkExists and getData if (e instanceof KeeperException && ((KeeperException) e).code() == NONODE) { return false; } throw new PrestoException(ZOOKEEPER_ERROR, "Error checking if path %s is an AccumuloTable object", e); } }
public AccumuloView getView(SchemaTableName stName) { try { String tablePath = getTablePath(stName); if (curator.checkExists().forPath(tablePath) != null) { return toAccumuloView(curator.getData().forPath(tablePath)); } return null; } catch (Exception e) { // Capture race condition between checkExists and getData if (e instanceof KeeperException && ((KeeperException) e).code() == NONODE) { return null; } throw new PrestoException(ZOOKEEPER_ERROR, "Error fetching view", e); } }
public AccumuloTable getTable(SchemaTableName stName) { try { if (curator.checkExists().forPath(getTablePath(stName)) != null) { return toAccumuloTable(curator.getData().forPath(getTablePath(stName))); } return null; } catch (Exception e) { // Capture race condition between checkExists and getData if (e instanceof KeeperException && ((KeeperException) e).code() == NONODE) { return null; } throw new PrestoException(ZOOKEEPER_ERROR, "Error fetching table", e); } }
private void cleanupHbckZnode() { try { if (zkw != null && hbckZodeCreated) { ZKUtil.deleteNode(zkw, hbckEphemeralNodePath); hbckZodeCreated = false; } } catch (KeeperException e) { // Ignore if (!e.code().equals(KeeperException.Code.NONODE)) { LOG.warn("Delete HBCK znode " + hbckEphemeralNodePath + " failed ", e); } } }
@Override public Boolean handle(ZooKeeperClient zkc) throws IOException { // check existence after syncing try { return null != Utils.sync(zkc, logRootPath).exists(logRootPath, false); } catch (KeeperException e) { throw new ZKException("Error on checking if log " + logRootPath + " exists", e.code()); } catch (InterruptedException e) { throw new DLInterruptedException("Interrupted on checking if log " + logRootPath + " exists", e); } } }, conf, uri);
public void processRequest(Request request) throws RequestProcessorException { KeeperException ke = new KeeperException.UnimplementedException(); request.setException(ke); ReplyHeader rh = new ReplyHeader(request.cxid, request.zxid, ke.code().intValue()); try { request.cnxn.sendResponse(rh, null, "response"); } catch (IOException e) { throw new RequestProcessorException("Can't send the response", e); } request.cnxn.sendCloseSession(); }
private void deleteNodeIfExists(ZooKeeper zk, String nodeName) throws InterruptedException { try { zk.delete(nodeName, -1); } catch (KeeperException ke) { Code code = ke.code(); boolean valid = code == KeeperException.Code.NONODE || code == KeeperException.Code.NOTEMPTY; if (!valid) { Assert.fail("Unexpected exception code for delete: " + ke.getMessage()); } } }
@Test public void testDeleteWithChildren() throws Exception { ZooKeeper zk = createClient(); zk.create("/parent", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); zk.create("/parent/child", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); try { zk.delete("/parent", -1); Assert.fail("Should have received a not equals message"); } catch (KeeperException e) { Assert.assertEquals(KeeperException.Code.NOTEMPTY, e.code()); } zk.delete("/parent/child", -1); zk.delete("/parent", -1); zk.close(); }
@Test(timeout = 10000) public void testReconfigFailWithoutAuth() throws InterruptedException { try { reconfigPort(); Assert.fail("Reconfig should fail without auth."); } catch (KeeperException e) { // However a failure is still expected as user is not authenticated, so ACL check will fail. Assert.assertTrue(e.code() == KeeperException.Code.NOAUTH); } }
@Test public void testInvalidFlagConversion() throws KeeperException { try { CreateMode.fromFlag(99); Assert.fail("Shouldn't be able to convert 99 to a CreateMode."); } catch(KeeperException ke) { Assert.assertEquals(Code.BADARGUMENTS, ke.code()); } try { CreateMode.fromFlag(-1); Assert.fail("Shouldn't be able to convert -1 to a CreateMode."); } catch(KeeperException ke) { Assert.assertEquals(Code.BADARGUMENTS, ke.code()); } } }
@Test(timeout = 10000) public void testReconfigFailWithAuthWithNoACL() throws InterruptedException { resetZKAdmin(); try { zkAdmin.addAuthInfo("digest", "user:test".getBytes()); reconfigPort(); Assert.fail("Reconfig should fail without a valid ACL associated with user."); } catch (KeeperException e) { // Again failure is expected because no ACL is associated with this user. Assert.assertTrue(e.code() == KeeperException.Code.NOAUTH); } }
@Test(timeout = 10000) public void testReconfigDisabled() throws InterruptedException { QuorumPeerConfig.setReconfigEnabled(false); try { reconfigPort(); Assert.fail("Reconfig should be disabled."); } catch (KeeperException e) { Assert.assertTrue(e.code() == KeeperException.Code.RECONFIGDISABLED); } }
/** * It tests that PrepRequestProcessor will return BadArgument KeeperException * if the request path (if it exists) is not valid, e.g. empty string. */ @Test public void testInvalidPath() throws Exception { pLatch = new CountDownLatch(1); processor = new PrepRequestProcessor(zks, new MyRequestProcessor()); SetDataRequest record = new SetDataRequest("", new byte[0], -1); Request req = createRequest(record, OpCode.setData); processor.pRequest(req); pLatch.await(); Assert.assertEquals(outcome.getHdr().getType(), OpCode.error); Assert.assertEquals(outcome.getException().code(), KeeperException.Code.BADARGUMENTS); }
@Test public void testLsrNonexistantZnodeCommand() throws Exception { final ZooKeeper zk = createClient(); ZooKeeperMain zkMain = new ZooKeeperMain(zk); zkMain.executeLine("create /b"); zkMain.executeLine("create /b/c"); LsCommand cmd = new LsCommand(); cmd.setZk(zk); cmd.parse("ls -R /b/c/d".split(" ")); try { runCommandExpect(cmd, new ArrayList<String>()); Assert.fail("Path doesn't exists so, command should fail."); } catch (CliWrapperException e) { Assert.assertEquals(KeeperException.Code.NONODE, ((KeeperException)e.getCause()).code()); } }
@Test public void testInvalidStatCommand() throws Exception { final ZooKeeper zk = createClient(); ZooKeeperMain zkMain = new ZooKeeperMain(zk); // node doesn't exists String cmdstring1 = "stat /node123"; zkMain.cl.parseCommand(cmdstring1); try { Assert.assertFalse(zkMain.processZKCmd(zkMain.cl)); Assert.fail("Path doesn't exists so, command should fail."); } catch (CliWrapperException e) { Assert.assertEquals(KeeperException.Code.NONODE, ((KeeperException)e.getCause()).code()); } }