From 7752c2d818e6d19e4d805c2fd6760b4a13d601bc Mon Sep 17 00:00:00 2001 From: PawelSzalapski Date: Thu, 2 Aug 2018 10:31:56 +0200 Subject: Implement second part of dynamic DMaaP config VESCollector app can now fetch CBS configuration and rebuilt the part regarding sending events dynamically, without restarting application. Application will still be restarted by a .sh script, if there were changes regarding collector.properties file. The decision of whether dynamic configuration should be triggered is now based on existence of env vars CONSUL_HOST, CONFIG_BINDING_SERVICE, HOSTNAME, not as previously on CBSPOLLTIME. Frequency at which the config check should happen is now exposed via property from collector.properties Change-Id: I98ff160fa51d08d84a23c716d90ceaacbe17ada6 Signed-off-by: PawelSzalapski Issue-ID: DCAEGEN2-519 --- .../event/publishing/DMaaPConfigurationParser.java | 7 +++++++ .../event/publishing/DMaaPPublishersBuilder.java | 1 - .../commonFunction/event/publishing/VavrUtils.java | 20 +++++++++++++++++--- 3 files changed, 24 insertions(+), 4 deletions(-) (limited to 'src/main/java/org/onap/dcae/commonFunction/event') diff --git a/src/main/java/org/onap/dcae/commonFunction/event/publishing/DMaaPConfigurationParser.java b/src/main/java/org/onap/dcae/commonFunction/event/publishing/DMaaPConfigurationParser.java index 179e8826..91db5172 100644 --- a/src/main/java/org/onap/dcae/commonFunction/event/publishing/DMaaPConfigurationParser.java +++ b/src/main/java/org/onap/dcae/commonFunction/event/publishing/DMaaPConfigurationParser.java @@ -29,6 +29,8 @@ import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; +import org.json.JSONObject; + import static io.vavr.API.*; import static org.onap.dcae.commonFunction.event.publishing.VavrUtils.enhanceError; import static org.onap.dcae.commonFunction.event.publishing.VavrUtils.f; @@ -45,6 +47,11 @@ public final class DMaaPConfigurationParser { .flatMap(DMaaPConfigurationParser::toConfigMap); } + public static Try> parseToDomainMapping(JSONObject config) { + return toJSON(config.toString()) + .flatMap(DMaaPConfigurationParser::toConfigMap); + } + private static Try readFromFile(Path configLocation) { return Try(() -> new String(Files.readAllBytes(configLocation))) .mapFailure(enhanceError(f("Could not read DMaaP configuration from location: '%s'", configLocation))); diff --git a/src/main/java/org/onap/dcae/commonFunction/event/publishing/DMaaPPublishersBuilder.java b/src/main/java/org/onap/dcae/commonFunction/event/publishing/DMaaPPublishersBuilder.java index 489fcbf0..4f672715 100644 --- a/src/main/java/org/onap/dcae/commonFunction/event/publishing/DMaaPPublishersBuilder.java +++ b/src/main/java/org/onap/dcae/commonFunction/event/publishing/DMaaPPublishersBuilder.java @@ -33,7 +33,6 @@ import static org.onap.dcae.commonFunction.event.publishing.VavrUtils.f; */ final class DMaaPPublishersBuilder { - @SuppressWarnings("mapFailure takes a generic varargs, unchecked because of Javas type system limitation, actually safe to do") static Try buildPublisher(PublisherConfig config) { return Try(() -> builder(config).build()) .mapFailure(enhanceError(f("DMaaP client builder throws exception for this configuration: '%s'", config))); diff --git a/src/main/java/org/onap/dcae/commonFunction/event/publishing/VavrUtils.java b/src/main/java/org/onap/dcae/commonFunction/event/publishing/VavrUtils.java index 78f34ff4..7d535a21 100644 --- a/src/main/java/org/onap/dcae/commonFunction/event/publishing/VavrUtils.java +++ b/src/main/java/org/onap/dcae/commonFunction/event/publishing/VavrUtils.java @@ -21,13 +21,18 @@ package org.onap.dcae.commonFunction.event.publishing; import io.vavr.API; import io.vavr.API.Match.Case; +import io.vavr.Function0; +import io.vavr.Function1; +import java.util.function.Consumer; +import java.util.function.Function; +import org.slf4j.Logger; import static io.vavr.API.$; /** * @author Pawel Szalapski (pawel.szalapski@nokia.com) */ -final class VavrUtils { +public final class VavrUtils { private VavrUtils() { // utils aggregator @@ -36,7 +41,7 @@ final class VavrUtils { /** * Shortcut for 'string interpolation' */ - static String f(String msg, Object... args) { + public static String f(String msg, Object... args) { return String.format(msg, args); } @@ -44,8 +49,17 @@ final class VavrUtils { * Wrap failure with a more descriptive message of what has failed and chain original cause. Used to provide a * context for errors instead of raw exception. */ - static Case enhanceError(String msg) { + public static Case enhanceError(String msg) { return API.Case($(), e -> new RuntimeException(msg, e)); } + public static Case enhanceError(String pattern, Object... arguments) { + return API.Case($(), e -> new RuntimeException(f(pattern, arguments), e)); + } + + public static Consumer logError(Logger withLogger) { + return e -> withLogger.error(e.getMessage(), e); + } + + } -- cgit 1.2.3-korg