use of com.datastax.driver.core.schemabuilder.KeyspaceOptions in project kafka-connect-scylladb by scylladb.
the class ScyllaDbSinkConnector method start.
/**
* Start the Connector. The method will establish a ScyllaDB session
* and perform the following:<ol>
* <li>Create a keyspace with the name under <code>scylladb.keyspace</code> configuration,
* if <code>scylladb.keyspace.create.enabled</code> is set to true.
* <li>Create a table for managing offsets in ScyllaDB with the name under
* <code>scylladb.offset.storage.table</code> configuration,
* if <code>scylladb.offset.storage.table.enable</code> is set to true.
* </ol>
*/
@Override
public void start(Map<String, String> settings) {
config = new ScyllaDbSinkConnectorConfig(settings);
ScyllaDbSessionFactory sessionFactory = new ScyllaDbSessionFactory();
try (ScyllaDbSession session = sessionFactory.newSession(config)) {
if (config.keyspaceCreateEnabled) {
KeyspaceOptions createKeyspace = SchemaBuilder.createKeyspace(config.keyspace).ifNotExists().with().durableWrites(true).replication(ImmutableMap.of("class", (Object) "SimpleStrategy", "replication_factor", config.keyspaceReplicationFactor));
session.executeStatement(createKeyspace);
}
if (config.offsetEnabledInScyllaDB) {
final Create createOffsetStorage = SchemaBuilder.createTable(config.keyspace, config.offsetStorageTable).addPartitionKey("topic", DataType.varchar()).addPartitionKey("partition", DataType.cint()).addColumn("offset", DataType.bigint()).ifNotExists();
session.executeStatement(createOffsetStorage);
}
} catch (IOException ex) {
// TODO: improve error handling for both cases
throw new ConnectException("Failed to start the Connector.", ex);
}
}
use of com.datastax.driver.core.schemabuilder.KeyspaceOptions in project scalardb by scalar-labs.
the class CassandraAdminTest method createNamespace_UseNetworkTopologyStrategy_ShouldExecuteCreateKeyspaceStatement.
@Test
public void createNamespace_UseNetworkTopologyStrategy_ShouldExecuteCreateKeyspaceStatement() throws ExecutionException {
// Arrange
String namespace = "sample_ns";
Map<String, String> options = new HashMap<>();
options.put(CassandraAdmin.REPLICATION_STRATEGY, ReplicationStrategy.NETWORK_TOPOLOGY_STRATEGY.toString());
options.put(CassandraAdmin.REPLICATION_FACTOR, "5");
// Act
cassandraAdmin.createNamespace(namespace, options);
// Assert
Map<String, Object> replicationOptions = new LinkedHashMap<>();
replicationOptions.put("class", ReplicationStrategy.NETWORK_TOPOLOGY_STRATEGY.toString());
replicationOptions.put("dc1", "5");
KeyspaceOptions query = SchemaBuilder.createKeyspace(namespace).with().replication(replicationOptions);
verify(cassandraSession).execute(query.getQueryString());
}
use of com.datastax.driver.core.schemabuilder.KeyspaceOptions in project scalardb by scalar-labs.
the class CassandraAdminTest method createNamespace_UseSimpleStrategy_ShouldExecuteCreateKeyspaceStatement.
@Test
public void createNamespace_UseSimpleStrategy_ShouldExecuteCreateKeyspaceStatement() throws ExecutionException {
// Arrange
String namespace = "sample_ns";
Map<String, String> options = new HashMap<>();
options.put(CassandraAdmin.REPLICATION_STRATEGY, ReplicationStrategy.SIMPLE_STRATEGY.toString());
options.put(CassandraAdmin.REPLICATION_FACTOR, "3");
// Act
cassandraAdmin.createNamespace(namespace, options);
// Assert
Map<String, Object> replicationOptions = new LinkedHashMap<>();
replicationOptions.put("class", ReplicationStrategy.SIMPLE_STRATEGY.toString());
replicationOptions.put("replication_factor", "3");
KeyspaceOptions query = SchemaBuilder.createKeyspace(namespace).with().replication(replicationOptions);
verify(cassandraSession).execute(query.getQueryString());
}
use of com.datastax.driver.core.schemabuilder.KeyspaceOptions in project scalardb by scalar-labs.
the class CassandraAdminTest method createNamespace_WithoutReplicationStrategyNorReplicationFactor_ShouldExecuteCreateKeyspaceStatementWithSimpleStrategy.
@Test
public void createNamespace_WithoutReplicationStrategyNorReplicationFactor_ShouldExecuteCreateKeyspaceStatementWithSimpleStrategy() throws ExecutionException {
// Arrange
String namespace = "sample_ns";
Map<String, String> options = new HashMap<>();
// Act
cassandraAdmin.createNamespace(namespace, options);
// Assert
Map<String, Object> replicationOptions = new LinkedHashMap<>();
replicationOptions.put("class", ReplicationStrategy.SIMPLE_STRATEGY.toString());
replicationOptions.put("replication_factor", "1");
KeyspaceOptions query = SchemaBuilder.createKeyspace(namespace).with().replication(replicationOptions);
verify(cassandraSession).execute(query.getQueryString());
}
use of com.datastax.driver.core.schemabuilder.KeyspaceOptions in project scalardb by scalar-labs.
the class CassandraAdminTest method createNamespace_WithReservedKeywords_ShouldExecuteCreateKeyspaceStatementProperly.
@Test
public void createNamespace_WithReservedKeywords_ShouldExecuteCreateKeyspaceStatementProperly() throws ExecutionException {
// Arrange
String namespace = "keyspace";
Map<String, String> options = Collections.emptyMap();
// Act
cassandraAdmin.createNamespace(namespace, options);
// Assert
Map<String, Object> replicationOptions = new LinkedHashMap<>();
replicationOptions.put("class", ReplicationStrategy.SIMPLE_STRATEGY.toString());
replicationOptions.put("replication_factor", "1");
KeyspaceOptions query = SchemaBuilder.createKeyspace(quote(namespace)).with().replication(replicationOptions);
verify(cassandraSession).execute(query.getQueryString());
}
Aggregations