Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor config package #528

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected AbstractRepairConfigurationProvider(final ApplicationContext anApplica
this.applicationContext = anApplicationContext;

Config config = applicationContext.getBean(Config.class);
this.defaultRepairConfiguration = config.getRepair().asRepairConfiguration();
this.defaultRepairConfiguration = config.getRepairConfig().asRepairConfiguration();
}

public final Set<RepairConfiguration> get(final TableReference tableReference)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@

import javax.management.remote.JMXConnector;

import com.ericsson.bss.cassandra.ecchronos.application.config.connection.Connection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ericsson.bss.cassandra.ecchronos.application.config.Config;
import com.ericsson.bss.cassandra.ecchronos.application.config.Credentials;
import com.ericsson.bss.cassandra.ecchronos.application.config.Security;
import com.ericsson.bss.cassandra.ecchronos.application.config.TLSConfig;
import com.ericsson.bss.cassandra.ecchronos.application.config.security.Credentials;
import com.ericsson.bss.cassandra.ecchronos.application.config.security.Security;
import com.ericsson.bss.cassandra.ecchronos.application.config.security.TLSConfig;
import com.ericsson.bss.cassandra.ecchronos.connection.JmxConnectionProvider;
import com.ericsson.bss.cassandra.ecchronos.connection.impl.LocalJmxConnectionProvider;
import com.google.common.base.Joiner;
Expand All @@ -41,11 +42,11 @@ public class DefaultJmxConnectionProvider implements JmxConnectionProvider
public DefaultJmxConnectionProvider(final Config config,
final Supplier<Security.JmxSecurity> jmxSecurity) throws IOException
{
Config.Connection<JmxConnectionProvider> jmxConfig = config.getConnectionConfig().getJmx();
Connection<JmxConnectionProvider> jmxConfig = config.getConnectionConfig().getJmxConnection();
String host = jmxConfig.getHost();
int port = jmxConfig.getPort();
boolean authEnabled = jmxSecurity.get().getCredentials().isEnabled();
boolean tlsEnabled = jmxSecurity.get().getTls().isEnabled();
boolean authEnabled = jmxSecurity.get().getJmxCredentials().isEnabled();
boolean tlsEnabled = jmxSecurity.get().getJmxTlsConfig().isEnabled();
LOG.info("Connecting through JMX using {}:{}, authentication: {}, tls: {}", host, port, authEnabled,
tlsEnabled);

Expand All @@ -69,30 +70,30 @@ public final void close() throws IOException

private Map<String, String> convertTls(final Supplier<Security.JmxSecurity> jmxSecurity)
{
TLSConfig tlsConfig = jmxSecurity.get().getTls();
TLSConfig tlsConfig = jmxSecurity.get().getJmxTlsConfig();
if (!tlsConfig.isEnabled())
{
return new HashMap<>();
}

Map<String, String> config = new HashMap<>();
config.put("com.sun.management.jmxremote.ssl.enabled.protocols", tlsConfig.getProtocol());
String ciphers = tlsConfig.getCipher_suites()
String ciphers = tlsConfig.getCipherSuites()
.map(Joiner.on(',')::join)
.orElse("");
config.put("com.sun.management.jmxremote.ssl.enabled.cipher.suites", ciphers);

config.put("javax.net.ssl.keyStore", tlsConfig.getKeystore());
config.put("javax.net.ssl.keyStorePassword", tlsConfig.getKeystore_password());
config.put("javax.net.ssl.trustStore", tlsConfig.getTruststore());
config.put("javax.net.ssl.trustStorePassword", tlsConfig.getTruststore_password());
config.put("javax.net.ssl.keyStore", tlsConfig.getKeyStorePath());
config.put("javax.net.ssl.keyStorePassword", tlsConfig.getKeyStorePassword());
config.put("javax.net.ssl.trustStore", tlsConfig.getTrustStorePath());
config.put("javax.net.ssl.trustStorePassword", tlsConfig.getTrustStorePassword());

return config;
}

private String[] convertCredentials(final Supplier<Security.JmxSecurity> jmxSecurity)
{
Credentials credentials = jmxSecurity.get().getCredentials();
Credentials credentials = jmxSecurity.get().getJmxCredentials();
if (!credentials.isEnabled())
{
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
import com.datastax.oss.driver.api.core.auth.AuthProvider;
import com.datastax.oss.driver.api.core.metadata.Node;
import com.datastax.oss.driver.api.core.ssl.SslEngineFactory;
import com.ericsson.bss.cassandra.ecchronos.application.config.connection.NativeConnection;
import com.ericsson.bss.cassandra.ecchronos.connection.CertificateHandler;
import com.ericsson.bss.cassandra.ecchronos.core.repair.DefaultRepairConfigurationProvider;
import io.micrometer.core.instrument.MeterRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ericsson.bss.cassandra.ecchronos.application.config.Config;
import com.ericsson.bss.cassandra.ecchronos.application.config.Security;
import com.ericsson.bss.cassandra.ecchronos.application.config.security.Security;
import com.ericsson.bss.cassandra.ecchronos.connection.NativeConnectionProvider;
import com.ericsson.bss.cassandra.ecchronos.connection.impl.LocalNativeConnectionProvider;

Expand All @@ -47,19 +48,19 @@ public DefaultNativeConnectionProvider(final Config config,
final DefaultRepairConfigurationProvider defaultRepairConfigurationProvider,
final MeterRegistry meterRegistry)
{
Config.NativeConnection nativeConfig = config.getConnectionConfig().getCql();
NativeConnection nativeConfig = config.getConnectionConfig().getCqlConnection();
String host = nativeConfig.getHost();
int port = nativeConfig.getPort();
boolean remoteRouting = nativeConfig.getRemoteRouting();
Security.CqlSecurity cqlSecurity = cqlSecuritySupplier.get();
boolean authEnabled = cqlSecurity.getCredentials().isEnabled();
boolean tlsEnabled = cqlSecurity.getTls().isEnabled();
boolean authEnabled = cqlSecurity.getCqlCredentials().isEnabled();
boolean tlsEnabled = cqlSecurity.getCqlTlsConfig().isEnabled();
LOG.info("Connecting through CQL using {}:{}, authentication: {}, tls: {}", host, port, authEnabled,
tlsEnabled);
AuthProvider authProvider = null;
if (authEnabled)
{
authProvider = new ReloadingAuthProvider(() -> cqlSecuritySupplier.get().getCredentials());
authProvider = new ReloadingAuthProvider(() -> cqlSecuritySupplier.get().getCqlCredentials());
}

SslEngineFactory sslEngineFactory = null;
Expand All @@ -74,7 +75,7 @@ public DefaultNativeConnectionProvider(final Config config,
.withRemoteRouting(remoteRouting)
.withAuthProvider(authProvider)
.withSslEngineFactory(sslEngineFactory)
.withMetricsEnabled(config.getStatistics().isEnabled())
.withMetricsEnabled(config.getStatisticsConfig().isEnabled())
.withMeterRegistry(meterRegistry)
.withSchemaChangeListener(defaultRepairConfigurationProvider)
.withNodeStateListener(defaultRepairConfigurationProvider);
Expand All @@ -88,7 +89,8 @@ public DefaultNativeConnectionProvider(final Config config,
final DefaultRepairConfigurationProvider defaultRepairConfigurationProvider,
final MeterRegistry meterRegistry)
{
this(config, cqlSecuritySupplier, new ReloadingCertificateHandler(() -> cqlSecuritySupplier.get().getTls()),
this(config, cqlSecuritySupplier,
new ReloadingCertificateHandler(() -> cqlSecuritySupplier.get().getCqlTlsConfig()),
defaultRepairConfigurationProvider, meterRegistry);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public ECChronosInternals(final Config configuration,
.withNativeConnectionProvider(nativeConnectionProvider)
.withHostStates(myHostStatesImpl)
.withStatementDecorator(statementDecorator)
.withKeyspaceName(configuration.getLockFactory().getCas().getKeyspace())
.withKeyspaceName(configuration.getLockFactory().getCasLockFactoryConfig().getKeyspaceName())
.build();

Node node = nativeConnectionProvider.getLocalNode();
Expand All @@ -94,7 +94,7 @@ public ECChronosInternals(final Config configuration,
.withReplicatedTableProvider(myReplicatedTableProvider)
.build();

if (configuration.getStatistics().isEnabled())
if (configuration.getStatisticsConfig().isEnabled())
{
myTableStorageStatesImpl = TableStorageStatesImpl.builder()
.withReplicatedTableProvider(myReplicatedTableProvider)
Expand All @@ -113,7 +113,7 @@ public ECChronosInternals(final Config configuration,
}
myScheduleManagerImpl = ScheduleManagerImpl.builder()
.withLockFactory(myLockFactory)
.withRunInterval(configuration.getScheduler().getFrequency().getInterval(TimeUnit.MILLISECONDS),
.withRunInterval(configuration.getSchedulerConfig().getFrequency().getInterval(TimeUnit.MILLISECONDS),
TimeUnit.MILLISECONDS)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.springframework.context.ApplicationContext;

import com.ericsson.bss.cassandra.ecchronos.application.config.ConfigurationHelper;
import com.ericsson.bss.cassandra.ecchronos.application.config.RepairSchedule;
import com.ericsson.bss.cassandra.ecchronos.application.config.repair.RepairSchedule;
import com.ericsson.bss.cassandra.ecchronos.core.repair.RepairConfiguration;
import com.ericsson.bss.cassandra.ecchronos.core.utils.TableReference;
import com.google.common.annotations.VisibleForTesting;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

package com.ericsson.bss.cassandra.ecchronos.application;

import com.ericsson.bss.cassandra.ecchronos.application.config.Config;
import com.ericsson.bss.cassandra.ecchronos.application.config.metrics.ExcludedMetric;
import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.config.MeterFilter;
Expand All @@ -31,9 +31,9 @@ public class MeterFilterImpl implements MeterFilter
{
private static final Logger LOG = LoggerFactory.getLogger(MeterFilterImpl.class);
private final String myPrefix;
private final Set<Config.ExcludedMetric> myExcludedMetrics;
private final Set<ExcludedMetric> myExcludedMetrics;

public MeterFilterImpl(final String prefix, final Set<Config.ExcludedMetric> excludedMetrics)
public MeterFilterImpl(final String prefix, final Set<ExcludedMetric> excludedMetrics)
{
myPrefix = prefix;
myExcludedMetrics = excludedMetrics;
Expand All @@ -55,9 +55,9 @@ public MeterFilterReply accept(final Meter.Id id)
}
metricName = removePrefixIfPresent(metricName);
List<Tag> tags = id.getTags();
for (Config.ExcludedMetric excludedMetric : myExcludedMetrics)
for (ExcludedMetric excludedMetric : myExcludedMetrics)
{
if (shouldExclude(metricName, excludedMetric.getName(), tags, excludedMetric.getTags()))
if (shouldExclude(metricName, excludedMetric.getMetricName(), tags, excludedMetric.getMetricTags()))
{
return MeterFilterReply.DENY;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@

public class ReloadingAuthProvider extends ProgrammaticPlainTextAuthProvider
{
private final Supplier<com.ericsson.bss.cassandra.ecchronos.application.config.Credentials> credentialSupplier;
private final Supplier<com.ericsson.bss.cassandra.ecchronos.application.config.security.Credentials>
credentialSupplier;

public ReloadingAuthProvider(
final Supplier<com.ericsson.bss.cassandra.ecchronos.application.config.Credentials> aCredentialSupplier)
final Supplier<com.ericsson.bss.cassandra.ecchronos.application.config.security.Credentials>
aCredentialSupplier)
{
super(aCredentialSupplier.get().getUsername(), aCredentialSupplier.get().getPassword());
this.credentialSupplier = aCredentialSupplier;
Expand All @@ -33,7 +35,8 @@ public ReloadingAuthProvider(
@Override
protected final Credentials getCredentials(final EndPoint endPoint, final String serverAuthenticator)
{
com.ericsson.bss.cassandra.ecchronos.application.config.Credentials credentials = credentialSupplier.get();
com.ericsson.bss.cassandra.ecchronos.application.config.security.Credentials credentials =
credentialSupplier.get();
return new Credentials(credentials.getUsername().toCharArray(), credentials.getPassword().toCharArray());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package com.ericsson.bss.cassandra.ecchronos.application;

import com.datastax.oss.driver.api.core.metadata.EndPoint;
import com.ericsson.bss.cassandra.ecchronos.application.config.TLSConfig;
import com.ericsson.bss.cassandra.ecchronos.application.config.security.TLSConfig;
import com.ericsson.bss.cassandra.ecchronos.connection.CertificateHandler;
import io.netty.buffer.ByteBufAllocator;
import io.netty.handler.ssl.SslContext;
Expand Down Expand Up @@ -92,7 +92,7 @@ public SSLEngine newSslEngine(final EndPoint remoteEndpoint)
sslParameters.setEndpointIdentificationAlgorithm("HTTPS");
sslEngine.setSSLParameters(sslParameters);
}
tlsConfig.getCipher_suites().ifPresent(sslEngine::setEnabledCipherSuites);
tlsConfig.getCipherSuites().ifPresent(sslEngine::setEnabledCipherSuites);
return sslEngine;
}

Expand Down Expand Up @@ -169,22 +169,22 @@ private Map<String, String> calculateChecksums(final TLSConfig tlsConfig)
throws IOException, NoSuchAlgorithmException
{
Map<String, String> checksums = new HashMap<>();
if (tlsConfig.getCertificate().isPresent()
&& tlsConfig.getCertificatePrivateKey().isPresent()
&& tlsConfig.getTrustCertificate().isPresent())
if (tlsConfig.getCertificatePath().isPresent()
&& tlsConfig.getCertificatePrivateKeyPath().isPresent()
&& tlsConfig.getTrustCertificatePath().isPresent())
{
String certificate = tlsConfig.getCertificate().get();
String certificate = tlsConfig.getCertificatePath().get();
checksums.put(certificate, getChecksum(certificate));
String certificatePrivateKey = tlsConfig.getCertificatePrivateKey().get();
String certificatePrivateKey = tlsConfig.getCertificatePrivateKeyPath().get();
checksums.put(certificatePrivateKey, getChecksum(certificatePrivateKey));
String trustCertificate = tlsConfig.getTrustCertificate().get();
String trustCertificate = tlsConfig.getTrustCertificatePath().get();
checksums.put(trustCertificate, getChecksum(trustCertificate));
}
else
{
String keyStore = tlsConfig.getKeystore();
String keyStore = tlsConfig.getKeyStorePath();
checksums.put(keyStore, getChecksum(keyStore));
String trustStore = tlsConfig.getTruststore();
String trustStore = tlsConfig.getTrustStorePath();
checksums.put(trustStore, getChecksum(trustStore));
}
return checksums;
Expand Down Expand Up @@ -212,13 +212,13 @@ protected static SslContext createSSLContext(final TLSConfig tlsConfig) throws I

SslContextBuilder builder = SslContextBuilder.forClient();

if (tlsConfig.getCertificate().isPresent()
&& tlsConfig.getCertificatePrivateKey().isPresent()
&& tlsConfig.getTrustCertificate().isPresent())
if (tlsConfig.getCertificatePath().isPresent()
&& tlsConfig.getCertificatePrivateKeyPath().isPresent()
&& tlsConfig.getTrustCertificatePath().isPresent())
{
File certificateFile = new File(tlsConfig.getCertificate().get());
File certificatePrivateKeyFile = new File(tlsConfig.getCertificatePrivateKey().get());
File trustCertificateFile = new File(tlsConfig.getTrustCertificate().get());
File certificateFile = new File(tlsConfig.getCertificatePath().get());
File certificatePrivateKeyFile = new File(tlsConfig.getCertificatePrivateKeyPath().get());
File trustCertificateFile = new File(tlsConfig.getTrustCertificatePath().get());

builder.keyManager(certificateFile, certificatePrivateKeyFile);
builder.trustManager(trustCertificateFile);
Expand All @@ -230,9 +230,9 @@ protected static SslContext createSSLContext(final TLSConfig tlsConfig) throws I
builder.keyManager(keyManagerFactory);
builder.trustManager(trustManagerFactory);
}
if (tlsConfig.getCipher_suites().isPresent())
if (tlsConfig.getCipherSuites().isPresent())
{
builder.ciphers(Arrays.asList(tlsConfig.getCipher_suites().get()));
builder.ciphers(Arrays.asList(tlsConfig.getCipherSuites().get()));
}
return builder.protocols(tlsConfig.getProtocols()).build();
}
Expand All @@ -241,12 +241,12 @@ protected static KeyManagerFactory getKeyManagerFactory(final TLSConfig tlsConfi
NoSuchAlgorithmException, KeyStoreException, CertificateException, UnrecoverableKeyException
{
String algorithm = tlsConfig.getAlgorithm().orElse(KeyManagerFactory.getDefaultAlgorithm());
char[] keystorePassword = tlsConfig.getKeystore_password().toCharArray();
char[] keystorePassword = tlsConfig.getKeyStorePassword().toCharArray();

try (InputStream keystoreFile = new FileInputStream(tlsConfig.getKeystore()))
try (InputStream keystoreFile = new FileInputStream(tlsConfig.getKeyStorePath()))
{
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(algorithm);
KeyStore keyStore = KeyStore.getInstance(tlsConfig.getStore_type());
KeyStore keyStore = KeyStore.getInstance(tlsConfig.getStoreType());
keyStore.load(keystoreFile, keystorePassword);
keyManagerFactory.init(keyStore, keystorePassword);
return keyManagerFactory;
Expand All @@ -257,12 +257,12 @@ protected static TrustManagerFactory getTrustManagerFactory(final TLSConfig tlsC
throws IOException, NoSuchAlgorithmException, KeyStoreException, CertificateException
{
String algorithm = tlsConfig.getAlgorithm().orElse(TrustManagerFactory.getDefaultAlgorithm());
char[] truststorePassword = tlsConfig.getTruststore_password().toCharArray();
char[] truststorePassword = tlsConfig.getTrustStorePassword().toCharArray();

try (InputStream truststoreFile = new FileInputStream(tlsConfig.getTruststore()))
try (InputStream truststoreFile = new FileInputStream(tlsConfig.getTrustStorePath()))
{
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(algorithm);
KeyStore keyStore = KeyStore.getInstance(tlsConfig.getStore_type());
KeyStore keyStore = KeyStore.getInstance(tlsConfig.getStoreType());
keyStore.load(truststoreFile, truststorePassword);
trustManagerFactory.init(keyStore);
return trustManagerFactory;
Expand Down
Loading