Search in sources :

Example 1 with Credentials

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

Example 2 with Credentials

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

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

Aggregations

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