Search in sources :

Example 6 with AuthInfo

use of org.apache.curator.framework.AuthInfo in project hadoop by apache.

the class ResourceManager method createAndStartCurator.

public CuratorFramework createAndStartCurator(Configuration conf) throws IOException {
    String zkHostPort = conf.get(YarnConfiguration.RM_ZK_ADDRESS);
    if (zkHostPort == null) {
        throw new YarnRuntimeException(YarnConfiguration.RM_ZK_ADDRESS + " is not configured.");
    }
    int numRetries = conf.getInt(YarnConfiguration.RM_ZK_NUM_RETRIES, YarnConfiguration.DEFAULT_ZK_RM_NUM_RETRIES);
    int zkSessionTimeout = conf.getInt(YarnConfiguration.RM_ZK_TIMEOUT_MS, YarnConfiguration.DEFAULT_RM_ZK_TIMEOUT_MS);
    int zkRetryInterval = conf.getInt(YarnConfiguration.RM_ZK_RETRY_INTERVAL_MS, YarnConfiguration.DEFAULT_RM_ZK_RETRY_INTERVAL_MS);
    // set up zk auths
    List<ZKUtil.ZKAuthInfo> zkAuths = RMZKUtils.getZKAuths(conf);
    List<AuthInfo> authInfos = new ArrayList<>();
    for (ZKUtil.ZKAuthInfo zkAuth : zkAuths) {
        authInfos.add(new AuthInfo(zkAuth.getScheme(), zkAuth.getAuth()));
    }
    if (HAUtil.isHAEnabled(conf) && HAUtil.getConfValueForRMInstance(YarnConfiguration.ZK_RM_STATE_STORE_ROOT_NODE_ACL, conf) == null) {
        String zkRootNodeUsername = HAUtil.getConfValueForRMInstance(YarnConfiguration.RM_ADDRESS, YarnConfiguration.DEFAULT_RM_ADDRESS, conf);
        byte[] defaultFencingAuth = (zkRootNodeUsername + ":" + zkRootNodePassword).getBytes(Charset.forName("UTF-8"));
        authInfos.add(new AuthInfo(new DigestAuthenticationProvider().getScheme(), defaultFencingAuth));
    }
    CuratorFramework client = CuratorFrameworkFactory.builder().connectString(zkHostPort).sessionTimeoutMs(zkSessionTimeout).retryPolicy(new RetryNTimes(numRetries, zkRetryInterval)).authorization(authInfos).build();
    client.start();
    return client;
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) AuthInfo(org.apache.curator.framework.AuthInfo) ArrayList(java.util.ArrayList) ZKUtil(org.apache.hadoop.util.ZKUtil) YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) CuratorFramework(org.apache.curator.framework.CuratorFramework) DigestAuthenticationProvider(org.apache.zookeeper.server.auth.DigestAuthenticationProvider)

Example 7 with AuthInfo

use of org.apache.curator.framework.AuthInfo in project helios by spotify.

the class AgentService method setupZookeeperClient.

/**
   * Create a Zookeeper client and create the control and state nodes if needed.
   *
   * @param config The service configuration.
   * @return A zookeeper client.
   */
private ZooKeeperClient setupZookeeperClient(final AgentConfig config, final String id, final CountDownLatch zkRegistrationSignal) {
    ACLProvider aclProvider = null;
    List<AuthInfo> authorization = null;
    final String agentUser = config.getZookeeperAclAgentUser();
    final String agentPassword = config.getZooKeeperAclAgentPassword();
    final String masterUser = config.getZookeeperAclMasterUser();
    final String masterDigest = config.getZooKeeperAclMasterDigest();
    if (!isNullOrEmpty(agentPassword)) {
        if (isNullOrEmpty(agentUser)) {
            throw new HeliosRuntimeException("Agent username must be set if a password is set");
        }
        authorization = Lists.newArrayList(new AuthInfo("digest", String.format("%s:%s", agentUser, agentPassword).getBytes()));
    }
    if (config.isZooKeeperEnableAcls()) {
        if (isNullOrEmpty(agentUser) || isNullOrEmpty(agentPassword)) {
            throw new HeliosRuntimeException("ZooKeeper ACLs enabled but agent username and/or password not set");
        }
        if (isNullOrEmpty(masterUser) || isNullOrEmpty(masterDigest)) {
            throw new HeliosRuntimeException("ZooKeeper ACLs enabled but master username and/or digest not set");
        }
        aclProvider = heliosAclProvider(masterUser, masterDigest, agentUser, digest(agentUser, agentPassword));
    }
    final RetryPolicy zooKeeperRetryPolicy = new ExponentialBackoffRetry(1000, 3);
    final CuratorFramework curator = new CuratorClientFactoryImpl().newClient(config.getZooKeeperConnectionString(), config.getZooKeeperSessionTimeoutMillis(), config.getZooKeeperConnectionTimeoutMillis(), zooKeeperRetryPolicy, aclProvider, authorization);
    final ZooKeeperClient client = new DefaultZooKeeperClient(curator, config.getZooKeeperClusterId());
    client.start();
    // Register the agent
    final AgentZooKeeperRegistrar agentZooKeeperRegistrar = new AgentZooKeeperRegistrar(config.getName(), id, config.getZooKeeperRegistrationTtlMinutes(), new SystemClock());
    zkRegistrar = ZooKeeperRegistrarService.newBuilder().setZooKeeperClient(client).setZooKeeperRegistrar(agentZooKeeperRegistrar).setZkRegistrationSignal(zkRegistrationSignal).build();
    return client;
}
Also used : ACLProvider(org.apache.curator.framework.api.ACLProvider) AuthInfo(org.apache.curator.framework.AuthInfo) SystemClock(com.spotify.helios.common.SystemClock) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) CuratorClientFactoryImpl(com.spotify.helios.servicescommon.coordination.CuratorClientFactoryImpl) HeliosRuntimeException(com.spotify.helios.common.HeliosRuntimeException) DefaultZooKeeperClient(com.spotify.helios.servicescommon.coordination.DefaultZooKeeperClient) CuratorFramework(org.apache.curator.framework.CuratorFramework) ZooKeeperClient(com.spotify.helios.servicescommon.coordination.ZooKeeperClient) DefaultZooKeeperClient(com.spotify.helios.servicescommon.coordination.DefaultZooKeeperClient) RetryPolicy(org.apache.curator.RetryPolicy)

Aggregations

AuthInfo (org.apache.curator.framework.AuthInfo)7 CuratorFramework (org.apache.curator.framework.CuratorFramework)4 ACLProvider (org.apache.curator.framework.api.ACLProvider)4 DefaultZooKeeperClient (com.spotify.helios.servicescommon.coordination.DefaultZooKeeperClient)3 ZooKeeperClient (com.spotify.helios.servicescommon.coordination.ZooKeeperClient)3 RetryPolicy (org.apache.curator.RetryPolicy)3 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)3 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)2 CuratorClientFactoryImpl (com.spotify.helios.servicescommon.coordination.CuratorClientFactoryImpl)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 SystemClock (com.spotify.helios.common.SystemClock)1 ConfigurationException (io.dropwizard.configuration.ConfigurationException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)1 RetryNTimes (org.apache.curator.retry.RetryNTimes)1 ZKUtil (org.apache.hadoop.util.ZKUtil)1 YarnRuntimeException (org.apache.hadoop.yarn.exceptions.YarnRuntimeException)1 ACL (org.apache.zookeeper.data.ACL)1 DigestAuthenticationProvider (org.apache.zookeeper.server.auth.DigestAuthenticationProvider)1