use of com.datastax.driver.core.Cluster in project stargate-core by tuplejump.
the class CQLDataLoaderD method createSession.
public Session createSession() {
Cluster.Builder builder = new Cluster.Builder();
Set<Map.Entry<String, Integer>> entries = hostsAndPorts.entrySet();
for (Map.Entry<String, Integer> entry : entries) {
builder.addContactPoints(entry.getKey()).withPort(entry.getValue());
}
Cluster cluster = builder.build();
session = cluster.connect();
return session;
}
use of com.datastax.driver.core.Cluster in project metacat by Netflix.
the class CassandraConnectorFactory method stop.
/**
* {@inheritDoc}
*/
@Override
public void stop() {
super.stop();
// Stop the cassandra cluster
final Cluster cluster = this.getInjector().getInstance(Cluster.class);
if (cluster != null) {
cluster.close();
}
}
use of com.datastax.driver.core.Cluster in project camel by apache.
the class CqlPopulateBean method populate.
public void populate() {
Cluster cluster = Cluster.builder().addContactPoint("cassandra").build();
Session session = cluster.connect();
session.execute("create keyspace if not exists test with replication = {'class':'SimpleStrategy', 'replication_factor':1};");
session.execute("create table if not exists test.users ( id int primary key, name text );");
session.execute("insert into test.users (id,name) values (1, 'oscerd') if not exists;");
session.close();
cluster.close();
}
use of com.datastax.driver.core.Cluster in project zeppelin by apache.
the class CassandraInterpreterTest method should_display_statistics_for_non_select_statement.
@Test
public void should_display_statistics_for_non_select_statement() throws Exception {
//Given
String query = "USE zeppelin;\nCREATE TABLE IF NOT EXISTS no_select(id int PRIMARY KEY);";
final String rawResult = reformatHtml(readTestResource("/scalate/NoResultWithExecutionInfo.html"));
//When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
final Cluster cluster = session.getCluster();
final int port = cluster.getConfiguration().getProtocolOptions().getPort();
final String address = cluster.getMetadata().getAllHosts().iterator().next().getAddress().getHostAddress().replaceAll("/", "").replaceAll("\\[", "").replaceAll("\\]", "");
//Then
final String expected = rawResult.replaceAll("TRIED_HOSTS", address + ":" + port).replaceAll("QUERIED_HOSTS", address + ":" + port);
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
assertThat(reformatHtml(actual.message().get(0).getData())).isEqualTo(expected);
}
use of com.datastax.driver.core.Cluster in project storm by apache.
the class ClusterFactory method make.
/**
* Creates a new Cluster based on the specified configuration.
* @param stormConf the storm configuration.
* @return a new a new {@link com.datastax.driver.core.Cluster} instance.
*/
@Override
protected Cluster make(Map<String, Object> stormConf) {
CassandraConf cassandraConf = new CassandraConf(stormConf);
Cluster.Builder cluster = Cluster.builder().withoutJMXReporting().withoutMetrics().addContactPoints(cassandraConf.getNodes()).withPort(cassandraConf.getPort()).withRetryPolicy(cassandraConf.getRetryPolicy()).withReconnectionPolicy(new ExponentialReconnectionPolicy(cassandraConf.getReconnectionPolicyBaseMs(), cassandraConf.getReconnectionPolicyMaxMs())).withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy()));
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);
return cluster.build();
}
Aggregations