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