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 --- src/main/java/org/onap/dcae/VesApplication.java | 32 +++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'src/main/java/org/onap/dcae/VesApplication.java') diff --git a/src/main/java/org/onap/dcae/VesApplication.java b/src/main/java/org/onap/dcae/VesApplication.java index 86b8ccb0..7eea0eb0 100644 --- a/src/main/java/org/onap/dcae/VesApplication.java +++ b/src/main/java/org/onap/dcae/VesApplication.java @@ -26,9 +26,11 @@ import org.onap.dcae.commonFunction.EventProcessor; import org.onap.dcae.commonFunction.event.publishing.DMaaPConfigurationParser; import org.onap.dcae.commonFunction.event.publishing.EventPublisher; import org.onap.dcae.commonFunction.event.publishing.PublisherConfig; +import org.onap.dcae.controller.ConfigLoader; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.Banner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -38,9 +40,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Lazy; import java.nio.file.Paths; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.*; @SpringBootApplication @EnableAutoConfiguration(exclude = {GsonAutoConfiguration.class, SecurityAutoConfiguration.class}) @@ -61,21 +61,39 @@ public class VesApplication { fProcessingInputQueue = new LinkedBlockingQueue<>(properties.maximumAllowedQueuedEvents()); - app.setAddCommandLineProperties(true); - app.run(); - + EventPublisher publisher = EventPublisher.createPublisher(oplog, + DMaaPConfigurationParser + .parseToDomainMapping(Paths.get(properties.dMaaPConfigurationFileLocation())) + .get()); + spawnDynamicConfigUpdateThread(publisher, properties); EventProcessor ep = new EventProcessor(EventPublisher.createPublisher(oplog, getDmapConfig()), properties); ExecutorService executor = Executors.newFixedThreadPool(MAX_THREADS); for (int i = 0; i < MAX_THREADS; ++i) { executor.execute(ep); } + + app.setBannerMode(Banner.Mode.OFF); + app.setAddCommandLineProperties(true); + app.run(); } + private static void spawnDynamicConfigUpdateThread(EventPublisher eventPublisher, ApplicationSettings properties) { + ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1); + ConfigLoader configLoader = ConfigLoader + .create(eventPublisher::reconfigure, + Paths.get(properties.dMaaPConfigurationFileLocation()), + properties.configurationFileLocation()); + scheduledThreadPoolExecutor + .scheduleAtFixedRate(() -> configLoader.updateConfig(), + properties.configurationUpdateFrequency(), + properties.configurationUpdateFrequency(), + TimeUnit.MINUTES); + } private static Map getDmapConfig() { return DMaaPConfigurationParser. - parseToDomainMapping(Paths.get(properties.cambriaConfigurationFileLocation())).get(); + parseToDomainMapping(Paths.get(properties.dMaaPConfigurationFileLocation())).get(); } @Bean -- cgit 1.2.3-korg