Search in sources :

Example 16 with Cluster

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;
}
Also used : Cluster(com.datastax.driver.core.Cluster) Map(java.util.Map)

Example 17 with Cluster

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();
    }
}
Also used : Cluster(com.datastax.driver.core.Cluster)

Example 18 with Cluster

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();
}
Also used : Cluster(com.datastax.driver.core.Cluster) Session(com.datastax.driver.core.Session)

Example 19 with Cluster

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);
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) Cluster(com.datastax.driver.core.Cluster)

Example 20 with Cluster

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();
}
Also used : Cluster(com.datastax.driver.core.Cluster) PlainTextAuthProvider(com.datastax.driver.core.PlainTextAuthProvider) ExponentialReconnectionPolicy(com.datastax.driver.core.policies.ExponentialReconnectionPolicy) TokenAwarePolicy(com.datastax.driver.core.policies.TokenAwarePolicy) QueryOptions(com.datastax.driver.core.QueryOptions) RoundRobinPolicy(com.datastax.driver.core.policies.RoundRobinPolicy)

Aggregations

Cluster (com.datastax.driver.core.Cluster)37 Test (org.junit.Test)16 Session (com.datastax.driver.core.Session)15 ResultSet (com.datastax.driver.core.ResultSet)9 Row (com.datastax.driver.core.Row)8 KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)5 ReconnectionPolicy (com.datastax.driver.core.policies.ReconnectionPolicy)4 IntegrationTest (tech.sirwellington.alchemy.annotations.testing.IntegrationTest)4 TableMetadata (com.datastax.driver.core.TableMetadata)3 Update (com.datastax.driver.core.querybuilder.Update)3 ArrayList (java.util.ArrayList)3 PlainTextAuthProvider (com.datastax.driver.core.PlainTextAuthProvider)2 PoolingOptions (com.datastax.driver.core.PoolingOptions)2 QueryOptions (com.datastax.driver.core.QueryOptions)2 RegularStatement (com.datastax.driver.core.RegularStatement)2 LoadBalancingPolicy (com.datastax.driver.core.policies.LoadBalancingPolicy)2 RoundRobinPolicy (com.datastax.driver.core.policies.RoundRobinPolicy)2 TokenAwarePolicy (com.datastax.driver.core.policies.TokenAwarePolicy)2 IOException (java.io.IOException)2 InetSocketAddress (java.net.InetSocketAddress)2