diff options
Diffstat (limited to 'hv-collector-main/src')
3 files changed, 34 insertions, 27 deletions
diff --git a/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/ArgVesHvConfiguration.kt b/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/ArgVesHvConfiguration.kt index 0f382196..81d916dd 100644 --- a/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/ArgVesHvConfiguration.kt +++ b/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/ArgVesHvConfiguration.kt @@ -19,10 +19,8 @@ */ 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.instances.option.monad.monad import arrow.typeclasses.binding import org.apache.commons.cli.CommandLine @@ -49,6 +47,7 @@ import org.onap.dcae.collectors.veshv.utils.commandline.hasOption import org.onap.dcae.collectors.veshv.utils.commandline.intValue import org.onap.dcae.collectors.veshv.utils.commandline.longValue import org.onap.dcae.collectors.veshv.utils.commandline.stringValue +import java.net.InetSocketAddress import java.time.Duration internal class ArgVesHvConfiguration : ArgBasedConfiguration<ServerConfiguration>(DefaultParser()) { @@ -81,8 +80,8 @@ internal class ArgVesHvConfiguration : ArgBasedConfiguration<ServerConfiguration val security = createSecurityConfiguration(cmdLine).bind() val configurationProviderParams = createConfigurationProviderParams(cmdLine).bind() ServerConfiguration( - healthCheckApiPort = healthCheckApiPort, - listenPort = listenPort, + serverListenAddress = InetSocketAddress(listenPort), + healthCheckApiListenAddress = InetSocketAddress(healthCheckApiPort), configurationProviderParams = configurationProviderParams, securityConfiguration = security, idleTimeout = Duration.ofSeconds(idleTimeoutSec), @@ -91,24 +90,22 @@ internal class ArgVesHvConfiguration : ArgBasedConfiguration<ServerConfiguration }.fix() private fun createConfigurationProviderParams(cmdLine: CommandLine): Option<ConfigurationProviderParams> = - ForOption extensions { - binding { - val configUrl = cmdLine.stringValue(CONSUL_CONFIG_URL).bind() - val firstRequestDelay = cmdLine.longValue( - CONSUL_FIRST_REQUEST_DELAY, - DefaultValues.CONSUL_FIRST_REQUEST_DELAY - ) - val requestInterval = cmdLine.longValue( - CONSUL_REQUEST_INTERVAL, - DefaultValues.CONSUL_REQUEST_INTERVAL - ) - ConfigurationProviderParams( - configUrl, - Duration.ofSeconds(firstRequestDelay), - Duration.ofSeconds(requestInterval) - ) - }.fix() - } + Option.monad().binding { + val configUrl = cmdLine.stringValue(CONSUL_CONFIG_URL).bind() + val firstRequestDelay = cmdLine.longValue( + CONSUL_FIRST_REQUEST_DELAY, + DefaultValues.CONSUL_FIRST_REQUEST_DELAY + ) + val requestInterval = cmdLine.longValue( + CONSUL_REQUEST_INTERVAL, + DefaultValues.CONSUL_REQUEST_INTERVAL + ) + ConfigurationProviderParams( + configUrl, + Duration.ofSeconds(firstRequestDelay), + Duration.ofSeconds(requestInterval) + ) + }.fix() internal object DefaultValues { const val HEALTH_CHECK_API_PORT = 6060 diff --git a/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/servers/HealthCheckServer.kt b/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/servers/HealthCheckServer.kt index 04fc021d..ae59da69 100644 --- a/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/servers/HealthCheckServer.kt +++ b/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/servers/HealthCheckServer.kt @@ -32,7 +32,9 @@ object HealthCheckServer : ServerStarter() { override fun startServer(config: ServerConfiguration) = createHealthCheckServer(config).start() private fun createHealthCheckServer(config: ServerConfiguration) = - HealthCheckApiServer(HealthState.INSTANCE, config.healthCheckApiPort) + HealthCheckApiServer( + HealthState.INSTANCE, + config.healthCheckApiListenAddress) override fun serverStartedMessage(handle: ServerHandle) = "Health check server is up and listening on ${handle.host}:${handle.port}" diff --git a/hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/ArgVesHvConfigurationTest.kt b/hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/ArgVesHvConfigurationTest.kt index 0cf0bb2c..1aac6a09 100644 --- a/hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/ArgVesHvConfigurationTest.kt +++ b/hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/ArgVesHvConfigurationTest.kt @@ -19,7 +19,6 @@ */ package org.onap.dcae.collectors.veshv.main -import arrow.core.identity import org.assertj.core.api.Assertions.assertThat import org.jetbrains.spek.api.Spek import org.jetbrains.spek.api.dsl.describe @@ -70,12 +69,21 @@ object ArgVesHvConfigurationTest : Spek({ ) } + it("should set proper listen port") { + assertThat(result.serverListenAddress.port).isEqualTo(listenPort.toInt()) + } + + + it("should set default listen address") { + assertThat(result.serverListenAddress.address.hostAddress).isEqualTo("0.0.0.0") + } + it("should set proper health check api port") { - assertThat(result.healthCheckApiPort).isEqualTo(healthCheckApiPort.toInt()) + assertThat(result.healthCheckApiListenAddress.port).isEqualTo(healthCheckApiPort.toInt()) } - it("should set proper listen port") { - assertThat(result.listenPort).isEqualTo(listenPort.toInt()) + it("should set default health check api address") { + assertThat(result.healthCheckApiListenAddress.address.hostAddress).isEqualTo("0.0.0.0") } it("should set proper first consul request delay") { |