Bug 732085 - KnowledgeAgent cannot build KnowledgeBase after ChangeSet from a URL Resource had been applied
Summary: KnowledgeAgent cannot build KnowledgeBase after ChangeSet from a URL Resource...
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: JBoss Enterprise BRMS Platform 5
Classification: JBoss
Component: BRE (Expert, Fusion)
Version: BRMS 5.2.0.GA
Hardware: Unspecified
OS: Unspecified
unspecified
high
Target Milestone: ---
: BRMS 5.3.0.GA
Assignee: Geoffrey De Smet
QA Contact: Jiri Svitak
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2011-08-19 18:09 UTC by Jiri Locker
Modified: 2015-06-02 01:34 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
An error occurred where the KnowledgeAgent could not build the KnowledgeBase after applying a URL resource changeset and throws RuntimeException. This was caused by fixes to previous issues and was resolved by creating an implementation class (ReaderResource) to bypass the previous fixes.
Clone Of:
Environment:
Last Closed: 2014-09-15 11:22:46 UTC
Type: ---


Attachments (Terms of Use)
BrmsClient.java (4.37 KB, text/plain)
2011-08-19 18:09 UTC, Jiri Locker
no flags Details
output.log (8.64 KB, text/plain)
2011-08-19 18:15 UTC, Jiri Locker
no flags Details


Links
System ID Priority Status Summary Last Updated
JBoss Issue Tracker JBRULES-3282 Major Closed ResourceChangeScanner does not call listener.exception(throwable) if the scan method throws a RuntimeException or Error 2018-02-01 09:28:09 UTC
JBoss Issue Tracker JBRULES-3358 Major Closed Fix reload of KnowledgeAgent resources: CSV, XLS, BPMN, DRF, PKG 2018-02-01 09:28:08 UTC

Description Jiri Locker 2011-08-19 18:09:42 UTC
Created attachment 519083 [details]
BrmsClient.java

Description of problem:

From some reason, after applying a URL Resource ChangeSet, KnowledgeAgent starts to map 'null' ReaderResources.

> ka.applyChangeSet(ResourceFactory.newUrlResource(url));

> [2011-08-19 19:33:40,219:debug] KnowledgeAgent mapping resource=[UrlResource path='http://localhost:8080/jboss-brms/org.drools.guvnor.Guvnor/package/mortgages/LATEST'] to KnowledgeDefinition=[Rule name=RegexDslRule, agendaGroup=MAIN, salience=0, no-loop=false]
> [2011-08-19 19:33:40,219:debug] KnowledgeAgent mapping resource=[ReaderResource resource=null encoding='null'] to KnowledgeDefinition=org.drools.rule.TypeDeclaration@4cc5aa00

Any subsequent applyChangeset() causes this exception:

> Exception in thread "main" java.lang.RuntimeException: Unknown resource type: null
>       at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:638)
>       at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:28)
>       at org.drools.agent.impl.KnowledgeAgentImpl.createPackageFromResource(KnowledgeAgentImpl.java:712)
>       at org.drools.agent.impl.KnowledgeAgentImpl.addResourcesToKnowledgeBase(KnowledgeAgentImpl.java:1002)
>       at org.drools.agent.impl.KnowledgeAgentImpl.rebuildResources(KnowledgeAgentImpl.java:785)
>       at org.drools.agent.impl.KnowledgeAgentImpl.buildKnowledgeBase(KnowledgeAgentImpl.java:657)
>       at org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:190)
>       at org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:169)

Version-Release number of selected component (if applicable):
This bug has been introduced somewhere between ER1 and ER2 releases.


Possible workaround:
set drools.agent.newInstance=false


How reproducible:
always


Steps to Reproduce:
see attached sample client code

  
Actual results:
After applying URL Resource ChangeSet, KnowledgeAgent maps 'null' ReaderResources. This causes NPE when KA attempts to build a new KB forced by a subsequent applyChangeSet() call (now with any Resource type).

Expected results:
After applying URL Resource ChangeSet, it should be possible to apply other ChangeSets without causing an exception, while 'drools.agent.newInstance' is set to 'true' (which is default)

Additional info:
See attachments for a sample client code and it's output including the exception call stack.

Comment 1 Jiri Locker 2011-08-19 18:15:13 UTC
Created attachment 519085 [details]
output.log

Comment 2 Jiri Locker 2011-08-19 18:20:13 UTC
> [2011-08-19 19:33:40,219:debug] KnowledgeAgent mapping resource=[ReaderResource resource=null encoding='null'] to KnowledgeDefinition=org.drools.rule.TypeDeclaration@4cc5aa00

Ok, now that I can see this line in a better light, I'm thinking it might not be related to the URL Resource, but probably to the content of the rules package (type declarations). Might be related to https://issues.jboss.org/browse/JBRULES-2962?

