From 1422bed4c1a002e663fd7c2c4c204831e5f7aa9a Mon Sep 17 00:00:00 2001 From: Filip Krzywka Date: Thu, 28 Feb 2019 17:33:02 +0100 Subject: Use CBS by means of SDK in place of Consul - changed IO creation in main to fix error with too early calling changeState method on collector HealthState - increased coverage a little with few tests - corrected coverage-report pom file to include new modules - temporarily changed to 1.1.4-SNAPSHOT version of sdk due to need of new version of CBSLookup Change-Id: Ic73b46cf881ab4fabf52bef0327b09082aa90dc6 Issue-ID: DCAEGEN2-1302 Signed-off-by: Filip Krzywka --- .../veshv/utils/logging/reactive_logging.kt | 16 ++++++++++++++++ .../onap/dcae/collectors/veshv/utils/shutdown_hook.kt | 19 +++---------------- 2 files changed, 19 insertions(+), 16 deletions(-) (limited to 'sources/hv-collector-utils/src/main/kotlin') diff --git a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/reactive_logging.kt b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/reactive_logging.kt index 99ecfd74..7d92ddaf 100644 --- a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/reactive_logging.kt +++ b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/reactive_logging.kt @@ -72,3 +72,19 @@ fun Flux.filterFailedWithLog(logger: Logger, Mono.just(t) }) } + + +fun Mono.onErrorLog(logger: Logger, + mdc: () -> Map, + msg: () -> String) = + doOnError { logException(logger, mdc, msg, it) } + +fun Flux.onErrorLog(logger: Logger, + mdc: () -> Map, + msg: () -> String) = + doOnError { logException(logger, mdc, msg, it) } + +private fun logException(logger: Logger, mdc: () -> Map, msg: () -> String, it: Throwable) { + logger.error(mdc) { "${msg()}: ${it.message}" } + logger.debug(mdc) { "Detailed stack trace: ${it}" } +} diff --git a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/shutdown_hook.kt b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/shutdown_hook.kt index 2678a8d5..87aea41e 100644 --- a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/shutdown_hook.kt +++ b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/shutdown_hook.kt @@ -19,23 +19,10 @@ */ package org.onap.dcae.collectors.veshv.utils -import arrow.effects.IO - /** * @author Piotr Jaszczyk * @since January 2019 */ - -fun registerShutdownHook(job: () -> Unit) { - Runtime.getRuntime().addShutdownHook(object : Thread() { - override fun run() { - job() - } - }) -} - -fun registerShutdownHook(job: IO) = IO { - registerShutdownHook { - job.unsafeRunSync() - } -} +fun registerShutdownHook(job: () -> Unit) = + Runtime.getRuntime() + .addShutdownHook(Thread({ job() }, "GracefulShutdownThread")) -- cgit 1.2.3-korg