List of usage examples for org.apache.zookeeper KeeperException code
Code code
To view the source code for org.apache.zookeeper KeeperException code.
Click Source Link
From source file:org.apache.accumulo.fate.zookeeper.ZooUtil.java
License:Apache License
public static boolean isLockHeld(ZooKeeperConnectionInfo info, LockID lid) throws KeeperException, InterruptedException { final Retry retry = RETRY_FACTORY.create(); while (true) { try {/*from w w w. ja va 2 s .c o m*/ List<String> children = getZooKeeper(info).getChildren(lid.path, false); if (children.size() == 0) { return false; } Collections.sort(children); String lockNode = children.get(0); if (!lid.node.equals(lockNode)) return false; Stat stat = getZooKeeper(info).exists(lid.path + "/" + lid.node, false); return stat != null && stat.getEphemeralOwner() == lid.eid; } catch (KeeperException ex) { final Code c = ex.code(); if (c == Code.CONNECTIONLOSS || c == Code.OPERATIONTIMEOUT || c == Code.SESSIONEXPIRED) { retryOrThrow(retry, ex); } } retry.waitForNextAttempt(); } }
From source file:org.apache.accumulo.fate.zookeeper.ZooUtil.java
License:Apache License
public static List<ACL> getACL(ZooKeeperConnectionInfo info, String zPath, Stat stat) throws KeeperException, InterruptedException { final Retry retry = RETRY_FACTORY.create(); while (true) { try {/*from w w w . ja v a 2s .c o m*/ return getZooKeeper(info).getACL(zPath, stat); } catch (KeeperException e) { final Code c = e.code(); if (c == Code.CONNECTIONLOSS || c == Code.OPERATIONTIMEOUT || c == Code.SESSIONEXPIRED) { retryOrThrow(retry, e); } else { throw e; } } retry.waitForNextAttempt(); } }
From source file:org.apache.accumulo.master.replication.UnorderedWorkAssigner.java
License:Apache License
/** * Initialize the queuedWork set with the work already sent out *//*w w w.j a va 2 s . c o m*/ @Override protected void initializeQueuedWork() { if (null != queuedWork) { return; } queuedWork = new HashSet<>(); while (true) { try { queuedWork.addAll(workQueue.getWorkQueued()); return; } catch (KeeperException e) { if (KeeperException.Code.NONODE.equals(e.code())) { log.warn("Could not find ZK root for replication work queue, will retry", e); sleepUninterruptibly(500, TimeUnit.MILLISECONDS); continue; } log.error("Error reading existing queued replication work from ZooKeeper", e); throw new RuntimeException("Error reading existing queued replication work from ZooKeeper", e); } catch (InterruptedException e) { log.error("Error reading existing queued replication work from ZooKeeper", e); throw new RuntimeException("Error reading existing queued replication work from ZooKeeper", e); } } }
From source file:org.apache.accumulo.server.monitor.LogService.java
License:Apache License
/** * Place the host:port advertisement for the Monitor's Log4j listener in ZooKeeper * * @param conf// ww w. j av a 2 s .c om * configuration for the instance * @param instanceId * instanceId for the instance * @param hostAddress * Address that monitor process is bound to */ public static void startLogListener(AccumuloConfiguration conf, String instanceId, String hostAddress) { try { SocketServer server = new SocketServer(conf.getPort(Property.MONITOR_LOG4J_PORT)[0]); // getLocalPort will return the actual ephemeral port used when '0' was provided. String logForwardingAddr = hostAddress + ":" + server.getLocalPort(); log.debug("Setting monitor log4j log-forwarding address to: " + logForwardingAddr); final String path = ZooUtil.getRoot(instanceId) + Constants.ZMONITOR_LOG4J_ADDR; final ZooReaderWriter zoo = ZooReaderWriter.getInstance(); // Delete before we try to re-create in case the previous session hasn't yet expired try { zoo.delete(path, -1); } catch (KeeperException e) { // We don't care if the node is already gone if (!KeeperException.Code.NONODE.equals(e.code())) { throw e; } } zoo.putEphemeralData(path, logForwardingAddr.getBytes(UTF_8)); new Daemon(server).start(); } catch (Throwable t) { log.info("Unable to start/advertise Log4j listener for log-forwarding to monitor", t); } }
From source file:org.apache.accumulo.server.security.handler.KerberosAuthenticator.java
License:Apache License
@Override public synchronized void createUser(String principal, AuthenticationToken token) throws AccumuloSecurityException { if (!(token instanceof KerberosToken)) { throw new UnsupportedOperationException( "Expected a KerberosToken but got a " + token.getClass().getSimpleName()); }/*w w w. j a v a 2 s . co m*/ try { createUserNodeInZk(Base64.getEncoder().encodeToString(principal.getBytes(UTF_8))); } catch (KeeperException e) { if (e.code().equals(KeeperException.Code.NODEEXISTS)) { throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_EXISTS, e); } log.error("Failed to create user in ZooKeeper", e); throw new AccumuloSecurityException(principal, SecurityErrorCode.CONNECTION_ERROR, e); } catch (InterruptedException e) { log.error("Interrupted trying to create node for user", e); throw new RuntimeException(e); } }
From source file:org.apache.accumulo.server.security.handler.ZKAuthenticator.java
License:Apache License
@Override public void createUser(String principal, AuthenticationToken token) throws AccumuloSecurityException { try {// ww w . j a v a 2 s.com if (!(token instanceof PasswordToken)) throw new AccumuloSecurityException(principal, SecurityErrorCode.INVALID_TOKEN); PasswordToken pt = (PasswordToken) token; constructUser(principal, ZKSecurityTool.createPass(pt.getPassword())); } catch (KeeperException e) { if (e.code().equals(KeeperException.Code.NODEEXISTS)) throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_EXISTS, e); throw new AccumuloSecurityException(principal, SecurityErrorCode.CONNECTION_ERROR, e); } catch (InterruptedException e) { log.error("{}", e.getMessage(), e); throw new RuntimeException(e); } catch (AccumuloException e) { log.error("{}", e.getMessage(), e); throw new AccumuloSecurityException(principal, SecurityErrorCode.DEFAULT_SECURITY_ERROR, e); } }
From source file:org.apache.accumulo.server.security.handler.ZKAuthenticator.java
License:Apache License
@Override public void dropUser(String user) throws AccumuloSecurityException { try {/*from w w w . j av a2s . co m*/ synchronized (zooCache) { zooCache.clear(); ZooReaderWriter.getInstance().recursiveDelete(ZKUserPath + "/" + user, NodeMissingPolicy.FAIL); } } catch (InterruptedException e) { log.error("{}", e.getMessage(), e); throw new RuntimeException(e); } catch (KeeperException e) { if (e.code().equals(KeeperException.Code.NONODE)) { throw new AccumuloSecurityException(user, SecurityErrorCode.USER_DOESNT_EXIST, e); } log.error("{}", e.getMessage(), e); throw new AccumuloSecurityException(user, SecurityErrorCode.CONNECTION_ERROR, e); } }
From source file:org.apache.accumulo.server.security.handler.ZKAuthorizor.java
License:Apache License
@Override public void dropUser(String user) throws AccumuloSecurityException { try {/*from w ww . j av a 2 s.c o m*/ synchronized (zooCache) { IZooReaderWriter zoo = ZooReaderWriter.getInstance(); zoo.recursiveDelete(ZKUserPath + "/" + user + ZKUserAuths, NodeMissingPolicy.SKIP); zooCache.clear(ZKUserPath + "/" + user); } } catch (InterruptedException e) { log.error("{}", e.getMessage(), e); throw new RuntimeException(e); } catch (KeeperException e) { log.error("{}", e.getMessage(), e); if (e.code().equals(KeeperException.Code.NONODE)) throw new AccumuloSecurityException(user, SecurityErrorCode.USER_DOESNT_EXIST, e); throw new AccumuloSecurityException(user, SecurityErrorCode.CONNECTION_ERROR, e); } }
From source file:org.apache.accumulo.server.security.handler.ZKPermHandler.java
License:Apache License
@Override public boolean hasTablePermission(String user, String table, TablePermission permission) throws TableNotFoundException { byte[] serializedPerms; final ZooReaderWriter zrw = ZooReaderWriter.getInstance(); try {/*from w w w . j a v a2 s.c o m*/ String path = ZKUserPath + "/" + user + ZKUserTablePerms + "/" + table; zrw.sync(path); serializedPerms = zrw.getData(path, null); } catch (KeeperException e) { if (e.code() == Code.NONODE) { // maybe the table was just deleted? try { // check for existence: zrw.getData(ZKTablePath + "/" + table, null); // it's there, you don't have permission return false; } catch (InterruptedException ex) { log.warn("Unhandled InterruptedException, failing closed for table permission check", e); return false; } catch (KeeperException ex) { // not there, throw an informative exception if (e.code() == Code.NONODE) { throw new TableNotFoundException(null, table, "while checking permissions"); } log.warn("Unhandled InterruptedException, failing closed for table permission check", e); } return false; } log.warn("Unhandled KeeperException, failing closed for table permission check", e); return false; } catch (InterruptedException e) { log.warn("Unhandled InterruptedException, failing closed for table permission check", e); return false; } if (serializedPerms != null) { return ZKSecurityTool.convertTablePermissions(serializedPerms).contains(permission); } return false; }
From source file:org.apache.accumulo.server.security.handler.ZKPermHandler.java
License:Apache License
@Override public boolean hasNamespacePermission(String user, String namespace, NamespacePermission permission) throws NamespaceNotFoundException { byte[] serializedPerms; final ZooReaderWriter zrw = ZooReaderWriter.getInstance(); try {//from w ww. j a v a2 s . c o m String path = ZKUserPath + "/" + user + ZKUserNamespacePerms + "/" + namespace; zrw.sync(path); serializedPerms = zrw.getData(path, null); } catch (KeeperException e) { if (e.code() == Code.NONODE) { // maybe the namespace was just deleted? try { // check for existence: zrw.getData(ZKNamespacePath + "/" + namespace, null); // it's there, you don't have permission return false; } catch (InterruptedException ex) { log.warn("Unhandled InterruptedException, failing closed for namespace permission check", e); return false; } catch (KeeperException ex) { // not there, throw an informative exception if (e.code() == Code.NONODE) { throw new NamespaceNotFoundException(null, namespace, "while checking permissions"); } log.warn("Unhandled InterruptedException, failing closed for table permission check", e); } return false; } log.warn("Unhandled KeeperException, failing closed for table permission check", e); return false; } catch (InterruptedException e) { log.warn("Unhandled InterruptedException, failing closed for table permission check", e); return false; } if (serializedPerms != null) { return ZKSecurityTool.convertNamespacePermissions(serializedPerms).contains(permission); } return false; }