aboutsummaryrefslogtreecommitdiffstats
path: root/hv-collector-main/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'hv-collector-main/src/main')
-rw-r--r--hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/ArgVesHvConfiguration.kt (renamed from hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfiguration.kt)39
-rw-r--r--hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/main.kt2
2 files changed, 25 insertions, 16 deletions
diff --git a/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfiguration.kt b/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/ArgVesHvConfiguration.kt
index d8ee244b..77d074e5 100644
--- a/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfiguration.kt
+++ b/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/ArgVesHvConfiguration.kt
@@ -19,6 +19,11 @@
*/
package org.onap.dcae.collectors.veshv.main
+import arrow.core.ForOption
+import arrow.core.Option
+import arrow.core.fix
+import arrow.instances.extensions
+import arrow.typeclasses.binding
import org.apache.commons.cli.CommandLine
import org.apache.commons.cli.DefaultParser
import org.onap.dcae.collectors.veshv.domain.SecurityConfiguration
@@ -28,7 +33,7 @@ import org.onap.dcae.collectors.veshv.utils.commandline.ArgBasedConfiguration
import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.*
import java.time.Duration
-internal class ArgBasedServerConfiguration : ArgBasedConfiguration<ServerConfiguration>(DefaultParser()) {
+internal class ArgVesHvConfiguration : ArgBasedConfiguration<ServerConfiguration>(DefaultParser()) {
override val cmdLineOptionsList = listOf(
LISTEN_PORT,
CONSUL_CONFIG_URL,
@@ -42,19 +47,24 @@ internal class ArgBasedServerConfiguration : ArgBasedConfiguration<ServerConfigu
DUMMY_MODE
)
- override fun getConfiguration(cmdLine: CommandLine): ServerConfiguration {
- val port = cmdLine.intValue(LISTEN_PORT, DefaultValues.PORT)
- val idleTimeoutSec = cmdLine.longValue(IDLE_TIMEOUT_SEC, DefaultValues.IDLE_TIMEOUT_SEC)
- val dummyMode = cmdLine.hasOption(DUMMY_MODE)
- val security = createSecurityConfiguration(cmdLine)
- val configurationProviderParams = createConfigurationProviderParams(cmdLine);
- return ServerConfiguration(
- port = port,
- configurationProviderParams = configurationProviderParams,
- securityConfiguration = security,
- idleTimeout = Duration.ofSeconds(idleTimeoutSec),
- dummyMode = dummyMode)
- }
+ override fun getConfiguration(cmdLine: CommandLine): Option<ServerConfiguration> =
+ ForOption extensions {
+ binding {
+ val listenPort = cmdLine.intValue(LISTEN_PORT).bind()
+ val idleTimeoutSec = cmdLine.longValue(IDLE_TIMEOUT_SEC, DefaultValues.IDLE_TIMEOUT_SEC)
+ val dummyMode = cmdLine.hasOption(DUMMY_MODE)
+ val security = createSecurityConfiguration(cmdLine)
+ val configurationProviderParams = createConfigurationProviderParams(cmdLine)
+
+ ServerConfiguration(
+ listenPort = listenPort,
+ configurationProviderParams = configurationProviderParams,
+ securityConfiguration = security,
+ idleTimeout = Duration.ofSeconds(idleTimeoutSec),
+ dummyMode = dummyMode)
+ }.fix()
+ }
+
private fun createConfigurationProviderParams(cmdLine: CommandLine): ConfigurationProviderParams {
val configUrl = cmdLine.stringValue(CONSUL_CONFIG_URL, DefaultValues.CONFIG_URL)
@@ -83,7 +93,6 @@ internal class ArgBasedServerConfiguration : ArgBasedConfiguration<ServerConfigu
}
internal object DefaultValues {
- const val PORT = 6061
const val CONSUL_FIRST_REQUEST_DELAY = 10L
const val CONSUL_REQUEST_INTERVAL = 5L
const val CONFIG_URL = ""
diff --git a/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/main.kt b/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/main.kt
index aa1f67b1..44d09d45 100644
--- a/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/main.kt
+++ b/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/main.kt
@@ -34,7 +34,7 @@ private val logger = Logger("org.onap.dcae.collectors.veshv.main")
private const val PROGRAM_NAME = "java org.onap.dcae.collectors.veshv.main.MainKt"
fun main(args: Array<String>) =
- ArgBasedServerConfiguration().parse(args)
+ ArgVesHvConfiguration().parse(args)
.mapLeft(handleWrongArgumentErrorCurried(PROGRAM_NAME))
.map(::createServer)
.map {