import com.google.gson.JsonParser;
import org.apache.commons.lang.StringUtils;
import org.onap.holmes.common.ConfigFileScanner;
+import org.onap.holmes.common.utils.CommonUtils;
import org.onap.holmes.common.utils.FileUtils;
import org.onap.holmes.common.utils.JerseyClient;
import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest;
final private Map<String, String> configInEffect = new HashMap(); // Contents for configInEffect are <closedControlLoop>:<ruleContents> pairs.
private String configFile = "/opt/hrmrules/index.json";
private ConfigFileScanner configFileScanner;
- private String url = "https://127.0.0.1:9101/api/holmes-rule-mgmt/v1/rule";
+ private String url;
public ConfigFileScanningTask(ConfigFileScanner configFileScanner) {
this.configFileScanner = configFileScanner;
+ this.url = getRequestPref() + "://127.0.0.1:9101/api/holmes-rule-mgmt/v1/rule";
}
@Override
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) {
}
return path;
}
+
private String readFile(String path) {
String finalPath = normalizePath(path);
File file = new File(finalPath);
}
return true;
}
+
+ private String getRequestPref() {
+ return CommonUtils.isHttpsEnabled() ? JerseyClient.PROTOCOL_HTTPS : JerseyClient.PROTOCOL_HTTP;
+ }
}