@Override public void processResult(int rc, String p, Object ctx, String name) { try { zk.setACL(p, acl, version); } catch (KeeperException | InterruptedException e) { out.print(e.getMessage()); } } });
@Override public Void run() throws KeeperException, InterruptedException { List<ACL> acl = zkClient.getACL(path, stat); if (acl == null || !acl.containsAll(zkAcl) || !zkAcl.containsAll(acl)) { zkClient.setACL(path, zkAcl, stat.getAversion()); } return null; } }, Code.BADVERSION);
private static void resetAcls(final ZKWatcher zkw, final String znode, final boolean eraseAcls) throws Exception { List<String> children = ZKUtil.listChildrenNoWatch(zkw, znode); if (children != null) { for (String child: children) { resetAcls(zkw, ZNodePaths.joinZNode(znode, child), eraseAcls); } } ZooKeeper zk = zkw.getRecoverableZooKeeper().getZooKeeper(); if (eraseAcls) { LOG.info(" - erase ACLs for " + znode); zk.setACL(znode, ZooDefs.Ids.OPEN_ACL_UNSAFE, -1); } else { LOG.info(" - set ACLs for " + znode); zk.setACL(znode, ZKUtil.createACL(zkw, znode, true), -1); } }
Stat stat = zk.setACL(path, acl, version); if (cl.hasOption("s")) { new StatPrinter(out).print(stat);
private Stat transmitNode(ZooKeeper zooKeeper, DataStatAclNode node) { Preconditions.checkNotNull(zooKeeper, "zooKeeper must not be null"); Preconditions.checkNotNull(node, "node must not be null"); try { LOGGER.debug("attempting to transfer node to {} with ACL {}: {}", zooKeeperEndpointConfig, node.getAcls(), node); // set data without caring what the previous version of the data at that path zooKeeper.setData(node.getPath(), node.getData(), -1); zooKeeper.setACL(node.getPath(), node.getAcls(), -1); LOGGER.info("transferred node {} in {}", node, zooKeeperEndpointConfig); } catch (InterruptedException | KeeperException e) { if (e instanceof InterruptedException) { Thread.currentThread().interrupt(); } throw new RuntimeException(String.format("unable to transmit data to %s for path %s", zooKeeper, node.getPath()), e); } return node.getStat(); }
public void verifySetACLFailure_NoNode() { rc = KeeperException.Code.NONODE; stat = null; zk.setACL(path, acl, version, this, toString()); verify(); }
@Test public void testSuperACL() throws Exception { ZooKeeper zk = createClient(); try { zk.addAuthInfo("digest", "pat:pass".getBytes()); zk.create("/path1", null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT); zk.close(); // verify super can do anything and ignores ACLs zk = createClient(); zk.addAuthInfo("digest", "super:test".getBytes()); zk.getData("/path1", false, null); zk.setACL("/path1", Ids.READ_ACL_UNSAFE, -1); zk.create("/path1/foo", null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT); zk.setACL("/path1", Ids.OPEN_ACL_UNSAFE, -1); } finally { zk.close(); } } }
public void preAuth() throws Exception { ZooKeeper zk = createClient(); zk.addAuthInfo("key", "25".getBytes()); try { createNodePrintAcl(zk, "/pre", "testPreAuth"); zk.setACL("/", Ids.CREATOR_ALL_ACL, -1); zk.getChildren("/", false); zk.create("/abc", null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT); zk.setData("/abc", "testData1".getBytes(), -1); zk.create("/key", null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT); zk.setData("/key", "5".getBytes(), -1); Thread.sleep(1000); } catch (KeeperException e) { Assert.fail("test failed :" + e); } finally { zk.close(); } }
stat = zk.setACL(path, parseACLs(args[2]), args.length > 4 ? Integer.parseInt(args[3]) : -1); printStat(stat);
public void verifySetACLFailure_BadVersion() { new StringCB(zk).verifyCreate(); rc = Code.BADVERSION; stat = null; zk.setACL(path, acl, version + 1, this, toString()); verify(); }
public void verifySetACL() { stat.setAversion(1); new StringCB(zk).verifyCreate(); zk.setACL(path, acl, version, this, toString()); verify(); }
zk.setACL("/acltest", Ids.OPEN_ACL_UNSAFE, -1); zk.close(); zk = createClient();
zk.setACL("/foo", acls, -1); Assert.fail("Expected InvalidACLException for null value in ACL List"); } catch (InvalidACLException e) {
/** * setAcl is an idempotent operation. Retry before throwing exception * @return list of ACLs */ public Stat setAcl(String path, List<ACL> acls, int version) throws KeeperException, InterruptedException { try (TraceScope scope = TraceUtil.createTrace("RecoverableZookeeper.setAcl")) { RetryCounter retryCounter = retryCounterFactory.create(); while (true) { try { long startTime = EnvironmentEdgeManager.currentTime(); Stat nodeStat = checkZk().setACL(path, acls, version); return nodeStat; } catch (KeeperException e) { switch (e.code()) { case CONNECTIONLOSS: retryOrThrow(retryCounter, e, "setAcl"); break; case OPERATIONTIMEOUT: retryOrThrow(retryCounter, e, "setAcl"); break; default: throw e; } } retryCounter.sleepUntilNextRetry(); } } }
zk.setACL("/foo", null, 0); Assert.fail("Expected InvalidACLException for null ACL parameter"); } catch (InvalidACLException e) {
zk.setACL("/acltest", Ids.OPEN_ACL_UNSAFE, -1); zk.close(); zk = createClient();
@Test public void testDisconnectedAddAuth() throws Exception { File tmpDir = ClientBase.createTmpDir(); ClientBase.setupTestEnv(); ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000); SyncRequestProcessor.setSnapCount(1000); final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]); ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1); f.startup(zks); try { LOG.info("starting up the zookeeper server .. waiting"); Assert.assertTrue("waiting for server being up", ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); ZooKeeper zk = ClientBase.createZKClient(HOSTPORT); try { zk.addAuthInfo("digest", "pat:test".getBytes()); zk.setACL("/", Ids.CREATOR_ALL_ACL, -1); } finally { zk.close(); } } finally { f.shutdown(); zks.shutdown(); Assert.assertTrue("waiting for server down", ClientBase.waitForServerDown(HOSTPORT, ClientBase.CONNECTION_TIMEOUT)); } }
zk.setACL("/", Ids.CREATOR_ALL_ACL, -1);