I'm trying to use a basic definition of Hector to create a Cassandra Cluster. This is my code (only the connection and schema part).
CassandraHostConfigurator chc = new CassandraHostConfigurator(
"localhost");
chc.setMaxActive(20);
chc.setCassandraThriftSocketTimeout(3000);
chc.setMaxWaitTimeWhenExhausted(4000);
Cluster cluster = HFactory.getOrCreateCluster("mycluster", chc);
System.out.println("cluster: " + cluster.getKnownPoolHosts(false));
try{
KeyspaceDefinition keyspaceDef = cluster.describeKeyspace("sensornetwork");
} catch (HectorException he){
ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition("sensornetwork",
"ColumnFamilyName",
ComparatorType.BYTESTYPE);
KeyspaceDefinition newKeyspace = HFactory.createKeyspaceDefinition("sensornetwork",
ThriftKsDef.DEF_STRATEGY_CLASS,
1,
Arrays.asList(cfDef));
cluster.addKeyspace(newKeyspace, true);
}
// If keyspace does not exist, the CFs don't exist either. => create them.
Keyspace keyspace = HFactory.createKeyspace("sensornetwork", cluster);
I did this basically by following the Hector documentation on its own website.
The error I get is this one:
Exception in thread "main" me.prettyprint.hector.api.exceptions.HectorException: All host pools marked down. Retry burden pushed out to client. at me.prettyprint.cassandra.connection.HConnectionManager.getClientFromLBPolicy(HConnectionManager.java:401) at me.prettyprint.cassandra.connection.HConnectionManager.operateWithFailover(HConnectionManager.java:232) at me.prettyprint.cassandra.service.ThriftCluster.addKeyspace(ThriftCluster.java:168) at com.mycompany.mavenpails2.SpeedLayer.CassandraPrepwork(SpeedLayer.java:62)
Clearly I'm creating a cluster without a working pool connection. I've changed the port and tried everything but can't get it to work. Any suggestions?
Most likely "localhost" wasnt listening for thrift. Will probably want to use a cql client like https://github.com/datastax/java-driver instead. Otherwise make sure you have thrift enabled in cassandra.yaml