Bug 724294 (BRMS-239)

Summary: Issues with knowledge agent when using temporal constraints
Product: [JBoss] JBoss Enterprise BRMS Platform 5 Reporter: Jaroslaw Kijanowski <kijanowski>
Component: BRE (Expert, Fusion)Assignee: Nobody <nobody>
Status: VERIFIED --- QA Contact: Lukáš Petrovický <lpetrovi>
Severity: unspecified Docs Contact:
Priority: high    
Version: 5.0.1CC: atangrin, kverlaen, ldimaggi, lpetrovi, manstis, trikkola
Target Milestone: ---   
Target Release: future   
Hardware: Unspecified   
OS: Unspecified   
URL: http://jira.jboss.org/jira/browse/BRMS-239
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Using temporal constraints with the knowledge agent resulted in a java.lang.RuntimeException due to a missing domain on the class path. This happened when the facts were imported as a jar file, and it has been resolved by making sure the evaluator registry is populated during package deserialization.
Story Points: ---
Clone Of: Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Attachments:
Description Flags
repository_export.zip
none
CEP.java
none
Class demonstrating the problem
none
Binary package none

Description Jaroslaw Kijanowski 2009-10-26 17:45:21 UTC
securitylevel_name: Public

1. When I declare a fact as an event (in the advanced config):
declare TestModel
	@role(event)
	@timestamp(event_date)
	@expires(5m)
end

and try to use this package with the rule agent I end up with a null when getting a Fact Type:

	KnowledgeBaseImpl kb = (KnowledgeBaseImpl) kagent.getKnowledgeBase();
	FactType modelType = kb.getRuleBase().getFactType(path + ".TestModel");

modelType is null


2. When I use temporal constraints like this:
	$t1: TestModel( test == "2" ) from entry-point "ep"
	$t2: TestModel( test == "2", id != $t1.id, this after [0s,1m] $t1) from entry-point "ep"

and try to use this package with the rule agent I end up with following errors:
[2009:10:299 18:10:514:info] KnowledgAgent applying ChangeSet
[2009:10:299 18:10:518:debug] KnowledgeAgent subscribing to resource=[UrlResource path='http://10.16.93.36:8080/jboss-brms/org.drools.guvnor.Guvnor/package/withcep/LATEST']
[2009:10:299 18:10:518:debug] ResourceChangeNotification subscribing listener=org.drools.agent.impl.KnowledgeAgentImpl@ef5502 to resource=[UrlResource path='http://10.16.93.36:8080/jboss-brms/org.drools.guvnor.Guvnor/package/withcep/LATEST']
[2009:10:299 18:10:519:debug] ResourceChangeScanner subcribing notifier=org.drools.io.impl.ResourceChangeNotifierImpl@e2dae9 to resource=[UrlResource path='http://10.16.93.36:8080/jboss-brms/org.drools.guvnor.Guvnor/package/withcep/LATEST']
[2009:10:299 18:10:520:debug] KnowledgeAgent ChangeSet requires KnowledgeBuilder
[2009:10:299 18:10:520:debug] KnowledgeAgent rebuilding KnowledgeBase using ChangeSet
[2009:10:299 18:10:521:debug] KnowledgeAgent building resource=[UrlResource path='http://10.16.93.36:8080/jboss-brms/org.drools.guvnor.Guvnor/package/withcep/LATEST']
[2009:10:299 18:10:952:debug] ResourceChangeScanner attempt to scan 1 resources
[2009:10:299 18:10:338:exception]
java.lang.RuntimeException: KnowledgeAgent exception while trying to deserialize KnowledgeDefinitionsPackage  
	at org.drools.agent.impl.KnowledgeAgentImpl.rebuildResources(KnowledgeAgentImpl.java:418)
	at org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:120)
	at org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:109)
	at org.jboss.qa.guvnor.agent.JBRULES2278CEP.main(JBRULES2278CEP.java:76)
Caused by: java.lang.NullPointerException
	at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1820)
	at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1719)
	at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1305)
	at java.io.ObjectInputStream.readObject(ObjectInputStream.java:348)
	at org.drools.rule.DialectRuntimeRegistry.readExternal(DialectRuntimeRegistry.java:41)
	at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1755)
	at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1717)
	at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1305)
	at java.io.ObjectInputStream.readObject(ObjectInputStream.java:348)
	at org.drools.rule.Package.readExternal(Package.java:197)
	at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1755)
	at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1717)
	at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1305)
	at java.io.ObjectInputStream.readObject(ObjectInputStream.java:348)
	at org.drools.util.DroolsStreamUtils.streamIn(DroolsStreamUtils.java:189)
	at org.drools.util.DroolsStreamUtils.streamIn(DroolsStreamUtils.java:158)
	at org.drools.agent.impl.KnowledgeAgentImpl.rebuildResources(KnowledgeAgentImpl.java:408)
	... 3 more
[2009:10:299 18:10:344:info] KnowledgeAgent new KnowledgeBase now built and in use

Comment 1 Jaroslaw Kijanowski 2009-10-26 17:46:36 UTC
might be related

Comment 2 Jaroslaw Kijanowski 2009-10-26 17:46:36 UTC
Link: Added: This issue is related to JBRULES-2278


Comment 3 Jaroslaw Kijanowski 2009-10-26 17:54:04 UTC
#1 might go away if I use an uploaded model jar instead of a declared fact model, since now I end up with two 'declare' statements:
declare TestModel
	@role(event)
	@timestamp(event_date)
	@expires(5m)
