Search in sources :

Example 6 with ColumnFamilyDefinition

use of com.netflix.astyanax.ddl.ColumnFamilyDefinition in project titan by thinkaurelius.

the class AstyanaxStoreManager method ensureColumnFamilyExists.

private void ensureColumnFamilyExists(String name, String comparator) throws StorageException {
    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 TemporaryStorageException(e);
    }
}
Also used : KeyspaceDefinition(com.netflix.astyanax.ddl.KeyspaceDefinition) ColumnFamilyDefinition(com.netflix.astyanax.ddl.ColumnFamilyDefinition) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Example 7 with ColumnFamilyDefinition

use of com.netflix.astyanax.ddl.ColumnFamilyDefinition in project titan by thinkaurelius.

the class AstyanaxStoreManager method clearStorage.

@Override
public void clearStorage() throws StorageException {
    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 PermanentStorageException(e);
    }
}
Also used : ColumnFamilyDefinition(com.netflix.astyanax.ddl.ColumnFamilyDefinition) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Aggregations

ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)7 ColumnFamilyDefinition (com.netflix.astyanax.ddl.ColumnFamilyDefinition)7 KeyspaceDefinition (com.netflix.astyanax.ddl.KeyspaceDefinition)6 Cluster (com.netflix.astyanax.Cluster)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Keyspace (com.netflix.astyanax.Keyspace)2 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)2 PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)2 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 OperationException (com.netflix.astyanax.connectionpool.exceptions.OperationException)1 TemporaryStorageException (com.thinkaurelius.titan.diskstorage.TemporaryStorageException)1 UnknownHostException (java.net.UnknownHostException)1 TemporaryBackendException (org.janusgraph.diskstorage.TemporaryBackendException)1