Hello,
 
All of our Jess rules, functions work excellent in 6.0a5.  When I tried upgrading to
6.0 FCS, I got a Jess exception which doesn't seem to affect activations and
rules firing.  Even though the rules fire in spite of this exception, I do need to understand
the cause of this problem in order to upgrade to 6.0FCS.
 
I have enclosed the running of the Jess shell with these rules as well as the
relevant functions, queries that are involved in this exception.
 
In the rule, entire-tier-is-up, I am using a test CE for a function to loop
through the multislot "ids" values of "contains" template.  Whenever there is
more than one item in the "ids" multislot, I see this problem. However
when there is just one item, this does not happen.
 
I also read through the mailing group, and gathered that maybe using test CE that
involves a run-query in a rule LHS is probably a bad idea and started rethinking on the
implementation of the same using rules.  But it is turning out to be quite a messy
alternative.
 
In general, when is it appropriate to use test CE that in turn
could trigger run-query?  How does this affect performance as opposed to using
rules?
 
Any help is greatly appreciated!
 
Thanks,
Akila Suresh.
 
================================================================================
Jess, the Java Expert System Shell
Copyright (C) 1998 E.J. Friedman Hill and the Sandia Corporation
Jess Version 6.0 12/7/2001
 
Jess> (batch config/rsntdomain/spe/spe.clp)
TRUE
Jess> (bind ?*debug-mode* TRUE)
TRUE
Jess> (watch all)
TRUE
Jess> (assert (enabled spe-component))
(assert (app (id 1) (resourceClass "node") (resourceInstanceId "1") (status "STA
TUS_UP")))
(assert (app (id 2) (resourceClass "node") (resourceInstanceId "2") (status "STA
TUS_UP")))
(assert (tier (id 10) (resourceClass "/tier") (resourceInstanceId "web") (status
 "STATUS_UNKNOWN")))
(assert (service (id 100) (resourceClass "/service")  (resourceInstanceId "tradi
ng") (status "STATUS_UNKNOWN")))
(assert (contains (containerId 10) (ids 1 2)))
(assert (containedBy (parentId 10) (childId 1)))
(assert (containedBy (parentId 10) (childId 2)))
(assert (contains (containerId 100) (ids 10)))
(assert (containedBy (parentId 100) (childId 10)))
 ==> f-2 (MAIN::enabled spe-component)
<Fact-2>
Jess>  ==> f-3 (MAIN::app (id 1) (status "STATUS_UP") (admin-status nil) (resour
ceInstanceId "1") (resourceClass "node") (statusRuleType 1))
<Fact-3>
Jess>  ==> f-4 (MAIN::app (id 2) (status "STATUS_UP") (admin-status nil) (resour
ceInstanceId "2") (resourceClass "node") (statusRuleType 1))
<Fact-4>
Jess>  ==> f-5 (MAIN::tier (id 10) (status "STATUS_UNKNOWN") (admin-status nil)
(resourceInstanceId "web") (resourceClass "/tier") (statusRuleType 1))
<Fact-5>
Jess>  ==> f-6 (MAIN::service (id 100) (status "STATUS_UNKNOWN") (admin-status n
il) (resourceInstanceId "trading") (resourceClass "/service") (statusRuleType 1)
)
<Fact-6>
Jess>  ==> f-7 (MAIN::contains (containerId 10) (ids 1 2))
<Fact-7>
Jess>  ==> f-8 (MAIN::containedBy (parentId 10) (childId 1))
<Fact-8>
Jess>  ==> f-9 (MAIN::containedBy (parentId 10) (childId 2))
<Fact-9>
Jess>  ==> f-10 (MAIN::contains (containerId 100) (ids 10))
<Fact-10>
Jess>  ==> f-11 (MAIN::containedBy (parentId 100) (childId 10))
 ==> f-12 (MAIN::__query-trigger-search-for-object 1)
 <== Focus MAIN
 <== f-12 (MAIN::__query-trigger-search-for-object 1)
 ==> f-13 (MAIN::__query-trigger-search-for-object 2)
 <== f-13 (MAIN::__query-trigger-search-for-object 2)
==> Activation: MAIN::entire-tier-is-up :  f-2, f-6, f-11, f-7, f-5, f-3, f-8,
Jess reported an error in routine ValueVector.get
        while executing rule LHS (Node2)
        while executing rule LHS (Node2)
        while executing rule LHS (Node2)
        while executing rule LHS (Node2)
        while executing rule LHS (Node2)
        while executing rule LHS (TECT)
        while executing (assert (MAIN::containedBy (parentId 100) (childId 10)))
.
  Message: Bad index 1 in call to get() on this vector:  (MAIN::__query-trigger-
search-for-object 2).
  Program text: ( assert ( containedBy ( parentId 100 ) ( childId 10 ) ) )  at l
ine 13.
        at jess.ValueVector.get(ValueVector.java:77)
        at jess.Fact.get(Fact.java:109)
        at jess.Test2Simple.doTest(Test2Simple.java:86)
        at jess.Node2.runTests(Node2.java:436)
        at jess.Node2.doRunTestsVaryRight(Node2.java:338)
        at jess.Node2.runTestsVaryRight(Node2.java:304)
        at jess.Node2.callNodeLeft(Node2.java:185)
        at jess.NodeTest.passAlong(NodeTest.java:213)
        at jess.Node2.doRunTestsVaryRight(Node2.java:345)
        at jess.Node2.doRunTestsVaryRight(Node2.java:320)
        at jess.Node2.runTestsVaryRight(Node2.java:307)
        at jess.Node2.callNodeLeft(Node2.java:185)
        at jess.NodeTest.passAlong(NodeTest.java:213)
        at jess.Node2.doRunTestsVaryRight(Node2.java:345)
        at jess.Node2.runTestsVaryRight(Node2.java:304)
        at jess.Node2.callNodeLeft(Node2.java:185)
        at jess.NodeTest.passAlong(NodeTest.java:213)
        at jess.Node2.doRunTestsVaryRight(Node2.java:345)
        at jess.Node2.runTestsVaryRight(Node2.java:304)
        at jess.Node2.callNodeLeft(Node2.java:185)
        at jess.NodeTest.passAlong(NodeTest.java:213)
        at jess.Node2.doRunTestsVaryLeft(Node2.java:418)
        at jess.Node2.runTestsVaryLeft(Node2.java:378)
        at jess.Node2.callNodeRight(Node2.java:240)
        at jess.Node1.passAlong(Node1.java:62)
        at jess.Node1TECT.callNodeRight(Node1TECT.java:43)
        at jess.Node1.passAlong(Node1.java:62)
        at jess.RootNode.callNodeRight(ReteCompiler.java:707)
        at jess.Rete.processToken(Rete.java:848)
        at jess.FactList._assert(FactList.java:181)
        at jess.FactList.assertFact(FactList.java:143)
        at jess.Rete.assertFact(Rete.java:308)
        at jess.Assert.call(Funcall.java:312)
        at jess.FunctionHolder.call(FunctionHolder.java:37)
        at jess.Funcall.execute(Funcall.java:270)
        at jess.Jesp.parseAndExecuteFuncall(Jesp.java:1596)
        at jess.Jesp.parseSexp(Jesp.java:183)
        at jess.Jesp.parse(Jesp.java:62)
        at jess.Main.execute(Main.java:123)
        at jess.Main.main(Main.java:23)
Jess> (facts)
f-0   (MAIN::initial-fact)
f-1   (MAIN::utcTime (cTime 1.019085204E9))
f-2   (MAIN::enabled spe-component)
f-3   (MAIN::app (id 1) (status "STATUS_UP") (admin-status nil) (resourceInstanc
eId "1") (resourceClass "node") (statusRuleType 1))
f-4   (MAIN::app (id 2) (status "STATUS_UP") (admin-status nil) (resourceInstanc
eId "2") (resourceClass "node") (statusRuleType 1))
f-5   (MAIN::tier (id 10) (status "STATUS_UNKNOWN") (admin-status nil) (resource
InstanceId "web") (resourceClass "/tier") (statusRuleType 1))
f-6   (MAIN::service (id 100) (status "STATUS_UNKNOWN") (admin-status nil) (reso
urceInstanceId "trading") (resourceClass "/service") (statusRuleType 1))
f-7   (MAIN::contains (containerId 10) (ids 1 2))
f-8   (MAIN::containedBy (parentId 10) (childId 1))
f-9   (MAIN::containedBy (parentId 10) (childId 2))
f-10   (MAIN::contains (containerId 100) (ids 10))
f-11   (MAIN::containedBy (parentId 100) (childId 10))
For a total of 12 facts.
Jess> (run)
FIRE 1 MAIN::entire-tier-is-up f-2, f-6, f-11, f-7, f-5, f-3, f-8,
TIER: 10 is up.
1
Jess>
======================================================================================
 
(deftemplate contains (slot containerId) (multislot ids))
(deftemplate containedBy (slot parentId) (slot childId))
 

(defrule entire-tier-is-up
 
  (service (id ?serviceId))
 
  (containedBy (parentId ?serviceId) (childId ?tierId))
 
  ?c <- (contains (containerId ?tierId))
 
  ?tier <- (tier (id ?tierId) (resourceInstanceId ?tierResId) (status ?tierStatus&:(neq "STATUS_UP" ?tierStatus)))
 
  ?elementUp <- (app (id ?instanceId) (status "STATUS_UP"))
 
  (containedBy (parentId ?tierId) (childId ?instanceId))
 
  (test (is-up ?c))
 
  =>
 
  (modify ?tier (status "STATUS_UP"))
)
 
; Returns TRUE if all of the children of this container are up
(deffunction is-up (?containerId)
 (bind ?idList (fact-slot-value ?containerId ids))
 
        (if (= (length$ ?idList) 0)
 then
 (return FALSE))
 
 (foreach ?n ?idList
  (bind ?returnValue (is-object-status ?n "STATUS_UP"))
  (if (eq ?returnValue FALSE)
  then
   (return FALSE))
 )
 (return TRUE)
)
 
; Returns TRUE if the status of this object equals ?status
(deffunction is-object-status (?objectId ?status)
 (bind ?objects (run-query search-for-object ?objectId))
 (bind ?o nil)
 (while (?objects hasNext) do
  (bind ?o (call ?objects next)))
 (if (neq ?o nil)
   then
      (bind ?actualObject (call ?o fact 1)) ;Get the object from the token
  (if (eq (fact-slot-value ?actualObject status) ?status)
    then
   (return TRUE)
    else
   (return FALSE))
   else
  ; (printout t "object: " ?objectId " cannot be found." crlf)
  (return FALSE)
 )
)
 
; Returns a list of tokens that contain objects with the correct id
(defquery search-for-object
    "Finds managed-object facts with a specified id"
    (declare (variables ?X))
    (unique (managed-object (id ?X))))
 
====================================================================================

Reply via email to