end

declare TestModel
	id: Integer
	event_date: java.util.Date
	test: String
end

Will verify that...

Comment 4 Jaroslaw Kijanowski 2009-10-27 11:44:24 UTC
#1 goes away when I use a model jar. The package source contains only one 'declare' statement then. When I want to use a declarative model I end up with two 'declare' statements which is bad.

#2 is a bug, on the agent side I guess? I attach a repo zip to make it easier to reproduce.
It shows up when I use temporal constraints like 'this after [0s,1m] $t1'.
No issues with entry-points found.

Comment 5 Jaroslaw Kijanowski 2009-10-27 11:46:39 UTC
Attachment: Added: repository_export.zip
Attachment: Added: CEP.java


Comment 6 Dana Mison 2010-10-27 03:05:55 UTC
Release Notes Text: Added: test


Comment 7 Dana Mison 2010-10-27 03:13:23 UTC
Release Notes Text: Removed: test 


Comment 8 David Le Sage 2010-11-03 05:52:14 UTC
Release Notes Docs Status: Added: Not Yet Documented
Writer: Added: dlesage


Comment 9 Anne-Louise Tangring 2010-11-23 18:48:58 UTC
This is not a blocker for BRMS 5.1.0, moving to future.

Comment 10 Len DiMaggio 2011-09-13 17:53:10 UTC
QE should retest with 5.3 - if the bug is still present we should open a linked GUVNOR bug.

Comment 11 Tomas Schlosser 2011-09-16 07:31:02 UTC
I checked for the core cause of this bug and found out that the problem is missing domain on classpath. When you import you facts to Guvnor as a jar they are not included into resulting package. Therefore when trying to access the rules in Guvnor you have to have the necessary jar (or .class files) on classpath.
This gives us two options:
- document that when you import model as a jar you have to add it to the classpath of final application,
- try adding jars to the package and somehow add them to the classpath in runtime.
I haven't tested with Drools 5.3, but both BRMS-5.1.0.GA and BRMS-5.2.0.ER3 behave the same way.

Comment 12 Edson Tirelli 2011-09-19 14:33:33 UTC
#1 looks like a Guvnor problem. It should not be generating 2 incompatible declare statements. The engine merges compatible declare statements properly, but when it sees 2 declares for the same object type, one referencing a model in the classpath and the other generating a bean with fields, one declaring the type as an event and the other as a regular fact, it can't merge them automatically because the runtime semantics of them are completely different.

#2 works as designed. If the user has the domain model in a jar, it is his responsibility to deploy that jar into the runtime environment. We can't ship it with the package as we risk classpath clashes. This should be just documented as so, as suggested by Tomas.

Can someone in the Guvnor team take this over to fix #1, plz?

Comment 13 Lukáš Petrovický 2011-09-19 14:36:57 UTC
(In reply to comment #12)
> #1 looks like a Guvnor problem. It should not be generating 2 incompatible
> declare statements. The engine merges compatible declare statements properly,
> but when it sees 2 declares for the same object type, one referencing a model
> in the classpath and the other generating a bean with fields, one declaring the
> type as an event and the other as a regular fact, it can't merge them
> automatically because the runtime semantics of them are completely different.

> Can someone in the Guvnor team take this over to fix #1, plz?

Jervis, would someone from the Guvnor team please take a look at this? Thanks!

Comment 14 Edson Tirelli 2012-03-28 18:01:19 UTC
Michael, can you or someone from Guvnor take a look at this one, please? Thank you.

Comment 15 manstis 2012-03-29 20:24:21 UTC
Created attachment 573789 [details]
Class demonstrating the problem

Comment 16 manstis 2012-03-29 20:25:00 UTC
Created attachment 573790 [details]
Binary package

Comment 17 manstis 2012-03-29 20:30:17 UTC
This is a problem deserializing packages. Attachment CEP2.java and withcep.pkg are files that replicate the problem without needing Guvnor. There is a specific set of requirements for the deserialization to fail:-

(1) KnowledgeBuilderFactory.newKnowledgeBuilder() must not have been called in the JVM otherwise the test passes. 

(2) A KnowledgeBaseConfiguration containing the option EventProcessingOption.STREAM has to be provided otherwise the test passes.

Edson, I could not add a new test to CepEspTest or a new class entirely as all of these tests call KnowledgeBuilderFactory.newKnowledgeBuilder() that causes the Operator.CACHE to be populated correctly by EvaluatorRegistry and hence the problem not to occur. The class CEP2 contains more information as to what the problem is.

Comment 19 lcarlon 2012-06-08 00:22:38 UTC
    Technical note added. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    New Contents:
Using temporal constraints with the knowledge agent results in a java.lang.RuntimeException due to a missing domain on the class path. This happens when the facts are imported as a jar file, and the workaround is to copy the jar file to the classpath of the final application.

Comment 21 Edson Tirelli 2012-08-28 21:00:51 UTC
I "fixed" this problem by making sure the evaluator registry is populated during package deserialization. This fix is specific to 5.3.x version as in versions 5.4.x and newer, the KnowledgeAgent uses the proper API for deserialization.

Thanks for all the information on this bug and specially to Michael for the detailed analysis on the causes for this problem.

Comment 22 Tomas Schlosser 2012-09-26 07:57:18 UTC
Verified in BRMS-5.3.1-ER1