diff options
author | Jakub Dudycz <jakub.dudycz@nokia.com> | 2018-06-15 16:09:41 +0200 |
---|---|---|
committer | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2018-08-02 10:27:38 +0200 |
commit | 553154ae42e5362dacab6c190b8cf1e1388f5b87 (patch) | |
tree | 9f78fdd5da58082883724ead537dd5368c2cf940 /hv-collector-main | |
parent | 69f43f2532106b9d2d4c64fabbf4ea092e4dbf4a (diff) |
Change Consul configuration update policy
- At startup default config is applied
- Configuration is updated in intervals given at VES-HV
service startup to allow dynamic changes
- Included consul service startup in docker-compose file
- VES-HV now exits when fails to acquire confguration from consul
Closes ONAP-229
Change-Id: I896cfd177fa45381f9822278c2dffc113dd3df72
Signed-off-by: jakub.dudycz@nokia.com
Issue-ID: DCAEGEN2-601
Diffstat (limited to 'hv-collector-main')
4 files changed, 27 insertions, 31 deletions
diff --git a/hv-collector-main/Dockerfile b/hv-collector-main/Dockerfile index 1367ff1c..cab61dc3 100644 --- a/hv-collector-main/Dockerfile +++ b/hv-collector-main/Dockerfile @@ -9,7 +9,7 @@ EXPOSE 6061 WORKDIR /opt/ves-hv-collector ENTRYPOINT ["java", "-cp", "*:", "org.onap.dcae.collectors.veshv.main.MainKt"] -CMD ["--listen-port", "6061"] +CMD ["--listen-port", "6061","--config-url", "http://consul:8500/v1/kv/veshv-config"] COPY target/libs/external/* ./ COPY target/libs/internal/* ./ COPY target/hv-collector-main-*.jar ./ diff --git a/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfiguration.kt b/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfiguration.kt index f3e97be2..63de270e 100644 --- a/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfiguration.kt +++ b/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfiguration.kt @@ -24,17 +24,21 @@ import org.apache.commons.cli.DefaultParser import org.onap.dcae.collectors.veshv.domain.SecurityConfiguration import org.onap.dcae.collectors.veshv.model.ServerConfiguration import org.onap.dcae.collectors.veshv.utils.commandline.ArgBasedConfiguration -import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.CERT_FILE -import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.CONSUL_CONFIG_URL -import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.DUMMY_MODE -import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.IDLE_TIMEOUT_SEC +import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.LISTEN_PORT +import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.UPDATE_INTERVAL +import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.CONSUL_CONFIG_URL import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.PRIVATE_KEY_FILE +import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.CERT_FILE import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.TRUST_CERT_FILE +import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.IDLE_TIMEOUT_SEC +import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.DUMMY_MODE + import java.time.Duration internal object DefaultValues { const val PORT = 6061 + const val UPDATE_INTERVAL = 300L const val CONFIG_URL = "" const val PRIVATE_KEY_FILE = "/etc/ves-hv/server.key" const val CERT_FILE = "/etc/ves-hv/server.crt" @@ -45,6 +49,7 @@ internal object DefaultValues { internal class ArgBasedServerConfiguration : ArgBasedConfiguration<ServerConfiguration>(DefaultParser()) { override val cmdLineOptionsList = listOf( LISTEN_PORT, + UPDATE_INTERVAL, CONSUL_CONFIG_URL, PRIVATE_KEY_FILE, CERT_FILE, @@ -56,12 +61,14 @@ internal class ArgBasedServerConfiguration : ArgBasedConfiguration<ServerConfigu override fun getConfiguration(cmdLine: CommandLine): ServerConfiguration { val port = cmdLine.intValue(LISTEN_PORT, DefaultValues.PORT) val configUrl = cmdLine.stringValue(CONSUL_CONFIG_URL, DefaultValues.CONFIG_URL) + val updateInterval = cmdLine.longValue(UPDATE_INTERVAL, DefaultValues.UPDATE_INTERVAL) val idleTimeoutSec = cmdLine.longValue(IDLE_TIMEOUT_SEC, DefaultValues.IDLE_TIMEOUT_SEC) val dummyMode = cmdLine.hasOption(DUMMY_MODE) val security = createSecurityConfiguration(cmdLine) return ServerConfiguration( port = port, configurationUrl = configUrl, + configurationUpdateInterval = Duration.ofSeconds(updateInterval), securityConfiguration = security, idleTimeout = Duration.ofSeconds(idleTimeoutSec), dummyMode = dummyMode) diff --git a/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/main.kt b/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/main.kt index 074a75e4..d1c3b4a7 100644 --- a/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/main.kt +++ b/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/main.kt @@ -20,17 +20,13 @@ package org.onap.dcae.collectors.veshv.main import arrow.core.flatMap -import org.onap.dcae.collectors.veshv.boundary.ConfigurationProvider import org.onap.dcae.collectors.veshv.boundary.Server import org.onap.dcae.collectors.veshv.factory.CollectorFactory import org.onap.dcae.collectors.veshv.factory.ServerFactory import org.onap.dcae.collectors.veshv.impl.adapters.AdapterFactory -import org.onap.dcae.collectors.veshv.model.CollectorConfiguration import org.onap.dcae.collectors.veshv.model.ServerConfiguration -import org.onap.dcae.collectors.veshv.model.routing import org.onap.dcae.collectors.veshv.utils.commandline.handleErrorsInMain import org.onap.dcae.collectors.veshv.utils.logging.Logger -import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Domain private val logger = Logger("org.onap.dcae.collectors.veshv.main") private const val PROGRAM_NAME = "java org.onap.dcae.collectors.veshv.main.MainKt" @@ -55,7 +51,8 @@ fun main(args: Array<String>) { private fun createServer(config: ServerConfiguration): Server { val sink = if (config.dummyMode) AdapterFactory.loggingSink() else AdapterFactory.kafkaSink() val collectorProvider = CollectorFactory( - resolveConfigurationProvider(config), + AdapterFactory.consulConfigurationProvider( + config.configurationUrl, config.configurationUpdateInterval), sink, MicrometerMetrics() ).createVesHvCollectorProvider() @@ -63,23 +60,3 @@ private fun createServer(config: ServerConfiguration): Server { return ServerFactory.createNettyTcpServer(config, collectorProvider) } -private fun resolveConfigurationProvider(serverConfiguration: ServerConfiguration): ConfigurationProvider { - - if (serverConfiguration.configurationUrl.isEmpty()) { - logger.info("Configuration url not specified - using default config") - val sampleConfig = CollectorConfiguration( - kafkaBootstrapServers = "kafka:9092", - routing = routing { - defineRoute { - fromDomain(Domain.HVRANMEAS) - toTopic("ves_hvRanMeas") - withFixedPartitioning() - } - }.build() - ) - return AdapterFactory.staticConfigurationProvider(sampleConfig) - } - - logger.info("Using configuration url: ${serverConfiguration.configurationUrl}") - return AdapterFactory.consulConfigurationProvider(serverConfiguration.configurationUrl) -} diff --git a/hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfigurationTest.kt b/hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfigurationTest.kt index 4c2425bc..a14801da 100644 --- a/hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfigurationTest.kt +++ b/hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfigurationTest.kt @@ -30,6 +30,7 @@ import org.jetbrains.spek.api.dsl.on import org.onap.dcae.collectors.veshv.domain.SecurityConfiguration import org.onap.dcae.collectors.veshv.model.ServerConfiguration import java.nio.file.Paths +import java.time.Duration /** * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com> @@ -38,6 +39,8 @@ import java.nio.file.Paths object ArgBasedServerConfigurationTest : Spek({ lateinit var cut: ArgBasedServerConfiguration val configurationUrl = "http://test-address/test" + val listenPort = "6969" + val updateInterval = "10" val pk = Paths.get("/", "etc", "ves", "pk.pem") val cert = Paths.get("/", "etc", "ssl", "certs", "ca-bundle.crt") val trustCert = Paths.get("/", "etc", "ves", "trusted.crt") @@ -59,8 +62,9 @@ object ArgBasedServerConfigurationTest : Spek({ lateinit var result: ServerConfiguration beforeEachTest { - result = parse("--listen-port", "6969", + result = parse("--listen-port", listenPort, "--config-url", configurationUrl, + "--update-interval", updateInterval, "--private-key-file", pk.toFile().absolutePath, "--cert-file", cert.toFile().absolutePath, "--trust-cert-file", trustCert.toFile().absolutePath) @@ -70,6 +74,10 @@ object ArgBasedServerConfigurationTest : Spek({ assertThat(result.port).isEqualTo(6969) } + it("should set update interval") { + assertThat(result.configurationUpdateInterval).isEqualTo(Duration.ofSeconds(10)) + } + it("should set proper config url") { assertThat(result.configurationUrl).isEqualTo(configurationUrl) } @@ -112,6 +120,10 @@ object ArgBasedServerConfigurationTest : Spek({ assertThat(result.configurationUrl).isEqualTo(DefaultValues.CONFIG_URL) } + it("should set default update interval") { + assertThat(result.configurationUpdateInterval).isEqualTo(Duration.ofSeconds(DefaultValues.UPDATE_INTERVAL)) + } + on("security config") { val securityConfiguration = result.securityConfiguration |