Search in sources :

Example 6 with Cluster

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();
}
Also used : CassandraInterpreter(org.apache.zeppelin.cassandra.CassandraInterpreter) Cluster(com.datastax.driver.core.Cluster) Properties(java.util.Properties)

Example 7 with Cluster

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);
            }
        }
    }
}
Also used : UnKnownDatabaseInfo(com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo) DefaultDatabaseInfo(com.navercorp.pinpoint.bootstrap.plugin.jdbc.DefaultDatabaseInfo) DatabaseInfo(com.navercorp.pinpoint.bootstrap.context.DatabaseInfo) DatabaseInfoAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor) ArrayList(java.util.ArrayList) Cluster(com.datastax.driver.core.Cluster) Host(com.datastax.driver.core.Host)

Example 8 with Cluster

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();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) LatencyAwarePolicy(com.datastax.driver.core.policies.LatencyAwarePolicy) PoolingOptions(com.datastax.driver.core.PoolingOptions) Cluster(com.datastax.driver.core.Cluster) TokenAwarePolicy(com.datastax.driver.core.policies.TokenAwarePolicy) RoundRobinPolicy(com.datastax.driver.core.policies.RoundRobinPolicy) DCAwareRoundRobinPolicy(com.datastax.driver.core.policies.DCAwareRoundRobinPolicy)

Example 9 with Cluster

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;
    }
}
Also used : Closer(com.google.common.io.Closer) Cluster(com.datastax.driver.core.Cluster) IOException(java.io.IOException) Session(com.datastax.driver.core.Session)

Example 10 with Cluster

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

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