Search in sources :

Example 26 with ACLProvider

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.api.ACLProvider in project paascloud-master by paascloud.

the class ZookeeperRegistryCenter method init.

/**
 * Init.
 */
@Override
public void init() {
    log.debug("Elastic job: zookeeper registry center init, server lists is: {}.", zkConfig.getZkAddressList());
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString(zkConfig.getZkAddressList()).retryPolicy(new ExponentialBackoffRetry(zkConfig.getBaseSleepTimeMilliseconds(), zkConfig.getMaxRetries(), zkConfig.getMaxSleepTimeMilliseconds()));
    if (0 != zkConfig.getSessionTimeoutMilliseconds()) {
        builder.sessionTimeoutMs(zkConfig.getSessionTimeoutMilliseconds());
    }
    if (0 != zkConfig.getConnectionTimeoutMilliseconds()) {
        builder.connectionTimeoutMs(zkConfig.getConnectionTimeoutMilliseconds());
    }
    if (!Strings.isNullOrEmpty(zkConfig.getDigest())) {
        builder.authorization("digest", zkConfig.getDigest().getBytes(Charsets.UTF_8)).aclProvider(new ACLProvider() {

            @Override
            public List<ACL> getDefaultAcl() {
                return ZooDefs.Ids.CREATOR_ALL_ACL;
            }

            @Override
            public List<ACL> getAclForPath(final String path) {
                return ZooDefs.Ids.CREATOR_ALL_ACL;
            }
        });
    }
    client = builder.build();
    client.start();
    try {
        if (!client.blockUntilConnected(zkConfig.getMaxSleepTimeMilliseconds() * zkConfig.getMaxRetries(), TimeUnit.MILLISECONDS)) {
            client.close();
            throw new KeeperException.OperationTimeoutException();
        }
    // CHECKSTYLE:OFF
    } catch (final Exception ex) {
        // CHECKSTYLE:ON
        RegExceptionHandler.handleException(ex);
    }
}
Also used : ACLProvider(org.apache.curator.framework.api.ACLProvider) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) KeeperException(org.apache.zookeeper.KeeperException)

Example 27 with ACLProvider

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.api.ACLProvider in project incubator-atlas by apache.

the class CuratorFactory method getAclProvider.

private ACLProvider getAclProvider(HAConfiguration.ZookeeperProperties zookeeperProperties) {
    ACLProvider aclProvider = null;
    if (zookeeperProperties.hasAcl()) {
        final ACL acl = AtlasZookeeperSecurityProperties.parseAcl(zookeeperProperties.getAcl());
        LOG.info("Setting ACL for id {} with scheme {} and perms {}.", getIdForLogging(acl.getId().getScheme(), acl.getId().getId()), acl.getId().getScheme(), acl.getPerms());
        LOG.info("Current logged in user: {}", getCurrentUser());
        final List<ACL> acls = Arrays.asList(acl);
        aclProvider = new ACLProvider() {

            @Override
            public List<ACL> getDefaultAcl() {
                return acls;
            }

            @Override
            public List<ACL> getAclForPath(String path) {
                return acls;
            }
        };
    }
    return aclProvider;
}
Also used : ACLProvider(org.apache.curator.framework.api.ACLProvider) ACL(org.apache.zookeeper.data.ACL) List(java.util.List)

Example 28 with ACLProvider

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.api.ACLProvider in project knox by apache.

the class CuratorClientService method createClient.

private RemoteConfigurationRegistryClient createClient(RemoteConfigurationRegistryConfig config) {
    ACLProvider aclProvider;
    if (config.isSecureRegistry()) {
        configureSasl(config);
        if (AUTH_TYPE_KERBEROS.equalsIgnoreCase(config.getAuthType()) && !config.isBackwardsCompatible()) {
            aclProvider = new SASLOwnerACLProvider(true);
        } else {
            aclProvider = new SASLOwnerACLProvider(false);
        }
    } else {
        // Clear SASL system property
        System.clearProperty(LOGIN_CONTEXT_NAME_PROPERTY);
        aclProvider = new DefaultACLProvider();
    }
    CuratorFramework client = CuratorFrameworkFactory.builder().connectString(config.getConnectionString()).retryPolicy(new ExponentialBackoffRetry(1000, 3)).aclProvider(aclProvider).build();
    client.start();
    return (new ClientAdapter(client, config));
}
Also used : ACLProvider(org.apache.curator.framework.api.ACLProvider) DefaultACLProvider(org.apache.curator.framework.imps.DefaultACLProvider) CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) DefaultACLProvider(org.apache.curator.framework.imps.DefaultACLProvider)

Aggregations

ACLProvider (org.apache.curator.framework.api.ACLProvider)26 ACL (org.apache.zookeeper.data.ACL)15 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)12 CuratorFramework (org.apache.curator.framework.CuratorFramework)10 DefaultACLProvider (org.apache.curator.framework.imps.DefaultACLProvider)8 RetryPolicy (org.apache.curator.RetryPolicy)7 Test (org.junit.Test)6 List (java.util.List)5 AuthInfo (org.apache.curator.framework.AuthInfo)5 ZooKeeperClientConfig (org.apache.nifi.controller.cluster.ZooKeeperClientConfig)4 NiFiProperties (org.apache.nifi.util.NiFiProperties)4 Id (org.apache.zookeeper.data.Id)4 Test (org.testng.annotations.Test)4 DefaultZooKeeperClient (com.spotify.helios.servicescommon.coordination.DefaultZooKeeperClient)3 ZooKeeperClient (com.spotify.helios.servicescommon.coordination.ZooKeeperClient)3 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)2 CuratorClientFactoryImpl (com.spotify.helios.servicescommon.coordination.CuratorClientFactoryImpl)2 ArrayList (java.util.ArrayList)2