Search in sources :

Example 1 with KeyspaceDefinition

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

the class AstyanaxStoreManager method getCompressionOptions.

@Override
public Map<String, String> getCompressionOptions(String cf) throws BackendException {
    try {
        Keyspace k = keyspaceContext.getClient();
        KeyspaceDefinition kdef = k.describeKeyspace();
        if (null == kdef) {
            throw new PermanentBackendException("Keyspace " + k.getKeyspaceName() + " is undefined");
        }
        ColumnFamilyDefinition cfdef = kdef.getColumnFamily(cf);
        if (null == cfdef) {
            throw new PermanentBackendException("Column family " + cf + " is undefined");
        }
        return cfdef.getCompressionOptions();
    } catch (ConnectionException e) {
        throw new PermanentBackendException(e);
    }
}
Also used : KeyspaceDefinition(com.netflix.astyanax.ddl.KeyspaceDefinition) ColumnFamilyDefinition(com.netflix.astyanax.ddl.ColumnFamilyDefinition) PermanentBackendException(com.thinkaurelius.titan.diskstorage.PermanentBackendException) Keyspace(com.netflix.astyanax.Keyspace) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Example 2 with KeyspaceDefinition

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

the class AstyanaxStoreManager method ensureKeyspaceExists.

private void ensureKeyspaceExists(Cluster cl) throws BackendException {
    KeyspaceDefinition ksDef;
    try {
        ksDef = cl.describeKeyspace(keySpaceName);
        if (null != ksDef && ksDef.getName().equals(keySpaceName)) {
            log.debug("Found keyspace {}", keySpaceName);
            return;
        }
    } catch (ConnectionException e) {
        log.debug("Failed to describe keyspace {}", keySpaceName);
    }
    log.debug("Creating keyspace {}...", keySpaceName);
    try {
        ksDef = cl.makeKeyspaceDefinition().setName(keySpaceName).setStrategyClass(storageConfig.get(REPLICATION_STRATEGY)).setStrategyOptions(strategyOptions);
        cl.addKeyspace(ksDef);
        log.debug("Created keyspace {}", keySpaceName);
    } catch (ConnectionException e) {
        log.debug("Failed to create keyspace {}", keySpaceName);
        throw new TemporaryBackendException(e);
    }
}
Also used : KeyspaceDefinition(com.netflix.astyanax.ddl.KeyspaceDefinition) TemporaryBackendException(com.thinkaurelius.titan.diskstorage.TemporaryBackendException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Example 3 with KeyspaceDefinition

use of com.netflix.astyanax.ddl.KeyspaceDefinition 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)

Aggregations

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