Search in sources :

Example 1 with ZKConnectionListener

use of org.apache.oozie.event.listener.ZKConnectionListener in project oozie by apache.

the class ZKUtils method createClient.

private void createClient() throws Exception {
    // Connect to the ZooKeeper server
    RetryPolicy retryPolicy = ZKUtils.getRetryPolicy();
    String zkConnectionString = ConfigurationService.get(ZK_CONNECTION_STRING);
    String zkNamespace = getZKNameSpace();
    int zkConnectionTimeout = ConfigurationService.getInt(ZK_CONNECTION_TIMEOUT);
    int zkSessionTimeout = ConfigurationService.getInt(ZK_SESSION_TIMEOUT, 300);
    ACLProvider aclProvider;
    if (Services.get().getConf().getBoolean(ZK_SECURE, false)) {
        log.info("Connecting to ZooKeeper with SASL/Kerberos and using 'sasl' ACLs");
        setJaasConfiguration();
        System.setProperty(ZooKeeperSaslClient.LOGIN_CONTEXT_NAME_KEY, "Client");
        System.setProperty("zookeeper.authProvider.1", "org.apache.zookeeper.server.auth.SASLAuthenticationProvider");
        saslACL = Collections.singletonList(new ACL(Perms.ALL, new Id("sasl", getServicePrincipal())));
        aclProvider = new SASLOwnerACLProvider();
    } else {
        log.info("Connecting to ZooKeeper without authentication");
        // open to everyone
        aclProvider = new DefaultACLProvider();
    }
    client = CuratorFrameworkFactory.builder().namespace(zkNamespace).connectString(zkConnectionString).retryPolicy(retryPolicy).aclProvider(aclProvider).connectionTimeoutMs(// in ms
    zkConnectionTimeout * 1000).sessionTimeoutMs(// in ms
    zkSessionTimeout * 1000).build();
    client.start();
    client.getConnectionStateListenable().addListener(new ZKConnectionListener());
}
Also used : ACLProvider(org.apache.curator.framework.api.ACLProvider) DefaultACLProvider(org.apache.curator.framework.imps.DefaultACLProvider) DefaultACLProvider(org.apache.curator.framework.imps.DefaultACLProvider) ACL(org.apache.zookeeper.data.ACL) ZKConnectionListener(org.apache.oozie.event.listener.ZKConnectionListener) Id(org.apache.zookeeper.data.Id) RetryPolicy(org.apache.curator.RetryPolicy)

Aggregations

RetryPolicy (org.apache.curator.RetryPolicy)1 ACLProvider (org.apache.curator.framework.api.ACLProvider)1 DefaultACLProvider (org.apache.curator.framework.imps.DefaultACLProvider)1 ZKConnectionListener (org.apache.oozie.event.listener.ZKConnectionListener)1 ACL (org.apache.zookeeper.data.ACL)1 Id (org.apache.zookeeper.data.Id)1