aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Jaszczyk <piotr.jaszczyk@nokia.com>2019-03-26 12:36:10 +0000
committerPiotr Jaszczyk <piotr.jaszczyk@nokia.com>2019-03-26 12:36:10 +0000
commitcb08e0822cc44fc7b382e9b48682ab93607f7c43 (patch)
treee11492e6a1b41025dafea9f9cdb190c9b255bc41
parentf3d3e6745328b9ec8bb68dfbfb3d3d57aa47b36f (diff)
Revert "Read HV-VES healtcheck api port from cmd line"
This reverts commit f3d3e6745328b9ec8bb68dfbfb3d3d57aa47b36f. Change-Id: I9d8813484831483812b0f7062d39e3d031dd7083 Signed-off-by: Piotr Jaszczyk <piotr.jaszczyk@nokia.com> Issue-ID: DCAEGEN2-1364
-rw-r--r--sources/hv-collector-commandline/src/main/kotlin/org/onap/dcae/collectors/veshv/commandline/ArgBasedConfiguration.kt3
-rw-r--r--sources/hv-collector-configuration/src/main/kotlin/org/onap/dcae/collectors/veshv/config/api/ConfigurationModule.kt6
-rw-r--r--sources/hv-collector-configuration/src/main/kotlin/org/onap/dcae/collectors/veshv/config/impl/ArgHvVesConfiguration.kt62
-rw-r--r--sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ArgHvVesConfigurationTest.kt16
-rw-r--r--sources/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/main.kt2
-rw-r--r--sources/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/servers/HealthCheckServer.kt3
6 files changed, 14 insertions, 78 deletions
diff --git a/sources/hv-collector-commandline/src/main/kotlin/org/onap/dcae/collectors/veshv/commandline/ArgBasedConfiguration.kt b/sources/hv-collector-commandline/src/main/kotlin/org/onap/dcae/collectors/veshv/commandline/ArgBasedConfiguration.kt
index d8c83ea0..93d42f96 100644
--- a/sources/hv-collector-commandline/src/main/kotlin/org/onap/dcae/collectors/veshv/commandline/ArgBasedConfiguration.kt
+++ b/sources/hv-collector-commandline/src/main/kotlin/org/onap/dcae/collectors/veshv/commandline/ArgBasedConfiguration.kt
@@ -26,6 +26,9 @@ import arrow.core.flatMap
import org.apache.commons.cli.CommandLine
import org.apache.commons.cli.CommandLineParser
import org.apache.commons.cli.Options
+import java.io.File
+import java.nio.file.Path
+import java.nio.file.Paths
abstract class ArgBasedConfiguration<T>(private val parser: CommandLineParser) {
abstract val cmdLineOptionsList: List<CommandLineOption>
diff --git a/sources/hv-collector-configuration/src/main/kotlin/org/onap/dcae/collectors/veshv/config/api/ConfigurationModule.kt b/sources/hv-collector-configuration/src/main/kotlin/org/onap/dcae/collectors/veshv/config/api/ConfigurationModule.kt
index 1b9248b5..9f8c552b 100644
--- a/sources/hv-collector-configuration/src/main/kotlin/org/onap/dcae/collectors/veshv/config/api/ConfigurationModule.kt
+++ b/sources/hv-collector-configuration/src/main/kotlin/org/onap/dcae/collectors/veshv/config/api/ConfigurationModule.kt
@@ -19,7 +19,6 @@
*/
package org.onap.dcae.collectors.veshv.config.api
-import arrow.core.getOrElse
import org.onap.dcae.collectors.veshv.config.api.model.HvVesConfiguration
import org.onap.dcae.collectors.veshv.config.api.model.MissingArgumentException
import org.onap.dcae.collectors.veshv.config.api.model.ValidationException
@@ -30,16 +29,13 @@ import org.onap.dcae.collectors.veshv.utils.arrow.throwOnLeft
import reactor.core.publisher.Flux
class ConfigurationModule {
- private val DEFAULT_HEALTHCHECK_PORT: Int = 6060
private val cmd = ArgHvVesConfiguration()
private val configReader = FileConfigurationReader()
private val configValidator = ConfigurationValidator()
- fun healthCheckPort(args: Array<String>): Int = cmd.parseToInt(args).getOrElse { DEFAULT_HEALTHCHECK_PORT }
-
fun hvVesConfigurationUpdates(args: Array<String>): Flux<HvVesConfiguration> =
- Flux.just(cmd.parseToFile(args))
+ Flux.just(cmd.parse(args))
.throwOnLeft { MissingArgumentException(it.message, it.cause) }
.map { it.reader().use(configReader::loadConfig) }
.map { configValidator.validate(it) }
diff --git a/sources/hv-collector-configuration/src/main/kotlin/org/onap/dcae/collectors/veshv/config/impl/ArgHvVesConfiguration.kt b/sources/hv-collector-configuration/src/main/kotlin/org/onap/dcae/collectors/veshv/config/impl/ArgHvVesConfiguration.kt
index 71ed509b..9587d5b0 100644
--- a/sources/hv-collector-configuration/src/main/kotlin/org/onap/dcae/collectors/veshv/config/impl/ArgHvVesConfiguration.kt
+++ b/sources/hv-collector-configuration/src/main/kotlin/org/onap/dcae/collectors/veshv/config/impl/ArgHvVesConfiguration.kt
@@ -19,72 +19,18 @@
*/
package org.onap.dcae.collectors.veshv.config.impl
-import arrow.core.Either
import arrow.core.Option
-import arrow.core.Try
-import arrow.core.flatMap
import org.apache.commons.cli.CommandLine
-import org.apache.commons.cli.CommandLineParser
import org.apache.commons.cli.DefaultParser
-import org.apache.commons.cli.Options
+import org.onap.dcae.collectors.veshv.commandline.ArgBasedConfiguration
import org.onap.dcae.collectors.veshv.commandline.CommandLineOption.CONFIGURATION_FILE
-import org.onap.dcae.collectors.veshv.commandline.CommandLineOption.HEALTH_CHECK_API_PORT
-import org.onap.dcae.collectors.veshv.commandline.WrongArgumentError
-import org.onap.dcae.collectors.veshv.commandline.intValue
import org.onap.dcae.collectors.veshv.commandline.stringValue
import java.io.File
-class ArgHvVesConfiguration(private val parser: CommandLineParser = DefaultParser()) {
- val cmdLineOptionsList = listOf(CONFIGURATION_FILE, HEALTH_CHECK_API_PORT)
+internal class ArgHvVesConfiguration : ArgBasedConfiguration<File>(DefaultParser()) {
+ override val cmdLineOptionsList = listOf(CONFIGURATION_FILE)
- fun getConfiguration(cmdLine: CommandLine): Option<File> =
+ override fun getConfiguration(cmdLine: CommandLine): Option<File> =
cmdLine.stringValue(CONFIGURATION_FILE).map(::File)
- fun getHealthcheckPort(cmdLine: CommandLine): Option<Int> =
- cmdLine.intValue(HEALTH_CHECK_API_PORT)
-
- lateinit var parsingResult: CommandLine
-
- fun parseToFile(args: Array<out String>): Either<WrongArgumentError, File> {
- parseIfEmpty(args)
- return Try { parsingResult }.toEither()
- .mapLeft { WrongArgumentError(it, cmdLineOptionsList) }
- .map(this::getConfiguration)
- .flatMap {
- it.toEither {
- WrongArgumentError(
- message = "Unexpected error when parsing command line arguments",
- cmdLineOptionsList = cmdLineOptionsList)
- }
- }
- }
-
- fun parseToInt(args: Array<out String>): Either<WrongArgumentError, Int> {
- parseIfEmpty(args)
- return Try { parsingResult }.toEither()
- .mapLeft { WrongArgumentError(it, cmdLineOptionsList) }
- .map(this::getHealthcheckPort)
- .flatMap {
- it.toEither {
- WrongArgumentError(
- message = "Unexpected error when parsing command line arguments",
- cmdLineOptionsList = cmdLineOptionsList)
- }
- }
- }
-
- private fun parseIfEmpty(args: Array<out String>) {
- if (!this::parsingResult.isInitialized) {
- parsingResult = parseArgumentsArray(args)
- }
- }
-
- private fun parseArgumentsArray(args: Array<out String>) =
- cmdLineOptionsList
- .map { it.option }
- .fold(Options(), Options::addOption)
- .let { parser.parse(it, args) }
-
}
-
-
diff --git a/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ArgHvVesConfigurationTest.kt b/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ArgHvVesConfigurationTest.kt
index 6fe76958..dbe757c4 100644
--- a/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ArgHvVesConfigurationTest.kt
+++ b/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ArgHvVesConfigurationTest.kt
@@ -19,7 +19,6 @@
*/
package org.onap.dcae.collectors.veshv.config.impl
-import arrow.core.identity
import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
@@ -28,6 +27,8 @@ import org.jetbrains.spek.api.dsl.it
import org.jetbrains.spek.api.dsl.on
import org.onap.dcae.collectors.veshv.commandline.WrongArgumentError
import org.onap.dcae.collectors.veshv.tests.utils.absoluteResourcePath
+import org.onap.dcae.collectors.veshv.tests.utils.parseExpectingFailure
+import org.onap.dcae.collectors.veshv.tests.utils.parseExpectingSuccess
import java.io.File
/**
@@ -69,15 +70,4 @@ object ArgVesHvConfigurationTest : Spek({
}
}
}
-})
-
-fun ArgHvVesConfiguration.parseExpectingSuccess(vararg cmdLine: String): File =
- parseToFile(cmdLine).fold(
- { throw AssertionError("Parsing result should be present") },
- ::identity
- )
-
-fun ArgHvVesConfiguration.parseExpectingFailure(vararg cmdLine: String): WrongArgumentError =
- parseToFile(cmdLine).fold(
- ::identity
- ) { throw AssertionError("parsing should have failed") }
+}) \ No newline at end of file
diff --git a/sources/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/main.kt b/sources/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/main.kt
index 511f5ee3..c8a3c013 100644
--- a/sources/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/main.kt
+++ b/sources/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/main.kt
@@ -40,7 +40,7 @@ private val logger = Logger("$VES_HV_PACKAGE.main")
private val hvVesServer = AtomicReference<ServerHandle>()
fun main(args: Array<String>) {
- HealthCheckServer.start(ConfigurationModule().healthCheckPort(args))
+ HealthCheckServer.start()
ConfigurationModule()
.hvVesConfigurationUpdates(args)
.publishOn(Schedulers.single(Schedulers.elastic()))
diff --git a/sources/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/servers/HealthCheckServer.kt b/sources/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/servers/HealthCheckServer.kt
index 9b58dcc9..bc284d08 100644
--- a/sources/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/servers/HealthCheckServer.kt
+++ b/sources/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/servers/HealthCheckServer.kt
@@ -34,9 +34,10 @@ import java.net.InetSocketAddress
*/
object HealthCheckServer {
+ private const val DEFAULT_HEALTHCHECK_PORT = 6060
private val logger = Logger(HealthCheckServer::class)
- fun start(port: Int) =
+ fun start(port: Int = DEFAULT_HEALTHCHECK_PORT) =
createHealthCheckServer(port)
.start()
.then(::logServerStarted)