.setSocketTimeout(connectionTimeout) .setConnectTimeout(connectionTimeout) .setSeeds(StringUtils.join(hostnames, ","));
private ConnectionPoolConfiguration getConnectionPoolConfig ( final String poolName, final int poolSize ){ ConnectionPoolConfiguration config; final String username = cassandraFig.getUsername(); final String password = cassandraFig.getPassword(); if ( username != null && !username.isEmpty() && password != null && !password.isEmpty() ){ config = new ConnectionPoolConfigurationImpl( poolName ) .setPort( cassandraFig.getThriftPort() ) .setLocalDatacenter( cassandraFig.getLocalDataCenter() ) .setMaxConnsPerHost( poolSize ) .setSeeds( cassandraFig.getHosts() ) .setConnectTimeout( cassandraFig.getTimeout() ) .setSocketTimeout( cassandraFig.getTimeout() ) .setAuthenticationCredentials(new SimpleAuthenticationCredentials( username, password)); } else { // create instance of the connection pool without credential if they are not set config = new ConnectionPoolConfigurationImpl( poolName ) .setPort( cassandraFig.getThriftPort() ) .setLocalDatacenter( cassandraFig.getLocalDataCenter() ) .setMaxConnsPerHost( poolSize ) .setSeeds( cassandraFig.getHosts() ) .setSocketTimeout( cassandraFig.getTimeout() ) .setConnectTimeout( cassandraFig.getTimeout() ); } return config; }
public CassandraStorage(CassandraDataSegmentConfig config) { this.astyanaxContext = new AstyanaxContext.Builder() .forCluster(CLUSTER_NAME) .forKeyspace(config.getKeyspace()) .withAstyanaxConfiguration(new AstyanaxConfigurationImpl().setDiscoveryType(NodeDiscoveryType.NONE)) .withConnectionPoolConfiguration( new ConnectionPoolConfigurationImpl("MyConnectionPool").setMaxConnsPerHost(10) .setSeeds(config.getHost())).withConnectionPoolMonitor(new CountingConnectionPoolMonitor()) .buildKeyspace(ThriftFamilyFactory.getInstance()); this.astyanaxContext.start(); this.keyspace = this.astyanaxContext.getEntity(); this.config = config; indexStorage = new CassandraChunkedStorageProvider(keyspace, INDEX_TABLE_NAME); descriptorStorage = new ColumnFamily<String, String>(DESCRIPTOR_TABLE_NAME, StringSerializer.get(), StringSerializer.get()); } }
protected AstyanaxContext<Keyspace> createContext(Map<String, Object> config) { Map<String, Object> settings = Maps.newHashMap(); for (Map.Entry<String, Object> defaultEntry : DEFAULTS.entrySet()) { if (config.containsKey(defaultEntry.getKey())) { settings.put(defaultEntry.getKey(), config.get(defaultEntry.getKey())); } else { settings.put(defaultEntry.getKey(), defaultEntry.getValue()); } } // in the defaults case, we don't know the seed hosts until context // creation time if (settings.get(ASTYANAX_CONNECTION_POOL_CONFIGURATION) instanceof ConnectionPoolConfigurationImpl) { ConnectionPoolConfigurationImpl cpConfig = (ConnectionPoolConfigurationImpl) settings .get(ASTYANAX_CONNECTION_POOL_CONFIGURATION); cpConfig.setSeeds((String) config.get(StormCassandraConstants.CASSANDRA_HOST)); } return new AstyanaxContext.Builder() .forCluster((String) settings.get(CASSANDRA_CLUSTER_NAME)) .forKeyspace((String) config.get(StormCassandraConstants.CASSANDRA_STATE_KEYSPACE)) .withAstyanaxConfiguration((AstyanaxConfiguration) settings.get(ASTYANAX_CONFIGURATION)) .withConnectionPoolConfiguration( (ConnectionPoolConfiguration) settings.get(ASTYANAX_CONNECTION_POOL_CONFIGURATION)) .withConnectionPoolMonitor((ConnectionPoolMonitor) settings.get(ASTYANAX_CONNECTION_POOL_MONITOR)) .buildKeyspace(ThriftFamilyFactory.getInstance()); }
@Nonnull @Override public Collection<Runnable> getRunnables(@Nonnull UUID jobId, int sliceId, @Nonnull UUID workerId, @Nonnull ScopedProgressClient progressClient) throws IOException { context = new AstyanaxContext.Builder().forCluster(clusterName) .forKeyspace(keyspaceName) .withAstyanaxConfiguration(new AstyanaxConfigurationImpl().setDiscoveryType(NodeDiscoveryType.NONE)) .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("defaultConnPool") .setPort(port) .setMaxConnsPerHost(100) .setSeeds(seeds)) .withConnectionPoolMonitor(new Slf4jConnectionPoolMonitorImpl()) .buildKeyspace(ThriftFamilyFactory.getInstance()); context.start(); Keyspace keyspace = context.getEntity(); ColumnFamily<byte[], byte[]> cfDef = new ColumnFamily<>(columnFamilyName, BytesArraySerializer.get(), BytesArraySerializer.get()); ArrayList<Runnable> runnables = Lists.newArrayList(); byte[] colNameBytes = colName.getBytes(Charsets.UTF_8); for (int i = 0; i < numThreads; i++) { runnables.add(new CassandraRunnable(taskOperation, keyGeneratorFactory.getKeyGenerator(), workerId, sliceId, numQuanta, batchSize, jobId, valueGeneratorFactory.getValueGenerator(), keyspace, cfDef, colNameBytes)); } return runnables; }
public synchronized Cluster registerCluster(String clusterName, String contactPoint, int port) { logger.info("Connected Cassandra Cluster: " + clusterName); if(clusterContext == null) { clusterContext = new AstyanaxContext.Builder().forCluster(clusterName) .withAstyanaxConfiguration(new AstyanaxConfigurationImpl() .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE) ) .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool") .setPort(port) .setMaxConnsPerHost(1) .setSeeds(contactPoint) ) .withConnectionPoolMonitor(new CountingConnectionPoolMonitor()) .buildCluster(ThriftFamilyFactory.getInstance()); clusterContext.start(); } logger.warn("Cluster already registered"); return clusterContext.getClient(); }
public synchronized Cluster registerCluster(String clusterName, String contactPoint, int port) { logger.info("Connected Cassandra Cluster: " + clusterName); if(clusterContext == null) { clusterContext = new AstyanaxContext.Builder().forCluster(clusterName) .withAstyanaxConfiguration(new AstyanaxConfigurationImpl() .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE) ) .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool") .setPort(port) .setMaxConnsPerHost(1) .setSeeds(contactPoint) ) .withConnectionPoolMonitor(new CountingConnectionPoolMonitor()) .buildCluster(ThriftFamilyFactory.getInstance()); clusterContext.start(); } logger.warn("Cluster already registered"); return clusterContext.getClient(); }
public synchronized Keyspace registerKeyspace(String clusterName, String ksName, String contactPoint, int port) { logger.info("Cassandra Cluster: " + clusterName); if(keyspaceContext == null) { keyspaceContext = new AstyanaxContext.Builder() .forCluster(clusterName) .forKeyspace(ksName) .withAstyanaxConfiguration(new AstyanaxConfigurationImpl() .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE) ) .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool") .setPort(port) .setMaxConnsPerHost(1) .setSeeds(contactPoint) ) .withConnectionPoolMonitor(new CountingConnectionPoolMonitor()) .buildKeyspace(ThriftFamilyFactory.getInstance()); keyspaceContext.start(); } logger.warn("Keyspace already registered"); return keyspaceContext.getClient(); }
public synchronized Keyspace registerKeyspace(String clusterName, String ksName, String contactPoint, int port) { logger.info("Cassandra Cluster: " + clusterName); if(keyspaceContext == null) { keyspaceContext = new AstyanaxContext.Builder() .forCluster(clusterName) .forKeyspace(ksName) .withAstyanaxConfiguration(new AstyanaxConfigurationImpl() .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE) ) .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool") .setPort(port) .setMaxConnsPerHost(1) .setSeeds(contactPoint) ) .withConnectionPoolMonitor(new CountingConnectionPoolMonitor()) .buildKeyspace(ThriftFamilyFactory.getInstance()); keyspaceContext.start(); } logger.warn("Keyspace already registered"); return keyspaceContext.getClient(); }
/** * Builds a {@link Keyspace} from current configuration. */ public Keyspace build() { final AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder() .forCluster(clusterName) .forKeyspace(keyspaceName) .withAstyanaxConfiguration(new AstyanaxConfigurationImpl() .setDiscoveryType(RING_DESCRIBE) ) .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("ConnectionPool") .setPort(thriftPort) .setSeeds(hosts) ) .withConnectionPoolMonitor(new CountingConnectionPoolMonitor()) .buildKeyspace(ThriftFamilyFactory.getInstance()); context.start(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public synchronized void run() { context.shutdown(); } }); return context.getClient(); } }
private AstyanaxContext<Keyspace> getKeyspaceContext(final String ks, final String seedHost) { AstyanaxContext<Keyspace> ctx = new AstyanaxContext.Builder() .forKeyspace(ks) .withConnectionPoolConfiguration( new ConnectionPoolConfigurationImpl("myCPConfig-" + ks) .setSeeds(seedHost) .setPort(7102)) .withAstyanaxConfiguration( new AstyanaxConfigurationImpl() .setDefaultReadConsistencyLevel(ConsistencyLevel.CL_LOCAL_QUORUM) .setConnectionPoolType(ConnectionPoolType.TOKEN_AWARE) .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)) .buildKeyspace(ThriftFamilyFactory.getInstance()); return ctx; }
public AstyanaxContext<Cluster> newAstyanaxContextForCluster() { AstyanaxContext<Cluster> context = new AstyanaxContext.Builder() .forCluster(clusterName) .withAstyanaxConfiguration(new AstyanaxConfigurationImpl() .setDiscoveryType(NodeDiscoveryType.NONE)) .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("BrooklynPool") .setPort(thriftPort) .setMaxConnsPerHost(1) .setConnectTimeout(5000) // 10s .setSeeds(String.format("%s:%d", hostname, thriftPort))) .withConnectionPoolMonitor(new CountingConnectionPoolMonitor()) .buildCluster(ThriftFamilyFactory.getInstance()); context.start(); return context; }
.setPort(9160) .setMaxConnsPerHost(1) .setSeeds("127.0.0.1:9160")
.setPort(9160) .setMaxConnsPerHost(1) .setSeeds("127.0.0.1:9160")
public CassandraStorage(CassandraDataSegmentConfig config) { this.astyanaxContext = new AstyanaxContext.Builder() .forCluster(CLUSTER_NAME) .forKeyspace(config.getKeyspace()) .withAstyanaxConfiguration(new AstyanaxConfigurationImpl().setDiscoveryType(NodeDiscoveryType.NONE)) .withConnectionPoolConfiguration( new ConnectionPoolConfigurationImpl("MyConnectionPool").setMaxConnsPerHost(10) .setSeeds(config.getHost())).withConnectionPoolMonitor(new CountingConnectionPoolMonitor()) .buildKeyspace(ThriftFamilyFactory.getInstance()); this.astyanaxContext.start(); this.keyspace = this.astyanaxContext.getEntity(); this.config = config; indexStorage = new CassandraChunkedStorageProvider(keyspace, INDEX_TABLE_NAME); descriptorStorage = new ColumnFamily<String, String>(DESCRIPTOR_TABLE_NAME, StringSerializer.get(), StringSerializer.get()); } }
public AstyanaxContext<Keyspace> newAstyanaxContextForKeyspace(String keyspace) { AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder() .forCluster(clusterName) .forKeyspace(keyspace) .withAstyanaxConfiguration(new AstyanaxConfigurationImpl() .setDiscoveryType(NodeDiscoveryType.NONE)) .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("BrooklynPool") .setPort(thriftPort) .setMaxConnsPerHost(1) .setConnectTimeout(5000) // 10s .setSeeds(String.format("%s:%d", hostname, thriftPort))) .withConnectionPoolMonitor(new CountingConnectionPoolMonitor()) .buildKeyspace(ThriftFamilyFactory.getInstance()); context.start(); return context; }
.setMaxConnsPerHost(20) .setInitConnsPerHost(10) .setSeeds(SEEDS) .setPort(9042)
.setMaxConnsPerHost(20) .setInitConnsPerHost(10) .setSeeds(SEEDS) .setPort(9160)
.setPort(DynamicPropertyFactory.getInstance().getIntProperty(ZUUL_CASSANDRA_PORT, 7102).get()) .setMaxConnsPerHost(DynamicPropertyFactory.getInstance().getIntProperty(ZUUL_CASSANDRA_MAXCONNECTIONSPERHOST, 1).get()) .setSeeds(DynamicPropertyFactory.getInstance().getStringProperty(ZUUL_CASSANDRA_HOST, "").get() + ":" + DynamicPropertyFactory.getInstance().getIntProperty(ZUUL_CASSANDRA_PORT, 7102).get()
.setPort(DynamicPropertyFactory.getInstance().getIntProperty(ZUUL_CASSANDRA_PORT, 7102).get()) .setMaxConnsPerHost(DynamicPropertyFactory.getInstance().getIntProperty(ZUUL_CASSANDRA_MAXCONNECTIONSPERHOST, 1).get()) .setSeeds(DynamicPropertyFactory.getInstance().getStringProperty(ZUUL_CASSANDRA_HOST, "").get() + ":" + DynamicPropertyFactory.getInstance().getIntProperty(ZUUL_CASSANDRA_PORT, 7102).get()