/** * Create the kespace, ignore exceptions if it already exists * @param keyspace */ public static void createKeyspace(final Keyspace keyspace){ ImmutableMap.Builder<Object, Object> strategyOptions = ImmutableMap.builder().put( "replication_factor", "1" ); ImmutableMap<String, Object> options = ImmutableMap.<String, Object>builder().put( "strategy_class", "org.apache.cassandra.locator.SimpleStrategy" ).put( "strategy_options", strategyOptions.build() ) .build(); try { keyspace.createKeyspaceIfNotExists( options ); } catch ( Throwable t ) { logger.info( "Error on creating keyspace, ignoring", t ); } }
@Override public OperationResult<SchemaChangeResult> exec(Keyspace ks) throws ConnectionException { return ks.createKeyspaceIfNotExists(options); } });
@Override public OperationResult<SchemaChangeResult> exec(Keyspace ks) throws ConnectionException { return ks.createKeyspaceIfNotExists(properties); } });
@Override public OperationResult<SchemaChangeResult> exec(Keyspace ks) throws ConnectionException { return ks.createKeyspaceIfNotExists(options, cfs); } });
private Keyspace createKeyspaceIfNotExists() { // Don't do in production; better to create from cqlsh to avoid parallel issues from eventual consistency. Keyspace ks = null; try { ks = keyspaceContext.getClient(); Properties props = new Properties(); props.setProperty("name", KEYSPACE_NAME); props.setProperty("strategy_class", "SimpleStrategy"); props.setProperty("strategy_options.replication_factor", "1"); ks.createKeyspaceIfNotExists(props); KeyspaceDefinition ksDef = ks.describeKeyspace(); } catch (Exception e) { logger.info("Didn't (re)create keyspace, message={}", e.getMessage()); } return ks; }
private Keyspace createKeyspaceIfNotExists() { // Don't do in production; better to create from cqlsh to avoid parallel issues from eventual consistency. Keyspace ks = null; try { ks = keyspaceContext.getClient(); Properties props = new Properties(); props.setProperty("name", KEYSPACE_NAME); props.setProperty("strategy_class", "SimpleStrategy"); props.setProperty("strategy_options.replication_factor", "1"); ks.createKeyspaceIfNotExists(props); KeyspaceDefinition ksDef = ks.describeKeyspace(); } catch (Exception e) { logger.info("Didn't (re)create keyspace, message={}", e.getMessage()); } return ks; }