org.apache.hadoop.hbase.zookeeper.ZKUtil.createACL()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(125)

本文整理了Java中org.apache.hadoop.hbase.zookeeper.ZKUtil.createACL()方法的一些代码示例,展示了ZKUtil.createACL()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZKUtil.createACL()方法的具体详情如下:
包路径:org.apache.hadoop.hbase.zookeeper.ZKUtil
类名称:ZKUtil
方法名:createACL

ZKUtil.createACL介绍

暂无

代码示例

代码示例来源:origin: apache/hbase

  1. private static ArrayList<ACL> createACL(ZKWatcher zkw, String node) {
  2. return createACL(zkw, node, isSecureZooKeeper(zkw.getConfiguration()));
  3. }

代码示例来源:origin: apache/hbase

  1. /**
  2. * Async creates the specified node with the specified data.
  3. *
  4. * <p>Throws an exception if the node already exists.
  5. *
  6. * <p>The node created is persistent and open access.
  7. *
  8. * @param zkw zk reference
  9. * @param znode path of node to create
  10. * @param data data of node to create
  11. * @param cb the callback to use for the creation
  12. * @param ctx the context to use for the creation
  13. */
  14. public static void asyncCreate(ZKWatcher zkw,
  15. String znode, byte [] data, final AsyncCallback.StringCallback cb,
  16. final Object ctx) {
  17. zkw.getRecoverableZooKeeper().getZooKeeper().create(znode, data,
  18. createACL(zkw, znode), CreateMode.PERSISTENT, cb, ctx);
  19. }

代码示例来源:origin: apache/hbase

  1. /**
  2. * Set the znode perms recursively. This will do post-order recursion, so that baseZnode ACLs
  3. * will be set last in case the master fails in between.
  4. * @param znode the ZNode to set the permissions for
  5. */
  6. private void setZnodeAclsRecursive(String znode) throws KeeperException, InterruptedException {
  7. List<String> children = recoverableZooKeeper.getChildren(znode, false);
  8. for (String child : children) {
  9. setZnodeAclsRecursive(ZNodePaths.joinZNode(znode, child));
  10. }
  11. List<ACL> acls = ZKUtil.createACL(this, znode, true);
  12. LOG.info("Setting ACLs for znode:" + znode + " , acl:" + acls);
  13. recoverableZooKeeper.setAcl(znode, acls, -1);
  14. }

