本文整理匯總了Java中org.apache.zookeeper.ZooKeeper.setACL方法的典型用法代碼示例。如果您正苦於以下問題:Java ZooKeeper.setACL方法的具體用法?Java ZooKeeper.setACL怎麽用?Java ZooKeeper.setACL使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.zookeeper.ZooKeeper
的用法示例。
在下文中一共展示了ZooKeeper.setACL方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testSuperACL
import org.apache.zookeeper.ZooKeeper; //導入方法依賴的package包/類
@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();
}
}
示例2: preAuth
import org.apache.zookeeper.ZooKeeper; //導入方法依賴的package包/類
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();
}
}
示例3: resetAcls
import org.apache.zookeeper.ZooKeeper; //導入方法依賴的package包/類
private static void resetAcls(final ZooKeeperWatcher 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, ZKUtil.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);
}
}
示例4: testDisconnectedAddAuth
import org.apache.zookeeper.ZooKeeper; //導入方法依賴的package包/類
@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 = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
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));
}
}
示例5: testDisconnectedAddAuth
import org.apache.zookeeper.ZooKeeper; //導入方法依賴的package包/類
@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));
}
}