private static AstyanaxContext<Cluster> createCluster(AstyanaxContext.Builder cb) { AstyanaxContext<Cluster> clusterCtx = cb.buildCluster(ThriftFamilyFactory.getInstance()); clusterCtx.start(); return clusterCtx; }
public AstyanaxStoreManager(Configuration config) throws BackendException { super(config); this.clusterName = config.get(CLUSTER_NAME); retryDelaySlice = config.get(RETRY_DELAY_SLICE); retryMaxDelaySlice = config.get(RETRY_MAX_DELAY_SLICE); retrySuspendWindow = config.get(RETRY_SUSPEND_WINDOW); retryBackoffStrategy = getRetryBackoffStrategy(config.get(RETRY_BACKOFF_STRATEGY)); retryPolicy = getRetryPolicy(config.get(RETRY_POLICY)); localDatacenter = config.has(LOCAL_DATACENTER) ? config.get(LOCAL_DATACENTER) : ""; final int maxConnsPerHost = config.get(MAX_CONNECTIONS_PER_HOST); final int maxClusterConnsPerHost = config.get(MAX_CLUSTER_CONNECTIONS_PER_HOST); this.clusterContext = createCluster(getContextBuilder(config, maxClusterConnsPerHost, "Cluster")); ensureKeyspaceExists(clusterContext.getClient()); this.keyspaceContext = getContextBuilder(config, maxConnsPerHost, "Keyspace").buildKeyspace(ThriftFamilyFactory.getInstance()); this.keyspaceContext.start(); openStores = new HashMap<String, AstyanaxKeyColumnValueStore>(8); }
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()); } }
@Override public void start() throws Exception { _astyanaxContext.start(); }
@Override public void start() throws Exception { _astyanaxContext.start(); }
@Override public void init() { ks = ksContext.getClient(); ksContext.start(); }
@SuppressWarnings({ "rawtypes", "unchecked" }) public CassandraMapState(Options<T> options, Map conf) { this.options = options; this.serializer = options.serializer; AstyanaxContext<Keyspace> context = createContext((Map<String, Object>) conf.get(options.clientConfigKey)); context.start(); this.keyspace = context.getEntity(); }
private static AstyanaxContext<Cluster> createCluster(AstyanaxContext.Builder cb) { AstyanaxContext<Cluster> clusterCtx = cb.buildCluster(ThriftFamilyFactory.getInstance()); clusterCtx.start(); return clusterCtx; }
private static AstyanaxContext<Cluster> createCluster(AstyanaxContext.Builder cb) { AstyanaxContext<Cluster> clusterCtx = cb.buildCluster(ThriftFamilyFactory.getInstance()); clusterCtx.start(); return clusterCtx; }
@Test public void keyspaceDescribePartitioner() throws Exception { String keyspaceName = "AstyanaxTestKeyspaceDescribeRing".toLowerCase(); AstyanaxContext<Keyspace> context = AstyanaxContextFactory.getKeyspace(keyspaceName); context.start(); keyspace = context.getClient(); Map<String, Object> options = ImmutableMap.<String, Object>builder() .put("strategy_options", ImmutableMap.<String, Object>builder() .put("replication_factor", "1") .build()) .put("strategy_class", "SimpleStrategy") .build(); keyspace.createKeyspace(options); Thread.sleep(1000); String partitioner = keyspace.describePartitioner(); Assert.assertNotNull(partitioner); keyspace.dropKeyspace(); } }
@Inject public InstanceDataDAOCassandra(IConfiguration config,EurekaHostsSupplier eurekaHostsSupplier) throws ConnectionException { this.config = config; BOOT_CLUSTER = config.getBootClusterName(); if(BOOT_CLUSTER == null || BOOT_CLUSTER.isEmpty()) throw new RuntimeException("BootCluster can not be blank. Please use getBootClusterName() property."); KS_NAME = config.getCassandraKeyspaceName(); if(KS_NAME == null || KS_NAME.isEmpty()) throw new RuntimeException("Cassandra Keyspace can not be blank. Please use getCassandraKeyspaceName() property."); thriftPortForAstyanax = config.getCassandraThriftPortForAstyanax(); if(thriftPortForAstyanax <= 0) throw new RuntimeException("Thrift Port for Astyanax can not be blank. Please use getCassandraThriftPortForAstyanax() property."); this.eurekaHostsSupplier = eurekaHostsSupplier; if(config.isEurekaHostSupplierEnabled()) ctx = initWithThriftDriverWithEurekaHostsSupplier(); else ctx = initWithThriftDriverWithExternalHostsSupplier(); ctx.start(); bootKeyspace = ctx.getClient(); }
public void start(Map<String, Object> config) { try { List<AstyanaxContext<Keyspace>> contexts = createContext(config); for (AstyanaxContext<Keyspace> context : contexts) { this.addAstyanaxContext(context.getKeyspaceName(), context); this.getAstyanaxContext(context.getKeyspaceName()).start(); // test the connection this.getKeyspace(context.getKeyspaceName()).describeKeyspace(); } } catch (Throwable e) { LOG.warn("Astyanax initialization failed.", e); throw new IllegalStateException("Failed to prepare Astyanax", e); } }
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 AstyanaxStoreManager(Configuration config) throws BackendException { super(config); this.clusterName = config.get(CLUSTER_NAME); retryDelaySlice = config.get(RETRY_DELAY_SLICE); retryMaxDelaySlice = config.get(RETRY_MAX_DELAY_SLICE); retrySuspendWindow = config.get(RETRY_SUSPEND_WINDOW); retryBackoffStrategy = getRetryBackoffStrategy(config.get(RETRY_BACKOFF_STRATEGY)); retryPolicy = getRetryPolicy(config.get(RETRY_POLICY)); localDatacenter = config.has(LOCAL_DATACENTER) ? config.get(LOCAL_DATACENTER) : ""; final int maxConnsPerHost = config.get(MAX_CONNECTIONS_PER_HOST); final int maxClusterConnsPerHost = config.get(MAX_CLUSTER_CONNECTIONS_PER_HOST); this.clusterContext = createCluster(getContextBuilder(config, maxClusterConnsPerHost, "Cluster")); ensureKeyspaceExists(clusterContext.getClient()); this.keyspaceContext = getContextBuilder(config, maxConnsPerHost, "Keyspace").buildKeyspace(ThriftFamilyFactory.getInstance()); this.keyspaceContext.start(); openStores = new HashMap<String, AstyanaxKeyColumnValueStore>(8); }
public AstyanaxStoreManager(Configuration config) throws BackendException { super(config); this.clusterName = config.get(CLUSTER_NAME); retryDelaySlice = config.get(RETRY_DELAY_SLICE); retryMaxDelaySlice = config.get(RETRY_MAX_DELAY_SLICE); retrySuspendWindow = config.get(RETRY_SUSPEND_WINDOW); retryBackoffStrategy = getRetryBackoffStrategy(config.get(RETRY_BACKOFF_STRATEGY)); retryPolicy = getRetryPolicy(config.get(RETRY_POLICY)); localDatacenter = config.has(LOCAL_DATACENTER) ? config.get(LOCAL_DATACENTER) : ""; final int maxConnsPerHost = config.get(MAX_CONNECTIONS_PER_HOST); final int maxClusterConnsPerHost = config.get(MAX_CLUSTER_CONNECTIONS_PER_HOST); this.clusterContext = createCluster(getContextBuilder(config, maxClusterConnsPerHost, "Cluster")); ensureKeyspaceExists(clusterContext.getClient()); this.keyspaceContext = getContextBuilder(config, maxConnsPerHost, "Keyspace").buildKeyspace(ThriftFamilyFactory.getInstance()); this.keyspaceContext.start(); openStores = new HashMap<String, AstyanaxKeyColumnValueStore>(8); }
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; }
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; }