diff options
author | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2018-07-04 13:16:21 +0200 |
---|---|---|
committer | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2018-08-02 12:01:26 +0200 |
commit | e31d59f63ebe5536d2d2d868703eb8896924b63d (patch) | |
tree | 0ed280beb287c59fbd7a3494684884f5738e377d /hv-collector-dcae-app-simulator/src/main | |
parent | e5ce5ac06cf1ce95a65f18ad05be9e8432be6d49 (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-dcae-app-simulator/src/main')
-rw-r--r-- | hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/main.kt | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/main.kt b/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/main.kt index f7d44ede..a8a4cf5a 100644 --- a/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/main.kt +++ b/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/main.kt @@ -19,30 +19,38 @@ */ package org.onap.dcae.collectors.veshv.simulators.dcaeapp -import arrow.core.Failure -import arrow.core.Success import org.onap.dcae.collectors.veshv.simulators.dcaeapp.config.ArgBasedDcaeAppSimConfiguration import org.onap.dcae.collectors.veshv.simulators.dcaeapp.config.DcaeAppSimConfiguration import org.onap.dcae.collectors.veshv.simulators.dcaeapp.kafka.KafkaSource import org.onap.dcae.collectors.veshv.simulators.dcaeapp.remote.ApiServer -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(LoggerFactory.getLogger("DCAE simulator :: main")) +private const val PACKAGE_NAME = "org.onap.dcae.collectors.veshv.simulators.dcaeapp" +private val logger = Logger(PACKAGE_NAME) +const val PROGRAM_NAME = "java $PACKAGE_NAME.MainKt" -fun main(args: Array<String>) { - logger.info("Starting DCAE APP simulator") +fun main(args: Array<String>) = + ArgBasedDcaeAppSimConfiguration().parse(args) + .mapLeft(handleWrongArgumentErrorCurried(PROGRAM_NAME)) + .map(::startApp) + .unsafeRunEitherSync( + { ex -> + logger.error("Failed to start a server", ex) + ExitFailure(1) + }, + { + logger.info("Started DCAE-APP Simulator API server") + } + ) - val config = ArgBasedDcaeAppSimConfiguration().parse(args) - when (config) { - is Success -> startApp(config.value).unsafeRunSync() - is Failure -> config.handleErrorsInMain("", logger) - } -} private fun startApp(config: DcaeAppSimConfiguration) = KafkaSource.create(config.kafkaBootstrapServers, config.kafkaTopics) .start() .map(::ApiServer) - .flatMap { it.start(config.apiPort) } + .flatMap { it.start(config.apiPort).void() } |