aboutsummaryrefslogtreecommitdiffstats
path: root/hv-collector-client-simulator
diff options
context:
space:
mode:
authorPiotr Jaszczyk <piotr.jaszczyk@nokia.com>2018-07-04 13:16:21 +0200
committerPiotr Jaszczyk <piotr.jaszczyk@nokia.com>2018-08-02 12:01:26 +0200
commite31d59f63ebe5536d2d2d868703eb8896924b63d (patch)
tree0ed280beb287c59fbd7a3494684884f5738e377d /hv-collector-client-simulator
parente5ce5ac06cf1ce95a65f18ad05be9e8432be6d49 (diff)
Use IO monad when starting servers
Change-Id: I3e97161535fc721dda6109c4cb5f23a1db0afde3 Signed-off-by: Piotr Jaszczyk <piotr.jaszczyk@nokia.com> Issue-ID: DCAEGEN2-601
Diffstat (limited to 'hv-collector-client-simulator')
-rw-r--r--hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/main.kt34
-rw-r--r--hv-collector-client-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgBasedClientConfigurationTest.kt13
2 files changed, 22 insertions, 25 deletions
diff --git a/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/main.kt b/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/main.kt
index dbeba2b2..63c48757 100644
--- a/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/main.kt
+++ b/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/main.kt
@@ -19,38 +19,36 @@
*/
package org.onap.dcae.collectors.veshv.simulators.xnf
-import arrow.core.Failure
-import arrow.core.Success
import org.onap.dcae.collectors.veshv.simulators.xnf.config.ArgBasedClientConfiguration
import org.onap.dcae.collectors.veshv.simulators.xnf.impl.HttpServer
import org.onap.dcae.collectors.veshv.simulators.xnf.impl.VesHvClient
-import org.onap.dcae.collectors.veshv.utils.commandline.handleErrorsInMain
+import org.onap.dcae.collectors.veshv.utils.arrow.ExitFailure
+import org.onap.dcae.collectors.veshv.utils.arrow.unsafeRunEitherSync
+import org.onap.dcae.collectors.veshv.utils.arrow.void
+import org.onap.dcae.collectors.veshv.utils.commandline.handleWrongArgumentErrorCurried
import org.onap.dcae.collectors.veshv.utils.logging.Logger
+import org.slf4j.LoggerFactory
-
-private val logger = Logger("Simulator :: main")
-private const val PROGRAM_NAME = "java org.onap.dcae.collectors.veshv.main.MainKt"
+private const val PACKAGE_NAME = "org.onap.dcae.collectors.veshv.simulators.xnf"
+private val logger = Logger(PACKAGE_NAME)
+const val PROGRAM_NAME = "java $PACKAGE_NAME.MainKt"
/**
* @author Jakub Dudycz <jakub.dudycz@nokia.com>
* @since June 2018
*/
-fun main(args: Array<String>) {
- val httpServer = ArgBasedClientConfiguration().parse(args)
+fun main(args: Array<String>) =
+ ArgBasedClientConfiguration().parse(args)
+ .mapLeft(handleWrongArgumentErrorCurried(PROGRAM_NAME))
.map(::VesHvClient)
.map(::HttpServer)
-
- when (httpServer) {
- is Success -> httpServer.value.start().unsafeRunAsync {
- it.fold(
+ .map { it.start().void() }
+ .unsafeRunEitherSync(
{ ex ->
logger.error("Failed to start a server", ex)
+ ExitFailure(1)
},
- { srv ->
- logger.info("Started Simulator API server (listening on ${srv.bindHost}:${srv.bindPort})")
+ {
+ logger.info("Started xNF Simulator API server")
}
)
- }
- is Failure -> httpServer.handleErrorsInMain(PROGRAM_NAME, logger)
- }
-}
diff --git a/hv-collector-client-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgBasedClientConfigurationTest.kt b/hv-collector-client-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgBasedClientConfigurationTest.kt
index 2746c0a6..3b1836eb 100644
--- a/hv-collector-client-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgBasedClientConfigurationTest.kt
+++ b/hv-collector-client-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgBasedClientConfigurationTest.kt
@@ -21,6 +21,7 @@ package org.onap.dcae.collectors.veshv.main.config
import arrow.core.Failure
import arrow.core.Success
+import arrow.core.identity
import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
@@ -46,13 +47,11 @@ object ArgBasedClientConfigurationTest : Spek({
cut = ArgBasedClientConfiguration()
}
- fun parse(vararg cmdLine: String): ClientConfiguration {
- val result = cut.parse(cmdLine)
- return when (result) {
- is Success -> result.value
- is Failure -> throw AssertionError("Parsing result should be present")
- }
- }
+ fun parse(vararg cmdLine: String): ClientConfiguration =
+ cut.parse(cmdLine).fold(
+ {throw AssertionError("Parsing result should be present")},
+ ::identity
+ )
describe("parsing arguments") {
lateinit var result: ClientConfiguration