I am using IBM's ILOG 7.1 via Java (aka JRules). I need to debug some pre-existing functionality, where there is a set of rules being executed. Only some of the rules that should be executed are actually in the output of my trace. So I'm left wondering:
- Are the rules not actually getting executed?
- Are the rules simply not getting outputted as part of the trace?
I am not sure.
The Java code that I have to execute and log the traced rules is as follows:
public RulesDTO executeRules(RulesDTO rulesDTO) {
try {
String sessionId = rulesDTO.getSessionId();
String clientIp = rulesDTO.getClientIp();
LOG.info("Starting to execute rules.");
String ruleSetName = rulesDTO.getRuleSetName();
IlrSessionRequest request = this.rulesSessionProvider
.createRequest(ruleSetName);
Map<String, Object> parNameToObjectMap = new HashMap<String, Object>();
parNameToObjectMap.put("params", rulesDTO);
parNameToObjectMap.put("timeOut",
getEngineExecutionTimeout());
request.setInputParameters(parNameToObjectMap);
boolean isTraceEnabled = true;
// Enable trace to retrieve info on executed rules
request.setTraceEnabled(isTraceEnabled);
// get all traces
request.getTraceFilter().setInfoAllFilters(isTraceEnabled);
IlrSessionResponse response = null;
try {
// calls ILOG engine, itself, to execute rules
response = executeRulesRequest(request, ruleSetName);
}
catch (TimeoutException te) {
LOG.error(String.format("Rules %s timed out [timeout=%d]",
ruleSetName, getEngineExecutionTimeout()));
throw te;
}
logRuleExecutions(rulesDTO.getID(), sessionId, response);
return rulesDTO;
}
catch (Throwable t) {
LOG.error("Rule set execution failed. ilogVersion=7.1", t);
throw new RulesException(
"Rule set execution failed. ilogVersion=7.1", t);
}
}
private void logRuleExecutions(
long searchId, String sessionId, IlrSessionResponse response) {
IlrExecutionTrace executionTrace = response.getRulesetExecutionTrace();
List<IlrExecutionEvent> executionEvents = executionTrace.getExecutionEvents();
// ExecutedRule is a custom class I have wrapping IlrExecutionEvent
List<ExecutedRule> executedRules = getRuleExecutions(executionEvents);
int numRulesExecuted = executedRules.size();
LOG.info("sessionId={}, SearchId={}, numRules={}",
new Object[] {sessionId, searchId, numRulesExecuted});
// loop over executedRules list and just log each one
logFilteredRules(executedRules, searchId, sessionId);
}
private List<ExecutedRule> getRuleExecutions(List<IlrExecutionEvent> executionEvents) {
List<ExecutedRule> executedRules = new LinkedList<ExecutedRule>();
for (IlrExecutionEvent event : executionEvents) {
if (event instanceof IlrRuleEvent) {
IlrRuleEvent ruleEvent = (IlrRuleEvent) event;
allRuleExecutions.add(convertToRuleExecution(ruleEvent));
}
else {
List<IlrExecutionEvent> subEvents = ((IlrTaskEvent) event).getSubExecutionEvents();
LOG.debug("Size of subEvents={}", subEvents.size());
List<ExecutedRule> executedSubRules = getRuleExecutions(subEvents);
executedRules.addAll(executedSubRules);
}
}
}
In addition to the fact only some of the rules appear to be getting invoked, it appears that only earlier rules are invoked, and not rules that ought to be executed after the initial rules. Any help would be greatly appreciated. Thanks. :-)