From a788d58f813b71644059623877aca629ab49ab74 Mon Sep 17 00:00:00 2001 From: Jakub Dudycz Date: Thu, 5 Jul 2018 14:35:43 +0200 Subject: Implement blocking consul calls Replaced interval based requesting for consul configuration with blocking query calls Closes ONAP-80 Change-Id: If70365bae9fde513d99b047209d085122a5df0dd Signed-off-by: Jakub Dudycz Issue-ID: DCAEGEN2-601 --- .../veshv/main/ArgBasedServerConfiguration.kt | 19 +++++-------------- .../org/onap/dcae/collectors/veshv/main/main.kt | 5 +---- .../veshv/main/ArgBasedServerConfigurationTest.kt | 21 ++++++++++++++------- 3 files changed, 20 insertions(+), 25 deletions(-) (limited to 'hv-collector-main/src') 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 63de270e..9e4c5f2d 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,21 +24,12 @@ 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 -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 org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.* import java.time.Duration internal object DefaultValues { const val PORT = 6061 - const val UPDATE_INTERVAL = 300L + const val CONSUL_FIRST_REQUEST_DELAY = 10L const val CONFIG_URL = "" const val PRIVATE_KEY_FILE = "/etc/ves-hv/server.key" const val CERT_FILE = "/etc/ves-hv/server.crt" @@ -49,8 +40,8 @@ internal object DefaultValues { internal class ArgBasedServerConfiguration : ArgBasedConfiguration(DefaultParser()) { override val cmdLineOptionsList = listOf( LISTEN_PORT, - UPDATE_INTERVAL, CONSUL_CONFIG_URL, + CONSUL_FIRST_REQUEST_DELAY, PRIVATE_KEY_FILE, CERT_FILE, TRUST_CERT_FILE, @@ -61,14 +52,14 @@ internal class ArgBasedServerConfiguration : ArgBasedConfiguration) = private fun createServer(config: ServerConfiguration): Server { val sink = if (config.dummyMode) AdapterFactory.loggingSink() else AdapterFactory.kafkaSink() val collectorProvider = CollectorFactory( - AdapterFactory.consulConfigurationProvider( - config.configurationUrl, config.configurationUpdateInterval), - sink, - MicrometerMetrics() + AdapterFactory.consulConfigurationProvider(config.configurationUrl, config.firstRequestDelay), sink, MicrometerMetrics() ).createVesHvCollectorProvider() return ServerFactory.createNettyTcpServer(config, collectorProvider) 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 2c49cf98..8f0c2af9 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 @@ -40,8 +40,8 @@ import java.time.Duration object ArgBasedServerConfigurationTest : Spek({ lateinit var cut: ArgBasedServerConfiguration val configurationUrl = "http://test-address/test" + val firstRequestDelay = "10" 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") @@ -63,7 +63,7 @@ object ArgBasedServerConfigurationTest : Spek({ beforeEachTest { result = parse("--listen-port", listenPort, "--config-url", configurationUrl, - "--update-interval", updateInterval, + "--first-request-delay", firstRequestDelay, "--private-key-file", pk.toFile().absolutePath, "--cert-file", cert.toFile().absolutePath, "--trust-cert-file", trustCert.toFile().absolutePath) @@ -73,8 +73,8 @@ object ArgBasedServerConfigurationTest : Spek({ assertThat(result.port).isEqualTo(6969) } - it("should set update interval") { - assertThat(result.configurationUpdateInterval).isEqualTo(Duration.ofSeconds(10)) + it("should set proper first consul request delay") { + assertThat(result.firstRequestDelay).isEqualTo(Duration.ofSeconds(10)) } it("should set proper config url") { @@ -86,19 +86,25 @@ object ArgBasedServerConfigurationTest : Spek({ SecurityConfiguration(pk, cert, trustCert) ) } + + } given("some parameters are present in the short form") { lateinit var result: ServerConfiguration beforeEachTest { - result = parse("-p", "666", "-c", configurationUrl) + result = parse("-p", "666", "-c", configurationUrl, "-d", firstRequestDelay) } it("should set proper port") { assertThat(result.port).isEqualTo(666) } + it("should set proper first consul request delay") { + assertThat(result.firstRequestDelay).isEqualTo(Duration.ofSeconds(10)) + } + it("should set proper config url") { assertThat(result.configurationUrl).isEqualTo(configurationUrl) } @@ -119,8 +125,9 @@ 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)) + it("should set default first consul request delay") { + assertThat(result.firstRequestDelay) + .isEqualTo(Duration.ofSeconds(DefaultValues.CONSUL_FIRST_REQUEST_DELAY)) } on("security config") { -- cgit 1.2.3-korg