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;
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations