Remove default consul configuration 97/58897/1
authorJakub Dudycz <jakub.dudycz@nokia.com>
Tue, 31 Jul 2018 12:49:35 +0000 (14:49 +0200)
committerPiotr Jaszczyk <piotr.jaszczyk@nokia.com>
Fri, 3 Aug 2018 09:27:21 +0000 (11:27 +0200)
Default consul configuration is not needed in real life use case
and it doesnt even bring anything useful in our test environment,
since it's immediately overriden.

Tasks:
- remove default consul configuration
- make "config-url" argument required

Closes ONAP-727

Change-Id: I4a01cebfc6b2918fa3aa6020504def60572b09da
Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
Issue-ID: DCAEGEN2-601

hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/factory/CollectorFactory.kt
hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/impl/socket/SslContextFactory.kt
hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/ArgVesHvConfiguration.kt
hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/ArgVesHvConfigurationTest.kt
hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/CommandLineOption.kt

index 7ce49a8..7be24d2 100644 (file)
@@ -28,12 +28,9 @@ import org.onap.dcae.collectors.veshv.domain.WireFrameDecoder
 import org.onap.dcae.collectors.veshv.impl.Router
 import org.onap.dcae.collectors.veshv.impl.VesDecoder
 import org.onap.dcae.collectors.veshv.impl.VesHvCollector
-import org.onap.dcae.collectors.veshv.impl.adapters.ConsulConfigurationProvider
 import org.onap.dcae.collectors.veshv.impl.wire.WireChunkDecoder
 import org.onap.dcae.collectors.veshv.model.CollectorConfiguration
-import org.onap.dcae.collectors.veshv.model.routing
 import org.onap.dcae.collectors.veshv.utils.logging.Logger
-import org.onap.ves.VesEventV5
 import java.util.concurrent.atomic.AtomicReference
 
 /**
@@ -45,8 +42,7 @@ class CollectorFactory(val configuration: ConfigurationProvider,
                        private val metrics: Metrics) {
 
     fun createVesHvCollectorProvider(): CollectorProvider {
-        val initialValue = createVesHvCollector(defaultConfiguration())
-        val collector: AtomicReference<Collector> = AtomicReference(initialValue)
+        val collector: AtomicReference<Collector> = AtomicReference()
         configuration()
                 .map(this::createVesHvCollector)
                 .doOnNext { logger.info("Using updated configuration for new connections") }
@@ -61,17 +57,6 @@ class CollectorFactory(val configuration: ConfigurationProvider,
         return collector::get
     }
 
-    private fun defaultConfiguration() =
-            CollectorConfiguration(
-                    kafkaBootstrapServers = "kafka:9092",
-                    routing = routing {
-                        defineRoute {
-                            fromDomain(VesEventV5.VesEvent.CommonEventHeader.Domain.HVRANMEAS)
-                            toTopic("ves_hvRanMeas")
-                            withFixedPartitioning()
-                        }
-                    }.build())
-
     private fun createVesHvCollector(config: CollectorConfiguration): Collector {
         return VesHvCollector(
                 wireChunkDecoderSupplier = { alloc -> WireChunkDecoder(WireFrameDecoder(), alloc) },
index 0dce0d6..3f7238f 100644 (file)
@@ -19,9 +19,7 @@
  */
 package org.onap.dcae.collectors.veshv.impl.socket
 
-import arrow.core.None
 import arrow.core.Option
-import arrow.core.Some
 import io.netty.handler.ssl.ClientAuth
 import io.netty.handler.ssl.SslContext
 import io.netty.handler.ssl.SslContextBuilder
index 77d074e..7c958b9 100644 (file)
@@ -30,7 +30,16 @@ import org.onap.dcae.collectors.veshv.domain.SecurityConfiguration
 import org.onap.dcae.collectors.veshv.model.ConfigurationProviderParams
 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.CERT_FILE
+import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.CONSUL_CONFIG_URL
+import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.CONSUL_FIRST_REQUEST_DELAY
+import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.CONSUL_REQUEST_INTERVAL
+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.LISTEN_PORT
+import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.PRIVATE_KEY_FILE
+import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.SSL_DISABLE
+import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.TRUST_CERT_FILE
 import java.time.Duration
 
 internal class ArgVesHvConfiguration : ArgBasedConfiguration<ServerConfiguration>(DefaultParser()) {
@@ -54,8 +63,7 @@ internal class ArgVesHvConfiguration : ArgBasedConfiguration<ServerConfiguration
                     val idleTimeoutSec = cmdLine.longValue(IDLE_TIMEOUT_SEC, DefaultValues.IDLE_TIMEOUT_SEC)
                     val dummyMode = cmdLine.hasOption(DUMMY_MODE)
                     val security = createSecurityConfiguration(cmdLine)
-                    val configurationProviderParams = createConfigurationProviderParams(cmdLine)
-
+                    val configurationProviderParams = createConfigurationProviderParams(cmdLine).bind()
                     ServerConfiguration(
                             listenPort = listenPort,
                             configurationProviderParams = configurationProviderParams,
@@ -65,18 +73,20 @@ internal class ArgVesHvConfiguration : ArgBasedConfiguration<ServerConfiguration
                 }.fix()
             }
 
