4

Is there a way to check if an Astyanax Keyspace exists in the current context? Right now my code does the following:

keyspace = context.getClient();
try{
   keyspace.describeKeyspace(); 
}catch (BadRequestException e){
   keyspace.createKeyspace(ImmutableMap.<String, Object>builder()
                .put("strategy_options", ImmutableMap.<String, Object>builder()
                        .put("replication_factor", "1")
                        .build())
                .put("strategy_class", "SimpleStrategy")
                .build();
}

Is this the only way to check if the keyspace exists?

Danny Sullivan
  • 3,626
  • 3
  • 30
  • 39

1 Answers1

0

I'm doing it like this...

try {
    keyspace.getKeyspaceProperties();
    LOG.debug("keyspace exist");
} catch (Exception e) {
    LOG.debug("keyspace does NOT exist");
}

This code will generate an exception so be sure to put some comment. If people check the log they will understand what is going on

UPDATE There is a person who made a feature request on github Issue #382. Hope it help...

Pokstar
  • 1
  • 3
  • I think this is essentially what I'm doing above, but using the getKeyspaceProperties method as opposed to the describeKeyspace method. I was looking for something along the lines of if(keyspace.getKeyspaceProperties() == null){ ... } – Danny Sullivan Aug 17 '13 at 14:07