aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/dcae/ApplicationSettings.java
diff options
context:
space:
mode:
authorPawelSzalapski <pawel.szalapski@nokia.com>2018-08-02 10:31:56 +0200
committerPawelSzalapski <pawel.szalapski@nokia.com>2018-08-06 09:43:32 +0200
commit7752c2d818e6d19e4d805c2fd6760b4a13d601bc (patch)
tree053cbc5afd76a8b9644ec62298053aad8cf5e2a8 /src/main/java/org/onap/dcae/ApplicationSettings.java
parent654ebdff4c9ec2487b819d2b76273732759de4c7 (diff)
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 <pawel.szalapski@nokia.com> Issue-ID: DCAEGEN2-519
Diffstat (limited to 'src/main/java/org/onap/dcae/ApplicationSettings.java')
-rw-r--r--src/main/java/org/onap/dcae/ApplicationSettings.java33
1 files changed, 19 insertions, 14 deletions
diff --git a/src/main/java/org/onap/dcae/ApplicationSettings.java b/src/main/java/org/onap/dcae/ApplicationSettings.java
index 9063faa4..e4621849 100644
--- a/src/main/java/org/onap/dcae/ApplicationSettings.java
+++ b/src/main/java/org/onap/dcae/ApplicationSettings.java
@@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.annotation.Nullable;
-import java.io.File;
+import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Base64;
@@ -48,9 +48,8 @@ import static java.util.Arrays.stream;
public class ApplicationSettings {
private static final Logger inlog = LoggerFactory.getLogger(ApplicationSettings.class);
- private static final String COLLECTOR_PROPERTIES = "etc/collector.properties";
-
private final String appInvocationDir;
+ private final String configurationFileLocation;
private final PropertiesConfiguration properties = new PropertiesConfiguration();
public ApplicationSettings(String[] args, Function1<String[], Map<String, String>> argsParser) {
@@ -61,20 +60,14 @@ public class ApplicationSettings {
this.appInvocationDir = appInvocationDir;
properties.setDelimiterParsingDisabled(true);
Map<String, String> parsedArgs = argsParser.apply(args);
- loadProperties(Paths.get(new File(COLLECTOR_PROPERTIES).getAbsolutePath()).toString());
- loadCommandLineProperties(parsedArgs);
+ configurationFileLocation = findOutConfigurationFileLocation(parsedArgs);
+ loadPropertiesFromFile();
parsedArgs.filterKeys(k -> !k.equals("c")).forEach(this::updateProperty);
}
- private void loadCommandLineProperties(Map<String, String> parsedArgs) {
- parsedArgs.get("c").forEach(e -> {
- properties.clear();
- loadProperties(e);
- });
- }
- private void loadProperties(String property) {
+ private void loadPropertiesFromFile() {
try {
- properties.load(property);
+ properties.load(configurationFileLocation);
} catch (ConfigurationException ex) {
inlog.error("Cannot load properties cause:", ex);
throw new RuntimeException(ex);
@@ -90,6 +83,14 @@ public class ApplicationSettings {
.toMap(t -> t.split(",")[0].trim(), t -> new String(Base64.getDecoder().decode(t.split(",")[1])).trim());
}
+ private String findOutConfigurationFileLocation(Map<String, String> parsedArgs) {
+ return prependWithUserDirOnRelative(parsedArgs.get("c").getOrElse("etc/collector.properties"));
+ }
+
+ public Path configurationFileLocation() {
+ return Paths.get(configurationFileLocation);
+ }
+
public int maximumAllowedQueuedEvents() {
return properties.getInt("collector.inputQueue.maxPending", 1024 * 4);
}
@@ -115,6 +116,10 @@ public class ApplicationSettings {
return properties.getInt("collector.service.secure.port", 8443);
}
+ public int configurationUpdateFrequency() {
+ return properties.getInt("collector.dynamic.config.update.frequency", 5);
+ }
+
public boolean httpsEnabled() {
return httpsPort() > 0;
}
@@ -139,7 +144,7 @@ public class ApplicationSettings {
return properties.getString("exceptionConfig", null);
}
- public String cambriaConfigurationFileLocation() {
+ public String dMaaPConfigurationFileLocation() {
return prependWithUserDirOnRelative(properties.getString("collector.dmaapfile", "etc/DmaapConfig.json"));
}