代码示例来源:origin: apache/hbase

  1. boolean ret = true;
  2. try {
  3. zkw.getRecoverableZooKeeper().create(znode, data, createACL(zkw, znode),
  4. CreateMode.EPHEMERAL);
  5. } catch (KeeperException.NodeExistsException nee) {

代码示例来源:origin: apache/hbase

  1. @Test
  2. public void testUnsecure() throws ZooKeeperConnectionException, IOException {
  3. Configuration conf = HBaseConfiguration.create();
  4. conf.set(Superusers.SUPERUSER_CONF_KEY, "user1");
  5. String node = "/hbase/testUnsecure";
  6. ZKWatcher watcher = new ZKWatcher(conf, node, null, false);
  7. List<ACL> aclList = ZKUtil.createACL(watcher, node, false);
  8. assertEquals(1, aclList.size());
  9. assertTrue(aclList.contains(Ids.OPEN_ACL_UNSAFE.iterator().next()));
  10. }

代码示例来源:origin: apache/hbase

  1. /**
  2. * Creates the specified znode with the specified data but does not watch it.
  3. *
  4. * Returns the znode of the newly created node
  5. *
  6. * If there is another problem, a KeeperException will be thrown.
  7. *
  8. * @param zkw zk reference
  9. * @param znode path of node
  10. * @param data data of node
  11. * @param createMode specifying whether the node to be created is ephemeral and/or sequential
  12. * @return true name of the newly created znode or null
  13. * @throws KeeperException if unexpected zookeeper exception
  14. */
  15. public static String createNodeIfNotExistsNoWatch(ZKWatcher zkw, String znode, byte[] data,
  16. CreateMode createMode) throws KeeperException {
  17. String createdZNode = null;
  18. try {
  19. createdZNode = zkw.getRecoverableZooKeeper().create(znode, data,
  20. createACL(zkw, znode), createMode);
  21. } catch (KeeperException.NodeExistsException nee) {
  22. return znode;
  23. } catch (InterruptedException e) {
  24. zkw.interruptedException(e);
  25. return null;
  26. }
  27. return createdZNode;
  28. }

代码示例来源:origin: apache/hbase

  1. private static void resetAcls(final ZKWatcher zkw, final String znode,
  2. final boolean eraseAcls) throws Exception {
  3. List<String> children = ZKUtil.listChildrenNoWatch(zkw, znode);
  4. if (children != null) {
  5. for (String child: children) {
  6. resetAcls(zkw, ZNodePaths.joinZNode(znode, child), eraseAcls);
  7. }
  8. }
  9. ZooKeeper zk = zkw.getRecoverableZooKeeper().getZooKeeper();
  10. if (eraseAcls) {
  11. LOG.info(" - erase ACLs for " + znode);
  12. zk.setACL(znode, ZooDefs.Ids.OPEN_ACL_UNSAFE, -1);
  13. } else {
  14. LOG.info(" - set ACLs for " + znode);
  15. zk.setACL(znode, ZKUtil.createACL(zkw, znode, true), -1);
  16. }
  17. }

代码示例来源:origin: apache/hbase

  1. @Test
  2. public void testSecuritySingleSuperuser() throws ZooKeeperConnectionException, IOException {
  3. Configuration conf = HBaseConfiguration.create();
  4. conf.set(Superusers.SUPERUSER_CONF_KEY, "user1");
  5. String node = "/hbase/testSecuritySingleSuperuser";
  6. ZKWatcher watcher = new ZKWatcher(conf, node, null, false);
  7. List<ACL> aclList = ZKUtil.createACL(watcher, node, true);
  8. assertEquals(2, aclList.size()); // 1+1, since ACL will be set for the creator by default
  9. assertTrue(aclList.contains(new ACL(Perms.ALL, new Id("sasl", "user1"))));
  10. assertTrue(aclList.contains(Ids.CREATOR_ALL_ACL.iterator().next()));
  11. }

代码示例来源:origin: apache/hbase

  1. /**
  2. * Convert from ZKUtilOp to ZKOp
  3. */
  4. private static Op toZooKeeperOp(ZKWatcher zkw, ZKUtilOp op) throws UnsupportedOperationException {
  5. if(op == null) {
  6. return null;
  7. }
  8. if (op instanceof CreateAndFailSilent) {
  9. CreateAndFailSilent cafs = (CreateAndFailSilent)op;
  10. return Op.create(cafs.getPath(), cafs.getData(), createACL(zkw, cafs.getPath()),
  11. CreateMode.PERSISTENT);
  12. } else if (op instanceof DeleteNodeFailSilent) {
  13. DeleteNodeFailSilent dnfs = (DeleteNodeFailSilent)op;
  14. return Op.delete(dnfs.getPath(), -1);
  15. } else if (op instanceof SetData) {
  16. SetData sd = (SetData) op;
  17. return Op.setData(sd.getPath(), sd.getData(), sd.getVersion());
  18. } else {
  19. throw new UnsupportedOperationException("Unexpected ZKUtilOp type: "
  20. + op.getClass().getName());
  21. }
  22. }

代码示例来源:origin: apache/hbase

  1. /**
  2. * Creates the specified node and all parent nodes required for it to exist. The creation of
  3. * parent znodes is not atomic with the leafe znode creation but the data is written atomically
  4. * when the leaf node is created.
  5. *
  6. * No watches are set and no errors are thrown if the node already exists.
  7. *
  8. * The nodes created are persistent and open access.
  9. *
  10. * @param zkw zk reference
  11. * @param znode path of node
  12. * @throws KeeperException if unexpected zookeeper exception
  13. */
  14. public static void createWithParents(ZKWatcher zkw, String znode, byte[] data)
  15. throws KeeperException {
  16. try {
  17. if(znode == null) {
  18. return;
  19. }
  20. zkw.getRecoverableZooKeeper().create(znode, data, createACL(zkw, znode),
  21. CreateMode.PERSISTENT);
  22. } catch(KeeperException.NodeExistsException nee) {
  23. return;
  24. } catch(KeeperException.NoNodeException nne) {
  25. createWithParents(zkw, getParent(znode));
  26. createWithParents(zkw, znode, data);
  27. } catch(InterruptedException ie) {
  28. zkw.interruptedException(ie);
  29. }
  30. }

代码示例来源:origin: apache/hbase

  1. boolean ret = true;
  2. try {
  3. zkw.getRecoverableZooKeeper().create(znode, data, createACL(zkw, znode),
  4. CreateMode.PERSISTENT);
  5. } catch (KeeperException.NodeExistsException nee) {

代码示例来源:origin: apache/hbase

  1. throws KeeperException, KeeperException.NodeExistsException {
  2. try {
  3. zkw.getRecoverableZooKeeper().create(znode, data, createACL(zkw, znode),
  4. CreateMode.PERSISTENT);
  5. Stat stat = zkw.getRecoverableZooKeeper().exists(znode, zkw);

代码示例来源:origin: apache/hbase

  1. @Test
  2. public void testCreateACL() throws ZooKeeperConnectionException, IOException {
  3. Configuration conf = HBaseConfiguration.create();
  4. conf.set(Superusers.SUPERUSER_CONF_KEY, "user1,@group1,user2,@group2,user3");
  5. String node = "/hbase/testCreateACL";
  6. ZKWatcher watcher = new ZKWatcher(conf, node, null, false);
  7. List<ACL> aclList = ZKUtil.createACL(watcher, node, true);
  8. assertEquals(4, aclList.size()); // 3+1, since ACL will be set for the creator by default
  9. assertFalse(aclList.contains(new ACL(Perms.ALL, new Id("sasl", "@group1"))));
  10. assertFalse(aclList.contains(new ACL(Perms.ALL, new Id("sasl", "@group2"))));
  11. assertTrue(aclList.contains(new ACL(Perms.ALL, new Id("sasl", "user1"))));
  12. assertTrue(aclList.contains(new ACL(Perms.ALL, new Id("sasl", "user2"))));
  13. assertTrue(aclList.contains(new ACL(Perms.ALL, new Id("sasl", "user3"))));
  14. }

代码示例来源:origin: apache/hbase

  1. @Test
  2. public void testCreateACLWithSameUser() throws ZooKeeperConnectionException, IOException {
  3. Configuration conf = HBaseConfiguration.create();
  4. conf.set(Superusers.SUPERUSER_CONF_KEY, "user4,@group1,user5,user6");
  5. UserGroupInformation.setLoginUser(UserGroupInformation.createRemoteUser("user4"));
  6. String node = "/hbase/testCreateACL";
  7. ZKWatcher watcher = new ZKWatcher(conf, node, null, false);
  8. List<ACL> aclList = ZKUtil.createACL(watcher, node, true);
  9. assertEquals(3, aclList.size()); // 3, since service user the same as one of superuser
  10. assertFalse(aclList.contains(new ACL(Perms.ALL, new Id("sasl", "@group1"))));
  11. assertTrue(aclList.contains(new ACL(Perms.ALL, new Id("auth", ""))));
  12. assertTrue(aclList.contains(new ACL(Perms.ALL, new Id("sasl", "user5"))));
  13. assertTrue(aclList.contains(new ACL(Perms.ALL, new Id("sasl", "user6"))));
  14. }

代码示例来源:origin: org.apache.hbase/hbase-zookeeper

  1. private static ArrayList<ACL> createACL(ZKWatcher zkw, String node) {
  2. return createACL(zkw, node, isSecureZooKeeper(zkw.getConfiguration()));
  3. }

代码示例来源:origin: com.aliyun.hbase/alihbase-zookeeper

  1. @Test
  2. public void testUnsecure() throws ZooKeeperConnectionException, IOException {
  3. Configuration conf = HBaseConfiguration.create();
  4. conf.set(Superusers.SUPERUSER_CONF_KEY, "user1");
  5. String node = "/hbase/testUnsecure";
  6. ZKWatcher watcher = new ZKWatcher(conf, node, null, false);
  7. List<ACL> aclList = ZKUtil.createACL(watcher, node, false);
  8. assertEquals(1, aclList.size());
  9. assertTrue(aclList.contains(Ids.OPEN_ACL_UNSAFE.iterator().next()));
  10. }

代码示例来源:origin: org.apache.hbase/hbase-zookeeper

  1. @Test
  2. public void testUnsecure() throws ZooKeeperConnectionException, IOException {
  3. Configuration conf = HBaseConfiguration.create();
  4. conf.set(Superusers.SUPERUSER_CONF_KEY, "user1");
  5. String node = "/hbase/testUnsecure";
  6. ZKWatcher watcher = new ZKWatcher(conf, node, null, false);
  7. List<ACL> aclList = ZKUtil.createACL(watcher, node, false);
  8. assertEquals(1, aclList.size());
  9. assertTrue(aclList.contains(Ids.OPEN_ACL_UNSAFE.iterator().next()));
  10. }

代码示例来源:origin: org.apache.hbase/hbase-zookeeper

  1. @Test
  2. public void testSecuritySingleSuperuser() throws ZooKeeperConnectionException, IOException {
  3. Configuration conf = HBaseConfiguration.create();
  4. conf.set(Superusers.SUPERUSER_CONF_KEY, "user1");
  5. String node = "/hbase/testSecuritySingleSuperuser";
  6. ZKWatcher watcher = new ZKWatcher(conf, node, null, false);
  7. List<ACL> aclList = ZKUtil.createACL(watcher, node, true);
  8. assertEquals(2, aclList.size()); // 1+1, since ACL will be set for the creator by default
  9. assertTrue(aclList.contains(new ACL(Perms.ALL, new Id("sasl", "user1"))));
  10. assertTrue(aclList.contains(Ids.CREATOR_ALL_ACL.iterator().next()));
  11. }

代码示例来源:origin: com.aliyun.hbase/alihbase-zookeeper

  1. @Test
  2. public void testSecuritySingleSuperuser() throws ZooKeeperConnectionException, IOException {
  3. Configuration conf = HBaseConfiguration.create();
  4. conf.set(Superusers.SUPERUSER_CONF_KEY, "user1");
  5. String node = "/hbase/testSecuritySingleSuperuser";
  6. ZKWatcher watcher = new ZKWatcher(conf, node, null, false);
  7. List<ACL> aclList = ZKUtil.createACL(watcher, node, true);
  8. assertEquals(2, aclList.size()); // 1+1, since ACL will be set for the creator by default
  9. assertTrue(aclList.contains(new ACL(Perms.ALL, new Id("sasl", "user1"))));
  10. assertTrue(aclList.contains(Ids.CREATOR_ALL_ACL.iterator().next()));
  11. }

代码示例来源:origin: com.aliyun.hbase/alihbase-zookeeper

  1. @Test
  2. public void testCreateACL() throws ZooKeeperConnectionException, IOException {
  3. Configuration conf = HBaseConfiguration.create();
  4. conf.set(Superusers.SUPERUSER_CONF_KEY, "user1,@group1,user2,@group2,user3");
  5. String node = "/hbase/testCreateACL";
  6. ZKWatcher watcher = new ZKWatcher(conf, node, null, false);
  7. List<ACL> aclList = ZKUtil.createACL(watcher, node, true);
  8. assertEquals(4, aclList.size()); // 3+1, since ACL will be set for the creator by default
  9. assertFalse(aclList.contains(new ACL(Perms.ALL, new Id("sasl", "@group1"))));
  10. assertFalse(aclList.contains(new ACL(Perms.ALL, new Id("sasl", "@group2"))));
  11. assertTrue(aclList.contains(new ACL(Perms.ALL, new Id("sasl", "user1"))));
  12. assertTrue(aclList.contains(new ACL(Perms.ALL, new Id("sasl", "user2"))));
  13. assertTrue(aclList.contains(new ACL(Perms.ALL, new Id("sasl", "user3"))));
  14. }

相关文章