org.apache.hadoop.util.ZKUtil类的使用及代码示例

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

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

ZKUtil介绍

[英]Utilities for working with ZooKeeper.
[中]使用ZooKeeper的实用程序。

代码示例

代码示例来源:origin: org.apache.hadoop/hadoop-common

  1. /**
  2. * Utility method to fetch the ZK ACLs from the configuration.
  3. * @throws java.io.IOException if the Zookeeper ACLs configuration file
  4. * cannot be read
  5. */
  6. public static List<ACL> getZKAcls(Configuration conf) throws IOException {
  7. // Parse authentication from configuration.
  8. String zkAclConf = conf.get(CommonConfigurationKeys.ZK_ACL,
  9. CommonConfigurationKeys.ZK_ACL_DEFAULT);
  10. try {
  11. zkAclConf = ZKUtil.resolveConfIndirection(zkAclConf);
  12. return ZKUtil.parseACLs(zkAclConf);
  13. } catch (IOException | ZKUtil.BadAclFormatException e) {
  14. LOG.error("Couldn't read ACLs based on {}",
  15. CommonConfigurationKeys.ZK_ACL);
  16. throw e;
  17. }
  18. }

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

  1. public static List<ZKUtil.ZKAuthInfo> getZKAuths() throws Exception {
  2. // Parse Auths from configuration.
  3. String zkAuthConf = KylinConfig.getInstanceFromEnv().getZKAuths();
  4. try {
  5. zkAuthConf = ZKUtil.resolveConfIndirection(zkAuthConf);
  6. if (zkAuthConf != null) {
  7. return ZKUtil.parseAuth(zkAuthConf);
  8. } else {
  9. return Collections.emptyList();
  10. }
  11. } catch (Exception e) {
  12. logger.error("Couldn't read Auth based on 'kylin.env.zookeeper.zk-auth' in kylin.properties");
  13. throw e;
  14. }
  15. }

