From e7360f7e7e77672b885087af68a3d96ebbc8c313 Mon Sep 17 00:00:00 2001 From: Zlatko Murgoski Date: Mon, 4 Feb 2019 09:27:00 +0100 Subject: Restart Issue Restart Issue Issue-ID: DCAEGEN2-1104 Change-Id: Iac1ee2f79be00084f5c0cd963503d54d7d6e6cb9 Signed-off-by: Zlatko Murgoski --- .../org/onap/dcae/controller/ConfigLoader.java | 41 ++++++++++++------ .../controller/PreAppStartupConfigUpdater.java | 49 ---------------------- 2 files changed, 29 insertions(+), 61 deletions(-) delete mode 100644 src/main/java/org/onap/dcae/controller/PreAppStartupConfigUpdater.java (limited to 'src/main/java/org/onap/dcae/controller') diff --git a/src/main/java/org/onap/dcae/controller/ConfigLoader.java b/src/main/java/org/onap/dcae/controller/ConfigLoader.java index e11c2b8a..dbf52823 100644 --- a/src/main/java/org/onap/dcae/controller/ConfigLoader.java +++ b/src/main/java/org/onap/dcae/controller/ConfigLoader.java @@ -33,6 +33,7 @@ import io.vavr.control.Try; import java.nio.file.Path; import java.util.function.Consumer; import org.json.JSONObject; +import org.onap.dcae.VesApplication; import org.onap.dcae.common.publishing.PublisherConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,19 +46,21 @@ public class ConfigLoader { private final ConfigFilesFacade configFilesFacade; private final Function1> configurationSource; private final Function0> envVariablesSupplier; + private boolean toRestart = false; ConfigLoader(Consumer> eventPublisherReconfigurer, - ConfigFilesFacade configFilesFacade, - Function1> configurationSource, - Function0> envVariablesSupplier) { + ConfigFilesFacade configFilesFacade, + Function1> configurationSource, + Function0> envVariablesSupplier) { this.eventPublisherReconfigurer = eventPublisherReconfigurer; this.configFilesFacade = configFilesFacade; this.configurationSource = configurationSource; this.envVariablesSupplier = envVariablesSupplier; } - public static ConfigLoader create(Consumer> eventPublisherReconfigurer, - Path dMaaPConfigFile, Path propertiesConfigFile) { + public static ConfigLoader create( + Consumer> eventPublisherReconfigurer, + Path dMaaPConfigFile, Path propertiesConfigFile) { return new ConfigLoader(eventPublisherReconfigurer, new ConfigFilesFacade(dMaaPConfigFile, propertiesConfigFile), ConfigSource::getAppConfig, @@ -67,20 +70,27 @@ public class ConfigLoader { public void updateConfig() { log.info("Trying to dynamically update config from Config Binding Service"); readEnvProps(envVariablesSupplier.get()) - .onEmpty(() -> log.warn(SKIP_MSG)) - .forEach(this::updateConfig); + .onEmpty(() -> log.warn(SKIP_MSG)).forEach(this::updateConfig); } private void updateConfig(EnvProps props) { configurationSource.apply(props) .onFailure(logSkip()) .onSuccess(newConf -> { - updateConfigurationProperties(newConf); - updateDMaaPProperties(newConf); + updateConfigurationProperties(newConf); + updateDMaaPProperties(newConf); + reloadApplication(); } ); } + private void reloadApplication() { + if(toRestart){ + log.info("New app config - Application will be restarted"); + VesApplication.restartApplication(); + } + } + private void updateDMaaPProperties(JSONObject newConf) { configFilesFacade.readDMaaPConfiguration() .onFailure(logSkip()) @@ -98,9 +108,13 @@ public class ConfigLoader { private void compareAndOverwritePropertiesConfig(JSONObject newConf, Map oldProps) { Map newProperties = getProperties(newConf); - if (!oldProps.equals(newProperties)) { + Map result = oldProps.filterKeys((s) -> newProperties.keySet().contains(s)); + if (!result.equals(newProperties)) { configFilesFacade.writeProperties(newProperties) - .onSuccess(__ -> log.info("New properties configuration written to file")) + .onSuccess(__ -> { + toRestart= true; + log.info("New properties configuration written to file"); + }) .onFailure(logSkip()); } else { log.info("Collector properties from CBS are the same as currently used ones. " + SKIP_MSG); @@ -115,7 +129,10 @@ public class ConfigLoader { .onSuccess(parsedConfig -> configFilesFacade.writeDMaaPConfiguration(newDMaaPConf) .onFailure(logSkip()) - .onSuccess(__ -> log.info("New dMaaP configuration written to file"))); + .onSuccess(__ -> { + toRestart= true; + log.info("New dMaaP configuration written to file"); + })); } else { log.info("DMaaP config from CBS is the same as currently used one. " + SKIP_MSG); } diff --git a/src/main/java/org/onap/dcae/controller/PreAppStartupConfigUpdater.java b/src/main/java/org/onap/dcae/controller/PreAppStartupConfigUpdater.java deleted file mode 100644 index be569119..00000000 --- a/src/main/java/org/onap/dcae/controller/PreAppStartupConfigUpdater.java +++ /dev/null @@ -1,49 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * org.onap.dcaegen2.collectors.ves - * ================================================================================ - * Copyright (C) 2018 Nokia. All rights reserved. - * ================================================================================ - * 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.controller; - -import io.vavr.collection.Map; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.function.Consumer; -import org.onap.dcae.common.publishing.PublisherConfig; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * On the first application launch, the configuration update thread that application spawns, has no chance to run yet - * and prepare initial application configuration. In this case, it needs to be fetched from outside of the application, - * so this is run from the .sh script. - * Later on, once application is already started it will take care of the configuration update itself - * @author Pawel Szalapski (pawel.szalapski@nokia.com) - */ -public class PreAppStartupConfigUpdater { - private final static Logger log = LoggerFactory.getLogger(PreAppStartupConfigUpdater.class); - - private static final Path DEFAULT_CONFIGURATION_FILE_PATH = Paths.get("etc/collector.properties"); - private static final Path DEFAULT_DMAAP_FILE_PATH = Paths.get("etc/DmaapConfig.json"); - private static final Consumer> NO_OP_CONSUMER = c -> { }; - - public static void main(String[] args) { - log.info("Running initial configuration update, before the application gets started."); - ConfigLoader.create(NO_OP_CONSUMER, DEFAULT_DMAAP_FILE_PATH, DEFAULT_CONFIGURATION_FILE_PATH) - .updateConfig(); - } -} -- cgit 1.2.3-korg