Search in sources :

Example 1 with DigestAuthenticationProvider

use of org.apache.zookeeper.server.auth.DigestAuthenticationProvider 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)

Aggregations

ArrayList (java.util.ArrayList)1 AuthInfo (org.apache.curator.framework.AuthInfo)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1 RetryNTimes (org.apache.curator.retry.RetryNTimes)1 ZKUtil (org.apache.hadoop.util.ZKUtil)1 YarnRuntimeException (org.apache.hadoop.yarn.exceptions.YarnRuntimeException)1 DigestAuthenticationProvider (org.apache.zookeeper.server.auth.DigestAuthenticationProvider)1