From: Jakub Dudycz Date: Tue, 7 Aug 2018 12:18:37 +0000 (+0200) Subject: Create health check module X-Git-Tag: 1.0.0~40 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=dd827e2c1cc984d9ed1fed9914cbef0e985ea625;p=dcaegen2%2Fcollectors%2Fhv-ves.git Create health check module Create ves-hv-collector-health-check module with dummy api server and connect it with ves-hv-collector-main This is a preparation for health check mechanism implementation Change-Id: I2f668ab7337b1ed7e2afea6c56f34880de3ef1b5 Issue-ID: DCAEGEN2-659 Signed-off-by: Jakub Dudycz --- diff --git a/docker-compose.yml b/docker-compose.yml index f0713c7e..7bd84f53 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,6 +34,7 @@ services: # context: hv-collector-main # dockerfile: Dockerfile ports: + - "6060:6060" - "6061:6061/tcp" command: ["--listen-port", "6061","--config-url", "http://consul:8500/v1/kv/veshv-config"] depends_on: diff --git a/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/model/ServerConfiguration.kt b/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/model/ServerConfiguration.kt index b0f3ec06..c14d36e6 100644 --- a/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/model/ServerConfiguration.kt +++ b/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/model/ServerConfiguration.kt @@ -31,4 +31,5 @@ data class ServerConfiguration( val configurationProviderParams: ConfigurationProviderParams, val securityConfiguration: SecurityConfiguration, val idleTimeout: Duration, + val healthCheckApiPort: Int, val dummyMode: Boolean = false) diff --git a/hv-collector-health-check/pom.xml b/hv-collector-health-check/pom.xml new file mode 100644 index 00000000..4072ec24 --- /dev/null +++ b/hv-collector-health-check/pom.xml @@ -0,0 +1,57 @@ + + + + 4.0.0 + + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + + + + + false + false + + + + org.onap.dcaegen2.collectors.veshv + ves-hv-collector + 1.0.0-SNAPSHOT + .. + + + hv-collector-health-check + VES HighVolume Collector :: Health check + + + + + kotlin-maven-plugin + org.jetbrains.kotlin + + + maven-surefire-plugin + org.apache.maven.plugins + + + + + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + + + io.ratpack + ratpack-core + + + io.arrow-kt + arrow-effects + + + \ No newline at end of file diff --git a/hv-collector-health-check/src/main/kotlin/org/onap/dcae/collectors/veshv/healthcheck/http/HealthCheckApiServer.kt b/hv-collector-health-check/src/main/kotlin/org/onap/dcae/collectors/veshv/healthcheck/http/HealthCheckApiServer.kt new file mode 100644 index 00000000..9cab031a --- /dev/null +++ b/hv-collector-health-check/src/main/kotlin/org/onap/dcae/collectors/veshv/healthcheck/http/HealthCheckApiServer.kt @@ -0,0 +1,49 @@ +/* + * ============LICENSE_START======================================================= + * dcaegen2-collectors-veshv + * ================================================================================ + * Copyright (C) 2018 NOKIA + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.dcae.collectors.veshv.healthcheck.http + +import arrow.effects.IO +import ratpack.handling.Chain +import ratpack.http.Status +import ratpack.server.RatpackServer +import ratpack.server.ServerConfig + +/** + * @author Jakub Dudycz + * @since August 2018 + */ +class HealthCheckApiServer { + + fun start(port: Int): IO = IO { + RatpackServer + .start { + it + .serverConfig(ServerConfig.embedded().port(port).development(false)) + .handlers(this::configureHandlers) + } + } + + private fun configureHandlers(chain: Chain) { + chain + .get("healthcheck") { ctx -> + ctx.response.status(Status.OK).send() + } + } +} \ No newline at end of file diff --git a/hv-collector-main/pom.xml b/hv-collector-main/pom.xml index e594aeff..0e956288 100644 --- a/hv-collector-main/pom.xml +++ b/hv-collector-main/pom.xml @@ -87,13 +87,21 @@ hv-collector-core ${project.parent.version} + + ${project.parent.groupId} + hv-collector-health-check + ${project.parent.version} + ${project.parent.groupId} hv-collector-test-utils ${project.parent.version} test - + + io.ratpack + ratpack-core + io.arrow-kt arrow-core 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 7c958b97..26230cd3 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 @@ -35,6 +35,7 @@ import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.CONSUL import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.CONSUL_FIRST_REQUEST_DELAY import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.CONSUL_REQUEST_INTERVAL import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.DUMMY_MODE +import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.HEALTH_CHECK_API_PORT import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.IDLE_TIMEOUT_SEC import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.LISTEN_PORT import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.PRIVATE_KEY_FILE @@ -44,6 +45,7 @@ import java.time.Duration internal class ArgVesHvConfiguration : ArgBasedConfiguration(DefaultParser()) { override val cmdLineOptionsList = listOf( + HEALTH_CHECK_API_PORT, LISTEN_PORT, CONSUL_CONFIG_URL, CONSUL_FIRST_REQUEST_DELAY, @@ -59,12 +61,17 @@ internal class ArgVesHvConfiguration : ArgBasedConfiguration = ForOption extensions { binding { + val healthCheckApiPort = cmdLine.intValue( + HEALTH_CHECK_API_PORT, + DefaultValues.HEALTH_CHECK_API_PORT + ) 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).bind() ServerConfiguration( + healthCheckApiPort = healthCheckApiPort, listenPort = listenPort, configurationProviderParams = configurationProviderParams, securityConfiguration = security, @@ -77,9 +84,14 @@ internal class ArgVesHvConfiguration : ArgBasedConfiguration(private val parser: CommandLineParser) { protected fun CommandLine.stringValue(cmdLineOpt: CommandLineOption, default: String): String = optionValue(cmdLineOpt).getOrElse { default } + protected fun CommandLine.intValue(cmdLineOpt: CommandLineOption, default: Int): Int = + intValue(cmdLineOpt).getOrElse { default } + protected fun CommandLine.intValue(cmdLineOpt: CommandLineOption): Option = optionValue(cmdLineOpt).map(String::toInt) 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 44de9d7a..836a05df 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 @@ -23,6 +23,12 @@ import org.apache.commons.cli.Option enum class CommandLineOption(val option: Option) { + HEALTH_CHECK_API_PORT(Option.builder("H") + .longOpt("health-check-api-port") + .hasArg() + .desc("Health check rest api listen port") + .build() + ), LISTEN_PORT(Option.builder("p") .longOpt("listen-port") .required() diff --git a/pom.xml b/pom.xml index cf5d5ad3..19b98927 100644 --- a/pom.xml +++ b/pom.xml @@ -44,11 +44,12 @@ hv-collector-ct hv-collector-dcae-app-simulator hv-collector-domain + hv-collector-health-check hv-collector-main + hv-collector-test-utils hv-collector-utils hv-collector-ves-message-generator hv-collector-xnf-simulator - hv-collector-test-utils