本文整理了Java中org.apache.hadoop.util.ZKUtil
类的一些代码示例,展示了ZKUtil
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZKUtil
类的具体详情如下:
包路径:org.apache.hadoop.util.ZKUtil
类名称:ZKUtil
[英]Utilities for working with ZooKeeper.
[中]使用ZooKeeper的实用程序。
代码示例来源:origin: org.apache.hadoop/hadoop-common
/**
* Utility method to fetch the ZK ACLs from the configuration.
* @throws java.io.IOException if the Zookeeper ACLs configuration file
* cannot be read
*/
public static List<ACL> getZKAcls(Configuration conf) throws IOException {
// Parse authentication from configuration.
String zkAclConf = conf.get(CommonConfigurationKeys.ZK_ACL,
CommonConfigurationKeys.ZK_ACL_DEFAULT);
try {
zkAclConf = ZKUtil.resolveConfIndirection(zkAclConf);
return ZKUtil.parseACLs(zkAclConf);
} catch (IOException | ZKUtil.BadAclFormatException e) {
LOG.error("Couldn't read ACLs based on {}",
CommonConfigurationKeys.ZK_ACL);
throw e;
}
}
代码示例来源:origin: apache/kylin
public static List<ZKUtil.ZKAuthInfo> getZKAuths() throws Exception {
// Parse Auths from configuration.
String zkAuthConf = KylinConfig.getInstanceFromEnv().getZKAuths();
try {
zkAuthConf = ZKUtil.resolveConfIndirection(zkAuthConf);
if (zkAuthConf != null) {
return ZKUtil.parseAuth(zkAuthConf);
} else {
return Collections.emptyList();
}
} catch (Exception e) {
logger.error("Couldn't read Auth based on 'kylin.env.zookeeper.zk-auth' in kylin.properties");
throw e;
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
newAcl.setId(new Id(a.substring(0, firstColon), a.substring(
firstColon + 1, lastColon)));
newAcl.setPerms(getPermFromString(a.substring(lastColon + 1)));
acl.add(newAcl);
代码示例来源:origin: com.github.jiayuhan-it/hadoop-common
zkAclConf = ZKUtil.resolveConfIndirection(zkAclConf);
List<ACL> zkAcls = ZKUtil.parseACLs(zkAclConf);
if (zkAcls.isEmpty()) {
zkAcls = Ids.CREATOR_ALL_ACL;
zkAuthConf = ZKUtil.resolveConfIndirection(zkAuthConf);
List<ZKAuthInfo> zkAuths;
if (zkAuthConf != null) {
zkAuths = ZKUtil.parseAuth(zkAuthConf);
} else {
zkAuths = Collections.emptyList();
代码示例来源:origin: com.github.jiayuhan-it/hadoop-common
@Test
public void testNullACL() {
List<ACL> result = ZKUtil.parseACLs(null);
assertTrue(result.isEmpty());
}
代码示例来源:origin: ch.cern.hadoop/hadoop-common
@Test
public void testEmptyAuth() {
List<ZKAuthInfo> result = ZKUtil.parseAuth("");
assertTrue(result.isEmpty());
}
代码示例来源:origin: ch.cern.hadoop/hadoop-common
@Test
public void testConfIndirection() throws IOException {
assertNull(ZKUtil.resolveConfIndirection(null));
assertEquals("x", ZKUtil.resolveConfIndirection("x"));
TEST_FILE.getParentFile().mkdirs();
Files.write("hello world", TEST_FILE, Charsets.UTF_8);
assertEquals("hello world", ZKUtil.resolveConfIndirection(
"@" + TEST_FILE.getAbsolutePath()));
try {
ZKUtil.resolveConfIndirection("@" + BOGUS_FILE);
fail("Did not throw for non-existent file reference");
} catch (FileNotFoundException fnfe) {
assertTrue(fnfe.getMessage().startsWith(BOGUS_FILE));
}
}
}
代码示例来源:origin: com.cloudera.llama/llama
private List<ACL> createAclsForExclusiveReadAccess() throws LlamaException {
List<ACL> acls = new ArrayList<ACL>();
for (ACL acl : conf.getZkAcls()) {
acls.add(new ACL(
ZKUtil.removeSpecificPerms(acl.getPerms(), ZooDefs.Perms.READ),
acl.getId()));
}
Id llamaId;
try {
llamaId =
new Id(authScheme, DigestAuthenticationProvider.generateDigest(
fencingUsername + ":" + fencingPassword));
} catch (NoSuchAlgorithmException e) {
throw new LlamaException(ErrorCode.INTERNAL_ERROR,
"Unable to create username:password digest for ZK");
}
acls.add(new ACL(ZooDefs.Perms.READ, llamaId));
return acls;
}
代码示例来源:origin: io.hops/hadoop-common
zkAclConf = ZKUtil.resolveConfIndirection(zkAclConf);
List<ACL> zkAcls = ZKUtil.parseACLs(zkAclConf);
if (zkAcls.isEmpty()) {
zkAcls = Ids.CREATOR_ALL_ACL;
zkAuthConf = ZKUtil.resolveConfIndirection(zkAuthConf);
List<ZKAuthInfo> zkAuths;
if (zkAuthConf != null) {
zkAuths = ZKUtil.parseAuth(zkAuthConf);
} else {
zkAuths = Collections.emptyList();
代码示例来源:origin: ch.cern.hadoop/hadoop-common
@Test
public void testNullACL() {
List<ACL> result = ZKUtil.parseACLs(null);
assertTrue(result.isEmpty());
}
代码示例来源:origin: ch.cern.hadoop/hadoop-common
@Test
public void testNullAuth() {
List<ZKAuthInfo> result = ZKUtil.parseAuth(null);
assertTrue(result.isEmpty());
}
代码示例来源:origin: com.github.jiayuhan-it/hadoop-common
@Test
public void testConfIndirection() throws IOException {
assertNull(ZKUtil.resolveConfIndirection(null));
assertEquals("x", ZKUtil.resolveConfIndirection("x"));
TEST_FILE.getParentFile().mkdirs();
Files.write("hello world", TEST_FILE, Charsets.UTF_8);
assertEquals("hello world", ZKUtil.resolveConfIndirection(
"@" + TEST_FILE.getAbsolutePath()));
try {
ZKUtil.resolveConfIndirection("@" + BOGUS_FILE);
fail("Did not throw for non-existent file reference");
} catch (FileNotFoundException fnfe) {
assertTrue(fnfe.getMessage().startsWith(BOGUS_FILE));
}
}
}
代码示例来源:origin: ch.cern.hadoop/hadoop-common
@Test
public void testRemoveSpecificPerms() {
int perms = Perms.ALL;
int remove = Perms.CREATE;
int newPerms = ZKUtil.removeSpecificPerms(perms, remove);
assertEquals("Removal failed", 0, newPerms & Perms.CREATE);
}
代码示例来源:origin: apache/kylin
public static List<ACL> getZKAcls() throws Exception {
// Parse ACLs from configuration.
String zkAclConf = KylinConfig.getInstanceFromEnv().getZKAcls();
try {
zkAclConf = ZKUtil.resolveConfIndirection(zkAclConf);
return ZKUtil.parseACLs(zkAclConf);
} catch (Exception e) {
logger.error("Couldn't read ACLs based on 'kylin.env.zookeeper.zk-acl' in kylin.properties");
throw e;
}
}
代码示例来源:origin: ch.cern.hadoop/hadoop-common
zkAclConf = ZKUtil.resolveConfIndirection(zkAclConf);
List<ACL> zkAcls = ZKUtil.parseACLs(zkAclConf);
if (zkAcls.isEmpty()) {
zkAcls = Ids.CREATOR_ALL_ACL;
zkAuthConf = ZKUtil.resolveConfIndirection(zkAuthConf);
List<ZKAuthInfo> zkAuths;
if (zkAuthConf != null) {
zkAuths = ZKUtil.parseAuth(zkAuthConf);
} else {
zkAuths = Collections.emptyList();
代码示例来源:origin: org.apache.hadoop/hadoop-common
/**
* Utility method to fetch ZK auth info from the configuration.
* @throws java.io.IOException if the Zookeeper ACLs configuration file
* cannot be read
* @throws ZKUtil.BadAuthFormatException if the auth format is invalid
*/
public static List<ZKUtil.ZKAuthInfo> getZKAuthInfos(Configuration conf,
String configKey) throws IOException {
char[] zkAuthChars = conf.getPassword(configKey);
String zkAuthConf =
zkAuthChars != null ? String.valueOf(zkAuthChars) : null;
try {
zkAuthConf = ZKUtil.resolveConfIndirection(zkAuthConf);
if (zkAuthConf != null) {
return ZKUtil.parseAuth(zkAuthConf);
} else {
return Collections.emptyList();
}
} catch (IOException | ZKUtil.BadAuthFormatException e) {
LOG.error("Couldn't read Auth based on {}", configKey);
throw e;
}
}
}
代码示例来源:origin: ch.cern.hadoop/hadoop-common
@Test
public void testEmptyACL() {
List<ACL> result = ZKUtil.parseACLs("");
assertTrue(result.isEmpty());
}
代码示例来源:origin: com.github.jiayuhan-it/hadoop-common
@Test
public void testNullAuth() {
List<ZKAuthInfo> result = ZKUtil.parseAuth(null);
assertTrue(result.isEmpty());
}
代码示例来源:origin: com.github.jiayuhan-it/hadoop-common
@Test
public void testRemoveSpecificPerms() {
int perms = Perms.ALL;
int remove = Perms.CREATE;
int newPerms = ZKUtil.removeSpecificPerms(perms, remove);
assertEquals("Removal failed", 0, newPerms & Perms.CREATE);
}
代码示例来源:origin: io.hops/hadoop-common
newAcl.setId(new Id(a.substring(0, firstColon), a.substring(
firstColon + 1, lastColon)));
newAcl.setPerms(getPermFromString(a.substring(lastColon + 1)));
acl.add(newAcl);
内容来源于网络,如有侵权,请联系作者删除!