List of usage examples for org.apache.zookeeper ZooKeeper getACL
public List<ACL> getACL(final String path, Stat stat) throws KeeperException, InterruptedException
From source file:com.boundary.zoocreeper.Backup.java
License:Apache License
private void doBackup(ZooKeeper zk, JsonGenerator jgen, String path) throws KeeperException, InterruptedException, IOException { try {//from ww w.ja va2 s . c o m final Stat stat = new Stat(); List<ACL> acls = nullToEmpty(zk.getACL(path, stat)); if (stat.getEphemeralOwner() != 0 && !options.backupEphemeral) { LOGGER.debug("Skipping ephemeral node: {}", path); return; } final Stat dataStat = new Stat(); byte[] data = zk.getData(path, false, dataStat); for (int i = 0; stat.compareTo(dataStat) != 0 && i < options.numRetries; i++) { LOGGER.warn("Retrying getACL / getData to read consistent state"); acls = zk.getACL(path, stat); data = zk.getData(path, false, dataStat); } if (stat.compareTo(dataStat) != 0) { throw new IllegalStateException("Unable to read consistent data for znode: " + path); } LOGGER.debug("Backing up node: {}", path); dumpNode(jgen, path, stat, acls, data); final List<String> childPaths = nullToEmpty(zk.getChildren(path, false, null)); Collections.sort(childPaths); for (String childPath : childPaths) { final String fullChildPath = createFullPath(path, childPath); if (!this.options.isPathExcluded(LOGGER, fullChildPath)) { if (this.options.isPathIncluded(LOGGER, fullChildPath)) { doBackup(zk, jgen, fullChildPath); } } } } catch (NoNodeException e) { LOGGER.warn("Node disappeared during backup: {}", path); } }
From source file:com.github.mosuka.zookeeper.nicli.command.GetAclCommand.java
License:Apache License
@Override public void run(Map<String, Object> parameters) { try {/*www . jav a 2s .c o m*/ String path = (String) parameters.get("path"); boolean withStat = parameters.containsKey("with_stat") ? (Boolean) parameters.get("with_stat") : DEFAULT_WITH_STAT; ZooKeeper zk = getZookeeperConnection().getZooKeeper(); Stat stat = new Stat(); List<ACL> acl = zk.getACL(path, stat); if (acl != null) { putResponse("acl", ACLUtil.acl2List(acl)); } if (stat != null && withStat) { putResponse("stat", StatUtil.stat2Map(stat)); } setStatus(Command.STATUS_SUCCESS); setMessage(Command.SUCCESS_MESSAGE); } catch (KeeperException e) { setStatus(Command.STATUS_ERROR); setMessage(e.getMessage()); } catch (InterruptedException e) { setStatus(Command.STATUS_ERROR); setMessage(e.getMessage()); } catch (ClassCastException e) { setStatus(Command.STATUS_ERROR); setMessage(e.getMessage()); } catch (NullPointerException e) { setStatus(Command.STATUS_ERROR); setMessage(e.getMessage()); } }
From source file:org.apache.bookkeeper.bookie.EnableZkSecurityBasicTest.java
License:Apache License
private void checkACls(ZooKeeper zk, String path) throws KeeperException, InterruptedException { List<String> children = zk.getChildren(path, null); for (String child : children) { String fullPath = path.equals("/") ? path + child : path + "/" + child; List<ACL> acls = zk.getACL(fullPath, new Stat()); checkACls(zk, fullPath);//ww w . ja v a 2s. com if (!fullPath.startsWith("/zookeeper") // skip zookeeper internal nodes && !fullPath.equals("/ledgers") // node created by test setup && !fullPath.equals("/ledgers/" + BookKeeperConstants.AVAILABLE_NODE) // node created by test setup ) { assertEquals(1, acls.size()); assertEquals(31, acls.get(0).getPerms()); assertEquals(31, acls.get(0).getPerms()); assertEquals("unexpected ACLS on " + fullPath + ": " + acls.get(0), "foo", acls.get(0).getId().getId()); assertEquals("unexpected ACLS on " + fullPath + ": " + acls.get(0), "sasl", acls.get(0).getId().getScheme()); } } }
From source file:org.apache.bookkeeper.zookeeper.BkZooKeeperClient.java
License:Apache License
@Override public List<ACL> getACL(final String path, final Stat stat) throws KeeperException, InterruptedException { return BkZooWorker.syncCallWithRetries(this, new ZooCallable<List<ACL>>() { @Override//w ww. ja va 2 s . com public String toString() { return String.format("getACL (%s, stat = %s)", path, stat); } @Override public List<ACL> call() throws KeeperException, InterruptedException { ZooKeeper zkHandle = zk.get(); if (null == zkHandle) { return BkZooKeeperClient.super.getACL(path, stat); } return zkHandle.getACL(path, stat); } }, operationRetryPolicy, rateLimiter, getACLStats); }
From source file:org.apache.bookkeeper.zookeeper.ZooKeeperClient.java
License:Apache License
@Override public List<ACL> getACL(final String path, final Stat stat) throws KeeperException, InterruptedException { return ZooWorker.syncCallWithRetries(this, new ZooCallable<List<ACL>>() { @Override/*from w ww. java2 s .co m*/ public String toString() { return String.format("getACL (%s, stat = %s)", path, stat); } @Override public List<ACL> call() throws KeeperException, InterruptedException { ZooKeeper zkHandle = zk.get(); if (null == zkHandle) { return ZooKeeperClient.super.getACL(path, stat); } return zkHandle.getACL(path, stat); } }, operationRetryPolicy, rateLimiter, getACLStats); }
From source file:org.apache.hadoop.hbase.TestZooKeeper.java
License:Apache License
/** * A test for HBASE-3238// w ww . j a va 2 s . c o m * @throws IOException A connection attempt to zk failed * @throws InterruptedException One of the non ZKUtil actions was interrupted * @throws KeeperException Any of the zookeeper connections had a * KeeperException */ @Test public void testCreateSilentIsReallySilent() throws InterruptedException, KeeperException, IOException { Configuration c = TEST_UTIL.getConfiguration(); String aclZnode = "/aclRoot"; String quorumServers = ZKConfig.getZKQuorumServersString(c); int sessionTimeout = 5 * 1000; // 5 seconds ZooKeeper zk = new ZooKeeper(quorumServers, sessionTimeout, EmptyWatcher.instance); zk.addAuthInfo("digest", "hbase:rox".getBytes()); // Assumes the root of the ZooKeeper space is writable as it creates a node // wherever the cluster home is defined. ZooKeeperWatcher zk2 = new ZooKeeperWatcher(TEST_UTIL.getConfiguration(), "testCreateSilentIsReallySilent", null); // Save the previous ACL Stat s = null; List<ACL> oldACL = null; while (true) { try { s = new Stat(); oldACL = zk.getACL("/", s); break; } catch (KeeperException e) { switch (e.code()) { case CONNECTIONLOSS: case SESSIONEXPIRED: case OPERATIONTIMEOUT: LOG.warn("Possibly transient ZooKeeper exception", e); Threads.sleep(100); break; default: throw e; } } } // I set this acl after the attempted creation of the cluster home node. // Add retries in case of retryable zk exceptions. while (true) { try { zk.setACL("/", ZooDefs.Ids.CREATOR_ALL_ACL, -1); break; } catch (KeeperException e) { switch (e.code()) { case CONNECTIONLOSS: case SESSIONEXPIRED: case OPERATIONTIMEOUT: LOG.warn("Possibly transient ZooKeeper exception: " + e); Threads.sleep(100); break; default: throw e; } } } while (true) { try { zk.create(aclZnode, null, ZooDefs.Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT); break; } catch (KeeperException e) { switch (e.code()) { case CONNECTIONLOSS: case SESSIONEXPIRED: case OPERATIONTIMEOUT: LOG.warn("Possibly transient ZooKeeper exception: " + e); Threads.sleep(100); break; default: throw e; } } } zk.close(); ZKUtil.createAndFailSilent(zk2, aclZnode); // Restore the ACL ZooKeeper zk3 = new ZooKeeper(quorumServers, sessionTimeout, EmptyWatcher.instance); zk3.addAuthInfo("digest", "hbase:rox".getBytes()); try { zk3.setACL("/", oldACL, -1); } finally { zk3.close(); } }
From source file:org.apache.nifi.toolkit.zkmigrator.ZooKeeperMigrator.java
License:Apache License
private DataStatAclNode retrieveNode(ZooKeeper zooKeeper, String path) { Preconditions.checkNotNull(zooKeeper, "ZooKeeper client must not be null"); Preconditions.checkNotNull(path, "path must not be null"); final Stat stat = new Stat(); final byte[] data; final List<ACL> acls; final long ephemeralOwner; try {/*from www.j av a 2s.c om*/ data = zooKeeper.getData(path, false, stat); acls = zooKeeper.getACL(path, stat); ephemeralOwner = stat.getEphemeralOwner(); } catch (InterruptedException | KeeperException e) { if (e instanceof InterruptedException) { Thread.currentThread().interrupt(); } throw new RuntimeException(String .format("unable to get data, ACLs, and stats from %s for node at path %s", zooKeeper, path), e); } return new DataStatAclNode(path, data, stat, acls, ephemeralOwner); }
From source file:org.apache.solr.security.hadoop.TestZkAclsWithHadoopAuth.java
License:Apache License
private void checkSecurityACLs(ZooKeeper keeper, String path) throws Exception { List<ACL> acls = keeper.getACL(path, new Stat()); String message = String.format(Locale.ROOT, "Path %s ACLs found %s", path, acls); assertEquals(message, 1, acls.size()); assertTrue(message, acls.contains(new ACL(ZooDefs.Perms.ALL, SOLR_ZK_ID))); }
From source file:org.apache.solr.security.hadoop.TestZkAclsWithHadoopAuth.java
License:Apache License
private void checkNonSecurityACLs(ZooKeeper keeper, String path) throws Exception { List<ACL> acls = keeper.getACL(path, new Stat()); String message = String.format(Locale.ROOT, "Path %s ACLs found %s", path, acls); assertEquals(message, 2, acls.size()); assertTrue(message, acls.contains(new ACL(ZooDefs.Perms.ALL, SOLR_ZK_ID))); assertTrue(message, acls.contains(new ACL(ZooDefs.Perms.READ, FOO_ZK_ID))); }