use of org.apache.cassandra.thrift.KsDef in project coprhd-controller by CoprHD.
the class GeoDbSvcStartupTest method checkSchema.
@Test
public void checkSchema() throws Exception {
// Check if snitch setup is OK
NodeProbe cmd = new NodeProbe(HOST, JMX_PORT);
String dc = cmd.getDataCenter();
Assert.assertTrue("Unexpected DC name " + dc, "vdc1".equalsIgnoreCase(dc));
// Check schema setup is OK
TSocket socket = new TSocket(HOST, RPC_PORT);
TTransport transport = new TFastFramedTransport(socket);
transport.open();
try {
Cassandra.Client client = new Cassandra.Client(new TBinaryProtocol(transport, true, true));
KsDef def = client.describe_keyspace(DbClientContext.GEO_KEYSPACE_NAME);
String strategyClass = def.strategy_class;
log.info("Current strategy class in geodb schema: " + strategyClass);
Assert.assertTrue("Unexpected strategy class " + strategyClass, strategyClass.contains("NetworkTopologyStrategy"));
Map<String, String> strategyOptions = def.getStrategy_options();
Assert.assertTrue(strategyOptions.size() > 0);
} finally {
transport.close();
}
}
use of org.apache.cassandra.thrift.KsDef in project scale7-pelops by s7.
the class AbstractIntegrationTest method setup.
/**
* Starts embedded cassandra server.
*
* @throws Exception
* if an error occurs
*/
public static void setup(List<CfDef> columnDefinitions) throws Exception {
if (cassandraServer == null) {
cassandraServer = new EmbeddedCassandraServer();
cassandraServer.start();
// wait until cassandra server starts up. could wait less time, but
// 2 seconds to be sure.
Thread.sleep(2000);
}
colFamilyDefs = columnDefinitions;
keyspaceManager = new KeyspaceManager(cluster);
columnFamilyManager = new ColumnFamilyManager(cluster, KEYSPACE);
List<KsDef> keyspaces = keyspaceManager.getKeyspaceNames();
for (KsDef ksDef : keyspaces) if (ksDef.name.equals(KEYSPACE)) {
keyspaceManager.dropKeyspace(KEYSPACE);
}
KsDef keyspaceDefinition = new KsDef(KEYSPACE, KeyspaceManager.KSDEF_STRATEGY_SIMPLE, new ArrayList<CfDef>());
Map<String, String> strategyOptions = new HashMap<String, String>();
strategyOptions.put("replication_factor", "1");
keyspaceDefinition.setStrategy_options(strategyOptions);
for (CfDef colFamilyDef : colFamilyDefs) {
keyspaceDefinition.addToCf_defs(colFamilyDef);
}
keyspaceManager.addKeyspace(keyspaceDefinition);
}
use of org.apache.cassandra.thrift.KsDef in project eiger by wlloyd.
the class KSMetaData method toThrift.
public KsDef toThrift() {
List<CfDef> cfDefs = new ArrayList<CfDef>();
for (CFMetaData cfm : cfMetaData().values()) cfDefs.add(cfm.toThrift());
KsDef ksdef = new KsDef(name, strategyClass.getName(), cfDefs);
ksdef.setStrategy_options(strategyOptions);
if (strategyOptions != null && strategyOptions.containsKey("replication_factor"))
ksdef.setReplication_factor(Integer.parseInt(strategyOptions.get("replication_factor")));
ksdef.setDurable_writes(durableWrites);
return ksdef;
}
use of org.apache.cassandra.thrift.KsDef in project titan by thinkaurelius.
the class CassandraThriftStoreManager method ensureKeyspaceExists.
private KsDef ensureKeyspaceExists(String keyspaceName) throws NotFoundException, InvalidRequestException, TException, SchemaDisagreementException, StorageException {
CTConnection connection = null;
try {
connection = pool.borrowObject(SYSTEM_KS);
Cassandra.Client client = connection.getClient();
try {
// Side effect: throws Exception if keyspaceName doesn't exist
// Don't remove
client.set_keyspace(keyspaceName);
client.set_keyspace(SYSTEM_KS);
log.debug("Found existing keyspace {}", keyspaceName);
} catch (InvalidRequestException e) {
// Keyspace didn't exist; create it
log.debug("Creating keyspace {}...", keyspaceName);
KsDef ksdef = new KsDef().setName(keyspaceName).setCf_defs(// cannot be null but can be empty
new LinkedList<CfDef>()).setStrategy_class("org.apache.cassandra.locator.SimpleStrategy").setStrategy_options(ImmutableMap.of("replication_factor", String.valueOf(replicationFactor)));
client.set_keyspace(SYSTEM_KS);
try {
client.system_add_keyspace(ksdef);
log.debug("Created keyspace {}", keyspaceName);
} catch (InvalidRequestException ire) {
log.error("system_add_keyspace failed for keyspace=" + keyspaceName, ire);
throw ire;
}
}
return client.describe_keyspace(keyspaceName);
} catch (Exception e) {
throw new TemporaryStorageException(e);
} finally {
pool.returnObjectUnsafe(SYSTEM_KS, connection);
}
}
use of org.apache.cassandra.thrift.KsDef in project titan by thinkaurelius.
the class CassandraThriftStoreManager method getCompressionOptions.
@Override
public Map<String, String> getCompressionOptions(String cf) throws StorageException {
CTConnection conn = null;
Map<String, String> result = null;
try {
conn = pool.borrowObject(keySpaceName);
Cassandra.Client client = conn.getClient();
KsDef ksDef = client.describe_keyspace(keySpaceName);
for (CfDef cfDef : ksDef.getCf_defs()) {
if (null != cfDef && cfDef.getName().equals(cf)) {
result = cfDef.getCompression_options();
break;
}
}
return result;
} catch (InvalidRequestException e) {
log.debug("Keyspace {} does not exist", keySpaceName);
return null;
} catch (Exception e) {
throw new TemporaryStorageException(e);
} finally {
pool.returnObjectUnsafe(keySpaceName, conn);
}
}
Aggregations