From fc6ab3e5fee2bc3e607848caa665b166d6f38dd6 Mon Sep 17 00:00:00 2001 From: Jakub Dudycz Date: Tue, 24 Jul 2018 11:48:12 +0200 Subject: 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 Issue-ID: DCAEGEN2-601 --- .../utils/commandline/ArgBasedConfiguration.kt | 29 ++++++++++++++-------- .../veshv/utils/commandline/CommandLineOption.kt | 1 + .../veshv/utils/commandline/WrongArgumentError.kt | 1 + 3 files changed, 21 insertions(+), 10 deletions(-) (limited to 'hv-collector-utils/src/main') diff --git a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/ArgBasedConfiguration.kt b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/ArgBasedConfiguration.kt index 49219531..9c873a0f 100644 --- a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/ArgBasedConfiguration.kt +++ b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/ArgBasedConfiguration.kt @@ -22,6 +22,7 @@ package org.onap.dcae.collectors.veshv.utils.commandline import arrow.core.Either import arrow.core.Option import arrow.core.Try +import arrow.core.flatMap import arrow.core.getOrElse import org.apache.commons.cli.CommandLine import org.apache.commons.cli.CommandLineParser @@ -42,9 +43,16 @@ abstract class ArgBasedConfiguration(private val parser: CommandLineParser) { .toEither() .mapLeft { ex -> WrongArgumentError(ex, commandLineOptions) } .map(this::getConfiguration) + .flatMap { + it.toEither { + WrongArgumentError( + "Unexpected error when parsing command line arguments", + commandLineOptions) + } + } } - protected abstract fun getConfiguration(cmdLine: CommandLine): T + protected abstract fun getConfiguration(cmdLine: CommandLine): Option protected fun CommandLine.intValue(cmdLineOpt: CommandLineOption, default: Int): Int = intValue(cmdLineOpt).getOrElse { default } @@ -52,12 +60,19 @@ abstract class ArgBasedConfiguration(private val parser: CommandLineParser) { protected fun CommandLine.longValue(cmdLineOpt: CommandLineOption, default: Long): Long = longValue(cmdLineOpt).getOrElse { default } - protected fun CommandLine.stringValue(cmdLineOpt: CommandLineOption): Option = - optionValue(cmdLineOpt) - protected fun CommandLine.stringValue(cmdLineOpt: CommandLineOption, default: String): String = optionValue(cmdLineOpt).getOrElse { default } + + protected fun CommandLine.intValue(cmdLineOpt: CommandLineOption): Option = + optionValue(cmdLineOpt).map(String::toInt) + + protected fun CommandLine.longValue(cmdLineOpt: CommandLineOption): Option = + optionValue(cmdLineOpt).map(String::toLong) + + protected fun CommandLine.stringValue(cmdLineOpt: CommandLineOption): Option = + optionValue(cmdLineOpt) + protected fun CommandLine.hasOption(cmdLineOpt: CommandLineOption): Boolean = this.hasOption(cmdLineOpt.option.opt) @@ -65,10 +80,4 @@ abstract class ArgBasedConfiguration(private val parser: CommandLineParser) { private fun CommandLine.optionValue(cmdLineOpt: CommandLineOption): Option = Option.fromNullable(getOptionValue(cmdLineOpt.option.opt)) - - private fun CommandLine.intValue(cmdLineOpt: CommandLineOption): Option = - optionValue(cmdLineOpt).map(String::toInt) - - private fun CommandLine.longValue(cmdLineOpt: CommandLineOption): Option = - optionValue(cmdLineOpt).map(String::toLong) } diff --git a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/CommandLineOption.kt b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/CommandLineOption.kt index 1d94dc30..6180adf5 100644 --- a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/CommandLineOption.kt +++ b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/CommandLineOption.kt @@ -25,6 +25,7 @@ import org.apache.commons.cli.Option enum class CommandLineOption(val option: Option) { LISTEN_PORT(Option.builder("p") .longOpt("listen-port") + .required() .hasArg() .desc("Listen port") .build() diff --git a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/WrongArgumentError.kt b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/WrongArgumentError.kt index f3bb3146..632858b2 100644 --- a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/WrongArgumentError.kt +++ b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/WrongArgumentError.kt @@ -39,3 +39,4 @@ data class WrongArgumentError( formatter.printHelp(programName, options) } } + -- cgit 1.2.3-korg