Skip to content
Permalink
Browse files

Validate config already at initialization.

Signed-off-by: Juergen Fickel <juergen.fickel@bosch-si.com>
  • Loading branch information
jufickel-b committed Feb 20, 2019
1 parent e01d4e1 commit 7e7a088661c202f1ee83d5ca5eab59adc1847c54
Showing with 2,230 additions and 1,113 deletions.
  1. +9 −35 services/base/src/main/java/org/eclipse/ditto/services/base/config/DefaultClusterConfig.java
  2. +24 −44 services/base/src/main/java/org/eclipse/ditto/services/base/config/DefaultHealthCheckConfig.java
  3. +13 −38 services/base/src/main/java/org/eclipse/ditto/services/base/config/DefaultHttpConfig.java
  4. +31 −56 services/base/src/main/java/org/eclipse/ditto/services/base/config/DefaultLimitsConfig.java
  5. +47 −41 services/base/src/main/java/org/eclipse/ditto/services/base/config/DefaultMetricsConfig.java
  6. +2 −0 services/base/src/main/java/org/eclipse/ditto/services/base/config/DittoServiceConfig.java
  7. +180 −0 services/base/src/main/java/org/eclipse/ditto/services/base/config/ServiceSpecificConfig.java
  8. +31 −0 ...es/concierge/util/src/main/java/org/eclipse/ditto/services/concierge/util/config/CacheConfig.java
  9. +83 −0 ...oncierge/util/src/main/java/org/eclipse/ditto/services/concierge/util/config/ConciergeConfig.java
  10. +18 −42 ...e/ditto/services/concierge/util/config/{DittoConciergeCacheConfig.java → DefaultCacheConfig.java}
  11. +96 −0 ...erge/util/src/main/java/org/eclipse/ditto/services/concierge/util/config/DefaultCachesConfig.java
  12. +76 −0 ...util/src/main/java/org/eclipse/ditto/services/concierge/util/config/DefaultEnforcementConfig.java
  13. +90 −0 ...src/main/java/org/eclipse/ditto/services/concierge/util/config/DefaultThingsAggregatorConfig.java
  14. +8 −284 ...rge/util/src/main/java/org/eclipse/ditto/services/concierge/util/config/DittoConciergeConfig.java
  15. +97 −0 ...l/src/main/java/org/eclipse/ditto/services/connectivity/util/DefaultExponentialBackOffConfig.java
  16. +96 −0 ...vity/util/src/main/java/org/eclipse/ditto/services/connectivity/util/DefaultJavaScriptConfig.java
  17. +76 −0 ...nnectivity/util/src/main/java/org/eclipse/ditto/services/connectivity/util/DefaultMqttConfig.java
  18. +86 −0 ...nnectivity/util/src/main/java/org/eclipse/ditto/services/connectivity/util/DefaultRateConfig.java
  19. +77 −0 ...tivity/util/src/main/java/org/eclipse/ditto/services/connectivity/util/DefaultSnapshotConfig.java
  20. +7 −1 services/utils/config/src/main/java/org/eclipse/ditto/services/utils/config/ConfigWithFallback.java
  21. +358 −56 services/utils/config/src/main/java/org/eclipse/ditto/services/utils/config/DefaultScopedConfig.java
  22. +6 −1 services/utils/config/src/main/java/org/eclipse/ditto/services/utils/config/ScopedConfig.java
  23. +26 −0 ...es/utils/config/src/test/java/org/eclipse/ditto/services/utils/config/ConfigWithFallbackTest.java
  24. +35 −1 ...s/utils/config/src/test/java/org/eclipse/ditto/services/utils/config/DefaultScopedConfigTest.java
  25. +21 −0 services/utils/config/src/test/resources/test.conf
  26. +86 −0 ...n/java/org/eclipse/ditto/services/utils/persistence/mongo/config/DefaultCircuitBreakerConfig.java
  27. +105 −0 ...n/java/org/eclipse/ditto/services/utils/persistence/mongo/config/DefaultConnectionPoolConfig.java
  28. +16 −508 ...src/main/java/org/eclipse/ditto/services/utils/persistence/mongo/config/DefaultMongoDbConfig.java
  29. +86 −0 .../main/java/org/eclipse/ditto/services/utils/persistence/mongo/config/DefaultMonitoringConfig.java
  30. +80 −0 ...src/main/java/org/eclipse/ditto/services/utils/persistence/mongo/config/DefaultOptionsConfig.java
  31. +86 −0 ...src/main/java/org/eclipse/ditto/services/utils/persistence/mongo/config/DefaultTimeoutConfig.java
  32. +174 −0 ...stence/src/main/java/org/eclipse/ditto/services/utils/persistence/mongo/config/MongoDbConfig.java
  33. +0 −1 ...e/src/main/java/org/eclipse/ditto/services/utils/persistence/mongo/config/MongoDbUriSupplier.java
  34. +4 −4 ...test/java/org/eclipse/ditto/services/utils/persistence/mongo/config/DefaultMongoDbConfigTest.java
  35. +0 −1 ...c/test/java/org/eclipse/ditto/services/utils/persistence/mongo/config/MongoDbUriSupplierTest.java
