use of com.twitter.distributedlog.ZooKeeperClient.Credentials in project distributedlog by twitter.
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");
}
use of com.twitter.distributedlog.ZooKeeperClient.Credentials in project distributedlog by twitter.
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 com.twitter.distributedlog.ZooKeeperClient.Credentials in project distributedlog by twitter.
the class BookKeeperClient method initialize.
private synchronized void initialize() throws IOException {
if (null != this.bkc) {
return;
}
boolean registerExpirationHandler;
if (null == this.zkc) {
int zkSessionTimeout = conf.getBKClientZKSessionTimeoutMilliSeconds();
RetryPolicy retryPolicy = null;
if (conf.getBKClientZKNumRetries() > 0) {
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);
}
registerExpirationHandler = conf.getBKClientZKNumRetries() <= 0;
try {
commonInitialization(conf, ledgersPath, channelFactory, statsLogger, requestTimer, registerExpirationHandler);
} catch (InterruptedException e) {
throw new DLInterruptedException("Interrupted on creating bookkeeper client " + name + " : ", e);
} catch (KeeperException e) {
throw new ZKException("Error on creating bookkeeper client " + name + " : ", e);
}
if (ownZK) {
LOG.info("BookKeeper Client created {} with its own ZK Client : ledgersPath = {}, numRetries = {}, " + "sessionTimeout = {}, backoff = {}, maxBackoff = {}, dnsResolver = {}, registerExpirationHandler = {}", new Object[] { name, ledgersPath, conf.getBKClientZKNumRetries(), conf.getBKClientZKSessionTimeoutMilliSeconds(), conf.getBKClientZKRetryBackoffStartMillis(), conf.getBKClientZKRetryBackoffMaxMillis(), conf.getBkDNSResolverOverrides(), registerExpirationHandler });
} else {
LOG.info("BookKeeper Client created {} with shared zookeeper client : ledgersPath = {}, numRetries = {}, " + "sessionTimeout = {}, backoff = {}, maxBackoff = {}, dnsResolver = {}, registerExpirationHandler = {}", new Object[] { name, ledgersPath, conf.getZKNumRetries(), conf.getZKSessionTimeoutMilliseconds(), conf.getZKRetryBackoffStartMillis(), conf.getZKRetryBackoffMaxMillis(), conf.getBkDNSResolverOverrides(), registerExpirationHandler });
}
}
Aggregations