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 <jakub.dudycz@nokia.com>
# 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:
val configurationProviderParams: ConfigurationProviderParams,
val securityConfiguration: SecurityConfiguration,
val idleTimeout: Duration,
+ val healthCheckApiPort: Int,
val dummyMode: Boolean = false)
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <licenses>
+ <license>
+ <name>The Apache Software License, Version 2.0</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+ </license>
+ </licenses>
+
+ <properties>
+ <skipAnalysis>false</skipAnalysis>
+ <failIfMissingUnitTests>false</failIfMissingUnitTests>
+ </properties>
+
+ <parent>
+ <groupId>org.onap.dcaegen2.collectors.veshv</groupId>
+ <artifactId>ves-hv-collector</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <artifactId>hv-collector-health-check</artifactId>
+ <description>VES HighVolume Collector :: Health check</description>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>kotlin-maven-plugin</artifactId>
+ <groupId>org.jetbrains.kotlin</groupId>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <groupId>org.apache.maven.plugins</groupId>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jetbrains.kotlin</groupId>
+ <artifactId>kotlin-stdlib-jdk8</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.ratpack</groupId>
+ <artifactId>ratpack-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.arrow-kt</groupId>
+ <artifactId>arrow-effects</artifactId>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
--- /dev/null
+/*
+ * ============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 <jakub.dudycz@nokia.com>
+ * @since August 2018
+ */
+class HealthCheckApiServer {
+
+ fun start(port: Int): IO<RatpackServer> = 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
<artifactId>hv-collector-core</artifactId>
<version>${project.parent.version}</version>
</dependency>
+ <dependency>
+ <groupId>${project.parent.groupId}</groupId>
+ <artifactId>hv-collector-health-check</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>hv-collector-test-utils</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
-
+ <dependency>
+ <groupId>io.ratpack</groupId>
+ <artifactId>ratpack-core</artifactId>
+ </dependency>
<dependency>
<groupId>io.arrow-kt</groupId>
<artifactId>arrow-core</artifactId>
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
internal class ArgVesHvConfiguration : ArgBasedConfiguration<ServerConfiguration>(DefaultParser()) {
override val cmdLineOptionsList = listOf(
+ HEALTH_CHECK_API_PORT,
LISTEN_PORT,
CONSUL_CONFIG_URL,
CONSUL_FIRST_REQUEST_DELAY,
override fun getConfiguration(cmdLine: CommandLine): Option<ServerConfiguration> =
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,
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)
-
+ 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),
}
internal object DefaultValues {
+ const val HEALTH_CHECK_API_PORT = 6060
const val CONSUL_FIRST_REQUEST_DELAY = 10L
const val CONSUL_REQUEST_INTERVAL = 5L
const val PRIVATE_KEY_FILE = "/etc/ves-hv/server.key"
import org.onap.dcae.collectors.veshv.boundary.ServerHandle
import org.onap.dcae.collectors.veshv.factory.CollectorFactory
import org.onap.dcae.collectors.veshv.factory.ServerFactory
+import org.onap.dcae.collectors.veshv.healthcheck.http.HealthCheckApiServer
import org.onap.dcae.collectors.veshv.impl.adapters.AdapterFactory
import org.onap.dcae.collectors.veshv.model.ServerConfiguration
import org.onap.dcae.collectors.veshv.utils.arrow.ExitFailure
fun main(args: Array<String>) =
ArgVesHvConfiguration().parse(args)
.mapLeft(handleWrongArgumentErrorCurried(PROGRAM_NAME))
+ .map(::startHealthCheckApiServer)
.map(::createServer)
.map {
it.start()
{ logger.info("Gentle shutdown") }
)
-
private fun createServer(config: ServerConfiguration): Server {
val sink = if (config.dummyMode) AdapterFactory.loggingSink() else AdapterFactory.kafkaSink()
val collectorProvider = CollectorFactory(
return ServerFactory.createNettyTcpServer(config, collectorProvider)
}
-private fun logServerStarted(handle: ServerHandle): ServerHandle {
- logger.info("HighVolume VES Collector is up and listening on ${handle.host}:${handle.port}")
- return handle
+private fun logServerStarted(handle: ServerHandle): ServerHandle = handle.also {
+ logger.info("HighVolume VES Collector is up and listening on ${it.host}:${it.port}")
+}
+
+private fun startHealthCheckApiServer(config: ServerConfiguration): ServerConfiguration = config.apply {
+ HealthCheckApiServer()
+ .start(healthCheckApiPort)
+ .unsafeRunSync()
+ .also { logger.info("Health check api server started on port ${it.bindPort}") }
}
*/
object ArgVesHvConfigurationTest : Spek({
lateinit var cut: ArgVesHvConfiguration
+ val healthCheckApiPort = "6070"
val configurationUrl = "http://test-address/test"
val firstRequestDelay = "10"
val requestInterval = "5"
beforeEachTest {
result = cut.parseExpectingSuccess("--ssl-disable",
+ "--health-check-api-port", healthCheckApiPort,
"--listen-port", listenPort,
"--config-url", configurationUrl,
"--first-request-delay", firstRequestDelay,
"--trust-cert-file", trustCert.toFile().absolutePath)
}
- it("should set proper port") {
+ it("should set proper health check api port") {
+ assertThat(result.healthCheckApiPort).isEqualTo(healthCheckApiPort.toInt())
+ }
+
+ it("should set proper listen port") {
assertThat(result.listenPort).isEqualTo(listenPort.toInt())
}
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<Int> =
optionValue(cmdLineOpt).map(String::toInt)
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()
<module>hv-collector-ct</module>
<module>hv-collector-dcae-app-simulator</module>
<module>hv-collector-domain</module>
+ <module>hv-collector-health-check</module>
<module>hv-collector-main</module>
+ <module>hv-collector-test-utils</module>
<module>hv-collector-utils</module>
<module>hv-collector-ves-message-generator</module>
<module>hv-collector-xnf-simulator</module>
- <module>hv-collector-test-utils</module>
</modules>
<properties>