Comment 5 Lukáš Petrovický 2012-01-11 08:56:08 UTC
(In reply to comment #4)
> Is this is a duplicate of these?

I wouldn't say it's a duplicate - maybe just a dependency. Once this bug is fixed, we'll have to verify that the other functionality (XLS, CSV...) works as well.

Comment 6 JBoss JIRA Server 2012-01-16 21:56:45 UTC
Edson Tirelli <ed.tirelli@gmail.com> updated the status of jira JBRULES-3282 to Closed

Comment 7 Edson Tirelli 2012-01-23 21:42:13 UTC
After fixing the related tickets, I created a test case for this, but was unable to reproduce the problem. My understanding is that previous fixes also fixed this ticket.

The test case was committed to both to 5.3.x branch and master (5.4.Beta2) branch:

https://github.com/droolsjbpm/drools/commit/6b24680265bb565e80bf7efa3d4c6bb7c5b793db

https://github.com/droolsjbpm/drools/commit/99bad018b97a417b63dbd13372f8d920b1912021

If you still see any problem, please modify the test case to raise the issue and send a pull request.

Thank you.

Comment 8 JBoss JIRA Server 2012-01-23 21:50:34 UTC
Edson Tirelli <ed.tirelli@gmail.com> updated the status of jira JBRULES-3358 to Resolved

Comment 9 JBoss JIRA Server 2012-01-23 21:50:38 UTC
Edson Tirelli <ed.tirelli@gmail.com> updated the status of jira JBRULES-3358 to Closed

Comment 10 Ryan Zhang 2012-02-15 09:12:20 UTC
Please verify the issue on 5.3 ER4.

Comment 11 Jiri Svitak 2012-02-27 13:28:44 UTC
Not fixed in BRMS 5.3 ER4. I was able to reproduce this issue with the case above provided by Jiri Locker. I have looked at your own test cases, but they work just with PKG files on disk. This one requires running Guvnor (corresponding version) with created and builded sample 'mortgages' package.

How to reproduce:
1. Download BRMS 5.3 ER4 engine binaries and Guvnor from 5.3 ER4 (the same versions are necessary for package serialization compatibility). You can try also your master version (Guvnor and engine have to be compatible), but I cannot guarantee success of seeing the error.
2. Enable (uncomment) user admin in jboss-as/server/default/conf/props/brms-users.properties
3. Start web server with Guvnor.
4. Login and confirm creation of sample packages.
5. Go to mortgages package and build it.
6. Run attached java class above. First time knowledge agent will load mortgages package correctly. Second try will fail with an exception.

I have not tried this with PKG files on disk, but just with real running Guvnor and it fails. This is not duplicate issue of https://bugzilla.redhat.com/show_bug.cgi?id=733008. As described above this should not be difficult to reproduce. If you require adding to your test suite, then tell me where to put tests which require running Guvnor.

Comment 12 Jiri Svitak 2012-02-27 13:32:27 UTC
And one last thing - your test case for PKG file uses scanning service. So use the java class BrmsClient added by Jiri Locker which doesn't use scanning service. It's possible that you've tested different scenario.

Comment 13 Jiri Svitak 2012-02-27 18:38:07 UTC
I have found an error in test case above. Method kagent.applyChangeset() is used twice, before each kagent.getKnowledgeBase(). I have tried to modify test case to use kagent.applyChangeset() just once in the start and then kagent.getKnowledgeBase() twice. It works this way. But test case throws quite misleading exception, so I think that user should be notified, that he already has changeset registered and that it's not necessary to apply it again. Otherwise he may be easily confused.

Comment 14 Jiri Locker 2012-02-28 11:20:31 UTC
Sure, I admit that applying the same change set more than once does not make much sense. But if that happens, kagent probably shouldn't crash like this

> Exception in thread "main" java.lang.RuntimeException: Unknown resource type: null

I can think of two possible solutions:

1) throw IllegalStateException explaining that applying the same change set more than once is illegal

2) ignore the attempt and just log a warning message

I would prefer solution #2.

Comment 15 Geoffrey De Smet 2012-04-12 13:23:58 UTC
I am building an arquillian test to reproduce this under
  org.drools.guvnor.server.files.PackageDeploymentServletIntegrationTest#testScenariosAndChangeSet

Comment 16 Geoffrey De Smet 2012-04-12 14:46:31 UTC
Master and 5.4 are being blocked by another, earlier issue:
  https://issues.jboss.org/browse/JBRULES-3457

Comment 17 Geoffrey De Smet 2012-04-12 16:32:22 UTC
The NPE is caused because an old and deep HACK in
  KnowledgeAgentImpl.autoBuildResourceMapping()
which adds null Resources
and the KnowledgeAgentImpl#rebuildResources method cannot cope with that.

I am not convinced that the NPE wouldn't occur too if we added different resources (that needs to be tested). The hack was added for JBRULES-2082.

Removing the hack didn't work reliably, so I had no choice to add a workaround in KnowledgeAgentImpl#rebuildResources to cope with the hack:
  https://github.com/droolsjbpm/drools/commit/3a197f70f664b4d984b4e595b125315ab7761bbc

Applied on master, 5.4 and 5.3.

Comment 18 Ryan Zhang 2012-04-23 07:39:22 UTC
Update status to ON_QA. Please verify them against ER6.

Comment 19 Jiri Svitak 2012-04-25 13:45:16 UTC
Verified in BRMS 5.3.0 ER6.

Comment 23 lcarlon 2012-06-05 06:09:11 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:
An error occurred where the KnowledgeAgent could not build the KnowledgeBase after applying a URL resource changeset and throws RuntimeException. This was caused by fixes to previous issues and was resolved by creating an implementation class (ReaderResource) to bypass the previous fixes.

Comment 24 lcarlon 2012-06-05 06:11:25 UTC
Hi Geoffrey,

Could you take a look at the release note for this one and let me know if anything needs to be changed.

Thanks
Lee

Comment 25 Geoffrey De Smet 2014-09-15 11:22:46 UTC
This issue is out of date.


Note You need to log in before you can comment on or make changes to this bug.