diff options
author | Guangrong Fu <fu.guangrong@zte.com.cn> | 2022-01-20 11:45:39 +0800 |
---|---|---|
committer | Guangrong Fu <fu.guangrong@zte.com.cn> | 2022-01-20 14:12:30 +0800 |
commit | 58e113734959922ec70516f9be1d7ebcc3fd5dc3 (patch) | |
tree | 5211783a135b2909c06cf21fafbd656ac988365e /rulemgt/src/main/java | |
parent | ad3329cc6366a42824d3894cc669de9f260219ba (diff) |
bugfix - rule deployment issue during init
Issue-ID: HOLMES-488
Signed-off-by: Guangrong Fu <fu.guangrong@zte.com.cn>
Change-Id: If667a3691aa67a2559020b0bc91f7f4c21347026
Diffstat (limited to 'rulemgt/src/main/java')
-rw-r--r-- | rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTask.java | 31 |
1 files changed, 23 insertions, 8 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 884ea31..574432c 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 @@ -53,6 +53,26 @@ public class ConfigFileScanningTask implements Runnable { @Override public void run() { + List<RuleResult4API> deployedRules = null; + boolean isRuleQueryAvailable = true; + + try { + deployedRules = getExistingRules(); + } catch (Exception e) { + LOGGER.warn("Failed to get existing rules for comparison.", e); + isRuleQueryAvailable = false; + } + + // If it fails to load rule through API, it means that something must be wrong with the + // holmes-rule-mgmt service. Hence, there's no need to go on with remaining steps. + if (!isRuleQueryAvailable) { + return; + } + + for (RuleResult4API ruleResult4API : deployedRules) { + configInEffect.put(ruleResult4API.getLoopControlName(), ruleResult4API.getContent()); + } + if (null == configFileScanner) { configFileScanner = new ConfigFileScanner(); } @@ -60,8 +80,6 @@ public class ConfigFileScanningTask implements Runnable { 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()); @@ -69,15 +87,14 @@ public class ConfigFileScanningTask implements Runnable { .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 + final List<RuleResult4API> existingRules = deployedRules; existingKeys.stream().filter(key -> !newKeys.contains(key)).forEach(key -> { - if (deleteRule(find(deployedRules, key))) { - configInEffect.remove(key); + if (deleteRule(find(existingRules, key))) { LOGGER.info("Rule '{}' has been removed.", key); } }); @@ -85,10 +102,8 @@ public class ConfigFileScanningTask implements Runnable { // 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); + if (deleteRule(find(existingRules, key))) { deployRule(key, newConfig.get(key)); - configInEffect.put(key, newConfig.get(key)); LOGGER.info("Rule '{}' has been updated.", key); } } |