summaryrefslogtreecommitdiffstats
path: root/hv-collector-utils
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-utils
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-utils')
-rw-r--r--hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/ArgBasedConfiguration.kt29
-rw-r--r--hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/CommandLineOption.kt1
-rw-r--r--hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/WrongArgumentError.kt1
3 files changed, 21 insertions, 10 deletions
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<T>(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<T>
protected fun CommandLine.intValue(cmdLineOpt: CommandLineOption, default: Int): Int =
intValue(cmdLineOpt).getOrElse { default }
@@ -52,12 +60,19 @@ abstract class ArgBasedConfiguration<T>(private val parser: CommandLineParser) {
protected fun CommandLine.longValue(cmdLineOpt: CommandLineOption, default: Long): Long =
longValue(cmdLineOpt).getOrElse { default }
- protected fun CommandLine.stringValue(cmdLineOpt: CommandLineOption): Option<String> =
- optionValue(cmdLineOpt)
-
protected fun CommandLine.stringValue(cmdLineOpt: CommandLineOption, default: String): String =
optionValue(cmdLineOpt).getOrElse { default }
+
+ protected fun CommandLine.intValue(cmdLineOpt: CommandLineOption): Option<Int> =
+ optionValue(cmdLineOpt).map(String::toInt)
+
+ protected fun CommandLine.longValue(cmdLineOpt: CommandLineOption): Option<Long> =
+ optionValue(cmdLineOpt).map(String::toLong)
+
+ protected fun CommandLine.stringValue(cmdLineOpt: CommandLineOption): Option<String> =
+ optionValue(cmdLineOpt)
+
protected fun CommandLine.hasOption(cmdLineOpt: CommandLineOption): Boolean =
this.hasOption(cmdLineOpt.option.opt)
@@ -65,10 +80,4 @@ abstract class ArgBasedConfiguration<T>(private val parser: CommandLineParser) {
private fun CommandLine.optionValue(cmdLineOpt: CommandLineOption): Option<String> =
Option.fromNullable(getOptionValue(cmdLineOpt.option.opt))
-
- private fun CommandLine.intValue(cmdLineOpt: CommandLineOption): Option<Int> =
- optionValue(cmdLineOpt).map(String::toInt)
-
- private fun CommandLine.longValue(cmdLineOpt: CommandLineOption): Option<Long> =
- 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)
}
}
+