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 apex-malhar by apache.
the class ConnectionStateManager method establishSessionWithPolicies.
private void establishSessionWithPolicies() {
Cluster.Builder clusterBuilder = Cluster.builder();
String[] seedNodesSplit = seedNodesStr.split(";");
Collection<InetAddress> allSeeds = new ArrayList<>();
Set<String> allKnownPorts = new HashSet<>();
for (String seedNode : seedNodesSplit) {
String[] nodeAndPort = seedNode.split(":");
if (nodeAndPort.length > 1) {
allKnownPorts.add(nodeAndPort[1]);
}
try {
allSeeds.add(InetAddress.getByName(nodeAndPort[0]));
} catch (UnknownHostException e) {
LOG.error(" Error while trying to initialize the seed brokers for the cassandra cluster " + e.getMessage(), e);
}
}
clusterBuilder = clusterBuilder.addContactPoints(allSeeds);
clusterBuilder.withClusterName(clusterName).withLoadBalancingPolicy(loadBalancingPolicy).withRetryPolicy(retryPolicy).withQueryOptions(queryOptions).withReconnectionPolicy(reconnectionPolicy);
// Finally initialize the cluster info
if (allKnownPorts.size() > 0) {
int shortlistedPort = Integer.parseInt(allKnownPorts.iterator().next());
clusterBuilder = clusterBuilder.withPort(shortlistedPort);
}
cluster = clusterBuilder.build();
Metadata metadata = cluster.getMetadata();
LOG.info("Connected to cluster: \n" + metadata.getClusterName());
for (Host host : metadata.getAllHosts()) {
LOG.info(String.format("Datacenter: %s; Host: %s; Rack: %s\n", host.getDatacenter(), host.getAddress(), host.getRack()));
}
session = cluster.connect(keyspaceName);
}
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 zipkin by openzipkin.
the class Schema method getKeyspaceMetadata.
static KeyspaceMetadata getKeyspaceMetadata(Session session) {
String keyspace = session.getLoggedKeyspace();
Cluster cluster = session.getCluster();
KeyspaceMetadata keyspaceMetadata = cluster.getMetadata().getKeyspace(keyspace);
if (keyspaceMetadata == null) {
throw new IllegalStateException(String.format("Cannot read keyspace metadata for give keyspace: %s and cluster: %s", keyspace, cluster.getClusterName()));
}
return keyspaceMetadata;
}
Aggregations