Search code examples
cassandrahector

Create a Cassandra keyspace with 'network topology' using Hector?


I want to create a Cassandra keyspace with 'network topology'. I can do it using CLI like this.

CREATE KEYSPACE test
WITH placement_strategy = 'NetworkTopologyStrategy'
AND strategy_options={us-east:6,us-west:3};

How can I achieve the same using Hector?

Thanks,
Bhathiya


Solution

  • For the record, this works.

    Map<String,String> options = new HashMap<String,String>();
    options.put("dc1", "3");    
    options.put("dc2", "1");    
    ThriftKsDef kd = (ThriftKsDef) HFactory.createKeyspaceDefinition(keyspaceName,
         strategyClass, replicationFactor, cfDefs);    
    if(options != null){    
         kd.setStrategyOptions(options);    
    }    
    getCluster().addKeyspace(kd, true);