CASSANDRASC-103 Automated yaml type binding for deserialization
patch by Yifan Cai; reviewed by Francisco Guerrero for CASSANDRASC-103
diff --git a/CHANGES.txt b/CHANGES.txt
index 43b7652..c12d3ca 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,5 +1,6 @@
1.0.0
-----
+ * Automated yaml type binding for deserialization (CASSANDRASC-103)
* Upgrade Vert.x version in Sidecar to 4.5 (CASSANDRASC-101)
* Break restore job into stage and import phases and persist restore slice status on phase completion (CASSANDRASC-99)
* Improve logging for traffic shaping / rate limiting configuration (CASSANDRASC-98)
diff --git a/spotbugs-exclude.xml b/spotbugs-exclude.xml
index 03be65c..75f0517 100644
--- a/spotbugs-exclude.xml
+++ b/spotbugs-exclude.xml
@@ -85,4 +85,9 @@
<Class name="org.apache.cassandra.sidecar.common.ResourceUtils" />
</Match>
+ <Match>
+ <Bug pattern="UWF_UNWRITTEN_FIELD" />
+ <Class name="org.apache.cassandra.sidecar.config.yaml.DriverConfigurationImpl" />
+ </Match>
+
</FindBugsFilter>
diff --git a/src/main/java/org/apache/cassandra/sidecar/config/yaml/CassandraInputValidationConfigurationImpl.java b/src/main/java/org/apache/cassandra/sidecar/config/yaml/CassandraInputValidationConfigurationImpl.java
index b382a58..1538fac 100644
--- a/src/main/java/org/apache/cassandra/sidecar/config/yaml/CassandraInputValidationConfigurationImpl.java
+++ b/src/main/java/org/apache/cassandra/sidecar/config/yaml/CassandraInputValidationConfigurationImpl.java
@@ -55,18 +55,16 @@
@JsonProperty(FORBIDDEN_KEYSPACES_PROPERTY)
protected final Set<String> forbiddenKeyspaces;
- @JsonProperty(value = ALLOWED_CHARS_FOR_NAME_PROPERTY, defaultValue = DEFAULT_ALLOWED_CHARS_FOR_NAME)
+ @JsonProperty(value = ALLOWED_CHARS_FOR_NAME_PROPERTY)
protected final String allowedPatternForName;
- @JsonProperty(value = ALLOWED_CHARS_FOR_QUOTED_NAME_PROPERTY, defaultValue = DEFAULT_ALLOWED_CHARS_FOR_QUOTED_NAME)
+ @JsonProperty(value = ALLOWED_CHARS_FOR_QUOTED_NAME_PROPERTY)
protected final String allowedPatternForQuotedName;
- @JsonProperty(value = ALLOWED_CHARS_FOR_COMPONENT_NAME_PROPERTY,
- defaultValue = DEFAULT_ALLOWED_CHARS_FOR_COMPONENT_NAME)
+ @JsonProperty(value = ALLOWED_CHARS_FOR_COMPONENT_NAME_PROPERTY)
protected final String allowedPatternForComponentName;
- @JsonProperty(value = ALLOWED_CHARS_FOR_RESTRICTED_COMPONENT_NAME_PROPERTY,
- defaultValue = DEFAULT_ALLOWED_CHARS_FOR_RESTRICTED_COMPONENT_NAME)
+ @JsonProperty(value = ALLOWED_CHARS_FOR_RESTRICTED_COMPONENT_NAME_PROPERTY)
protected final String allowedPatternForRestrictedComponentName;
public CassandraInputValidationConfigurationImpl()
@@ -105,7 +103,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = ALLOWED_CHARS_FOR_NAME_PROPERTY, defaultValue = DEFAULT_ALLOWED_CHARS_FOR_NAME)
+ @JsonProperty(value = ALLOWED_CHARS_FOR_NAME_PROPERTY)
public String allowedPatternForName()
{
return allowedPatternForName;
@@ -115,7 +113,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = ALLOWED_CHARS_FOR_QUOTED_NAME_PROPERTY, defaultValue = DEFAULT_ALLOWED_CHARS_FOR_QUOTED_NAME)
+ @JsonProperty(value = ALLOWED_CHARS_FOR_QUOTED_NAME_PROPERTY)
public String allowedPatternForQuotedName()
{
return allowedPatternForQuotedName;
@@ -125,8 +123,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = ALLOWED_CHARS_FOR_COMPONENT_NAME_PROPERTY,
- defaultValue = DEFAULT_ALLOWED_CHARS_FOR_COMPONENT_NAME)
+ @JsonProperty(value = ALLOWED_CHARS_FOR_COMPONENT_NAME_PROPERTY)
public String allowedPatternForComponentName()
{
return allowedPatternForComponentName;
@@ -136,8 +133,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = ALLOWED_CHARS_FOR_RESTRICTED_COMPONENT_NAME_PROPERTY,
- defaultValue = DEFAULT_ALLOWED_CHARS_FOR_RESTRICTED_COMPONENT_NAME)
+ @JsonProperty(value = ALLOWED_CHARS_FOR_RESTRICTED_COMPONENT_NAME_PROPERTY)
public String allowedPatternForRestrictedComponentName()
{
return allowedPatternForRestrictedComponentName;
diff --git a/src/main/java/org/apache/cassandra/sidecar/config/yaml/HealthCheckConfigurationImpl.java b/src/main/java/org/apache/cassandra/sidecar/config/yaml/HealthCheckConfigurationImpl.java
index 2298bb5..47c7fb8 100644
--- a/src/main/java/org/apache/cassandra/sidecar/config/yaml/HealthCheckConfigurationImpl.java
+++ b/src/main/java/org/apache/cassandra/sidecar/config/yaml/HealthCheckConfigurationImpl.java
@@ -33,10 +33,10 @@
public static final String POLL_FREQ_MILLIS_PROPERTY = "poll_freq_millis";
public static final int DEFAULT_CHECK_INTERVAL_MILLIS = 30000;
- @JsonProperty(value = INITIAL_DELAY_MILLIS_PROPERTY, defaultValue = DEFAULT_INITIAL_DELAY_MILLIS + "")
+ @JsonProperty(value = INITIAL_DELAY_MILLIS_PROPERTY)
protected final int initialDelayMillis;
- @JsonProperty(value = POLL_FREQ_MILLIS_PROPERTY, defaultValue = DEFAULT_CHECK_INTERVAL_MILLIS + "")
+ @JsonProperty(value = POLL_FREQ_MILLIS_PROPERTY)
protected final int checkIntervalMillis;
public HealthCheckConfigurationImpl()
@@ -64,7 +64,7 @@
* @return the interval, in milliseconds, in which the health checks will be performed
*/
@Override
- @JsonProperty(value = POLL_FREQ_MILLIS_PROPERTY, defaultValue = DEFAULT_CHECK_INTERVAL_MILLIS + "")
+ @JsonProperty(value = POLL_FREQ_MILLIS_PROPERTY)
public int checkIntervalMillis()
{
return checkIntervalMillis;
diff --git a/src/main/java/org/apache/cassandra/sidecar/config/yaml/KeyStoreConfigurationImpl.java b/src/main/java/org/apache/cassandra/sidecar/config/yaml/KeyStoreConfigurationImpl.java
index 84a5fcb..bd2b350 100644
--- a/src/main/java/org/apache/cassandra/sidecar/config/yaml/KeyStoreConfigurationImpl.java
+++ b/src/main/java/org/apache/cassandra/sidecar/config/yaml/KeyStoreConfigurationImpl.java
@@ -32,10 +32,10 @@
@JsonProperty("password")
protected final String password;
- @JsonProperty(value = "type", defaultValue = DEFAULT_TYPE)
+ @JsonProperty(value = "type")
protected final String type;
- @JsonProperty(value = "check_interval_sec", defaultValue = DEFAULT_CHECK_INTERVAL_SECONDS + "")
+ @JsonProperty(value = "check_interval_sec")
protected final int checkIntervalInSeconds;
public KeyStoreConfigurationImpl()
@@ -80,7 +80,7 @@
* @return the type of the store
*/
@Override
- @JsonProperty(value = "type", defaultValue = DEFAULT_TYPE)
+ @JsonProperty(value = "type")
public String type()
{
return type;
@@ -90,7 +90,7 @@
* @return the interval, in seconds, in which the key store will be checked for changes in the filesystem
*/
@Override
- @JsonProperty(value = "check_interval_sec", defaultValue = DEFAULT_CHECK_INTERVAL_SECONDS + "")
+ @JsonProperty(value = "check_interval_sec")
public int checkIntervalInSeconds()
{
return checkIntervalInSeconds;
diff --git a/src/main/java/org/apache/cassandra/sidecar/config/yaml/RestoreJobConfigurationImpl.java b/src/main/java/org/apache/cassandra/sidecar/config/yaml/RestoreJobConfigurationImpl.java
index 9ce5efb..3e00311 100644
--- a/src/main/java/org/apache/cassandra/sidecar/config/yaml/RestoreJobConfigurationImpl.java
+++ b/src/main/java/org/apache/cassandra/sidecar/config/yaml/RestoreJobConfigurationImpl.java
@@ -37,19 +37,19 @@
public static final int DEFAULT_PROCESS_MAX_CONCURRENCY = 20; // process at most 20 slices concurrently
public static final long DEFAULT_RESTORE_JOB_TABLES_TTL_SECONDS = TimeUnit.DAYS.toSeconds(90);
- @JsonProperty(value = "job_discovery_active_loop_delay_millis", defaultValue = "5")
+ @JsonProperty(value = "job_discovery_active_loop_delay_millis")
protected final long jobDiscoveryActiveLoopDelayMillis;
- @JsonProperty(value = "job_discovery_idle_loop_delay_millis", defaultValue = "10")
+ @JsonProperty(value = "job_discovery_idle_loop_delay_millis")
protected final long jobDiscoveryIdleLoopDelayMillis;
- @JsonProperty(value = "job_discovery_recency_days", defaultValue = "5")
+ @JsonProperty(value = "job_discovery_recency_days")
protected final int jobDiscoveryRecencyDays;
- @JsonProperty(value = "slice_process_max_concurrency", defaultValue = "20")
+ @JsonProperty(value = "slice_process_max_concurrency")
protected final int processMaxConcurrency;
- @JsonProperty(value = "restore_job_tables_ttl_seconds", defaultValue = "90")
+ @JsonProperty(value = "restore_job_tables_ttl_seconds")
protected final long restoreJobTablesTtlSeconds;
protected RestoreJobConfigurationImpl()
@@ -86,7 +86,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = "job_discovery_active_loop_delay_millis", defaultValue = "5")
+ @JsonProperty(value = "job_discovery_active_loop_delay_millis")
public long jobDiscoveryActiveLoopDelayMillis()
{
return jobDiscoveryActiveLoopDelayMillis;
@@ -96,7 +96,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = "job_discovery_idle_loop_delay_millis", defaultValue = "10")
+ @JsonProperty(value = "job_discovery_idle_loop_delay_millis")
public long jobDiscoveryIdleLoopDelayMillis()
{
return jobDiscoveryActiveLoopDelayMillis;
@@ -106,7 +106,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = "job_discovery_recency_days", defaultValue = "5")
+ @JsonProperty(value = "job_discovery_recency_days")
public int jobDiscoveryRecencyDays()
{
return jobDiscoveryRecencyDays;
@@ -116,7 +116,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = "slice_process_max_concurrency", defaultValue = "20")
+ @JsonProperty(value = "slice_process_max_concurrency")
public int processMaxConcurrency()
{
return processMaxConcurrency;
@@ -126,7 +126,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = "restore_job_tables_ttl_seconds", defaultValue = "90")
+ @JsonProperty(value = "restore_job_tables_ttl_seconds")
public long restoreJobTablesTtlSeconds()
{
return restoreJobTablesTtlSeconds;
diff --git a/src/main/java/org/apache/cassandra/sidecar/config/yaml/S3ClientConfigurationImpl.java b/src/main/java/org/apache/cassandra/sidecar/config/yaml/S3ClientConfigurationImpl.java
index 2f3ba4f..d5bf576 100644
--- a/src/main/java/org/apache/cassandra/sidecar/config/yaml/S3ClientConfigurationImpl.java
+++ b/src/main/java/org/apache/cassandra/sidecar/config/yaml/S3ClientConfigurationImpl.java
@@ -34,13 +34,13 @@
public static final long DEFAULT_THREAD_KEEP_ALIVE_SECONDS = 60;
public static final int DEFAULT_S3_CLIENT_CONCURRENCY = 4;
- @JsonProperty(value = "thread_name_prefix", defaultValue = "s3-client")
+ @JsonProperty(value = "thread_name_prefix")
protected final String threadNamePrefix;
- @JsonProperty(value = "concurrency", defaultValue = "4")
+ @JsonProperty(value = "concurrency")
protected final int concurrency;
- @JsonProperty(value = "thread_keep_alive_seconds", defaultValue = "60")
+ @JsonProperty(value = "thread_keep_alive_seconds")
protected final long threadKeepAliveSeconds;
@JsonProperty(value = PROXY_PROPERTY)
@@ -70,7 +70,7 @@
*/
@NotNull
@Override
- @JsonProperty(value = "thread_name_prefix", defaultValue = "s3-client")
+ @JsonProperty(value = "thread_name_prefix")
public String threadNamePrefix()
{
return threadNamePrefix;
@@ -80,7 +80,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = "concurrency", defaultValue = "4")
+ @JsonProperty(value = "concurrency")
public int concurrency()
{
return concurrency;
@@ -90,7 +90,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = "thread_keep_alive_seconds", defaultValue = "60")
+ @JsonProperty(value = "thread_keep_alive_seconds")
public long threadKeepAliveSeconds()
{
return threadKeepAliveSeconds;
diff --git a/src/main/java/org/apache/cassandra/sidecar/config/yaml/SSTableImportConfigurationImpl.java b/src/main/java/org/apache/cassandra/sidecar/config/yaml/SSTableImportConfigurationImpl.java
index c82d09d..523978d 100644
--- a/src/main/java/org/apache/cassandra/sidecar/config/yaml/SSTableImportConfigurationImpl.java
+++ b/src/main/java/org/apache/cassandra/sidecar/config/yaml/SSTableImportConfigurationImpl.java
@@ -35,7 +35,7 @@
protected static final CacheConfiguration DEFAULT_CACHE_CONFIGURATION =
new CacheConfigurationImpl(TimeUnit.HOURS.toMillis(2), 10_000);
- @JsonProperty(value = POLL_INTERVAL_MILLIS_PROPERTY, defaultValue = DEFAULT_POLL_INTERVAL_MILLIS + "")
+ @JsonProperty(value = POLL_INTERVAL_MILLIS_PROPERTY)
protected final int importIntervalMillis;
@JsonProperty(value = CACHE_PROPERTY)
@@ -67,7 +67,7 @@
* @return the interval in milliseconds in which the SSTable Importer will process pending imports
*/
@Override
- @JsonProperty(value = POLL_INTERVAL_MILLIS_PROPERTY, defaultValue = DEFAULT_POLL_INTERVAL_MILLIS + "")
+ @JsonProperty(value = POLL_INTERVAL_MILLIS_PROPERTY)
public int importIntervalMillis()
{
return importIntervalMillis;
diff --git a/src/main/java/org/apache/cassandra/sidecar/config/yaml/SSTableUploadConfigurationImpl.java b/src/main/java/org/apache/cassandra/sidecar/config/yaml/SSTableUploadConfigurationImpl.java
index 68a8a45..2f69352 100644
--- a/src/main/java/org/apache/cassandra/sidecar/config/yaml/SSTableUploadConfigurationImpl.java
+++ b/src/main/java/org/apache/cassandra/sidecar/config/yaml/SSTableUploadConfigurationImpl.java
@@ -37,10 +37,10 @@
public static final String FILE_PERMISSIONS_PROPERTY = "file_permissions";
public static final String DEFAULT_FILE_PERMISSIONS = "rw-r--r--";
- @JsonProperty(value = CONCURRENT_UPLOAD_LIMIT_PROPERTY, defaultValue = DEFAULT_CONCURRENT_UPLOAD_LIMIT + "")
+ @JsonProperty(value = CONCURRENT_UPLOAD_LIMIT_PROPERTY)
protected final int concurrentUploadsLimit;
- @JsonProperty(value = MIN_FREE_SPACE_PERCENT_PROPERTY, defaultValue = DEFAULT_MIN_FREE_SPACE_PERCENT + "")
+ @JsonProperty(value = MIN_FREE_SPACE_PERCENT_PROPERTY)
protected final float minimumSpacePercentageRequired;
protected String filePermissions;
@@ -78,7 +78,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = CONCURRENT_UPLOAD_LIMIT_PROPERTY, defaultValue = DEFAULT_CONCURRENT_UPLOAD_LIMIT + "")
+ @JsonProperty(value = CONCURRENT_UPLOAD_LIMIT_PROPERTY)
public int concurrentUploadsLimit()
{
return concurrentUploadsLimit;
@@ -88,7 +88,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = MIN_FREE_SPACE_PERCENT_PROPERTY, defaultValue = DEFAULT_MIN_FREE_SPACE_PERCENT + "")
+ @JsonProperty(value = MIN_FREE_SPACE_PERCENT_PROPERTY)
public float minimumSpacePercentageRequired()
{
return minimumSpacePercentageRequired;
diff --git a/src/main/java/org/apache/cassandra/sidecar/config/yaml/SchemaKeyspaceConfigurationImpl.java b/src/main/java/org/apache/cassandra/sidecar/config/yaml/SchemaKeyspaceConfigurationImpl.java
index 12ef36f..9c7b611 100644
--- a/src/main/java/org/apache/cassandra/sidecar/config/yaml/SchemaKeyspaceConfigurationImpl.java
+++ b/src/main/java/org/apache/cassandra/sidecar/config/yaml/SchemaKeyspaceConfigurationImpl.java
@@ -32,16 +32,16 @@
public static final String DEFAULT_REPLICATION_STRATEGY = "SimpleStrategy";
public static final int DEFAULT_REPLICATION_FACTOR = 1;
- @JsonProperty(value = "is_enabled", defaultValue = "false")
+ @JsonProperty(value = "is_enabled")
protected final boolean isEnabled;
- @JsonProperty(value = "keyspace", defaultValue = "sidecar_internal")
+ @JsonProperty(value = "keyspace")
protected final String keyspace;
- @JsonProperty(value = "replication_strategy", defaultValue = "SimpleStrategy")
+ @JsonProperty(value = "replication_strategy")
protected final String replicationStrategy;
- @JsonProperty(value = "replication_factor", defaultValue = "1")
+ @JsonProperty(value = "replication_factor")
protected final int replicationFactor;
protected SchemaKeyspaceConfigurationImpl()
@@ -61,7 +61,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = "is_enabled", defaultValue = "false")
+ @JsonProperty(value = "is_enabled")
public boolean isEnabled()
{
return isEnabled;
@@ -71,7 +71,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = "keyspace", defaultValue = "sidecar_internal")
+ @JsonProperty(value = "keyspace")
public String keyspace()
{
return keyspace;
@@ -81,7 +81,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = "replication_strategy", defaultValue = "SimpleStrategy")
+ @JsonProperty(value = "replication_strategy")
public String replicationStrategy()
{
return replicationStrategy;
@@ -91,7 +91,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = "replication_factor", defaultValue = "1")
+ @JsonProperty(value = "replication_factor")
public int replicationFactor()
{
return replicationFactor;
diff --git a/src/main/java/org/apache/cassandra/sidecar/config/yaml/ServiceConfigurationImpl.java b/src/main/java/org/apache/cassandra/sidecar/config/yaml/ServiceConfigurationImpl.java
index 4dccae4..3b38dca 100644
--- a/src/main/java/org/apache/cassandra/sidecar/config/yaml/ServiceConfigurationImpl.java
+++ b/src/main/java/org/apache/cassandra/sidecar/config/yaml/ServiceConfigurationImpl.java
@@ -97,16 +97,16 @@
@JsonProperty(value = SERVER_VERTICLE_INSTANCES_PROPERTY, defaultValue = DEFAULT_SERVER_VERTICLE_INSTANCES + "")
protected final int serverVerticleInstances;
- @JsonProperty(value = THROTTLE_PROPERTY, required = true)
+ @JsonProperty(value = THROTTLE_PROPERTY)
protected final ThrottleConfiguration throttleConfiguration;
- @JsonProperty(value = SSTABLE_UPLOAD_PROPERTY, required = true)
+ @JsonProperty(value = SSTABLE_UPLOAD_PROPERTY)
protected final SSTableUploadConfiguration ssTableUploadConfiguration;
- @JsonProperty(value = SSTABLE_IMPORT_PROPERTY, required = true)
+ @JsonProperty(value = SSTABLE_IMPORT_PROPERTY)
protected final SSTableImportConfiguration ssTableImportConfiguration;
- @JsonProperty(value = WORKER_POOLS_PROPERTY, required = true)
+ @JsonProperty(value = WORKER_POOLS_PROPERTY)
protected final Map<String, ? extends WorkerPoolConfiguration> workerPoolsConfiguration;
@JsonProperty(value = JMX_PROPERTY)
@@ -154,7 +154,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = HOST_PROPERTY, defaultValue = DEFAULT_HOST)
+ @JsonProperty(value = HOST_PROPERTY)
public String host()
{
return host;
@@ -164,7 +164,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = PORT_PROPERTY, defaultValue = DEFAULT_PORT + "")
+ @JsonProperty(value = PORT_PROPERTY)
public int port()
{
return port;
@@ -174,7 +174,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = REQUEST_IDLE_TIMEOUT_MILLIS_PROPERTY, defaultValue = DEFAULT_REQUEST_IDLE_TIMEOUT_MILLIS + "")
+ @JsonProperty(value = REQUEST_IDLE_TIMEOUT_MILLIS_PROPERTY)
public int requestIdleTimeoutMillis()
{
return requestIdleTimeoutMillis;
@@ -184,7 +184,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = REQUEST_TIMEOUT_MILLIS_PROPERTY, defaultValue = DEFAULT_REQUEST_TIMEOUT_MILLIS + "")
+ @JsonProperty(value = REQUEST_TIMEOUT_MILLIS_PROPERTY)
public long requestTimeoutMillis()
{
return requestTimeoutMillis;
@@ -194,7 +194,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = TCP_KEEP_ALIVE_PROPERTY, defaultValue = DEFAULT_TCP_KEEP_ALIVE + "")
+ @JsonProperty(value = TCP_KEEP_ALIVE_PROPERTY)
public boolean tcpKeepAlive()
{
return tcpKeepAlive;
@@ -204,7 +204,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = ACCEPT_BACKLOG_PROPERTY, defaultValue = DEFAULT_ACCEPT_BACKLOG + "")
+ @JsonProperty(value = ACCEPT_BACKLOG_PROPERTY)
public int acceptBacklog()
{
return acceptBacklog;
@@ -214,7 +214,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = ALLOWABLE_SKEW_IN_MINUTES_PROPERTY, defaultValue = DEFAULT_ALLOWABLE_SKEW_IN_MINUTES + "")
+ @JsonProperty(value = ALLOWABLE_SKEW_IN_MINUTES_PROPERTY)
public int allowableSkewInMinutes()
{
return allowableSkewInMinutes;
@@ -224,7 +224,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = SERVER_VERTICLE_INSTANCES_PROPERTY, defaultValue = DEFAULT_SERVER_VERTICLE_INSTANCES + "")
+ @JsonProperty(value = SERVER_VERTICLE_INSTANCES_PROPERTY)
public int serverVerticleInstances()
{
return serverVerticleInstances;
@@ -234,7 +234,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = THROTTLE_PROPERTY, required = true)
+ @JsonProperty(value = THROTTLE_PROPERTY)
public ThrottleConfiguration throttleConfiguration()
{
return throttleConfiguration;
@@ -244,7 +244,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = SSTABLE_UPLOAD_PROPERTY, required = true)
+ @JsonProperty(value = SSTABLE_UPLOAD_PROPERTY)
public SSTableUploadConfiguration ssTableUploadConfiguration()
{
return ssTableUploadConfiguration;
@@ -254,7 +254,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = SSTABLE_IMPORT_PROPERTY, required = true)
+ @JsonProperty(value = SSTABLE_IMPORT_PROPERTY)
public SSTableImportConfiguration ssTableImportConfiguration()
{
return ssTableImportConfiguration;
@@ -264,7 +264,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = WORKER_POOLS_PROPERTY, required = true)
+ @JsonProperty(value = WORKER_POOLS_PROPERTY)
public Map<String, ? extends WorkerPoolConfiguration> workerPoolsConfiguration()
{
return workerPoolsConfiguration;
diff --git a/src/main/java/org/apache/cassandra/sidecar/config/yaml/SidecarConfigurationImpl.java b/src/main/java/org/apache/cassandra/sidecar/config/yaml/SidecarConfigurationImpl.java
index 697554c..d2c2ef4 100644
--- a/src/main/java/org/apache/cassandra/sidecar/config/yaml/SidecarConfigurationImpl.java
+++ b/src/main/java/org/apache/cassandra/sidecar/config/yaml/SidecarConfigurationImpl.java
@@ -24,7 +24,13 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import com.google.common.collect.Sets;
+import com.google.common.reflect.ClassPath;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.DeserializationFeature;
@@ -32,23 +38,15 @@
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import org.apache.cassandra.sidecar.common.DataObjectBuilder;
-import org.apache.cassandra.sidecar.config.CacheConfiguration;
import org.apache.cassandra.sidecar.config.CassandraInputValidationConfiguration;
import org.apache.cassandra.sidecar.config.DriverConfiguration;
import org.apache.cassandra.sidecar.config.HealthCheckConfiguration;
import org.apache.cassandra.sidecar.config.InstanceConfiguration;
-import org.apache.cassandra.sidecar.config.JmxConfiguration;
-import org.apache.cassandra.sidecar.config.KeyStoreConfiguration;
import org.apache.cassandra.sidecar.config.RestoreJobConfiguration;
import org.apache.cassandra.sidecar.config.S3ClientConfiguration;
-import org.apache.cassandra.sidecar.config.SSTableImportConfiguration;
-import org.apache.cassandra.sidecar.config.SSTableUploadConfiguration;
import org.apache.cassandra.sidecar.config.ServiceConfiguration;
import org.apache.cassandra.sidecar.config.SidecarConfiguration;
import org.apache.cassandra.sidecar.config.SslConfiguration;
-import org.apache.cassandra.sidecar.config.ThrottleConfiguration;
-import org.apache.cassandra.sidecar.config.TrafficShapingConfiguration;
-import org.apache.cassandra.sidecar.config.WorkerPoolConfiguration;
/**
* Configuration for this Sidecar process
@@ -65,8 +63,9 @@
@JsonProperty(value = "driver_parameters")
protected final DriverConfiguration driverConfiguration;
- @JsonProperty(value = "sidecar", required = true)
+ @JsonProperty(value = "sidecar")
protected final ServiceConfiguration serviceConfiguration;
+
@JsonProperty("ssl")
protected final SslConfiguration sslConfiguration;
@@ -211,51 +210,71 @@
public static SidecarConfigurationImpl readYamlConfiguration(Path yamlConfigurationPath) throws IOException
{
- SimpleModule simpleModule = new SimpleModule()
- .addAbstractTypeMapping(CacheConfiguration.class,
- CacheConfigurationImpl.class)
- .addAbstractTypeMapping(CassandraInputValidationConfiguration.class,
- CassandraInputValidationConfigurationImpl.class)
- .addAbstractTypeMapping(HealthCheckConfiguration.class,
- HealthCheckConfigurationImpl.class)
- .addAbstractTypeMapping(InstanceConfiguration.class,
- InstanceConfigurationImpl.class)
- .addAbstractTypeMapping(KeyStoreConfiguration.class,
- KeyStoreConfigurationImpl.class)
- .addAbstractTypeMapping(SSTableImportConfiguration.class,
- SSTableImportConfigurationImpl.class)
- .addAbstractTypeMapping(SSTableUploadConfiguration.class,
- SSTableUploadConfigurationImpl.class)
- .addAbstractTypeMapping(ServiceConfiguration.class,
- ServiceConfigurationImpl.class)
- .addAbstractTypeMapping(SidecarConfiguration.class,
- SidecarConfigurationImpl.class)
- .addAbstractTypeMapping(SslConfiguration.class,
- SslConfigurationImpl.class)
- .addAbstractTypeMapping(ThrottleConfiguration.class,
- ThrottleConfigurationImpl.class)
- .addAbstractTypeMapping(WorkerPoolConfiguration.class,
- WorkerPoolConfigurationImpl.class)
- .addAbstractTypeMapping(JmxConfiguration.class,
- JmxConfigurationImpl.class)
- .addAbstractTypeMapping(TrafficShapingConfiguration.class,
- TrafficShapingConfigurationImpl.class)
- .addAbstractTypeMapping(DriverConfiguration.class,
- DriverConfigurationImpl.class)
- .addAbstractTypeMapping(RestoreJobConfiguration.class,
- RestoreJobConfigurationImpl.class)
- .addAbstractTypeMapping(S3ClientConfiguration.class,
- S3ClientConfigurationImpl.class);
-
ObjectMapper mapper = new ObjectMapper(new YAMLFactory())
.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
.configure(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS, true)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
- .registerModule(simpleModule);
+ .registerModule(resolveYamlTypeMappings());
return mapper.readValue(yamlConfigurationPath.toFile(), SidecarConfigurationImpl.class);
}
+ private static SimpleModule resolveYamlTypeMappings() throws IOException
+ {
+ String packageName = SidecarConfigurationImpl.class.getPackage().getName();
+ String outerPackageName = SidecarConfiguration.class.getPackage().getName();
+ SimpleModule module = new SimpleModule();
+ ClassPath path = ClassPath.from(ClassLoader.getSystemClassLoader());
+ Set<Class> declared = path.getTopLevelClasses(outerPackageName)
+ .stream()
+ .filter(c -> c.getName().endsWith("Configuration"))
+ .map(ClassPath.ClassInfo::load)
+ .collect(Collectors.toSet());
+ Set<Class> implemented = new HashSet<>();
+ ClassPath.from(ClassLoader.getSystemClassLoader()).getTopLevelClasses(packageName)
+ .stream()
+ .map(ClassPath.ClassInfo::load)
+ .forEach(clazz -> {
+ if (clazz.isInterface())
+ {
+ return;
+ }
+ // find the configuration interface it implements
+ // note: it assumes that the concrete implementation implement one and only one
+ // configuration interface, and the name of the configuration interface ends
+ // with "Configuration"
+ Class[] interfaces = clazz.getInterfaces();
+ Class configurationInterface = null;
+ for (Class c : interfaces)
+ {
+ if (c.getPackage().getName().equals(outerPackageName) && c.getName().endsWith("Configuration"))
+ {
+ configurationInterface = c;
+ if (!implemented.add(configurationInterface))
+ {
+ throw new IllegalStateException("Multiple implementations found for " +
+ "configuration interface: " + configurationInterface);
+ }
+ break;
+ }
+ }
+ // it does not implement any configuration interface
+ if (configurationInterface == null)
+ {
+ return;
+ }
+
+ module.addAbstractTypeMapping(configurationInterface, clazz);
+ });
+
+ Set<Class> unimplemented = Sets.difference(declared, implemented);
+ if (!unimplemented.isEmpty())
+ {
+ throw new IllegalStateException("Found unimplemented configuration class(es): " + unimplemented);
+ }
+ return module;
+ }
+
public static Builder builder()
{
return new Builder();
diff --git a/src/main/java/org/apache/cassandra/sidecar/config/yaml/SslConfigurationImpl.java b/src/main/java/org/apache/cassandra/sidecar/config/yaml/SslConfigurationImpl.java
index 0239121..20b457d 100644
--- a/src/main/java/org/apache/cassandra/sidecar/config/yaml/SslConfigurationImpl.java
+++ b/src/main/java/org/apache/cassandra/sidecar/config/yaml/SslConfigurationImpl.java
@@ -46,10 +46,10 @@
@JsonProperty("enabled")
protected final boolean enabled;
- @JsonProperty(value = "use_openssl", defaultValue = "true")
+ @JsonProperty(value = "use_openssl")
protected final boolean useOpenSsl;
- @JsonProperty(value = "handshake_timeout_sec", defaultValue = "10")
+ @JsonProperty(value = "handshake_timeout_sec")
protected final long handshakeTimeoutInSeconds;
protected String clientAuth;
@@ -97,7 +97,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = "use_openssl", defaultValue = "true")
+ @JsonProperty(value = "use_openssl")
public boolean preferOpenSSL()
{
return useOpenSsl;
@@ -107,7 +107,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = "handshake_timeout_sec", defaultValue = "10")
+ @JsonProperty(value = "handshake_timeout_sec")
public long handshakeTimeoutInSeconds()
{
return handshakeTimeoutInSeconds;
@@ -117,13 +117,13 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = "client_auth", defaultValue = "NONE")
+ @JsonProperty(value = "client_auth")
public String clientAuth()
{
return clientAuth;
}
- @JsonProperty(value = "client_auth", defaultValue = "NONE")
+ @JsonProperty(value = "client_auth")
public void setClientAuth(String clientAuth)
{
this.clientAuth = clientAuth;
diff --git a/src/main/java/org/apache/cassandra/sidecar/config/yaml/ThrottleConfigurationImpl.java b/src/main/java/org/apache/cassandra/sidecar/config/yaml/ThrottleConfigurationImpl.java
index b4b840f..24f45ce 100644
--- a/src/main/java/org/apache/cassandra/sidecar/config/yaml/ThrottleConfigurationImpl.java
+++ b/src/main/java/org/apache/cassandra/sidecar/config/yaml/ThrottleConfigurationImpl.java
@@ -33,11 +33,11 @@
public static final String TIMEOUT_SEC_PROPERTY = "timeout_sec";
public static final String DELAY_SEC_PROPERTY = "delay_sec";
- @JsonProperty(value = STREAM_REQUESTS_PER_SEC_PROPERTY, defaultValue = DEFAULT_STREAM_REQUESTS_PER_SEC + "")
+ @JsonProperty(value = STREAM_REQUESTS_PER_SEC_PROPERTY)
protected final long rateLimitStreamRequestsPerSecond;
- @JsonProperty(value = TIMEOUT_SEC_PROPERTY, defaultValue = DEFAULT_TIMEOUT_SEC + "")
+ @JsonProperty(value = TIMEOUT_SEC_PROPERTY)
protected final long timeoutInSeconds;
- @JsonProperty(value = DELAY_SEC_PROPERTY, defaultValue = DEFAULT_DELAY_SEC + "")
+ @JsonProperty(value = DELAY_SEC_PROPERTY)
protected final long delayInSeconds;
public ThrottleConfigurationImpl()
@@ -64,21 +64,21 @@
}
@Override
- @JsonProperty(value = STREAM_REQUESTS_PER_SEC_PROPERTY, defaultValue = DEFAULT_STREAM_REQUESTS_PER_SEC + "")
+ @JsonProperty(value = STREAM_REQUESTS_PER_SEC_PROPERTY)
public long rateLimitStreamRequestsPerSecond()
{
return rateLimitStreamRequestsPerSecond;
}
@Override
- @JsonProperty(value = TIMEOUT_SEC_PROPERTY, defaultValue = DEFAULT_TIMEOUT_SEC + "")
+ @JsonProperty(value = TIMEOUT_SEC_PROPERTY)
public long timeoutInSeconds()
{
return timeoutInSeconds;
}
@Override
- @JsonProperty(value = DELAY_SEC_PROPERTY, defaultValue = DEFAULT_DELAY_SEC + "")
+ @JsonProperty(value = DELAY_SEC_PROPERTY)
public long delayInSeconds()
{
return delayInSeconds;
diff --git a/src/main/java/org/apache/cassandra/sidecar/config/yaml/TrafficShapingConfigurationImpl.java b/src/main/java/org/apache/cassandra/sidecar/config/yaml/TrafficShapingConfigurationImpl.java
index f14573b..73d67e0 100644
--- a/src/main/java/org/apache/cassandra/sidecar/config/yaml/TrafficShapingConfigurationImpl.java
+++ b/src/main/java/org/apache/cassandra/sidecar/config/yaml/TrafficShapingConfigurationImpl.java
@@ -64,23 +64,22 @@
*/
public static final long DEFAULT_INBOUND_FILE_GLOBAL_BANDWIDTH_LIMIT = 0;
- @JsonProperty(value = "inbound_global_bandwidth_bps", defaultValue = "0")
+ @JsonProperty(value = "inbound_global_bandwidth_bps")
protected final long inboundGlobalBandwidthBytesPerSecond;
- @JsonProperty(value = "outbound_global_bandwidth_bps", defaultValue = "0")
+ @JsonProperty(value = "outbound_global_bandwidth_bps")
protected final long outboundGlobalBandwidthBytesPerSecond;
- @JsonProperty(value = "peak_outbound_global_bandwidth_bps",
- defaultValue = DEFAULT_PEAK_OUTBOUND_GLOBAL_BANDWIDTH_LIMIT + "")
+ @JsonProperty(value = "peak_outbound_global_bandwidth_bps")
protected final long peakOutboundGlobalBandwidthBytesPerSecond;
- @JsonProperty(value = "max_delay_to_wait_millis", defaultValue = DEFAULT_MAX_DELAY_TIME + "")
+ @JsonProperty(value = "max_delay_to_wait_millis")
protected final long maxDelayToWaitMillis;
- @JsonProperty(value = "check_interval_for_stats_millis", defaultValue = DEFAULT_CHECK_INTERVAL + "")
+ @JsonProperty(value = "check_interval_for_stats_millis")
protected final long checkIntervalForStatsMillis;
- @JsonProperty(value = "inbound_global_file_bandwidth_bps", defaultValue = "0")
+ @JsonProperty(value = "inbound_global_file_bandwidth_bps")
protected final long inboundGlobalFileBandwidthBytesPerSecond;
public TrafficShapingConfigurationImpl()
@@ -113,7 +112,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = "inbound_global_bandwidth_bps", defaultValue = "0")
+ @JsonProperty(value = "inbound_global_bandwidth_bps")
public long inboundGlobalBandwidthBytesPerSecond()
{
return inboundGlobalBandwidthBytesPerSecond;
@@ -123,7 +122,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = "outbound_global_bandwidth_bps", defaultValue = "0")
+ @JsonProperty(value = "outbound_global_bandwidth_bps")
public long outboundGlobalBandwidthBytesPerSecond()
{
return outboundGlobalBandwidthBytesPerSecond;
@@ -133,8 +132,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = "peak_outbound_global_bandwidth_bps",
- defaultValue = DEFAULT_PEAK_OUTBOUND_GLOBAL_BANDWIDTH_LIMIT + "")
+ @JsonProperty(value = "peak_outbound_global_bandwidth_bps")
public long peakOutboundGlobalBandwidthBytesPerSecond()
{
return peakOutboundGlobalBandwidthBytesPerSecond;
@@ -144,7 +142,7 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = "max_delay_to_wait_millis", defaultValue = DEFAULT_MAX_DELAY_TIME + "")
+ @JsonProperty(value = "max_delay_to_wait_millis")
public long maxDelayToWaitMillis()
{
return maxDelayToWaitMillis;
@@ -154,14 +152,14 @@
* {@inheritDoc}
*/
@Override
- @JsonProperty(value = "check_interval_for_stats_millis", defaultValue = DEFAULT_CHECK_INTERVAL + "")
+ @JsonProperty(value = "check_interval_for_stats_millis")
public long checkIntervalForStatsMillis()
{
return checkIntervalForStatsMillis;
}
@Override
- @JsonProperty(value = "inbound_global_file_bandwidth_bps", defaultValue = "0")
+ @JsonProperty(value = "inbound_global_file_bandwidth_bps")
public long inboundGlobalFileBandwidthBytesPerSecond()
{
return inboundGlobalFileBandwidthBytesPerSecond;
diff --git a/src/test/java/org/apache/cassandra/sidecar/config/SidecarConfigurationTest.java b/src/test/java/org/apache/cassandra/sidecar/config/SidecarConfigurationTest.java
index 62b2ac9..8775c67 100644
--- a/src/test/java/org/apache/cassandra/sidecar/config/SidecarConfigurationTest.java
+++ b/src/test/java/org/apache/cassandra/sidecar/config/SidecarConfigurationTest.java
@@ -190,6 +190,22 @@
assertThat(driverConfiguration.numConnections()).isEqualTo(6);
}
+ @Test
+ void testReadCustomSchemaKeyspaceConfiguration() throws IOException
+ {
+ Path yamlPath = yaml("config/sidecar_schema_keyspace_configuration.yaml");
+ SidecarConfiguration config = SidecarConfigurationImpl.readYamlConfiguration(yamlPath);
+
+ SchemaKeyspaceConfiguration configuration = config.serviceConfiguration().schemaKeyspaceConfiguration();
+ assertThat(configuration).isNotNull();
+ assertThat(configuration.isEnabled()).isTrue();
+ assertThat(configuration.keyspace()).isEqualTo("sidecar_internal");
+ assertThat(configuration.replicationStrategy()).isEqualTo("SimpleStrategy");
+ assertThat(configuration.replicationFactor()).isEqualTo(3);
+ assertThat(configuration.createReplicationStrategyString())
+ .isEqualTo("{'class':'SimpleStrategy', 'replication_factor':'3'}");
+ }
+
void validateSingleInstanceSidecarConfiguration(SidecarConfiguration config)
{
assertThat(config.cassandraInstances()).isNotNull().hasSize(1);
diff --git a/src/test/resources/config/sidecar_schema_keyspace_configuration.yaml b/src/test/resources/config/sidecar_schema_keyspace_configuration.yaml
new file mode 100644
index 0000000..a1f45c3
--- /dev/null
+++ b/src/test/resources/config/sidecar_schema_keyspace_configuration.yaml
@@ -0,0 +1,103 @@
+#
+# Cassandra SideCar configuration file
+#
+cassandra:
+ host: localhost
+ port: 9042
+ username: cassandra
+ password: cassandra
+ data_dirs:
+ - /ccm/test/node1/data0
+ - /ccm/test/node1/data1
+ staging_dir: /ccm/test/node1/sstable-staging
+ jmx_host: 127.0.0.1
+ jmx_port: 7199
+ jmx_role: controlRole
+ jmx_role_password: controlPassword
+ jmx_ssl_enabled: true
+
+sidecar:
+ host: 0.0.0.0
+ port: 0 # bind sever to the first available port
+ request_idle_timeout_millis: 300000 # this field expects integer value
+ request_timeout_millis: 300000
+ tcp_keep_alive: false
+ accept_backlog: 1024
+ server_verticle_instances: 2
+ throttle:
+ stream_requests_per_sec: 5000
+ delay_sec: 5
+ timeout_sec: 10
+ traffic_shaping:
+ inbound_global_bandwidth_bps: 500
+ outbound_global_bandwidth_bps: 1500
+ peak_outbound_global_bandwidth_bps: 2000
+ max_delay_to_wait_millis: 2500
+ check_interval_for_stats_millis: 3000
+ sstable_upload:
+ concurrent_upload_limit: 80
+ min_free_space_percent: 10
+ # file_permissions: "rw-r--r--" # when not specified, the default file permissions are owner read & write, group & others read
+ allowable_time_skew_in_minutes: 60
+ sstable_import:
+ poll_interval_millis: 100
+ cache:
+ expire_after_access_millis: 7200000 # 2 hours
+ maximum_size: 10000
+ worker_pools:
+ service:
+ name: "sidecar-worker-pool"
+ size: 20
+ max_execution_time_millis: 60000 # 60 seconds
+ internal:
+ name: "sidecar-internal-worker-pool"
+ size: 20
+ max_execution_time_millis: 900000 # 15 minutes
+ jmx:
+ max_retries: 42
+ retry_delay_millis: 1234
+ schema:
+ is_enabled: true
+ keyspace: sidecar_internal
+ replication_strategy: SimpleStrategy
+ replication_factor: 3
+
+#
+# Enable SSL configuration (Disabled by default)
+#
+# ssl:
+# enabled: true
+# use_openssl: true
+# handshake_timeout_sec: 10
+# client_auth: NONE # valid options are NONE, REQUEST, REQUIRED
+# accepted_protocols:
+# - TLSv1.2
+# - TLSv1.3
+# cipher_suites: []
+# keystore:
+# type: PKCS12
+# path: "path/to/keystore.p12"
+# password: password
+# check_interval_sec: 300
+# truststore:
+# path: "path/to/truststore.p12"
+# password: password
+
+
+healthcheck:
+ initial_delay_millis: 100
+ poll_freq_millis: 30000
+
+cassandra_input_validation:
+ forbidden_keyspaces:
+ - system_schema
+ - system_traces
+ - system_distributed
+ - system
+ - system_auth
+ - system_views
+ - system_virtual_schema
+ allowed_chars_for_directory: "[a-zA-Z][a-zA-Z0-9_]{0,47}"
+ allowed_chars_for_quoted_name: "[a-zA-Z_0-9]{1,48}"
+ allowed_chars_for_component_name: "[a-zA-Z0-9_-]+(.db|.cql|.json|.crc32|TOC.txt)"
+ allowed_chars_for_restricted_component_name: "[a-zA-Z0-9_-]+(.db|TOC.txt)"
diff --git a/src/test/resources/config/sidecar_single_instance.yaml b/src/test/resources/config/sidecar_single_instance.yaml
index c2d3a85..a04fe3d 100644
--- a/src/test/resources/config/sidecar_single_instance.yaml
+++ b/src/test/resources/config/sidecar_single_instance.yaml
@@ -56,6 +56,11 @@
jmx:
max_retries: 42
retry_delay_millis: 1234
+ schema:
+ is_enabled: false
+ keyspace: sidecar_internal
+ replication_strategy: SimpleStrategy
+ replication_factor: 1
#
# Enable SSL configuration (Disabled by default)