Search in sources :

Example 6 with PlainTextAuthProvider

use of com.datastax.driver.core.PlainTextAuthProvider in project storm by apache.

the class ClusterFactory method make.

/**
 * Creates a new Cluster based on the specified configuration.
 * @param topoConf the storm configuration.
 * @return a new a new {@link com.datastax.driver.core.Cluster} instance.
 */
@Override
protected Cluster make(Map<String, Object> topoConf) {
    CassandraConf cassandraConf = new CassandraConf(topoConf);
    Cluster.Builder cluster = Cluster.builder().withoutJMXReporting().withoutMetrics().addContactPoints(cassandraConf.getNodes()).withPort(cassandraConf.getPort()).withRetryPolicy(cassandraConf.getRetryPolicy()).withReconnectionPolicy(new ExponentialReconnectionPolicy(cassandraConf.getReconnectionPolicyBaseMs(), cassandraConf.getReconnectionPolicyMaxMs())).withLoadBalancingPolicy(cassandraConf.getLoadBalancingPolicy());
    cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis((int) cassandraConf.getSocketReadTimeoutMillis());
    cluster.getConfiguration().getSocketOptions().setConnectTimeoutMillis((int) cassandraConf.getSocketConnectTimeoutMillis());
    final String username = cassandraConf.getUsername();
    final String password = cassandraConf.getPassword();
    if (StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(password)) {
        cluster.withAuthProvider(new PlainTextAuthProvider(username, password));
    }
    QueryOptions options = new QueryOptions().setConsistencyLevel(cassandraConf.getConsistencyLevel());
    cluster.withQueryOptions(options);
    PoolingOptions poolOps = new PoolingOptions();
    poolOps.setMaxQueueSize(cassandraConf.getPoolMaxQueueSize());
    poolOps.setHeartbeatIntervalSeconds(cassandraConf.getHeartbeatIntervalSeconds());
    poolOps.setIdleTimeoutSeconds(cassandraConf.getIdleTimeoutSeconds());
    poolOps.setMaxRequestsPerConnection(HostDistance.LOCAL, cassandraConf.getMaxRequestPerConnectionLocal());
    poolOps.setMaxRequestsPerConnection(HostDistance.REMOTE, cassandraConf.getMaxRequestPerConnectionRemote());
    cluster.withPoolingOptions(poolOps);
    return cluster.build();
}
Also used : PoolingOptions(com.datastax.driver.core.PoolingOptions) Cluster(com.datastax.driver.core.Cluster) PlainTextAuthProvider(com.datastax.driver.core.PlainTextAuthProvider) ExponentialReconnectionPolicy(com.datastax.driver.core.policies.ExponentialReconnectionPolicy) QueryOptions(com.datastax.driver.core.QueryOptions)

Aggregations

PlainTextAuthProvider (com.datastax.driver.core.PlainTextAuthProvider)6 Cluster (com.datastax.driver.core.Cluster)2 QueryOptions (com.datastax.driver.core.QueryOptions)2 Authenticator (com.datastax.driver.core.Authenticator)1 PoolingOptions (com.datastax.driver.core.PoolingOptions)1 SocketOptions (com.datastax.driver.core.SocketOptions)1 DCAwareRoundRobinPolicy (com.datastax.driver.core.policies.DCAwareRoundRobinPolicy)1 ExponentialReconnectionPolicy (com.datastax.driver.core.policies.ExponentialReconnectionPolicy)1 TokenAwarePolicy (com.datastax.driver.core.policies.TokenAwarePolicy)1 IAuthenticator (org.apache.cassandra.auth.IAuthenticator)1 IRoleManager (org.apache.cassandra.auth.IRoleManager)1 PasswordAuthenticator (org.apache.cassandra.auth.PasswordAuthenticator)1 SaslNegotiator (org.apache.cassandra.auth.PasswordAuthenticator.SaslNegotiator)1 BeforeClass (org.junit.BeforeClass)1