@@ -14,7 +14,7 @@

import org.eclipse.ditto.services.base.config.ServiceSpecificConfig.ClusterConfig;
import org.eclipse.ditto.services.utils.config.ConfigWithFallback;
import org.eclipse.ditto.services.utils.config.KnownConfigValue;
import org.eclipse.ditto.services.utils.config.ScopedConfig;

import com.typesafe.config.Config;

@@ -23,46 +23,20 @@
*/
public final class DefaultClusterConfig implements ClusterConfig {

private enum ClusterConfigValue implements KnownConfigValue {

NUMBER_OF_SHARDS("number-of-shards", 30);

private final String path;
private final Object defaultValue;

private ClusterConfigValue(final String thePath, final Object theDefaultValue) {
path = thePath;
defaultValue = theDefaultValue;
}

@Override
public String getConfigPath() {
return path;
}

@Override
public Object getDefaultValue() {
return defaultValue;
}

}

private static final String CONFIG_PATH = "cluster";

private final Config config;
private final int numberOfShards;

private DefaultClusterConfig(final Config theConfig) {
config = theConfig;
private DefaultClusterConfig(final ScopedConfig config) {
numberOfShards = config.getInt(ClusterConfigValue.NUMBER_OF_SHARDS.getConfigPath());
}

/**
* Returns an instance of {@code DefaultClusterConfig} based on the settings of the specified Config.
*
* @param config is supposed to provide the settings of the cluster config at {@value #CONFIG_PATH}.
* @return the instance.
* @throws org.eclipse.ditto.services.utils.config.DittoConfigError if {@code config} is {@code null} if the
* value of {@code config} at {@code configPath} is not of type
* {@link com.typesafe.config.ConfigValueType#OBJECT}.
* @throws org.eclipse.ditto.services.utils.config.DittoConfigError if {@code config} is invalid.
*/
public static DefaultClusterConfig of(final Config config) {
return new DefaultClusterConfig(
@@ -71,7 +45,7 @@ public static DefaultClusterConfig of(final Config config) {

@Override
public int getNumberOfShards() {
return config.getInt(ClusterConfigValue.NUMBER_OF_SHARDS.getConfigPath());
return numberOfShards;
}

@Override
@@ -83,18 +57,18 @@ public boolean equals(final Object o) {
return false;
}
final DefaultClusterConfig that = (DefaultClusterConfig) o;
return config.equals(that.config);
return numberOfShards == that.numberOfShards;
}

@Override
public int hashCode() {
return Objects.hash(config);
return Objects.hash(numberOfShards);
}

@Override
public String toString() {
return getClass().getSimpleName() + " [" +
"config=" + config +
"numberOfShards=" + numberOfShards +
"]";
}

@@ -15,7 +15,7 @@

import org.eclipse.ditto.services.base.config.ServiceSpecificConfig.HealthCheckConfig;
import org.eclipse.ditto.services.utils.config.ConfigWithFallback;
import org.eclipse.ditto.services.utils.config.KnownConfigValue;
import org.eclipse.ditto.services.utils.config.ScopedConfig;

import com.typesafe.config.Config;

@@ -24,52 +24,26 @@
*/
public final class DefaultHealthCheckConfig implements HealthCheckConfig {

private enum HealthCheckConfigValue implements KnownConfigValue {

ENABLED("enabled", true),

INTERVAL("interval", Duration.ofMinutes(1L)),

PERSISTENCE_ENABLED("persistence.enabled", false),

PERSISTENCE_TIMEOUT("persistence.timeout", Duration.ofMinutes(1));

private final String path;
private final Object defaultValue;

private HealthCheckConfigValue(final String thePath, final Object theDefaultValue) {
path = thePath;
defaultValue = theDefaultValue;
}

@Override
public String getConfigPath() {
return path;
}

@Override
public Object getDefaultValue() {
return defaultValue;
}

}

private static final String CONFIG_PATH = "health-check";

private final Config config;
private final boolean enabled;
private final Duration interval;
private final boolean persistenceEnabled;
private final Duration persistenceTimeout;

private DefaultHealthCheckConfig(final Config theConfig) {
config = theConfig;
private DefaultHealthCheckConfig(final ScopedConfig config) {
enabled = config.getBoolean(HealthCheckConfigValue.ENABLED.getConfigPath());
interval = config.getDuration(HealthCheckConfigValue.INTERVAL.getConfigPath());
persistenceEnabled = config.getBoolean(HealthCheckConfigValue.PERSISTENCE_ENABLED.getConfigPath());
persistenceTimeout = config.getDuration(HealthCheckConfigValue.PERSISTENCE_TIMEOUT.getConfigPath());
}

/**
* Returns an instance of {@code DefaultHealthCheckConfig} based on the settings of the specified Config.
*
* @param config is supposed to provide the settings of the health check config at {@value #CONFIG_PATH}.
* @return the instance.
* @throws org.eclipse.ditto.services.utils.config.DittoConfigError if {@code config} is {@code null} if the
* value of {@code config} at {@code configPath} is not of type
* {@link com.typesafe.config.ConfigValueType#OBJECT}.
* @throws org.eclipse.ditto.services.utils.config.DittoConfigError if {@code config} is invalid.
*/
public static DefaultHealthCheckConfig of(final Config config) {
return new DefaultHealthCheckConfig(
@@ -78,22 +52,22 @@ public static DefaultHealthCheckConfig of(final Config config) {

@Override
public boolean isEnabled() {
return config.getBoolean(HealthCheckConfigValue.ENABLED.getConfigPath());
return enabled;
}

@Override
public Duration getInterval() {
return config.getDuration(HealthCheckConfigValue.INTERVAL.getConfigPath());
return interval;
}

@Override
public boolean isPersistenceEnabled() {
return config.getBoolean(HealthCheckConfigValue.PERSISTENCE_ENABLED.getConfigPath());
return persistenceEnabled;
}

@Override
public Duration getPersistenceTimeout() {
return config.getDuration(HealthCheckConfigValue.PERSISTENCE_TIMEOUT.getConfigPath());
return persistenceTimeout;
}

@Override
@@ -105,18 +79,24 @@ public boolean equals(final Object o) {
return false;
}
final DefaultHealthCheckConfig that = (DefaultHealthCheckConfig) o;
return config.equals(that.config);
return enabled == that.enabled &&
persistenceEnabled == that.persistenceEnabled &&
interval.equals(that.interval) &&
persistenceTimeout.equals(that.persistenceTimeout);
}

@Override
public int hashCode() {
return Objects.hash(config);
return Objects.hash(enabled, interval, persistenceEnabled, persistenceTimeout);
}

@Override
public String toString() {
return getClass().getSimpleName() + " [" +
"config=" + config +
"enabled=" + enabled +
", interval=" + interval +
", persistenceEnabled=" + persistenceEnabled +
", persistenceTimeout=" + persistenceTimeout +
"]";
}

@@ -16,7 +16,7 @@

import org.eclipse.ditto.services.base.config.ServiceSpecificConfig.HttpConfig;
import org.eclipse.ditto.services.utils.config.ConfigWithFallback;
import org.eclipse.ditto.services.utils.config.KnownConfigValue;
import org.eclipse.ditto.services.utils.config.ScopedConfig;

import com.typesafe.config.Config;

@@ -26,61 +26,35 @@
@Immutable
public final class DefaultHttpConfig implements HttpConfig {

private enum HttpConfigValue implements KnownConfigValue {

HOSTNAME("hostname", ""),

PORT("port", 8080);

private final String path;
private final Object defaultValue;

private HttpConfigValue(final String thePath, final Object theDefaultValue) {
path = thePath;
defaultValue = theDefaultValue;
}

@Override
public String getConfigPath() {
return path;
}

@Override
public Object getDefaultValue() {
return defaultValue;
}

}

private static final String CONFIG_PATH = "http";

private final Config config;
private final String hostname;
private final int port;

private DefaultHttpConfig(final Config theConfig) {
config = theConfig;
private DefaultHttpConfig(final ScopedConfig config) {
hostname = config.getString(HttpConfigValue.HOSTNAME.getConfigPath());
port = config.getInt(HttpConfigValue.PORT.getConfigPath());
}

/**
* Returns an instance of {@code DefaultHttpConfig} based on the settings of the specified Config.
*
* @param config is supposed to provide the settings of the HTTP config at {@value #CONFIG_PATH}.
* @return the instance.
* @throws org.eclipse.ditto.services.utils.config.DittoConfigError if {@code config} is {@code null} if the
* value of {@code config} at {@code configPath} is not of type
* {@link com.typesafe.config.ConfigValueType#OBJECT}.
* @throws org.eclipse.ditto.services.utils.config.DittoConfigError if {@code config} is invalid.
*/
public static DefaultHttpConfig of(final Config config) {
return new DefaultHttpConfig(ConfigWithFallback.newInstance(config, CONFIG_PATH, HttpConfigValue.values()));
}

@Override
public String getHostname() {
return config.getString(HttpConfigValue.HOSTNAME.getConfigPath());
return hostname;
}

@Override
public int getPort() {
return config.getInt(HttpConfigValue.PORT.getConfigPath());
return port;
}

@Override
@@ -92,18 +66,19 @@ public boolean equals(final Object o) {
return false;
}
final DefaultHttpConfig that = (DefaultHttpConfig) o;
return config.equals(that.config);
return port == that.port && hostname.equals(that.hostname);
}

@Override
public int hashCode() {
return Objects.hash(config);
return Objects.hash(hostname, port);
}

@Override
public String toString() {
return getClass().getSimpleName() + " [" +
"config=" + config +
"hostname=" + hostname +
", port=" + port +
"]";
}

0 comments on commit 7e7a088

Please sign in to comment.
You can’t perform that action at this time.