aboutsummaryrefslogtreecommitdiffstats
path: root/hv-collector-main/src
diff options
context:
space:
mode:
authorJakub Dudycz <jakub.dudycz@nokia.com>2018-07-24 11:48:12 +0200
committerPiotr Jaszczyk <piotr.jaszczyk@nokia.com>2018-08-03 09:41:09 +0200
commitfc6ab3e5fee2bc3e607848caa665b166d6f38dd6 (patch)
treec54a032ef0093f7024cff963addca163b0dcf98e /hv-collector-main/src
parent53dbf8e66ad83c2d5f06279a0d7446e5e8be68e8 (diff)
Rework argument configuration
- Unify names of argument configuration classes in DCAE APP simulator, XNF simualtor and VES HV Collector - Make some of the arguments required - Adjust docker-compose and Dockerfiles - Adjust test cases and error handling Closes ONAP-683 Change-Id: I4a9d43791cced9dcb52eb83e2f7956462e8712d9 Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com> Issue-ID: DCAEGEN2-601
Diffstat (limited to 'hv-collector-main/src')
-rw-r--r--hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/ArgVesHvConfiguration.kt (renamed from hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfiguration.kt)39
-rw-r--r--hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/main.kt2
-rw-r--r--hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/ArgVesHvConfigurationTest.kt (renamed from hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfigurationTest.kt)50
3 files changed, 59 insertions, 32 deletions
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/ArgVesHvConfiguration.kt
index d8ee244b..77d074e5 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/ArgVesHvConfiguration.kt
@@ -19,6 +19,11 @@
*/
package org.onap.dcae.collectors.veshv.main
+import arrow.core.ForOption
+import arrow.core.Option
+import arrow.core.fix
+import arrow.instances.extensions
+import arrow.typeclasses.binding
import org.apache.commons.cli.CommandLine
import org.apache.commons.cli.DefaultParser
import org.onap.dcae.collectors.veshv.domain.SecurityConfiguration
@@ -28,7 +33,7 @@ import org.onap.dcae.collectors.veshv.utils.commandline.ArgBasedConfiguration
import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.*
import java.time.Duration
-internal class ArgBasedServerConfiguration : ArgBasedConfiguration<ServerConfiguration>(DefaultParser()) {
+internal class ArgVesHvConfiguration : ArgBasedConfiguration<ServerConfiguration>(DefaultParser()) {
override val cmdLineOptionsList = listOf(
LISTEN_PORT,
CONSUL_CONFIG_URL,
@@ -42,19 +47,24 @@ internal class ArgBasedServerConfiguration : ArgBasedConfiguration<ServerConfigu
DUMMY_MODE
)
- override fun getConfiguration(cmdLine: CommandLine): ServerConfiguration {
- val port = cmdLine.intValue(LISTEN_PORT, DefaultValues.PORT)
- 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);
- return ServerConfiguration(
- port = port,
- configurationProviderParams = configurationProviderParams,
- securityConfiguration = security,
- idleTimeout = Duration.ofSeconds(idleTimeoutSec),
- dummyMode = dummyMode)
- }
+ override fun getConfiguration(cmdLine: CommandLine): Option<ServerConfiguration> =
+ ForOption extensions {
+ binding {
+ val listenPort = cmdLine.intValue(LISTEN_PORT).bind()
+ 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)
+
+ ServerConfiguration(
+ listenPort = listenPort,
+ configurationProviderParams = configurationProviderParams,
+ securityConfiguration = security,
+ idleTimeout = Duration.ofSeconds(idleTimeoutSec),
+ dummyMode = dummyMode)
+ }.fix()
+ }
+
private fun createConfigurationProviderParams(cmdLine: CommandLine): ConfigurationProviderParams {
val configUrl = cmdLine.stringValue(CONSUL_CONFIG_URL, DefaultValues.CONFIG_URL)
@@ -83,7 +93,6 @@ internal class ArgBasedServerConfiguration : ArgBasedConfiguration<ServerConfigu
}
internal object DefaultValues {
- const val PORT = 6061
const val CONSUL_FIRST_REQUEST_DELAY = 10L
const val CONSUL_REQUEST_INTERVAL = 5L
const val CONFIG_URL = ""
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 aa1f67b1..44d09d45 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
@@ -34,7 +34,7 @@ private val logger = Logger("org.onap.dcae.collectors.veshv.main")
private const val PROGRAM_NAME = "java org.onap.dcae.collectors.veshv.main.MainKt"
fun main(args: Array<String>) =
- ArgBasedServerConfiguration().parse(args)
+ ArgVesHvConfiguration().parse(args)
.mapLeft(handleWrongArgumentErrorCurried(PROGRAM_NAME))
.map(::createServer)
.map {
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/ArgVesHvConfigurationTest.kt
index fb0067ec..6b111ae4 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/ArgVesHvConfigurationTest.kt
@@ -27,8 +27,9 @@ import org.jetbrains.spek.api.dsl.given
import org.jetbrains.spek.api.dsl.it
import org.jetbrains.spek.api.dsl.on
import org.onap.dcae.collectors.veshv.domain.SecurityConfiguration
-import org.onap.dcae.collectors.veshv.main.ArgBasedServerConfiguration.*
+import org.onap.dcae.collectors.veshv.main.ArgVesHvConfiguration.DefaultValues
import org.onap.dcae.collectors.veshv.model.ServerConfiguration
+import org.onap.dcae.collectors.veshv.utils.commandline.WrongArgumentError
import java.nio.file.Paths
import java.time.Duration
@@ -36,8 +37,8 @@ import java.time.Duration
* @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
* @since May 2018
*/
-object ArgBasedServerConfigurationTest : Spek({
- lateinit var cut: ArgBasedServerConfiguration
+object ArgVesHvConfigurationTest : Spek({
+ lateinit var cut: ArgVesHvConfiguration
val configurationUrl = "http://test-address/test"
val firstRequestDelay = "10"
val requestInterval = "5"
@@ -47,15 +48,20 @@ object ArgBasedServerConfigurationTest : Spek({
val trustCert = Paths.get("/", "etc", "ves", "trusted.crt")
beforeEachTest {
- cut = ArgBasedServerConfiguration()
+ cut = ArgVesHvConfiguration()
}
fun parse(vararg cmdLine: String): ServerConfiguration =
cut.parse(cmdLine).fold(
- {throw AssertionError("Parsing result should be present")},
+ { throw AssertionError("Parsing result should be present") },
::identity
)
+ fun parseExpectingFailure(vararg cmdLine: String) =
+ cut.parse(cmdLine).fold(::identity) {
+ throw AssertionError("parsing should have failed")
+ }
+
describe("parsing arguments") {
given("all parameters are present in the long form") {
lateinit var result: ServerConfiguration
@@ -72,17 +78,17 @@ object ArgBasedServerConfigurationTest : Spek({
}
it("should set proper port") {
- assertThat(result.port).isEqualTo(6969)
+ assertThat(result.listenPort).isEqualTo(listenPort.toInt())
}
it("should set proper first consul request delay") {
assertThat(result.configurationProviderParams.firstRequestDelay)
- .isEqualTo(Duration.ofSeconds(10))
+ .isEqualTo(Duration.ofSeconds(firstRequestDelay.toLong()))
}
it("should set proper consul request interval") {
assertThat(result.configurationProviderParams.requestInterval)
- .isEqualTo(Duration.ofSeconds(5))
+ .isEqualTo(Duration.ofSeconds(requestInterval.toLong()))
}
it("should set proper config url") {
@@ -101,16 +107,16 @@ object ArgBasedServerConfigurationTest : Spek({
lateinit var result: ServerConfiguration
beforeEachTest {
- result = parse("-p", "666", "-c", configurationUrl, "-d", firstRequestDelay)
+ result = parse("-p", listenPort, "-c", configurationUrl, "-d", firstRequestDelay)
}
it("should set proper port") {
- assertThat(result.port).isEqualTo(666)
+ assertThat(result.listenPort).isEqualTo(listenPort.toInt())
}
it("should set proper first consul request delay") {
assertThat(result.configurationProviderParams.firstRequestDelay)
- .isEqualTo(Duration.ofSeconds(10))
+ .isEqualTo(Duration.ofSeconds(firstRequestDelay.toLong()))
}
it("should set proper config url") {
@@ -123,11 +129,7 @@ object ArgBasedServerConfigurationTest : Spek({
lateinit var result: ServerConfiguration
beforeEachTest {
- result = parse()
- }
-
- it("should set default port") {
- assertThat(result.port).isEqualTo(DefaultValues.PORT)
+ result = parse("--listen-port", listenPort)
}
it("should set default config url") {
@@ -161,5 +163,21 @@ object ArgBasedServerConfigurationTest : Spek({
}
}
}
+
+ describe("required parameter is absent") {
+ given("listen port is missing") {
+ it("should throw exception") {
+ assertThat(parseExpectingFailure(
+ "--ssl-disable",
+ "--config-url", configurationUrl,
+ "--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)
+ }
+ }
+ }
}
})