use of org.opennms.netmgt.correlation.drools.config.RuleSet in project opennms by OpenNMS.
the class DroolsCorrelationEngine method reloadConfig.
@Override
public void reloadConfig() {
EventBuilder ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_SUCCESSFUL_UEI, getName());
ebldr.addParam(EventConstants.PARM_DAEMON_NAME, "DroolsCorrelationEngine-" + m_name);
try {
LOG.info("Reloading configuration for engine {}", m_name);
EngineConfiguration cfg = JaxbUtils.unmarshal(EngineConfiguration.class, m_configPath);
Optional<RuleSet> opt = cfg.getRuleSetCollection().stream().filter(rs -> rs.getName().equals(getName())).findFirst();
if (opt.isPresent()) {
marshallStateToDisk(true);
opt.get().updateEngine(this);
initialize();
} else {
ebldr.setUei(EventConstants.RELOAD_DAEMON_CONFIG_FAILED_UEI);
ebldr.addParam(EventConstants.PARM_REASON, "RuleSet not found on " + m_configPath);
}
} catch (Exception e) {
ebldr.setUei(EventConstants.RELOAD_DAEMON_CONFIG_FAILED_UEI);
ebldr.addParam(EventConstants.PARM_REASON, e.getMessage());
} finally {
sendEvent(ebldr.getEvent());
}
}
use of org.opennms.netmgt.correlation.drools.config.RuleSet in project opennms by OpenNMS.
the class DroolsCorrelationEngineBuilder method doAddAndRemoveEngines.
// This handles only the addition of new engines and the removal of existing engines.
// For updating existing engines, use the appropriate value for the daemonName
private void doAddAndRemoveEngines() {
LOG.info("Analyzing directory {} to add/remove drools engines...", m_configDirectory);
EventBuilder ebldr = null;
try {
final PluginConfiguration[] newPlugins = locatePluginConfigurations();
final List<RuleSet> newEngines = Arrays.stream(newPlugins).peek(PluginConfiguration::readConfig).flatMap(pc -> pc.getRuleSets().stream()).collect(Collectors.toList());
final List<RuleSet> currentEngines = Arrays.stream(m_pluginConfigurations).flatMap(pc -> pc.getRuleSets().stream()).collect(Collectors.toList());
LOG.debug("Current engines: {}", currentEngines);
LOG.debug("New engines: {}", newEngines);
// Find old engines to remove
currentEngines.stream().filter(en -> !newEngines.contains(en)).forEach(en -> {
LOG.warn("Deleting engine {}", en);
m_correlator.removeCorrelationEngine(en.getName());
});
// Find new engines to add
newEngines.stream().filter(en -> !currentEngines.contains(en)).forEach(en -> {
LOG.warn("Adding engine {}", en);
addEngine(newPlugins, en);
});
m_pluginConfigurations = newPlugins;
ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_SUCCESSFUL_UEI, getName());
ebldr.addParam(EventConstants.PARM_DAEMON_NAME, getName());
} catch (Exception ex) {
LOG.error("Cannot process reloadDaemonConfig", ex);
ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_FAILED_UEI, getName());
ebldr.addParam(EventConstants.PARM_DAEMON_NAME, getName());
ebldr.addParam(EventConstants.PARM_REASON, ex.getMessage());
} finally {
if (ebldr != null)
try {
m_eventIpcManager.send(ebldr.getEvent());
} catch (EventProxyException epx) {
LOG.error("Can't send reloadDaemonConfig status event", epx);
}
}
}
use of org.opennms.netmgt.correlation.drools.config.RuleSet in project opennms by OpenNMS.
the class DroolsCorrelationEngineBuilder method onEvent.
@Override
public void onEvent(Event e) {
if (e.getUei().equals(EventConstants.RELOAD_DAEMON_CONFIG_UEI)) {
final String daemonName = getDaemonNameFromReloadDaemonEvent(e);
if (daemonName != null && daemonName.equals(getName())) {
doAddAndRemoveEngines();
return;
}
}
if (e.getUei().equals(EventConstants.RELOAD_DAEMON_CONFIG_FAILED_UEI)) {
final String daemonName = getDaemonNameFromReloadDaemonEvent(e);
Matcher m = Pattern.compile(getName() + "-(.+)$").matcher(daemonName);
if (m.find()) {
final String engineName = m.group(1);
LOG.warn("An error was detected while reloading engine {}, this engine will be removed. Fix the error and try again.", engineName);
m_correlator.removeCorrelationEngine(engineName);
for (PluginConfiguration p : m_pluginConfigurations) {
final RuleSet set = p.getRuleSets().stream().filter(r -> r.getName().equals(engineName)).findFirst().orElse(null);
if (set != null) {
p.getRuleSets().remove(set);
}
}
}
}
}
Aggregations