@Override public Cluster get() { String host = configuration.getHostAddress(); int port = configuration.getPort(); LOGGER.info("Connecting to cassandra cluster with host:{}, port:{}", host, port); Cluster cluster = Cluster.builder() .addContactPoint(host) .withPort(port) .build(); Metadata metadata = cluster.getMetadata(); LOGGER.info("Connected to cluster: {}", metadata.getClusterName()); metadata.getAllHosts().forEach(h -> { LOGGER.info("Datacenter:{}, host:{}, rack: {}", h.getDatacenter(), h.getAddress(), h.getRack()); }); return cluster; } }
metadata.getClusterName());
String transitUri = "cassandra://" + connectionSession.getCluster().getMetadata().getClusterName(); session.getProvenanceReporter().send(flowFile, transitUri, transmissionMillis, true); session.transfer(flowFile, REL_SUCCESS);
Metadata metadata = newCluster.getMetadata(); log.info("Connected to Cassandra cluster: {}", new Object[]{metadata.getClusterName()});
stopWatch.stop(); long duration = stopWatch.getDuration(TimeUnit.MILLISECONDS); String transitUri = "cassandra://" + connectionSession.getCluster().getMetadata().getClusterName() + "." + cassandraTable;
log.info("Connected to Cassandra cluster: {}", new Object[]{metadata.getClusterName()});
public String getCatalog() throws SQLException { checkNotClosed(); return metadata.getClusterName(); }
@Override public String describeClusterName() throws ConnectionException { return cluster.getMetadata().getClusterName(); }
private String getConnectionInfo(Metadata metadata) { StringBuilder sb = new StringBuilder(); sb.append("Connected to cluster: "); sb.append(metadata.getClusterName()); sb.append("\n"); for (Host host : metadata.getAllHosts()) { sb.append("Data center: "); sb.append(host.getDatacenter()); sb.append("; Host: "); sb.append(host.getAddress()); } return sb.toString(); }
public void stop() throws Exception { if (!this.started) return; if (cluster != null && !cluster.isClosed()) { Metadata metadata = cluster.getMetadata(); cluster.close(); logger.info(String.format("Disconnected from cluster: %s\n", metadata.getClusterName())); } this.started = false; }
LOGGER.info("Connected to cluster: {}\n", metadata.getClusterName()); for (Host host : metadata.getAllHosts()) { LOGGER.info("Datatacenter: {}; Host: {}; Rack: {}\n",
private void createTableSpace() { if (cluster == null) { cluster = Cluster.builder().addContactPointsWithPorts(contactPoints).build(); log.info("Connected Cassandra to cluster: " + cluster.getMetadata().getClusterName()); session = cluster.connect(); } session.execute("CREATE KEYSPACE IF NOT EXISTS " + serviceName + " WITH replication " + "= {'class':'NetworkTopologyStrategy', '"+this.dataCenter+"': "+this.replicationFactor+"};"); session.execute("CREATE TABLE IF NOT EXISTS " + serviceName + ".igep (" + "id text PRIMARY KEY," + "host text," + "port int);"); }
public void init() { if (cluster == null) { cluster = Cluster.builder().addContactPointsWithPorts(contactPoints).build(); SDFSLogger.getLog().info("Connected Cassandra to cluster: " + cluster.getMetadata().getClusterName()); session = cluster.connect(); } session.execute("CREATE KEYSPACE IF NOT EXISTS " + serviceName + " WITH replication " + "= {'class':'NetworkTopologyStrategy', '"+this.dataCenter+"': "+this.replicationFactor+"};"); }
public void connect(String node) { cluster = Cluster.builder().addContactPoint(node).build(); Metadata metadata = cluster.getMetadata(); System.out.printf("Connected to cluster: %s\n", metadata.getClusterName()); for (Host host : metadata.getAllHosts()) { System.out.printf("Datatacenter: %s; Host: %s; Rack: %s\n", host.getDatacenter(), host.getAddress(), host.getRack()); } session = cluster.connect("karaf_demo"); }
public static Cluster connect(String cassandraContactPoints) { if(cluster == null) { cluster = Cluster.builder() .addContactPoint(cassandraContactPoints) .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)) .build(); Metadata metadata = cluster.getMetadata(); log.info("Connected to cluster: %s\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())); } } return cluster; }
/** * Init Cassandra session from Cluster.s */ public void initSession() { if (null == cluster) { Builder builder = Cluster.builder().addContactPoint(hostName).withPort(port); if (Util.hasLength(userName)) { builder.withCredentials(userName, userPassword); } this.cluster = builder.build(); } Metadata metadata = cluster.getMetadata(); LOGGER.info("Connecting to cluster... '{}'", metadata.getClusterName()); for ( Host host : metadata.getAllHosts() ) { LOGGER.info("Datatacenter: '{}' Host: '{}' Rack '{}'", host.getDatacenter(), host.getAddress(), host.getRack()); } this.session = cluster.connect(); LOGGER.info("Connection Successful."); }
/** * Constructor. * * Initializes the connection to the Cassandra cluster and creates * the keyspace and/or table if necessary. * * @param cluster The Cassandra cluster * @param settings The various settings */ public CassandraDataStore(Cluster cluster, ICassandraSettings settings) { this.cluster = Args.notNull(cluster, "cluster"); this.settings = Args.notNull(settings, "settings"); Metadata metadata = cluster.getMetadata(); if (LOGGER.isInfoEnabled()) { LOGGER.info("Connected to cluster: {}", metadata.getClusterName()); for (Host host : metadata.getAllHosts()) { LOGGER.info("Datatacenter: {}; Host: {}; Rack: {}", new Object[]{host.getDatacenter(), host.getAddress(), host.getRack()}); } } session = cluster.connect(); String keyspaceName = settings.getKeyspaceName(); KeyspaceMetadata keyspaceMetadata = createKeyspaceIfNecessary(keyspaceName, metadata); createTableIfNecessary(keyspaceName, keyspaceMetadata); LOGGER.info("Data will be stored in table '{}' in keyspace '{}'.", settings.getTableName(), keyspaceName); }
this.cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(600000); metadata = cluster.getMetadata(); logger.debug("Connected to cluster (" + this.host + "): " + metadata.getClusterName() + "\n"); session = cluster.connect();
private CassandraFactory(String hostName, String port, String dcName, String username, String password, Integer connectTimeoutMillis, Integer readTimeoutMillis){ LoadBalancingPolicy loadBalancingPolicy = new DCAwareRoundRobinPolicy(dcName,2); PoolingOptions poolingOptions = new PoolingOptions(); poolingOptions.setCoreConnectionsPerHost(HostDistance.LOCAL,10); poolingOptions.setMaxConnectionsPerHost(HostDistance.LOCAL, 50); SocketOptions socketOptions = new SocketOptions().setReadTimeoutMillis(readTimeoutMillis) .setConnectTimeoutMillis(connectTimeoutMillis); Cluster.Builder builder = Cluster.builder().addContactPoints(hostName) .withPoolingOptions(poolingOptions) .withReconnectionPolicy(new ConstantReconnectionPolicy(100L)) .withLoadBalancingPolicy(loadBalancingPolicy) .withSocketOptions(socketOptions); if(!username.isEmpty() && !password.isEmpty()) { builder.withCredentials(username, password); } cluster = builder.build(); Metadata metadata = cluster.getMetadata(); LOGGER.info("Connected to cluster: {}", metadata.getClusterName()); for ( Host host : metadata.getAllHosts() ) { LOGGER.info("Datacenter: {}; Host: {}; Rack: {}", new String[]{ host.getDatacenter(), host.getAddress().getHostAddress(), host.getRack() }); } }
@Override public synchronized void startup() { if (cassandraCluster != null) return; Builder b = Cluster.builder(); b.withLoadBalancingPolicy(new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder().build())); for (String host : hosts) { b.addContactPoint(host); } if (port != null) { b.withPort(port); } cassandraCluster = b.build(); cassandraCluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(60000); logger.info("Connected to cluster: {}", cassandraCluster.getMetadata().getClusterName()); for (Host host : cassandraCluster.getMetadata().getAllHosts()) { logger.info("Datatacenter: {} Host: {} Rack: {}", host.getDatacenter(), host.getAddress(), host.getRack()); } session = cassandraCluster.connect(keyspace); }