Search in sources :

Example 1 with Cluster

use of com.netflix.astyanax.Cluster in project titan by thinkaurelius.

the class AstyanaxStoreManager method ensureColumnFamilyExists.

private void ensureColumnFamilyExists(String name, String comparator) throws BackendException {
    Cluster cl = clusterContext.getClient();
    try {
        KeyspaceDefinition ksDef = cl.describeKeyspace(keySpaceName);
        boolean found = false;
        if (null != ksDef) {
            for (ColumnFamilyDefinition cfDef : ksDef.getColumnFamilyList()) {
                found |= cfDef.getName().equals(name);
            }
        }
        if (!found) {
            ColumnFamilyDefinition cfDef = cl.makeColumnFamilyDefinition().setName(name).setKeyspace(keySpaceName).setComparatorType(comparator);
            ImmutableMap.Builder<String, String> compressionOptions = new ImmutableMap.Builder<String, String>();
            if (compressionEnabled) {
                compressionOptions.put("sstable_compression", compressionClass).put("chunk_length_kb", Integer.toString(compressionChunkSizeKB));
            }
            cl.addColumnFamily(cfDef.setCompressionOptions(compressionOptions.build()));
        }
    } catch (ConnectionException e) {
        throw new TemporaryBackendException(e);
    }
}
Also used : KeyspaceDefinition(com.netflix.astyanax.ddl.KeyspaceDefinition) TemporaryBackendException(com.thinkaurelius.titan.diskstorage.TemporaryBackendException) ColumnFamilyDefinition(com.netflix.astyanax.ddl.ColumnFamilyDefinition) Cluster(com.netflix.astyanax.Cluster) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Example 2 with Cluster

use of com.netflix.astyanax.Cluster in project titan by thinkaurelius.

the class AstyanaxStoreManager method clearStorage.

@Override
public void clearStorage() throws BackendException {
    try {
        Cluster cluster = clusterContext.getClient();
        Keyspace ks = cluster.getKeyspace(keySpaceName);
        // everything up, so first invocation would always fail as Keyspace doesn't yet exist.
        if (ks == null)
            return;
        for (ColumnFamilyDefinition cf : cluster.describeKeyspace(keySpaceName).getColumnFamilyList()) {
            ks.truncateColumnFamily(new ColumnFamily<Object, Object>(cf.getName(), null, null));
        }
    } catch (ConnectionException e) {
        throw new PermanentBackendException(e);
    }
}
Also used : ColumnFamilyDefinition(com.netflix.astyanax.ddl.ColumnFamilyDefinition) PermanentBackendException(com.thinkaurelius.titan.diskstorage.PermanentBackendException) Keyspace(com.netflix.astyanax.Keyspace) Cluster(com.netflix.astyanax.Cluster) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Aggregations

Cluster (com.netflix.astyanax.Cluster)2 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)2 ColumnFamilyDefinition (com.netflix.astyanax.ddl.ColumnFamilyDefinition)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Keyspace (com.netflix.astyanax.Keyspace)1 KeyspaceDefinition (com.netflix.astyanax.ddl.KeyspaceDefinition)1 PermanentBackendException (com.thinkaurelius.titan.diskstorage.PermanentBackendException)1 TemporaryBackendException (com.thinkaurelius.titan.diskstorage.TemporaryBackendException)1