Skip to content
Permalink
Browse files
Optionally support multiple cassandra instances in Sidecar
  • Loading branch information
sarankk authored and yifan-c committed Feb 23, 2022
1 parent 083772f commit fae3cb041ad547d11a759ea14bab66e932d27c16
Showing 32 changed files with 879 additions and 182 deletions.
@@ -1,5 +1,6 @@
1.0.0
-----
* Optionally support multiple cassandra instances in Sidecar (CASSANDRASC-33)
* Call the start method of CassandraAdaptorDelegate to start periodic health check (CASSANDRASC-32)
* Avoid having sidecar's health response code depend on Cassandra's health information (CASSANDRASC-29)
* Add Stream SSTable API to Sidecar to stream SSTable components through zero copy streaming (CASSANDRASC-28)
@@ -83,7 +83,7 @@ allprojects {
configFile file("${project.rootDir}/checkstyle.xml")
}
spotbugs {
toolVersion = '4.0.0'
toolVersion = '4.2.3'
excludeFilter = file("${project.rootDir}/spotbugs-exclude.xml")
}

@@ -147,12 +147,12 @@ configurations {
}

dependencies {
compile 'io.vertx:vertx-web:3.8.5'
compile 'io.vertx:vertx-dropwizard-metrics:3.8.5'
compile 'io.vertx:vertx-web-client:3.8.5'
compile "io.vertx:vertx-web:${project.vertxVersion}"
compile "io.vertx:vertx-dropwizard-metrics:${project.vertxVersion}"
compile "io.vertx:vertx-web-client:${project.vertxVersion}"

compile 'io.swagger.core.v3:swagger-jaxrs2:2.1.0'
compile 'org.jboss.resteasy:resteasy-vertx:3.1.2.Final'
compile "org.jboss.resteasy:resteasy-vertx:4.7.4.Final"
compile group: 'org.jboss.spec.javax.servlet', name: 'jboss-servlet-api_4.0_spec', version: '2.0.0.Final'

// Trying to be exactly compatible with Cassandra's deps
@@ -176,8 +176,8 @@ dependencies {
testCompile group: 'org.cassandraunit', name: 'cassandra-unit-shaded', version: '3.11.2.0'
testCompile 'com.datastax.cassandra:cassandra-driver-core:3.9.0:tests'
testCompile group: 'org.mockito', name: 'mockito-all', version: '1.10.19'
testCompile group: 'io.vertx', name: 'vertx-junit5', version: '3.8.5'

testCompile group: 'io.vertx', name: 'vertx-junit5', version: "${project.vertxVersion}"
compile project(":common")
compile project(":cassandra40")
}
@@ -2,3 +2,4 @@ version=1.0-SNAPSHOT
junitVersion=5.4.2
kubernetesClientVersion=9.0.0
cassandra40Version=4.0.1
vertxVersion=4.2.1
@@ -1,11 +1,15 @@
#
# Cassandra SideCar configuration file
#

cassandra:
- host: localhost
- port: 9042
- data_dirs: /cassandra/d1/data, /cassandra/d2/data
cassandra_instances:
- id: 1
host: localhost1
port: 9042
data_dirs: /cassandra/d1/data, /cassandra/d2/data
- id: 2
host: localhost2
port: 9042
data_dirs: /cassandra/d3/data, /cassandra/d4/data

sidecar:
- host: 0.0.0.0
@@ -27,24 +27,22 @@
import com.google.inject.Inject;
import com.google.inject.Singleton;
import io.vertx.core.http.HttpServer;
import org.apache.cassandra.sidecar.common.CassandraAdapterDelegate;
import org.apache.cassandra.sidecar.utils.SslUtils;

/**
* Main class for initiating the Cassandra sidecar
* Note: remember to start and stop all delegates of instances
*/
@Singleton
public class CassandraSidecarDaemon
{
private static final Logger logger = LoggerFactory.getLogger(CassandraSidecarDaemon.class);
private final CassandraAdapterDelegate delegate;
private final HttpServer server;
private final Configuration config;

@Inject
public CassandraSidecarDaemon(CassandraAdapterDelegate delegate, HttpServer server, Configuration config)
public CassandraSidecarDaemon(HttpServer server, Configuration config)
{
this.delegate = delegate;
this.server = server;
this.config = config;
}
@@ -53,16 +51,16 @@ public void start()
{
banner(System.out);
validate();
delegate.start();
logger.info("Starting Cassandra Sidecar on {}:{}", config.getHost(), config.getPort());
server.listen(config.getPort(), config.getHost());
this.config.getInstancesConfig().instances().forEach(instanceMetadata -> instanceMetadata.delegate().start());
}

public void stop()
{
logger.info("Stopping Cassandra Sidecar");
delegate.stop();
server.close();
this.config.getInstancesConfig().instances().forEach(instanceMetadata -> instanceMetadata.delegate().stop());
}

private void banner(PrintStream out)
@@ -18,23 +18,17 @@

package org.apache.cassandra.sidecar;

import java.util.Collection;
import java.util.List;
import javax.annotation.Nullable;

import org.apache.cassandra.sidecar.cluster.InstancesConfig;

/**
* Sidecar configuration
*/
public class Configuration
{
/* Cassandra Host */
private final String cassandraHost;

/* Cassandra Port */
private final Integer cassandraPort;

/* Cassandra Data Dirs */
private Collection<String> cassandraDataDirs;
/* Cassandra Instances Config */
private final InstancesConfig instancesConfig;

/* Sidecar's HTTP REST API port */
private final Integer port;
@@ -66,16 +60,13 @@

private final long throttleDelayInSeconds;

public Configuration(String cassandraHost, Integer cassandraPort, List<String> cassandraDataDirs, String host,
Integer port, Integer healthCheckFrequencyMillis, boolean isSslEnabled,
@Nullable String keyStorePath, @Nullable String keyStorePassword,
public Configuration(InstancesConfig instancesConfig, String host, Integer port, Integer healthCheckFrequencyMillis,
boolean isSslEnabled, @Nullable String keyStorePath, @Nullable String keyStorePassword,
@Nullable String trustStorePath, @Nullable String trustStorePassword,
long rateLimitStreamRequestsPerSecond, long throttleTimeoutInSeconds,
long throttleDelayInSeconds)
{
this.cassandraHost = cassandraHost;
this.cassandraPort = cassandraPort;
this.cassandraDataDirs = cassandraDataDirs;
this.instancesConfig = instancesConfig;
this.host = host;
this.port = port;
this.healthCheckFrequencyMillis = healthCheckFrequencyMillis;
@@ -91,33 +82,13 @@ public Configuration(String cassandraHost, Integer cassandraPort, List<String> c
}

/**
* Get the Cassandra host
* Get Cassandra Instances config
*
* @return
*/
public String getCassandraHost()
public InstancesConfig getInstancesConfig()
{
return cassandraHost;
}

/**
* Get the Cassandra port
*
* @return
*/
public Integer getCassandraPort()
{
return cassandraPort;
}

/**
* Get Cassandra data dirs
*
* @return
*/
public Collection<String> getCassandraDataDirs()
{
return cassandraDataDirs;
return instancesConfig;
}

/**
@@ -229,9 +200,7 @@ public long getThrottleDelayInSeconds()
*/
public static class Builder
{
private String cassandraHost;
private Integer cassandraPort;
private List<String> cassandraDataDirs;
private InstancesConfig instancesConfig;
private String host;
private Integer port;
private Integer healthCheckFrequencyMillis;
@@ -244,21 +213,9 @@ public long getThrottleDelayInSeconds()
private long throttleTimeoutInSeconds;
private long throttleDelayInSeconds;

public Builder setCassandraHost(String host)
{
this.cassandraHost = host;
return this;
}

public Builder setCassandraPort(Integer port)
{
this.cassandraPort = port;
return this;
}

public Builder setCassandraDataDirs(List<String> dataDirs)
public Builder setInstancesConfig(InstancesConfig instancesConfig)
{
this.cassandraDataDirs = dataDirs;
this.instancesConfig = instancesConfig;
return this;
}

@@ -330,10 +287,10 @@ public Builder setThrottleDelayInSeconds(long throttleDelayInSeconds)

public Configuration build()
{
return new Configuration(cassandraHost, cassandraPort, cassandraDataDirs, host, port,
healthCheckFrequencyMillis, isSslEnabled, keyStorePath, keyStorePassword,
trustStorePath, trustStorePassword, rateLimitStreamRequestsPerSecond,
throttleTimeoutInSeconds, throttleDelayInSeconds);
return new Configuration(instancesConfig, host, port, healthCheckFrequencyMillis, isSslEnabled,
keyStorePath, keyStorePassword, trustStorePath, trustStorePassword,
rateLimitStreamRequestsPerSecond, throttleTimeoutInSeconds,
throttleDelayInSeconds);
}
}
}

0 comments on commit fae3cb0

Please sign in to comment.