aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/dcae/controller
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/onap/dcae/controller')
-rw-r--r--src/main/java/org/onap/dcae/controller/ConfigLoader.java41
-rw-r--r--src/main/java/org/onap/dcae/controller/PreAppStartupConfigUpdater.java49
2 files changed, 29 insertions, 61 deletions
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<EnvProps, Try<JSONObject>> configurationSource;
private final Function0<Map<String, String>> envVariablesSupplier;
+ private boolean toRestart = false;
ConfigLoader(Consumer<Map<String, PublisherConfig>> eventPublisherReconfigurer,
- ConfigFilesFacade configFilesFacade,
- Function1<EnvProps, Try<JSONObject>> configurationSource,
- Function0<Map<String, String>> envVariablesSupplier) {
+ ConfigFilesFacade configFilesFacade,
+ Function1<EnvProps, Try<JSONObject>> configurationSource,
+ Function0<Map<String, String>> envVariablesSupplier) {
this.eventPublisherReconfigurer = eventPublisherReconfigurer;
this.configFilesFacade = configFilesFacade;
this.configurationSource = configurationSource;
this.envVariablesSupplier = envVariablesSupplier;
}
- public static ConfigLoader create(Consumer<Map<String, PublisherConfig>> eventPublisherReconfigurer,
- Path dMaaPConfigFile, Path propertiesConfigFile) {
+ public static ConfigLoader create(
+ Consumer<Map<String, PublisherConfig>> 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<String, String> oldProps) {
Map<String, String> newProperties = getProperties(newConf);
- if (!oldProps.equals(newProperties)) {
+ Map<String, String> 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<Map<String, PublisherConfig>> 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();
- }
-}