代码示例来源:origin: org.apache.hadoop/hadoop-common

  1. newAcl.setId(new Id(a.substring(0, firstColon), a.substring(
  2. firstColon + 1, lastColon)));
  3. newAcl.setPerms(getPermFromString(a.substring(lastColon + 1)));
  4. acl.add(newAcl);

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

  1. zkAclConf = ZKUtil.resolveConfIndirection(zkAclConf);
  2. List<ACL> zkAcls = ZKUtil.parseACLs(zkAclConf);
  3. if (zkAcls.isEmpty()) {
  4. zkAcls = Ids.CREATOR_ALL_ACL;
  5. zkAuthConf = ZKUtil.resolveConfIndirection(zkAuthConf);
  6. List<ZKAuthInfo> zkAuths;
  7. if (zkAuthConf != null) {
  8. zkAuths = ZKUtil.parseAuth(zkAuthConf);
  9. } else {
  10. zkAuths = Collections.emptyList();

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

  1. @Test
  2. public void testNullACL() {
  3. List<ACL> result = ZKUtil.parseACLs(null);
  4. assertTrue(result.isEmpty());
  5. }

代码示例来源:origin: ch.cern.hadoop/hadoop-common

  1. @Test
  2. public void testEmptyAuth() {
  3. List<ZKAuthInfo> result = ZKUtil.parseAuth("");
  4. assertTrue(result.isEmpty());
  5. }

代码示例来源:origin: ch.cern.hadoop/hadoop-common

  1. @Test
  2. public void testConfIndirection() throws IOException {
  3. assertNull(ZKUtil.resolveConfIndirection(null));
  4. assertEquals("x", ZKUtil.resolveConfIndirection("x"));
  5. TEST_FILE.getParentFile().mkdirs();
  6. Files.write("hello world", TEST_FILE, Charsets.UTF_8);
  7. assertEquals("hello world", ZKUtil.resolveConfIndirection(
  8. "@" + TEST_FILE.getAbsolutePath()));
  9. try {
  10. ZKUtil.resolveConfIndirection("@" + BOGUS_FILE);
  11. fail("Did not throw for non-existent file reference");
  12. } catch (FileNotFoundException fnfe) {
  13. assertTrue(fnfe.getMessage().startsWith(BOGUS_FILE));
  14. }
  15. }
  16. }

代码示例来源:origin: com.cloudera.llama/llama

  1. private List<ACL> createAclsForExclusiveReadAccess() throws LlamaException {
  2. List<ACL> acls = new ArrayList<ACL>();
  3. for (ACL acl : conf.getZkAcls()) {
  4. acls.add(new ACL(
  5. ZKUtil.removeSpecificPerms(acl.getPerms(), ZooDefs.Perms.READ),
  6. acl.getId()));
  7. }
  8. Id llamaId;
  9. try {
  10. llamaId =
  11. new Id(authScheme, DigestAuthenticationProvider.generateDigest(
  12. fencingUsername + ":" + fencingPassword));
  13. } catch (NoSuchAlgorithmException e) {
  14. throw new LlamaException(ErrorCode.INTERNAL_ERROR,
  15. "Unable to create username:password digest for ZK");
  16. }
  17. acls.add(new ACL(ZooDefs.Perms.READ, llamaId));
  18. return acls;
  19. }

代码示例来源:origin: io.hops/hadoop-common

  1. zkAclConf = ZKUtil.resolveConfIndirection(zkAclConf);
  2. List<ACL> zkAcls = ZKUtil.parseACLs(zkAclConf);
  3. if (zkAcls.isEmpty()) {
  4. zkAcls = Ids.CREATOR_ALL_ACL;
  5. zkAuthConf = ZKUtil.resolveConfIndirection(zkAuthConf);
  6. List<ZKAuthInfo> zkAuths;
  7. if (zkAuthConf != null) {
  8. zkAuths = ZKUtil.parseAuth(zkAuthConf);
  9. } else {
  10. zkAuths = Collections.emptyList();

代码示例来源:origin: ch.cern.hadoop/hadoop-common

  1. @Test
  2. public void testNullACL() {
  3. List<ACL> result = ZKUtil.parseACLs(null);
  4. assertTrue(result.isEmpty());
  5. }

代码示例来源:origin: ch.cern.hadoop/hadoop-common

  1. @Test
  2. public void testNullAuth() {
  3. List<ZKAuthInfo> result = ZKUtil.parseAuth(null);
  4. assertTrue(result.isEmpty());
  5. }

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

  1. @Test
  2. public void testConfIndirection() throws IOException {
  3. assertNull(ZKUtil.resolveConfIndirection(null));
  4. assertEquals("x", ZKUtil.resolveConfIndirection("x"));
  5. TEST_FILE.getParentFile().mkdirs();
  6. Files.write("hello world", TEST_FILE, Charsets.UTF_8);
  7. assertEquals("hello world", ZKUtil.resolveConfIndirection(
  8. "@" + TEST_FILE.getAbsolutePath()));
  9. try {
  10. ZKUtil.resolveConfIndirection("@" + BOGUS_FILE);
  11. fail("Did not throw for non-existent file reference");
  12. } catch (FileNotFoundException fnfe) {
  13. assertTrue(fnfe.getMessage().startsWith(BOGUS_FILE));
  14. }
  15. }
  16. }

代码示例来源:origin: ch.cern.hadoop/hadoop-common

  1. @Test
  2. public void testRemoveSpecificPerms() {
  3. int perms = Perms.ALL;
  4. int remove = Perms.CREATE;
  5. int newPerms = ZKUtil.removeSpecificPerms(perms, remove);
  6. assertEquals("Removal failed", 0, newPerms & Perms.CREATE);
  7. }

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

  1. public static List<ACL> getZKAcls() throws Exception {
  2. // Parse ACLs from configuration.
  3. String zkAclConf = KylinConfig.getInstanceFromEnv().getZKAcls();
  4. try {
  5. zkAclConf = ZKUtil.resolveConfIndirection(zkAclConf);
  6. return ZKUtil.parseACLs(zkAclConf);
  7. } catch (Exception e) {
  8. logger.error("Couldn't read ACLs based on 'kylin.env.zookeeper.zk-acl' in kylin.properties");
  9. throw e;
  10. }
  11. }

代码示例来源:origin: ch.cern.hadoop/hadoop-common

  1. zkAclConf = ZKUtil.resolveConfIndirection(zkAclConf);
  2. List<ACL> zkAcls = ZKUtil.parseACLs(zkAclConf);
  3. if (zkAcls.isEmpty()) {
  4. zkAcls = Ids.CREATOR_ALL_ACL;
  5. zkAuthConf = ZKUtil.resolveConfIndirection(zkAuthConf);
  6. List<ZKAuthInfo> zkAuths;
  7. if (zkAuthConf != null) {
  8. zkAuths = ZKUtil.parseAuth(zkAuthConf);
  9. } else {
  10. zkAuths = Collections.emptyList();

代码示例来源:origin: org.apache.hadoop/hadoop-common

  1. /**
  2. * Utility method to fetch ZK auth info from the configuration.
  3. * @throws java.io.IOException if the Zookeeper ACLs configuration file
  4. * cannot be read
  5. * @throws ZKUtil.BadAuthFormatException if the auth format is invalid
  6. */
  7. public static List<ZKUtil.ZKAuthInfo> getZKAuthInfos(Configuration conf,
  8. String configKey) throws IOException {
  9. char[] zkAuthChars = conf.getPassword(configKey);
  10. String zkAuthConf =
  11. zkAuthChars != null ? String.valueOf(zkAuthChars) : null;
  12. try {
  13. zkAuthConf = ZKUtil.resolveConfIndirection(zkAuthConf);
  14. if (zkAuthConf != null) {
  15. return ZKUtil.parseAuth(zkAuthConf);
  16. } else {
  17. return Collections.emptyList();
  18. }
  19. } catch (IOException | ZKUtil.BadAuthFormatException e) {
  20. LOG.error("Couldn't read Auth based on {}", configKey);
  21. throw e;
  22. }
  23. }
  24. }

代码示例来源:origin: ch.cern.hadoop/hadoop-common

  1. @Test
  2. public void testEmptyACL() {
  3. List<ACL> result = ZKUtil.parseACLs("");
  4. assertTrue(result.isEmpty());
  5. }

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

  1. @Test
  2. public void testNullAuth() {
  3. List<ZKAuthInfo> result = ZKUtil.parseAuth(null);
  4. assertTrue(result.isEmpty());
  5. }

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

  1. @Test
  2. public void testRemoveSpecificPerms() {
  3. int perms = Perms.ALL;
  4. int remove = Perms.CREATE;
  5. int newPerms = ZKUtil.removeSpecificPerms(perms, remove);
  6. assertEquals("Removal failed", 0, newPerms & Perms.CREATE);
  7. }

代码示例来源:origin: io.hops/hadoop-common

  1. newAcl.setId(new Id(a.substring(0, firstColon), a.substring(
  2. firstColon + 1, lastColon)));
  3. newAcl.setPerms(getPermFromString(a.substring(lastColon + 1)));
  4. acl.add(newAcl);

相关文章