use of com.github.nosan.embedded.cassandra.CassandraBuilder in project embedded-cassandra by nosan.
the class CassandraExamples method quickStart.
private void quickStart() {
// tag::quick-start[]
Cassandra cassandra = new CassandraBuilder().build();
cassandra.start();
try {
Settings settings = cassandra.getSettings();
try (CqlSession session = CqlSession.builder().addContactPoint(new InetSocketAddress(settings.getAddress(), settings.getPort())).withLocalDatacenter("datacenter1").build()) {
CqlScript.ofClassPath("schema.cql").forEachStatement(session::execute);
}
} finally {
cassandra.stop();
}
// end::quick-start[]
}
use of com.github.nosan.embedded.cassandra.CassandraBuilder in project embedded-cassandra by nosan.
the class CassandraExamples method workingDirectoryInitializer.
// end::start-shared-cassandra[]
private void workingDirectoryInitializer() {
// tag::working-directory-initializer[]
new CassandraBuilder().workingDirectoryInitializer(new WorkingDirectoryInitializer() {
@Override
public void init(Path workingDirectory, Version version) throws IOException {
// Custom logic
}
}).build();
// end::working-directory-initializer[]
// tag::working-directory-initializer-skip-existing[]
new CassandraBuilder().workingDirectoryInitializer(new DefaultWorkingDirectoryInitializer(new WebCassandraDirectoryProvider(), DefaultWorkingDirectoryInitializer.CopyStrategy.SKIP_EXISTING)).build();
// end::working-directory-initializer-skip-existing[]
}
use of com.github.nosan.embedded.cassandra.CassandraBuilder in project esop by instaclustr.
the class AbstractBackupTest method getCassandra.
protected Cassandra getCassandra(final Path cassandraHome, final String version, final WorkingDirectoryCustomizer customizer) throws Exception {
FileUtils.createDirectory(cassandraHome);
CassandraBuilder builder = new CassandraBuilder();
builder.version(Version.parse(version));
builder.jvmOptions("-Dcassandra.ring_delay_ms=1000", "-Xms1g", "-Xmx1g");
builder.workingDirectory(() -> cassandraHome);
builder.addConfigProperties(new HashMap<String, Object>() {
{
put("data_file_directories", new ArrayList<String>() {
{
add(cassandraHome.toAbsolutePath() + "/data/data");
add(cassandraHome.toAbsolutePath() + "/data/data2");
add(cassandraHome.toAbsolutePath() + "/data/data3");
}
});
}
});
if (customizer != null) {
builder.workingDirectoryCustomizers(customizer);
}
if (version.startsWith("2")) {
FileUtils.createDirectory(cassandraHome.resolve("data").resolve("data"));
builder.addConfigProperties(new HashMap<String, String[]>() {
{
put("data_file_directories", new String[] { cassandraHome.resolve("data").resolve("data").toAbsolutePath().toString() });
}
});
}
return builder.build();
}
use of com.github.nosan.embedded.cassandra.CassandraBuilder in project embedded-cassandra by nosan.
the class CassandraExamples method clientEncryptionOptions.
private void clientEncryptionOptions() {
// tag::client-encryption-options[]
ClassPathResource keystore = new ClassPathResource("server.keystore");
ClassPathResource truststore = new ClassPathResource("server.truststore");
new CassandraBuilder().addWorkingDirectoryResource(keystore, "conf/server.keystore").addWorkingDirectoryResource(truststore, "conf/server.truststore").addConfigProperty("client_encryption_options.enabled", true).addConfigProperty("client_encryption_options.require_client_auth", true).addConfigProperty("client_encryption_options.optional", false).addConfigProperty("client_encryption_options.keystore", "conf/server.keystore").addConfigProperty("client_encryption_options.truststore", "conf/server.truststore").addConfigProperty("client_encryption_options.keystore_password", "123456").addConfigProperty("client_encryption_options.truststore_password", "123456").addConfigProperty("native_transport_port_ssl", 9142).build();
// end::client-encryption-options[]
}
use of com.github.nosan.embedded.cassandra.CassandraBuilder in project embedded-cassandra-spring-boot-starter by nosan.
the class EmbeddedCassandraAutoConfiguration method embeddedCassandraBuilder.
@Bean
@ConditionalOnMissingBean
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
CassandraBuilder embeddedCassandraBuilder(EmbeddedCassandraProperties properties, ObjectProvider<CassandraBuilderConfigurator> configurators) throws IOException {
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
CassandraBuilder builder = new CassandraBuilder();
builder.addEnvironmentVariables(properties.getEnvironmentVariables());
builder.addSystemProperties(properties.getSystemProperties());
builder.addConfigProperties(properties.getConfigProperties());
builder.addJvmOptions(properties.getJvmOptions());
map.from(properties::getRegisterShutdownHook).to(builder::registerShutdownHook);
map.from(properties::getVersion).whenHasText().to(builder::version);
map.from(properties::getLogger).whenHasText().as(Logger::get).to(builder::logger);
map.from(properties::getName).whenHasText().to(builder::name);
map.from(properties::getWorkingDirectory).to(workingDirectory -> builder.workingDirectory(() -> workingDirectory));
map.from(properties::getStartupTimeout).whenNot(Duration::isNegative).whenNot(Duration::isZero).to(builder::startupTimeout);
Resource configFile = properties.getConfigFile();
if (configFile != null) {
builder.configFile(new UrlResource(configFile.getURL()));
}
for (Map.Entry<String, Resource> entry : properties.getWorkingDirectoryResources().entrySet()) {
builder.addWorkingDirectoryResource(new UrlResource(entry.getValue().getURL()), entry.getKey());
}
configurators.orderedStream().forEach(builder::configure);
return builder;
}
Aggregations