Search in sources :

Example 1 with ColumnFamilyDefinition

use of com.netflix.astyanax.ddl.ColumnFamilyDefinition in project coprhd-controller by CoprHD.

the class SchemaUtil method dropUnusedCfsIfExists.

public boolean dropUnusedCfsIfExists() {
    AstyanaxContext<Cluster> context = clientContext.getClusterContext();
    try {
        KeyspaceDefinition kd = context.getClient().describeKeyspace(_clusterName);
        if (kd == null) {
            String errMsg = "Fatal error: Keyspace not exist when drop cf";
            _log.error(errMsg);
            throw new IllegalStateException(errMsg);
        }
        for (String cfName : DbSchemaInterceptorImpl.getIgnoreCfList()) {
            ColumnFamilyDefinition cfd = kd.getColumnFamily(cfName);
            if (cfd != null) {
                _log.info("drop cf {} from db", cfName);
                String schemaVersion = dropColumnFamily(cfName, context);
                clientContext.waitForSchemaAgreement(schemaVersion);
            }
        }
    } catch (Exception e) {
        _log.error("drop Cf error ", e);
        return false;
    }
    return true;
}
Also used : KeyspaceDefinition(com.netflix.astyanax.ddl.KeyspaceDefinition) ColumnFamilyDefinition(com.netflix.astyanax.ddl.ColumnFamilyDefinition) Cluster(com.netflix.astyanax.Cluster) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) OperationException(com.netflix.astyanax.connectionpool.exceptions.OperationException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) UnknownHostException(java.net.UnknownHostException)

Example 2 with ColumnFamilyDefinition

use of com.netflix.astyanax.ddl.ColumnFamilyDefinition in project janusgraph by JanusGraph.

the class AstyanaxStoreManager method ensureColumnFamilyExists.

private void ensureColumnFamilyExists(String name) 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("org.apache.cassandra.db.marshal.BytesType");
            final ImmutableMap.Builder<String, String> compressionOptions = new ImmutableMap.Builder<>();
            if (storageConfig.has(COMPACTION_STRATEGY)) {
                cfDef.setCompactionStrategy(storageConfig.get(COMPACTION_STRATEGY));
            }
            if (!compactionOptions.isEmpty()) {
                cfDef.setCompactionStrategyOptions(compactionOptions);
            }
            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(org.janusgraph.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 3 with ColumnFamilyDefinition

use of com.netflix.astyanax.ddl.ColumnFamilyDefinition in project janusgraph by JanusGraph.

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;
        if (this.storageConfig.get(GraphDatabaseConfiguration.DROP_ON_CLEAR)) {
            ks.dropKeyspace();
        } else {
            final KeyspaceDefinition keyspaceDefinition = cluster.describeKeyspace(keySpaceName);
            if (keyspaceDefinition == null) {
                return;
            }
            for (final ColumnFamilyDefinition cf : keyspaceDefinition.getColumnFamilyList()) {
                ks.truncateColumnFamily(new ColumnFamily<>(cf.getName(), null, null));
            }
        }
    } catch (ConnectionException e) {
        throw new PermanentBackendException(e);
    }
}
Also used : KeyspaceDefinition(com.netflix.astyanax.ddl.KeyspaceDefinition) ColumnFamilyDefinition(com.netflix.astyanax.ddl.ColumnFamilyDefinition) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) Keyspace(com.netflix.astyanax.Keyspace) Cluster(com.netflix.astyanax.Cluster) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Example 4 with ColumnFamilyDefinition

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

the class AstyanaxStoreManager method getCompressionOptions.

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

Example 5 with ColumnFamilyDefinition

use of com.netflix.astyanax.ddl.ColumnFamilyDefinition in project janusgraph by JanusGraph.

the class AstyanaxStoreManager method getCompressionOptions.

@Override
public Map<String, String> getCompressionOptions(String cf) throws BackendException {
    try {
        Keyspace k = keyspaceContext.getClient();
        KeyspaceDefinition keyspaceDefinition = k.describeKeyspace();
        if (null == keyspaceDefinition) {
            throw new PermanentBackendException("Keyspace " + k.getKeyspaceName() + " is undefined");
        }
        ColumnFamilyDefinition columnFamilyDefinition = keyspaceDefinition.getColumnFamily(cf);
        if (null == columnFamilyDefinition) {
            throw new PermanentBackendException("Column family " + cf + " is undefined");
        }
        return columnFamilyDefinition.getCompressionOptions();
    } catch (ConnectionException e) {
        throw new PermanentBackendException(e);
    }
}
Also used : KeyspaceDefinition(com.netflix.astyanax.ddl.KeyspaceDefinition) ColumnFamilyDefinition(com.netflix.astyanax.ddl.ColumnFamilyDefinition) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) Keyspace(com.netflix.astyanax.Keyspace) 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