diff options
author | fkrzywka <filip.krzywka@nokia.com> | 2018-06-13 15:02:40 +0200 |
---|---|---|
committer | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2018-08-02 08:34:32 +0200 |
commit | ecf7cb09d4bce389b615257d3323ada0840100e8 (patch) | |
tree | 9e5157afe12daa501c60a7674fb44d5e38bb9e5d /hv-collector-dcae-app-simulator/src/main | |
parent | e93ba2b32d71844a7075a021631f40a0cc4888df (diff) |
Start DCAE App Simulator from command line
Closes ONAP-377
Change-Id: Iab959835dfafcfcfaf1322ead4ea83eff1e9284c
Signed-off-by: fkrzywka <filip.krzywka@nokia.com>
Issue-ID: DCAEGEN2-601
Diffstat (limited to 'hv-collector-dcae-app-simulator/src/main')
3 files changed, 97 insertions, 7 deletions
diff --git a/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/config/ArgBasedDcaeAppSimConfiguration.kt b/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/config/ArgBasedDcaeAppSimConfiguration.kt new file mode 100644 index 00000000..3f539302 --- /dev/null +++ b/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/config/ArgBasedDcaeAppSimConfiguration.kt @@ -0,0 +1,52 @@ +/* +* ============LICENSE_START======================================================= +* dcaegen2-collectors-veshv +* ================================================================================ +* Copyright (C) 2018 NOKIA +* ================================================================================ +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +*/ +package org.onap.dcae.collectors.veshv.simulators.dcaeapp.config + +import org.apache.commons.cli.CommandLine +import org.apache.commons.cli.DefaultParser +import org.onap.dcae.collectors.veshv.simulators.dcaeapp.config.DefaultValues.API_PORT +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.LISTEN_PORT +import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.KAFKA_SERVERS +import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.KAFKA_TOPICS + +internal object DefaultValues { + const val API_PORT = 8080 +} + +class ArgBasedDcaeAppSimConfiguration : ArgBasedConfiguration<DcaeAppSimConfiguration>(DefaultParser()) { + override val cmdLineOptionsList: List<CommandLineOption> = listOf( + LISTEN_PORT, + KAFKA_SERVERS, + KAFKA_TOPICS + ) + + override fun getConfiguration(cmdLine: CommandLine): DcaeAppSimConfiguration { + val port = cmdLine.intValue(LISTEN_PORT, API_PORT) + val kafkaBootstrapServers = cmdLine.stringValue(KAFKA_SERVERS) + val kafkaTopics = cmdLine.stringValue(KAFKA_TOPICS).split(",").toSet() + return DcaeAppSimConfiguration( + port, + kafkaBootstrapServers, + kafkaTopics) + } + +} diff --git a/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/config/DcaeAppSimConfiguration.kt b/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/config/DcaeAppSimConfiguration.kt new file mode 100644 index 00000000..5bd2d155 --- /dev/null +++ b/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/config/DcaeAppSimConfiguration.kt @@ -0,0 +1,26 @@ +/* + * ============LICENSE_START======================================================= + * dcaegen2-collectors-veshv + * ================================================================================ + * Copyright (C) 2018 NOKIA + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.dcae.collectors.veshv.simulators.dcaeapp.config + +data class DcaeAppSimConfiguration( + val apiPort: Int, + val kafkaBootstrapServers: String, + val kafkaTopics: Set<String> +) 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 170806a1..c037af35 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,20 +19,32 @@ */ package org.onap.dcae.collectors.veshv.simulators.dcaeapp +import org.onap.dcae.collectors.veshv.simulators.dcaeapp.config.ArgBasedDcaeAppSimConfiguration 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.WrongArgumentException import org.onap.dcae.collectors.veshv.utils.logging.Logger import org.slf4j.LoggerFactory private val logger = Logger(LoggerFactory.getLogger("DCAE simulator :: main")) fun main(args: Array<String>) { - logger.info("Starting DCAE APP simulator") - val port = 8080 - KafkaSource.create("kafka:9092", setOf("ves_hvRanMeas")) - .start() - .map(::ApiServer) - .flatMap { it.start(port) } - .block() + try { + logger.info("Starting DCAE APP simulator") + val simulatorConfig = ArgBasedDcaeAppSimConfiguration().parse(args) + + KafkaSource.create(simulatorConfig.kafkaBootstrapServers, simulatorConfig.kafkaTopics) + .start() + .map(::ApiServer) + .flatMap { it.start(simulatorConfig.apiPort) } + .block() + } catch (e: WrongArgumentException) { + e.printHelp("java org.onap.dcae.collectors.veshv.simulators.dcaeapp.MainKt") + System.exit(1) + } catch (e: Exception) { + logger.error(e.localizedMessage) + logger.debug("An error occurred when starting ves dcea app simulator", e) + System.exit(2) + } } |