use of org.apache.distributedlog.ZooKeeperClient.Credentials in project bookkeeper by apache.
the class BookKeeperClient method initialize.
private synchronized void initialize() throws IOException {
if (null != this.bkc) {
return;
}
if (null == this.zkc) {
int zkSessionTimeout = conf.getBKClientZKSessionTimeoutMilliSeconds();
RetryPolicy retryPolicy = new BoundExponentialBackoffRetryPolicy(conf.getBKClientZKRetryBackoffStartMillis(), conf.getBKClientZKRetryBackoffMaxMillis(), conf.getBKClientZKNumRetries());
Credentials credentials = Credentials.NONE;
if (conf.getZkAclId() != null) {
credentials = new DigestCredentials(conf.getZkAclId(), conf.getZkAclId());
}
this.zkc = new ZooKeeperClient(name + ":zk", zkSessionTimeout, 2 * zkSessionTimeout, zkServers, retryPolicy, statsLogger.scope("bkc_zkc"), conf.getZKClientNumberRetryThreads(), conf.getBKClientZKRequestRateLimit(), credentials);
}
try {
commonInitialization(conf, ledgersPath, eventLoopGroup, statsLogger, requestTimer);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new DLInterruptedException("Interrupted on creating bookkeeper client " + name + " : ", e);
}
if (ownZK) {
LOG.info("BookKeeper Client created {} with its own ZK Client : ledgersPath = {}, numRetries = {}, " + "sessionTimeout = {}, backoff = {}, maxBackoff = {}, dnsResolver = {}", new Object[] { name, ledgersPath, conf.getBKClientZKNumRetries(), conf.getBKClientZKSessionTimeoutMilliSeconds(), conf.getBKClientZKRetryBackoffStartMillis(), conf.getBKClientZKRetryBackoffMaxMillis(), conf.getBkDNSResolverOverrides() });
} else {
LOG.info("BookKeeper Client created {} with shared zookeeper client : ledgersPath = {}, numRetries = {}, " + "sessionTimeout = {}, backoff = {}, maxBackoff = {}, dnsResolver = {}", new Object[] { name, ledgersPath, conf.getZKNumRetries(), conf.getZKSessionTimeoutMilliseconds(), conf.getZKRetryBackoffStartMillis(), conf.getZKRetryBackoffMaxMillis(), conf.getBkDNSResolverOverrides() });
}
}
use of org.apache.distributedlog.ZooKeeperClient.Credentials in project bookkeeper by apache.
the class ZooKeeperClientBuilder method buildClient.
private ZooKeeperClient buildClient() {
validateParameters();
Credentials credentials = Credentials.NONE;
if (null != zkAclId) {
credentials = new DigestCredentials(zkAclId, zkAclId);
}
return new ZooKeeperClient(name, sessionTimeoutMs, conectionTimeoutMs, zkServers, retryPolicy, statsLogger, retryThreadCount, requestRateLimit, credentials);
}
use of org.apache.distributedlog.ZooKeeperClient.Credentials in project bookkeeper by apache.
the class TestZooKeeperClient method testAclDigestCredentialsBasics.
@Test(timeout = 60000)
public void testAclDigestCredentialsBasics() throws Exception {
ZooKeeperClient zkcAuth = buildClient();
zkcAuth.get().create("/test", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
try {
zkcAuth.get().create("/test/key1", new byte[0], DistributedLogConstants.EVERYONE_READ_CREATOR_ALL, CreateMode.PERSISTENT);
fail("should have failed");
} catch (Exception ex) {
}
Credentials credentials = new DigestCredentials("test", "test");
credentials.authenticate(zkcAuth.get());
// Should not throw now that we're authenticated.
zkcAuth.get().create("/test/key1", new byte[0], DistributedLogConstants.EVERYONE_READ_CREATOR_ALL, CreateMode.PERSISTENT);
rmAll(zkcAuth, "/test");
}
Aggregations