use of com.datastax.driver.core.PoolingOptions in project janusgraph by JanusGraph.
the class CQLStoreManager method initializeCluster.
Cluster initializeCluster() throws PermanentBackendException {
final Configuration configuration = getStorageConfig();
final List<InetSocketAddress> contactPoints;
try {
contactPoints = Array.of(this.hostnames).map(hostName -> hostName.split(":")).map(array -> Tuple.of(array[0], array.length == 2 ? Integer.parseInt(array[1]) : this.port)).map(tuple -> new InetSocketAddress(tuple._1, tuple._2)).toJavaList();
} catch (SecurityException | ArrayIndexOutOfBoundsException | NumberFormatException e) {
throw new PermanentBackendException("Error initialising cluster contact points", e);
}
final Builder builder = Cluster.builder().addContactPointsWithPorts(contactPoints).withClusterName(configuration.get(CLUSTER_NAME));
if (configuration.get(PROTOCOL_VERSION) != 0) {
builder.withProtocolVersion(ProtocolVersion.fromInt(configuration.get(PROTOCOL_VERSION)));
}
if (configuration.has(AUTH_USERNAME) && configuration.has(AUTH_PASSWORD)) {
builder.withCredentials(configuration.get(AUTH_USERNAME), configuration.get(AUTH_PASSWORD));
}
if (configuration.has(LOCAL_DATACENTER)) {
builder.withLoadBalancingPolicy(new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder().withLocalDc(configuration.get(LOCAL_DATACENTER)).build()));
}
if (configuration.get(SSL_ENABLED)) {
try {
final TrustManager[] trustManagers;
try (final FileInputStream keyStoreStream = new FileInputStream(configuration.get(SSL_TRUSTSTORE_LOCATION))) {
final KeyStore keystore = KeyStore.getInstance("jks");
keystore.load(keyStoreStream, configuration.get(SSL_TRUSTSTORE_PASSWORD).toCharArray());
final TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keystore);
trustManagers = trustManagerFactory.getTrustManagers();
}
final SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustManagers, null);
final JdkSSLOptions sslOptions = JdkSSLOptions.builder().withSSLContext(sslContext).build();
builder.withSSL(sslOptions);
} catch (NoSuchAlgorithmException | CertificateException | IOException | KeyStoreException | KeyManagementException e) {
throw new PermanentBackendException("Error initialising SSL connection properties", e);
}
}
// Build the PoolingOptions based on the configurations
PoolingOptions poolingOptions = new PoolingOptions();
poolingOptions.setMaxRequestsPerConnection(HostDistance.LOCAL, configuration.get(LOCAL_MAX_REQUESTS_PER_CONNECTION)).setMaxRequestsPerConnection(HostDistance.REMOTE, configuration.get(REMOTE_MAX_REQUESTS_PER_CONNECTION));
poolingOptions.setConnectionsPerHost(HostDistance.LOCAL, configuration.get(LOCAL_CORE_CONNECTIONS_PER_HOST), configuration.get(LOCAL_MAX_CONNECTIONS_PER_HOST)).setConnectionsPerHost(HostDistance.REMOTE, configuration.get(REMOTE_CORE_CONNECTIONS_PER_HOST), configuration.get(REMOTE_MAX_CONNECTIONS_PER_HOST));
return builder.withPoolingOptions(poolingOptions).build();
}
use of com.datastax.driver.core.PoolingOptions in project cassandra by apache.
the class CqlConfigHelper method getReadPoolingOptions.
private static PoolingOptions getReadPoolingOptions(Configuration conf) {
Optional<Integer> coreConnections = getInputCoreConnections(conf);
Optional<Integer> maxConnections = getInputMaxConnections(conf);
Optional<Integer> maxSimultaneousRequests = getInputMaxSimultReqPerConnections(conf);
PoolingOptions poolingOptions = new PoolingOptions();
for (HostDistance hostDistance : Arrays.asList(HostDistance.LOCAL, HostDistance.REMOTE)) {
if (coreConnections.isPresent())
poolingOptions.setCoreConnectionsPerHost(hostDistance, coreConnections.get());
if (maxConnections.isPresent())
poolingOptions.setMaxConnectionsPerHost(hostDistance, maxConnections.get());
if (maxSimultaneousRequests.isPresent())
poolingOptions.setNewConnectionThreshold(hostDistance, maxSimultaneousRequests.get());
}
return poolingOptions;
}
use of com.datastax.driver.core.PoolingOptions 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();
}
use of com.datastax.driver.core.PoolingOptions in project gora by apache.
the class CassandraClient method populatePoolingSettings.
private Cluster.Builder populatePoolingSettings(Properties properties, Cluster.Builder builder) {
String localCoreConnectionsPerHost = properties.getProperty(CassandraStoreParameters.LOCAL_CORE_CONNECTIONS_PER_HOST);
String remoteCoreConnectionsPerHost = properties.getProperty(CassandraStoreParameters.REMOTE_CORE_CONNECTIONS_PER_HOST);
String localMaxConnectionsPerHost = properties.getProperty(CassandraStoreParameters.LOCAL_MAX_CONNECTIONS_PER_HOST);
String remoteMaxConnectionsPerHost = properties.getProperty(CassandraStoreParameters.REMOTE_MAX_CONNECTIONS_PER_HOST);
String localNewConnectionThreshold = properties.getProperty(CassandraStoreParameters.LOCAL_NEW_CONNECTION_THRESHOLD);
String remoteNewConnectionThreshold = properties.getProperty(CassandraStoreParameters.REMOTE_NEW_CONNECTION_THRESHOLD);
String localMaxRequestsPerConnection = properties.getProperty(CassandraStoreParameters.LOCAL_MAX_REQUESTS_PER_CONNECTION);
String remoteMaxRequestsPerConnection = properties.getProperty(CassandraStoreParameters.REMOTE_MAX_REQUESTS_PER_CONNECTION);
PoolingOptions options = new PoolingOptions();
if (localCoreConnectionsPerHost != null) {
options.setCoreConnectionsPerHost(HostDistance.LOCAL, Integer.parseInt(localCoreConnectionsPerHost));
}
if (remoteCoreConnectionsPerHost != null) {
options.setCoreConnectionsPerHost(HostDistance.REMOTE, Integer.parseInt(remoteCoreConnectionsPerHost));
}
if (localMaxConnectionsPerHost != null) {
options.setMaxConnectionsPerHost(HostDistance.LOCAL, Integer.parseInt(localMaxConnectionsPerHost));
}
if (remoteMaxConnectionsPerHost != null) {
options.setMaxConnectionsPerHost(HostDistance.REMOTE, Integer.parseInt(remoteMaxConnectionsPerHost));
}
if (localNewConnectionThreshold != null) {
options.setNewConnectionThreshold(HostDistance.LOCAL, Integer.parseInt(localNewConnectionThreshold));
}
if (remoteNewConnectionThreshold != null) {
options.setNewConnectionThreshold(HostDistance.REMOTE, Integer.parseInt(remoteNewConnectionThreshold));
}
if (localMaxRequestsPerConnection != null) {
options.setMaxRequestsPerConnection(HostDistance.LOCAL, Integer.parseInt(localMaxRequestsPerConnection));
}
if (remoteMaxRequestsPerConnection != null) {
options.setMaxRequestsPerConnection(HostDistance.REMOTE, Integer.parseInt(remoteMaxRequestsPerConnection));
}
builder = builder.withPoolingOptions(options);
return builder;
}
Aggregations