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 Keyspace getKeyspace() { return this.getAstyanaxContext().getEntity(); }
public Keyspace getKeyspace(String keyspace) { return this.getAstyanaxContext(keyspace).getEntity(); }
@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(); }
protected static Boolean areVersionsConsistent(CassandraNode node) { AstyanaxContext<Cluster> context = null; try { context = new AstyanaxSample(node).newAstyanaxContextForCluster(); Map<String, List<String>> v = context.getEntity().describeSchemaVersions(); return v.size() == 1; } catch (Exception e) { return null; } finally { if (context != null) context.shutdown(); } }
public static void main(String[] args) throws Exception { AstyanaxSample support = new AstyanaxSample("ignored", "ec2-79-125-32-2.eu-west-1.compute.amazonaws.com", 9160); AstyanaxContext<Cluster> context = support.newAstyanaxContextForCluster(); try { System.out.println(context.getEntity().describeSchemaVersions()); } finally { context.shutdown(); } } }
keyspace = context.getEntity(); return keyspace;
@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; }
/** * Read from a {@link CassandraNode} using the Astyanax API. * @throws ConnectionException */ public void readData(String keyspaceName) throws ConnectionException { // Create context AstyanaxContext<Keyspace> context = newAstyanaxContextForKeyspace(keyspaceName); try { Keyspace keyspace = context.getEntity(); // Query data OperationResult<ColumnList<String>> query = keyspace.prepareQuery(sampleColumnFamily) .getKey("one") .execute(); assertEquals(query.getHost().getHostName(), hostname); assertTrue(query.getLatency() > 0L); ColumnList<String> columns = query.getResult(); assertEquals(columns.size(), 2); // Lookup columns in response by name String name = columns.getColumnByName("name").getStringValue(); assertEquals(name, "Alice"); // Iterate through the columns for (Column<String> c : columns) { assertTrue(ImmutableList.of("name", "company").contains(c.getName())); } } finally { context.shutdown(); } }
Keyspace keyspace = context.getEntity(); try { checkNull(keyspace.describeKeyspace().getColumnFamily(columnFamilyName), "key space for column family "+columnFamilyName);
protected static void checkConnection(int numRetries, Iterable<? extends Entity> nodes) throws ConnectionException { CassandraNode first = (CassandraNode) Iterables.get(nodes, 0); // have been seeing intermittent SchemaDisagreementException errors on AWS, probably due to Astyanax / how we are using it // (confirmed that clocks are in sync) String uniqueName = Identifiers.makeRandomId(8); AstyanaxSample astyanaxFirst = AstyanaxSample.builder().node(first).columnFamilyName(uniqueName).build(); Map<String, List<String>> versions; AstyanaxContext<Cluster> context = astyanaxFirst.newAstyanaxContextForCluster(); try { versions = context.getEntity().describeSchemaVersions(); } finally { context.shutdown(); } log.info("Cassandra schema versions are: "+versions); if (versions.size() > 1) { Assert.fail("Inconsistent versions on Cassandra start: "+versions); } String keyspacePrefix = "BrooklynTests_"+Identifiers.makeRandomId(8); String keyspaceName = astyanaxFirst.writeData(keyspacePrefix, numRetries); for (Entity node : nodes) { AstyanaxSample astyanaxSecond = AstyanaxSample.builder().node((CassandraNode)node).columnFamilyName(uniqueName).build(); astyanaxSecond.readData(keyspaceName, numRetries); } }
keyspace = keyspaceContext.getEntity();
keyspace = keyspaceContext.getEntity();
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()); } }