aboutsummaryrefslogtreecommitdiffstats
path: root/hv-collector-xnf-simulator
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-xnf-simulator
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-xnf-simulator')
-rw-r--r--hv-collector-xnf-simulator/Dockerfile3
-rw-r--r--hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/config/ArgXnfSimulatorConfiguration.kt (renamed from hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/config/ArgConfigurationProvider.kt)33
-rw-r--r--hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/main.kt4
-rw-r--r--hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgXnfSimulatorConfiurationTest.kt (renamed from hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgConfigurationProviderTest.kt)77
4 files changed, 85 insertions, 32 deletions
diff --git a/hv-collector-xnf-simulator/Dockerfile b/hv-collector-xnf-simulator/Dockerfile
index b713bafc..48f9dc56 100644
--- a/hv-collector-xnf-simulator/Dockerfile
+++ b/hv-collector-xnf-simulator/Dockerfile
@@ -5,11 +5,8 @@ LABEL license.name="The Apache Software License, Version 2.0"
LABEL license.url="http://www.apache.org/licenses/LICENSE-2.0"
LABEL maintainer="Nokia Wroclaw ONAP Team"
-EXPOSE 5000
-
WORKDIR /opt/ves-hv-client-simulator
ENTRYPOINT ["java", "-cp", "*:", "org.onap.dcae.collectors.veshv.simulators.xnf.MainKt"]
-CMD ["--ves-host", "ves-hv-collector", "--ves-port", "6061"]
COPY target/libs/external/* ./
COPY target/libs/internal/* ./
COPY target/hv-collector-xnf-simulator-*.jar ./
diff --git a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/config/ArgConfigurationProvider.kt b/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/config/ArgXnfSimulatorConfiguration.kt
index 8954fd22..999d0327 100644
--- a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/config/ArgConfigurationProvider.kt
+++ b/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/config/ArgXnfSimulatorConfiguration.kt
@@ -19,6 +19,11 @@
*/
package org.onap.dcae.collectors.veshv.simulators.xnf.config
+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
@@ -30,7 +35,7 @@ import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.*
* @author Jakub Dudycz <jakub.dudycz@nokia.com>
* @since June 2018
*/
-internal class ArgConfigurationProvider : ArgBasedConfiguration<SimulatorConfiguration>(DefaultParser()) {
+internal class ArgXnfSimulatorConfiguration : ArgBasedConfiguration<SimulatorConfiguration>(DefaultParser()) {
override val cmdLineOptionsList = listOf(
VES_HV_PORT,
VES_HV_HOST,
@@ -41,17 +46,20 @@ internal class ArgConfigurationProvider : ArgBasedConfiguration<SimulatorConfigu
TRUST_CERT_FILE
)
- override fun getConfiguration(cmdLine: CommandLine): SimulatorConfiguration {
- val vesHost = cmdLine.stringValue(VES_HV_HOST, DefaultValues.VES_HV_HOST)
- val vesPort = cmdLine.intValue(VES_HV_PORT, DefaultValues.VES_HV_PORT)
- val listenPort = cmdLine.intValue(LISTEN_PORT, DefaultValues.LISTEN_PORT)
+ override fun getConfiguration(cmdLine: CommandLine): Option<SimulatorConfiguration> =
+ ForOption extensions {
+ binding {
+ val listenPort = cmdLine.intValue(LISTEN_PORT).bind()
+ val vesHost = cmdLine.stringValue(VES_HV_HOST).bind()
+ val vesPort = cmdLine.intValue(VES_HV_PORT).bind()
- return SimulatorConfiguration(
- listenPort,
- vesHost,
- vesPort,
- parseSecurityConfig(cmdLine))
- }
+ SimulatorConfiguration(
+ listenPort,
+ vesHost,
+ vesPort,
+ parseSecurityConfig(cmdLine))
+ }.fix()
+ }
private fun parseSecurityConfig(cmdLine: CommandLine): SecurityConfiguration {
val sslDisable = cmdLine.hasOption(SSL_DISABLE)
@@ -70,8 +78,5 @@ internal class ArgConfigurationProvider : ArgBasedConfiguration<SimulatorConfigu
const val PRIVATE_KEY_FILE = "/etc/ves-hv/client.key"
const val CERT_FILE = "/etc/ves-hv/client.crt"
const val TRUST_CERT_FILE = "/etc/ves-hv/trust.crt"
- const val VES_HV_PORT = 6061
- const val VES_HV_HOST = "veshvcollector"
- const val LISTEN_PORT = 6062
}
}
diff --git a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/main.kt b/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/main.kt
index a47cef58..19c52efa 100644
--- a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/main.kt
+++ b/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/main.kt
@@ -19,7 +19,7 @@
*/
package org.onap.dcae.collectors.veshv.simulators.xnf
-import org.onap.dcae.collectors.veshv.simulators.xnf.config.ArgConfigurationProvider
+import org.onap.dcae.collectors.veshv.simulators.xnf.config.ArgXnfSimulatorConfiguration
import org.onap.dcae.collectors.veshv.simulators.xnf.impl.HttpServer
import org.onap.dcae.collectors.veshv.simulators.xnf.impl.XnfSimulator
import org.onap.dcae.collectors.veshv.utils.arrow.ExitFailure
@@ -36,7 +36,7 @@ const val PROGRAM_NAME = "java $PACKAGE_NAME.MainKt"
* @author Jakub Dudycz <jakub.dudycz@nokia.com>
* @since June 2018
*/
-fun main(args: Array<String>) = ArgConfigurationProvider().parse(args)
+fun main(args: Array<String>) = ArgXnfSimulatorConfiguration().parse(args)
.mapLeft(handleWrongArgumentErrorCurried(PROGRAM_NAME))
.map {
XnfSimulator(it)
diff --git a/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgConfigurationProviderTest.kt b/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgXnfSimulatorConfiurationTest.kt
index 04d81c74..e3a20c70 100644
--- a/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgConfigurationProviderTest.kt
+++ b/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgXnfSimulatorConfiurationTest.kt
@@ -20,6 +20,7 @@
package org.onap.dcae.collectors.veshv.main.config
import arrow.core.identity
+import org.assertj.core.api.Assertions
import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
@@ -27,22 +28,25 @@ 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.simulators.xnf.config.ArgConfigurationProvider
-import org.onap.dcae.collectors.veshv.simulators.xnf.config.ArgConfigurationProvider.DefaultValues
+import org.onap.dcae.collectors.veshv.simulators.xnf.config.ArgXnfSimulatorConfiguration
+import org.onap.dcae.collectors.veshv.simulators.xnf.config.ArgXnfSimulatorConfiguration.DefaultValues
import org.onap.dcae.collectors.veshv.simulators.xnf.config.SimulatorConfiguration
+import org.onap.dcae.collectors.veshv.utils.commandline.WrongArgumentError
import java.nio.file.Paths
import kotlin.test.assertTrue
-object ArgConfigurationProviderTest : Spek({
- lateinit var cut: ArgConfigurationProvider
- val vesHost = "localhosting"
+object ArgXnfSimulatorConfiurationTest : Spek({
+ lateinit var cut: ArgXnfSimulatorConfiguration
+ val listenPort = "4321"
+ val vesHost = "localhost"
+ val vesPort = "1234"
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")
beforeEachTest {
- cut = ArgConfigurationProvider()
+ cut = ArgXnfSimulatorConfiguration()
}
fun parse(vararg cmdLine: String): SimulatorConfiguration =
@@ -51,6 +55,12 @@ object ArgConfigurationProviderTest : Spek({
::identity
)
+ fun parseExpectingFailure(vararg cmdLine: String) =
+ cut.parse(cmdLine).fold(
+ ::identity,
+ { throw AssertionError("parsing should have failed") }
+ )
+
describe("parsing arguments") {
lateinit var result: SimulatorConfiguration
@@ -58,15 +68,24 @@ object ArgConfigurationProviderTest : Spek({
beforeEachTest {
result = parse("--ssl-disable",
- "--ves-port", "6969",
+ "--listen-port", listenPort,
"--ves-host", vesHost,
+ "--ves-port", vesPort,
"--private-key-file", pk.toFile().absolutePath,
"--cert-file", cert.toFile().absolutePath,
"--trust-cert-file", trustCert.toFile().absolutePath)
}
- it("should set proper port") {
- assertThat(result.vesPort).isEqualTo(6969)
+ it("should set proper listen port") {
+ assertThat(result.listenPort).isEqualTo(listenPort.toInt())
+ }
+
+ it("should set proper ves host") {
+ assertThat(result.vesHost).isEqualTo(vesHost)
+ }
+
+ it("should set proper ves port") {
+ assertThat(result.vesPort).isEqualTo(vesPort.toInt())
}
it("should set proper security configuration") {
@@ -79,18 +98,26 @@ object ArgConfigurationProviderTest : Spek({
given("some parameters are present in the short form") {
beforeEachTest {
- result = parse("-h", "ves-hv", "--ves-port", "666")
+ result = parse("-p", listenPort, "-h", vesHost, "--ves-port", vesPort)
+ }
+
+ it("should set proper listen port") {
+ assertThat(result.listenPort).isEqualTo(listenPort.toInt())
+ }
+
+ it("should set proper ves host") {
+ assertThat(result.vesHost).isEqualTo(vesHost)
}
- it("should set proper port") {
- assertThat(result.vesPort).isEqualTo(666)
+ it("should set proper ves port") {
+ assertThat(result.vesPort).isEqualTo(vesPort.toInt())
}
}
given("all optional parameters are absent") {
beforeEachTest {
- result = parse("-h", "ves-hv", "-v", "666")
+ result = parse("-p", listenPort, "-h", vesHost, "-v", vesPort)
}
on("security config") {
@@ -113,6 +140,7 @@ object ArgConfigurationProviderTest : Spek({
given("disabled ssl certs together with all other parameters") {
beforeEachTest {
result = parse("--ssl-disable",
+ "--listen-port", listenPort,
"--ves-port", "888",
"--ves-host", vesHost,
"--private-key-file", pk.toFile().absolutePath,
@@ -138,5 +166,28 @@ object ArgConfigurationProviderTest : Spek({
}
}
}
+
+ describe("required parameter is absent") {
+ given("ves port is missing") {
+ it("should throw exception") {
+ assertThat(parseExpectingFailure("-p", listenPort, "-h", vesHost))
+ .isInstanceOf(WrongArgumentError::class.java)
+ }
+ }
+
+ given("ves host is missing") {
+ it("should throw exception") {
+ assertThat(parseExpectingFailure("-p", listenPort, "-v", vesPort))
+ .isInstanceOf(WrongArgumentError::class.java)
+ }
+ }
+
+ given("listen port is missing") {
+ it("should throw exception") {
+ assertThat(parseExpectingFailure("-h", vesHost, "-v", vesPort))
+ .isInstanceOf(WrongArgumentError::class.java)
+ }
+ }
+ }
}
})