public static KsDef createKeySpace() throws IOException {
try {
logger.info("Creating keyspace: " + KEYSPACE_NAME);
Thread.sleep(new Random().nextInt(5000));
KsDef cfsKs = checkKeyspace();
if (cfsKs != null) {
logger.info("keyspace already exists. Skipping creation.");
return cfsKs;
}
List<CfDef> cfs = new ArrayList<CfDef>();
CfDef cf = new CfDef();
cf.setName(JOB_TRACKER_CF);
cf.setComparator_type("BytesType");
// there is only one row and one column.
cf.setKey_cache_size(10);
cf.setRow_cache_size(10);
cf.setGc_grace_seconds(60);
cf.setComment("Stores the current JobTracker node");
cf.setKeyspace(KEYSPACE_NAME);
cfs.add(cf);
Map<String, String> stratOpts = new HashMap<String, String>();
stratOpts.put(BriskSimpleSnitch.BRISK_DC, System.getProperty("cfs.replication", "1"));
stratOpts.put(BriskSimpleSnitch.CASSANDRA_DC, "0");
cfsKs = new KsDef().setName(KEYSPACE_NAME)
.setStrategy_class("org.apache.cassandra.locator.NetworkTopologyStrategy")
.setStrategy_options(stratOpts).setCf_defs(cfs);
client.system_add_keyspace(cfsKs);
waitForSchemaAgreement(client);