@RequestParam("replicationFactor") int replicationFactor,
@RequestParam("strategy") String strategy,
ModelMap model
) throws Exception {
Client client = clientProvider.getThriftClient();
name = name.trim();
if (name.length() == 0) {
throw new IllegalArgumentException("Name must not be empty");
}
String strategyClass = null;
if (strategy.equals("Simple")) {
strategyClass ="org.apache.cassandra.locator SimpleStrategy";
} else if (strategy.equals("NetworkTopology")) {
strategyClass = "org.apache.cassandra.locator NetworkTopologyStrategy";
} else if (strategy.equals("OldNetworkTopology")) {
strategyClass = "org.apache.cassandra.locator.OldNetworkTopologyStrategy";
}
KsDef ksDef = new KsDef(name, strategyClass, new ArrayList<CfDef>());
Map<String, String> strategyOptions = new HashMap<String, String>();
strategyOptions.put("replication_factor", String.valueOf(replicationFactor));
ksDef.setStrategy_options(strategyOptions);
client.system_add_keyspace(ksDef);
model.clear();
return "redirect:/keyspace/" + name + "/";
}