+    private fun createConfigurationProviderParams(cmdLine: CommandLine): Option<ConfigurationProviderParams> =
+            ForOption extensions {
+                binding {
+                    val configUrl = cmdLine.stringValue(CONSUL_CONFIG_URL).bind()
+                    val firstRequestDelay = cmdLine.longValue(CONSUL_FIRST_REQUEST_DELAY, DefaultValues.CONSUL_FIRST_REQUEST_DELAY)
+                    val requestInterval = cmdLine.longValue(CONSUL_REQUEST_INTERVAL, DefaultValues.CONSUL_REQUEST_INTERVAL)
 
-    private fun createConfigurationProviderParams(cmdLine: CommandLine): ConfigurationProviderParams {
-        val configUrl = cmdLine.stringValue(CONSUL_CONFIG_URL, DefaultValues.CONFIG_URL)
-        val firstRequestDelay = cmdLine.longValue(CONSUL_FIRST_REQUEST_DELAY, DefaultValues.CONSUL_FIRST_REQUEST_DELAY)
-        val requestInterval = cmdLine.longValue(CONSUL_REQUEST_INTERVAL, DefaultValues.CONSUL_REQUEST_INTERVAL)
-
-        return ConfigurationProviderParams(
-                configUrl,
-                Duration.ofSeconds(firstRequestDelay),
-                Duration.ofSeconds(requestInterval)
-        )
-    }
+                    ConfigurationProviderParams(
+                            configUrl,
+                            Duration.ofSeconds(firstRequestDelay),
+                            Duration.ofSeconds(requestInterval)
+                    )
+                }.fix()
+            }
 
     private fun createSecurityConfiguration(cmdLine: CommandLine): SecurityConfiguration {
         val sslDisable = cmdLine.hasOption(SSL_DISABLE)
@@ -95,7 +105,6 @@ internal class ArgVesHvConfiguration : ArgBasedConfiguration<ServerConfiguration
     internal object DefaultValues {
         const val CONSUL_FIRST_REQUEST_DELAY = 10L
         const val CONSUL_REQUEST_INTERVAL = 5L
-        const val CONFIG_URL = ""
         const val PRIVATE_KEY_FILE = "/etc/ves-hv/server.key"
         const val CERT_FILE = "/etc/ves-hv/server.crt"
         const val TRUST_CERT_FILE = "/etc/ves-hv/trust.crt"
index f15f7f4..14f9be0 100644 (file)
@@ -97,7 +97,9 @@ object ArgVesHvConfigurationTest : Spek({
             lateinit var result: ServerConfiguration
 
             beforeEachTest {
-                result = cut.parseExpectingSuccess("-p", listenPort, "-c", configurationUrl, "-d", firstRequestDelay)
+                result = cut.parseExpectingSuccess(
+                        "-p", listenPort, "-c", configurationUrl, "-d", firstRequestDelay
+                )
             }
 
             it("should set proper port") {
@@ -119,12 +121,9 @@ object ArgVesHvConfigurationTest : Spek({
             lateinit var result: ServerConfiguration
 
             beforeEachTest {
-                result = cut.parseExpectingSuccess("--listen-port", listenPort)
-            }
-
-            it("should set default config url") {
-                assertThat(result.configurationProviderParams.configurationUrl)
-                        .isEqualTo(DefaultValues.CONFIG_URL)
+                result = cut.parseExpectingSuccess(
+                        "--listen-port", listenPort, "--config-url", configurationUrl
+                )
             }
 
             it("should set default first consul request delay") {
@@ -155,11 +154,24 @@ object ArgVesHvConfigurationTest : Spek({
         }
 
         describe("required parameter is absent") {
-            given("listen port is missing") {
+            on("missing listen port") {
                 it("should throw exception") {
                     assertThat(cut.parseExpectingFailure(
-                            "--ssl-disable",
                             "--config-url", configurationUrl,
+                            "--ssl-disable",
+                            "--first-request-delay", firstRequestDelay,
+                            "--request-interval", requestInterval,
+                            "--private-key-file", pk.toFile().absolutePath,
+                            "--cert-file", cert.toFile().absolutePath,
+                            "--trust-cert-file", trustCert.toFile().absolutePath)
+                    ).isInstanceOf(WrongArgumentError::class.java)
+                }
+            }
+            on("missing configuration url") {
+                it("should throw exception") {
+                    assertThat(cut.parseExpectingFailure(
+                            "--listen-port", listenPort,
+                            "--ssl-disable",
                             "--first-request-delay", firstRequestDelay,
                             "--request-interval", requestInterval,
                             "--private-key-file", pk.toFile().absolutePath,
@@ -170,4 +182,4 @@ object ArgVesHvConfigurationTest : Spek({
             }
         }
     }
-})
+})
\ No newline at end of file
index 6180adf..44de9d7 100644 (file)
@@ -32,6 +32,7 @@ enum class CommandLineOption(val option: Option) {
     ),
     CONSUL_CONFIG_URL(Option.builder("c")
             .longOpt("config-url")
+            .required()
             .hasArg()
             .desc("URL of ves configuration on consul")
             .build()