use of com.datastax.driver.core.Cluster in project zeppelin by apache.
the class CassandraInterpreterTest method setUp.
@BeforeClass
public static void setUp() {
Properties properties = new Properties();
final Cluster cluster = session.getCluster();
properties.setProperty(CASSANDRA_CLUSTER_NAME, cluster.getClusterName());
properties.setProperty(CASSANDRA_COMPRESSION_PROTOCOL, "NONE");
properties.setProperty(CASSANDRA_CREDENTIALS_USERNAME, "none");
properties.setProperty(CASSANDRA_CREDENTIALS_PASSWORD, "none");
properties.setProperty(CASSANDRA_PROTOCOL_VERSION, "3");
properties.setProperty(CASSANDRA_LOAD_BALANCING_POLICY, "DEFAULT");
properties.setProperty(CASSANDRA_RETRY_POLICY, "DEFAULT");
properties.setProperty(CASSANDRA_RECONNECTION_POLICY, "DEFAULT");
properties.setProperty(CASSANDRA_SPECULATIVE_EXECUTION_POLICY, "DEFAULT");
properties.setProperty(CASSANDRA_MAX_SCHEMA_AGREEMENT_WAIT_SECONDS, DEFAULT_MAX_SCHEMA_AGREEMENT_WAIT_SECONDS + "");
properties.setProperty(CASSANDRA_POOLING_NEW_CONNECTION_THRESHOLD_LOCAL, "100");
properties.setProperty(CASSANDRA_POOLING_NEW_CONNECTION_THRESHOLD_REMOTE, "100");
properties.setProperty(CASSANDRA_POOLING_CORE_CONNECTION_PER_HOST_LOCAL, "2");
properties.setProperty(CASSANDRA_POOLING_CORE_CONNECTION_PER_HOST_REMOTE, "1");
properties.setProperty(CASSANDRA_POOLING_MAX_CONNECTION_PER_HOST_LOCAL, "8");
properties.setProperty(CASSANDRA_POOLING_MAX_CONNECTION_PER_HOST_REMOTE, "2");
properties.setProperty(CASSANDRA_POOLING_MAX_REQUESTS_PER_CONNECTION_LOCAL, "1024");
properties.setProperty(CASSANDRA_POOLING_MAX_REQUESTS_PER_CONNECTION_REMOTE, "256");
properties.setProperty(CASSANDRA_POOLING_IDLE_TIMEOUT_SECONDS, "120");
properties.setProperty(CASSANDRA_POOLING_POOL_TIMEOUT_MILLIS, "5000");
properties.setProperty(CASSANDRA_POOLING_HEARTBEAT_INTERVAL_SECONDS, "30");
properties.setProperty(CASSANDRA_QUERY_DEFAULT_CONSISTENCY, "ONE");
properties.setProperty(CASSANDRA_QUERY_DEFAULT_SERIAL_CONSISTENCY, "SERIAL");
properties.setProperty(CASSANDRA_QUERY_DEFAULT_FETCH_SIZE, "5000");
properties.setProperty(CASSANDRA_SOCKET_CONNECTION_TIMEOUT_MILLIS, "5000");
properties.setProperty(CASSANDRA_SOCKET_READ_TIMEOUT_MILLIS, "12000");
properties.setProperty(CASSANDRA_SOCKET_TCP_NO_DELAY, "true");
properties.setProperty(CASSANDRA_HOSTS, from(cluster.getMetadata().getAllHosts()).first().get().getAddress().getHostAddress());
properties.setProperty(CASSANDRA_PORT, cluster.getConfiguration().getProtocolOptions().getPort() + "");
interpreter = new CassandraInterpreter(properties);
interpreter.open();
}
use of com.datastax.driver.core.Cluster in project pinpoint by naver.
the class CassandraDriverConnectInterceptor method prepareAfterTrace.
@Override
protected void prepareAfterTrace(Object target, Object[] args, Object result, Throwable throwable) {
final boolean success = InterceptorUtils.isSuccess(throwable);
// Must not check if current transaction is trace target or not. Connection can be made by other thread.
List<String> hostList = new ArrayList<String>();
if (target instanceof Cluster) {
Cluster cluster = (Cluster) target;
final Set<Host> hosts = cluster.getMetadata().getAllHosts();
final int port = cluster.getConfiguration().getProtocolOptions().getPort();
for (Host host : hosts) {
final String hostAddress = host.getAddress().getHostAddress() + ":" + port;
hostList.add(hostAddress);
}
}
if (args == null) {
return;
}
final String keyspace = (String) args[0];
DatabaseInfo databaseInfo = createDatabaseInfo(keyspace, hostList);
if (success) {
if (recordConnection) {
if (result instanceof DatabaseInfoAccessor) {
((DatabaseInfoAccessor) result)._$PINPOINT$_setDatabaseInfo(databaseInfo);
}
}
}
}
use of com.datastax.driver.core.Cluster in project zipkin by openzipkin.
the class DefaultSessionFactory method buildCluster.
// Visible for testing
static Cluster buildCluster(Cassandra3Storage cassandra) {
Cluster.Builder builder = Cluster.builder();
List<InetSocketAddress> contactPoints = parseContactPoints(cassandra);
int defaultPort = findConnectPort(contactPoints);
builder.addContactPointsWithPorts(contactPoints);
// This ends up protocolOptions.port
builder.withPort(defaultPort);
if (cassandra.username != null && cassandra.password != null) {
builder.withCredentials(cassandra.username, cassandra.password);
}
builder.withRetryPolicy(ZipkinRetryPolicy.INSTANCE);
builder.withLoadBalancingPolicy(new TokenAwarePolicy(new LatencyAwarePolicy.Builder(cassandra.localDc != null ? DCAwareRoundRobinPolicy.builder().withLocalDc(cassandra.localDc).build() : new RoundRobinPolicy()).build()));
builder.withPoolingOptions(new PoolingOptions().setMaxConnectionsPerHost(HostDistance.LOCAL, cassandra.maxConnections));
if (cassandra.useSsl) {
builder = builder.withSSL();
}
return builder.build();
}
use of com.datastax.driver.core.Cluster in project zipkin by openzipkin.
the class DefaultSessionFactory method create.
/**
* Creates a session and ensures schema if configured. Closes the cluster and session if any
* exception occurred.
*/
@Override
public Session create(Cassandra3Storage cassandra) {
Closer closer = Closer.create();
try {
Cluster cluster = closer.register(buildCluster(cassandra));
cluster.register(new QueryLogger.Builder().build());
Session session;
if (cassandra.ensureSchema) {
session = closer.register(cluster.connect());
Schema.ensureExists(cassandra.keyspace, session);
session.execute("USE " + cassandra.keyspace);
} else {
session = cluster.connect(cassandra.keyspace);
}
initializeUDTs(session);
return session;
} catch (RuntimeException e) {
try {
closer.close();
} catch (IOException ignored) {
}
throw e;
}
}
use of com.datastax.driver.core.Cluster in project spring-boot by spring-projects.
the class CassandraAutoConfigurationTests method createClusterWithOverrides.
@Test
public void createClusterWithOverrides() {
load("spring.data.cassandra.cluster-name=testcluster");
assertThat(this.context.getBeanNamesForType(Cluster.class).length).isEqualTo(1);
Cluster cluster = this.context.getBean(Cluster.class);
assertThat(cluster.getClusterName()).isEqualTo("testcluster");
}
Aggregations