Search in sources :

Example 1 with Credentials

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");
}
Also used : DigestCredentials(com.twitter.distributedlog.ZooKeeperClient.DigestCredentials) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) DigestCredentials(com.twitter.distributedlog.ZooKeeperClient.DigestCredentials) Credentials(com.twitter.distributedlog.ZooKeeperClient.Credentials) Test(org.junit.Test)

Example 2 with Credentials

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);
}
Also used : DigestCredentials(com.twitter.distributedlog.ZooKeeperClient.DigestCredentials) DigestCredentials(com.twitter.distributedlog.ZooKeeperClient.DigestCredentials) Credentials(com.twitter.distributedlog.ZooKeeperClient.Credentials)

Example 3 with 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 });
    }
}
Also used : DigestCredentials(com.twitter.distributedlog.ZooKeeperClient.DigestCredentials) ZKException(com.twitter.distributedlog.exceptions.ZKException) DLInterruptedException(com.twitter.distributedlog.exceptions.DLInterruptedException) BoundExponentialBackoffRetryPolicy(org.apache.bookkeeper.zookeeper.BoundExponentialBackoffRetryPolicy) RetryPolicy(org.apache.bookkeeper.zookeeper.RetryPolicy) BoundExponentialBackoffRetryPolicy(org.apache.bookkeeper.zookeeper.BoundExponentialBackoffRetryPolicy) DLInterruptedException(com.twitter.distributedlog.exceptions.DLInterruptedException) DigestCredentials(com.twitter.distributedlog.ZooKeeperClient.DigestCredentials) Credentials(com.twitter.distributedlog.ZooKeeperClient.Credentials) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

Credentials (com.twitter.distributedlog.ZooKeeperClient.Credentials)3 DigestCredentials (com.twitter.distributedlog.ZooKeeperClient.DigestCredentials)3 KeeperException (org.apache.zookeeper.KeeperException)2 DLInterruptedException (com.twitter.distributedlog.exceptions.DLInterruptedException)1 ZKException (com.twitter.distributedlog.exceptions.ZKException)1 IOException (java.io.IOException)1 BoundExponentialBackoffRetryPolicy (org.apache.bookkeeper.zookeeper.BoundExponentialBackoffRetryPolicy)1 RetryPolicy (org.apache.bookkeeper.zookeeper.RetryPolicy)1 Test (org.junit.Test)1