summaryrefslogtreecommitdiffstats
path: root/rulemgt/src/main/java
diff options
context:
space:
mode:
authorGuangrong Fu <fu.guangrong@zte.com.cn>2021-12-02 09:52:12 +0800
committerGuangrong Fu <fu.guangrong@zte.com.cn>2021-12-02 09:52:12 +0800
commit7dedc836781b221c3a1945a8247be8ed23248a1e (patch)
treeb4eb25c3b53340140a83e67c72d98b261351744c /rulemgt/src/main/java
parent5cc6fc1a762c547f420ce281deac69f02f6c2b83 (diff)
Added exception protection.
Added try-catch block to prevent the polling thread from stop. Issue-ID: HOLMES-488 Signed-off-by: Guangrong Fu <fu.guangrong@zte.com.cn> Change-Id: Iebe943ab53e15428d90fe3ca271ca4a478936676
Diffstat (limited to 'rulemgt/src/main/java')
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTask.java68
1 files changed, 37 insertions, 31 deletions
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTask.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTask.java
index 9f7b89f..88ab637 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTask.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTask.java
@@ -54,41 +54,46 @@ public class ConfigFileScanningTask implements Runnable {
if (null == configFileScanner) {
configFileScanner = new ConfigFileScanner();
}
- Map<String, String> newConfig = extractConfigItems(configFileScanner.scan(configFile));
- List<RuleResult4API> deployedRules = getExistingRules();
-
- // deal with newly added rules
- final Set<String> existingKeys = new HashSet(configInEffect.keySet());
- final Set<String> newKeys = new HashSet(newConfig.keySet());
- newKeys.stream()
- .filter(key -> !existingKeys.contains(key))
- .forEach(key -> {
- if (deployRule(key, newConfig.get(key))) {
- configInEffect.put(key, newConfig.get(key));
- LOGGER.info("Rule '{}' has been deployed.", key);
- }
- });
-
- // deal with removed rules
- existingKeys.stream().filter(key -> !newKeys.contains(key)).forEach(key -> {
- if (deleteRule(find(deployedRules, key))) {
- configInEffect.remove(key);
- LOGGER.info("Rule '{}' has been removed.", key);
- }
- });
-
- // deal with changed rules
- existingKeys.stream().filter(key -> newKeys.contains(key)).forEach(key -> {
- if (changed(configInEffect.get(key), newConfig.get(key))) {
+ try {
+ Map<String, String> newConfig = extractConfigItems(configFileScanner.scan(configFile));
+
+ List<RuleResult4API> deployedRules = getExistingRules();
+
+ // deal with newly added rules
+ final Set<String> existingKeys = new HashSet(configInEffect.keySet());
+ final Set<String> newKeys = new HashSet(newConfig.keySet());
+ newKeys.stream()
+ .filter(key -> !existingKeys.contains(key))
+ .forEach(key -> {
+ if (deployRule(key, newConfig.get(key))) {
+ configInEffect.put(key, newConfig.get(key));
+ LOGGER.info("Rule '{}' has been deployed.", key);
+ }
+ });
+
+ // deal with removed rules
+ existingKeys.stream().filter(key -> !newKeys.contains(key)).forEach(key -> {
if (deleteRule(find(deployedRules, key))) {
configInEffect.remove(key);
- deployRule(key, newConfig.get(key));
- configInEffect.put(key, newConfig.get(key));
- LOGGER.info("Rule '{}' has been updated.", key);
+ LOGGER.info("Rule '{}' has been removed.", key);
}
- }
- });
+ });
+
+ // deal with changed rules
+ existingKeys.stream().filter(key -> newKeys.contains(key)).forEach(key -> {
+ if (changed(configInEffect.get(key), newConfig.get(key))) {
+ if (deleteRule(find(deployedRules, key))) {
+ configInEffect.remove(key);
+ deployRule(key, newConfig.get(key));
+ configInEffect.put(key, newConfig.get(key));
+ LOGGER.info("Rule '{}' has been updated.", key);
+ }
+ }
+ });
+ } catch (Exception e) {
+ LOGGER.warn("Unhandled error: \n" + e.getMessage(), e);
+ }
}
private Map<String, String> extractConfigItems(Map<String, String> configFiles) {
@@ -113,6 +118,7 @@ public class ConfigFileScanningTask implements Runnable {
}
return path;
}
+
private String readFile(String path) {
String finalPath = normalizePath(path);
File file = new File(finalPath);