Hi Glenn,<br><br>I'm going to start with the looping issue. The quick answer is use lock-on-active instead of no-loop.<br>This is the important bit of code as far as I'm concerned:<br><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> <br>
$tholdBreach
: Parameter.Threshold(windowSize == 15, </span><span style="font-size: 10pt; font-family: "Courier New";"></span>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> threshold
>= $averageUpdateValue) </span><b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0);">from</span></b><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> $param.thresholds</span><span style="font-size: 10pt; font-family: "Courier New";"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> $firedAlert
: AlertInformation(name == $<a href="http://param.name/" target="_blank">param.name</a>,
</span><span style="font-size: 10pt;"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> severity
!= $tholdBreach.severity)</span></p>So, the first time you run through this code you have data like the following:<br><br>Thresholds [ Threshold1{severity = MINOR, ...}, Threshold2{severity = CRITICAL, ...} ]<br><br>AlertInformation{severity = null, ...}<br>
<br>Execution 1)<br> Iteration 1 - AlertInformation.severity != Threshold1.severity<br> Result: Set AlertInformation.severity to MINOR<br><br>Execution 2)<br>Iteration 1 - AlertInformation.severity == Threshold1.severity // do nothing<br>
Iteration 2 - AlertInformation.severity != Threshold2.severity<br>
Result: Set AlertInformation.severity to CRITICAL<br>
<br>This pattern repeats giving you your infinite loop. Does that make sense? You have a list of items you are using for your comparison. The rule will only stop firing when the severity value in AlertInformation matches the severity values on every item in the list. Which can never happen. Lock-on-active will stop the rule from being reactivated as a result of its own execution. This should help but is probably not the best solution. You should look at tightening up your rules some more.<br>
<br>Your other issue, if I understand you correctly, is that you are having trouble with the order the of the list and don't want to have to sort it before adjudication, right?<br><br>If so, maybe you could use the 'not' keyword as follows:<br>
<br><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> $tholdBreach
: Parameter.Threshold(windowSize == 15, </span><span style="font-size: 10pt; font-family: "Courier New";"></span>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> threshold
>= $averageUpdateValue) </span><b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0);">from</span></b><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> $param.thresholds</span><span style="font-size: 10pt; font-family: "Courier New";"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> $firedAlert
: AlertInformation(name == $<a href="http://param.name/" target="_blank">param.name</a>,
</span><span style="font-size: 10pt;"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> severity
!= $tholdBreach.severity)</span></p> not Parameter.Threshold(windowSize == 15, threshold < $tholdBReach, threshold >= $averageUpdateValue) from <br> $param.thresholds<br>
<br>Here, I am checking to ensure there is not another Threshold with a lower threshold than the one in $tholdBreach that still satisfies our other criteria.<br><br>There's probably an easier way, but hopefully that will give you some ideas!<br>
<br>Hope it helps,<br>Enda<br><br><div class="gmail_quote">2010/3/10 Glenn Macgregor <span dir="ltr"><<a href="mailto:gmacgregor@pocketkings.ie">gmacgregor@pocketkings.ie</a>></span><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div link="blue" vlink="purple" lang="EN-IE">
<div>
<p class="MsoNormal">Hi All,</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">I am in the process of creating some rules for a POC I am
doing using drools, having some issues understanding why I have an infinite
loop in a rule.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Rule in question:</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal" style=""><b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0);">rule</span></b><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span><span style="font-size: 10pt; font-family: "Courier New"; color: green;">"Check Parameter Threshold
Update Breach"</span><span style="font-size: 10pt; font-family: "Courier New";"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span><b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0);">no-loop</span></b><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span><b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0);">true</span></b><span style="font-size: 10pt; font-family: "Courier New";"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span><b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0);">when</span></b><span style="font-size: 10pt; font-family: "Courier New";"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> ParameterUpdateEvent($name
: name)</span><span style="font-size: 10pt; font-family: "Courier New";"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span><b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0);">from</span></b><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> entry-point </span><span style="font-size: 10pt; font-family: "Courier New"; color: green;">"ParamUpdateStream"</span><span style="font-size: 10pt; font-family: "Courier New";"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> $param
: Parameter(name == $name)</span><span style="font-size: 10pt; font-family: "Courier New";"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> Number($averageUpdateValue
: doubleValue) </span><span style="font-size: 10pt; font-family: "Courier New";"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span><b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0);">from</span></b><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span><b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0);">accumulate</span></b><span style="font-size: 10pt; font-family: "Courier New"; color: black;">(ParameterUpdateEvent(name
== $<a href="http://param.name" target="_blank">param.name</a>, $value : value)</span><span style="font-size: 10pt; font-family: "Courier New";"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> over
window:time(15m)</span><span style="font-size: 10pt; font-family: "Courier New";"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span><b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0);">from</span></b><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> entry-point </span><span style="font-size: 10pt; font-family: "Courier New"; color: green;">"ParamUpdateStream"</span><span style="font-size: 10pt; font-family: "Courier New"; color: black;">,
average($value))</span><span style="font-size: 10pt; font-family: "Courier New";"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> $tholdBreach
: Parameter.Threshold(windowSize == 15, </span><span style="font-size: 10pt; font-family: "Courier New";"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> threshold
>= $averageUpdateValue) </span><b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0);">from</span></b><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> $param.thresholds</span><span style="font-size: 10pt; font-family: "Courier New";"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> $firedAlert
: AlertInformation(name == $<a href="http://param.name" target="_blank">param.name</a>, </span><span style="font-size: 10pt; font-family: "Courier New";"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> severity
!= $tholdBreach.severity)</span><span style="font-size: 10pt; font-family: "Courier New";"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span><b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0);">then</span></b><span style="font-size: 10pt; font-family: "Courier New";"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> System.out.println(</span><span style="font-size: 10pt; font-family: "Courier New"; color: green;">"Updating
alert from '"</span><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> + $firedAlert.getSeverity() +</span><span style="font-size: 10pt; font-family: "Courier New";"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span><span style="font-size: 10pt; font-family: "Courier New"; color: green;">"' to
'"</span><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> + $tholdBreach.getSeverity() + </span><span style="font-size: 10pt; font-family: "Courier New";"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span><span style="font-size: 10pt; font-family: "Courier New"; color: green;">"' alarm:
Average update value for "</span><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> + </span><span style="font-size: 10pt; font-family: "Courier New";"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> $param.getName()
+ </span><span style="font-size: 10pt; font-family: "Courier New"; color: green;">"
= "</span><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> + $averageUpdateValue);</span><span style="font-size: 10pt; font-family: "Courier New";"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> $firedAlert.setSeverity($tholdBreach.getSeverity());</span><span style="font-size: 10pt; font-family: "Courier New";"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span><b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0);">update</span></b><span style="font-size: 10pt; font-family: "Courier New"; color: black;">($firedAlert);</span><span style="font-size: 10pt; font-family: "Courier New";"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span><span style="font-size: 10pt; font-family: "Courier New"; color: olive;">//insert(new
AlertInformation($param.getName(), $tholdBreach.getSeverity()));</span><span style="font-size: 10pt; font-family: "Courier New";"></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span><span style="font-size: 10pt; font-family: "Courier New"; color: olive;">//modify($firedAlert);</span><span style="font-size: 10pt; font-family: "Courier New";"></span></p>
<p class="MsoNormal"><b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0);">end</span></b></p>
<p class="MsoNormal"><b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(150, 0, 0);"> </span></b></p>
<p class="MsoNormal">I understand what is happening up to the $tholdBreach :
Parameter.Threshold line. Each Parameter can have a list of thresholds and what
I want this line to do is pick the correct threshold if any are breached. For
instance Param1 has 2 thresholds: MINOR and CRITICAL, the MINOR threshold should
fire if averageUpdateValue is >= 50, the CRITICAL threshold should fire if
averageUpdateValue is >= 40. The first problem I need to solve (in a better
way) is getting the correct threshold out of this, the way I do it now is but
putting the MINOR threshold in the list before the CRITICAL one. This means
that it will be checked first from the line in question. This, to me, is not a
good solution. Is there a more deterministic way to do this, I was thinking of
somehow using the difference between the threshold and the averageUpdateValue
to get the right now but I don’t see how that can work from a rule stand
point.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">The other question I have is this rule loops infinitely when
the averageUpdateValue is below 40 (CRITICAL threshold) between a MINOR
alarm and a CRITICAL alarm and I don’t see why or how because
tholdBreach should always be the CRITICAL alarm and the rule would stop
on the next line, but it is alernatly returning CRITICAL then MINOR which
is confusing. To confuse this even more when I comment out the
update($firedAlert) and replace that with a retract($firedAlert) and insert(new
…) it does not loop.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Any ideas would be great.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Thanks</p>
<p class="MsoNormal"> </p><font color="#888888">
<p class="MsoNormal"> Glenn</p>
</font></div>
</div>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Enda J Diggins<br>