[JBoss JIRA] (JBRULES-3669) Bug when using two knowledge bases and one declarative model between
by Jackson Cunha (JIRA)
Jackson Cunha created JBRULES-3669:
--------------------------------------
Summary: Bug when using two knowledge bases and one declarative model between
Key: JBRULES-3669
URL: https://issues.jboss.org/browse/JBRULES-3669
Project: Drools
Issue Type: Bug
Security Level: Public (Everyone can see)
Components: drools-compiler
Affects Versions: 5.4.0.Final
Reporter: Jackson Cunha
Assignee: Mark Proctor
Hello conrads.
To explain what I need, the problem that I found and the solution that I planning to use, I will firstly describe my cenario.
Cenario
In my cenario, I have a declarative model and rules of different groups. I need put each rules group in a different knowledge base and all of it will share the same declarative model.
In a time, I will create a fact using fact types defined in a knowledge base that I will call as kbaseModel. This knowledge base will have only the declarative model and no rules.
All facts created will be used in other knowledge base, called kbaseRules. All kbaseRules have only rules and no declarative model, because model was defined in kbaseModel.
I could have many kbaseRules but exists only one kbaseModel.
Using the Drools API, teoricaly, I could implement my cenario using the following code:
//DRL for resourceModel
declare MyEntity
name : String
end
//DRL for resourceRules
rule "Simple Rule"
when
$entity: MyEntity()
then
System.out.println($entity)
end
Resource resourceModel = ... //Resource with only the declarative model and no rules
Resource resourceRules = ... //Resource with only rules and no declarative model
KnowledgeBuilder kbuilderModel = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilderModel add(resourceModel, ResourceType.DRL);
KnowledgeBase kbaseModel = kbuilderModel.newKnowledgeBase();
KnowledgeBuilder kbuilderRules = KnowledgeBuilderFactory.newKnowledgeBuilder(kbaseModel);
kbuilderRules.add(resourceRules, ResourceType.DRL);
KnowledgeBase kbaseRules = KnowledgeBaseFactory.newKnowledgeBase();
kbaseRules.addKnowledgePackages(kbuilderRules.getKnowledgePackages());
FactType factType = kbaseModel.getFactType("mymodel", "MyEntity");
Object myEntity = factType.newInstance();
factType.set(myEntity, "name", "Jackson Cunha Cassimiro");
StatelessKnowledgeSession session = kbaseRules.newStatelessKnowledgeSession();
session.execute(myEntity);
This code should work, but when I try to run I get this stacktrace:
java.lang.ClassNotFoundException: Unable to load class: mymodel.MyEntity
at org.drools.util.CompositeClassLoader.loadClass(CompositeClassLoader.java:92)
at org.drools.common.AbstractRuleBase.registerAndLoadTypeDefinition(AbstractRuleBase.java:649)
at org.drools.common.AbstractRuleBase.addPackages(AbstractRuleBase.java:553)
at org.drools.reteoo.ReteooRuleBase.addPackages(ReteooRuleBase.java:472)
at org.drools.impl.KnowledgeBaseImpl.addKnowledgePackages(KnowledgeBaseImpl.java:150)
at app.UsingDeclares.main(UsingDeclares.java:79)
Exception in thread "main" org.drools.RuntimeDroolsException: unable to resolve Type Declaration class 'mymodel.MyEntity'
at org.drools.common.AbstractRuleBase.addPackages(AbstractRuleBase.java:582)
at org.drools.reteoo.ReteooRuleBase.addPackages(ReteooRuleBase.java:472)
at org.drools.impl.KnowledgeBaseImpl.addKnowledgePackages(KnowledgeBaseImpl.java:150)
at app.UsingDeclares.main(UsingDeclares.java:79)
It happens because Drools can't find any reference of mymodel.MyEntity in kbaseRules, but this kbase was built from kbaseModel that already have this class declared. I think it can be a bug.
Debuging
During creation of kbaseModel, a method called mergePackage(pkgRegistry, packageDescr) from PackageBuilder class is invoked. The pkgRegistry not contains any reference to declarative model. The packageDescr contains a list of type definitions from declarative model. Inside mergePackage is invoked other method, called processTypeDeclarations(pkgRegistry, packageDescr) that will iterate over all type definitions from packageDescr and will fill a map called Map<String,byte[]> classLookups from JavaDialectRuntimeData class.
During the creation of kbaseRules the method mergePackage(pkgRegistry, packageDescr) from PackageBuilder is invoked again, but at this time pkgRegistry contains all type definitions defined previously in kbaseModel and packageDescr not contains any type definitions, only rules. When the method processTypeDeclarations(pkgRegistry, packageDescr) from PackageBuilder is called and try iterate over type definitions of packageDescr, this is empty and nothing is done and the map Map<String,byte[]> classLookups from JavaDialectRuntimeData will be empty too.
The classLookups empty is the cause of ClassNotFoundException.
Solution
The solution that I found was apply reflection to fill Map<String,byte[]> classLookups from JavaDialectRuntimeData correctly before add the packages into kbaseRules:
Collection<KnowledgePackage> packages = kbuilderRules.getKnowledgePackages();
Mirror mirror = new Mirror();//Reflection utilities
for (KnowledgePackage kPackage : packages) {
Package pkg = (Package) mirror.on(kPackage).get().field("pkg");
JavaDialectRuntimeData dialect = (JavaDialectRuntimeData) pkg.getDialectRuntimeRegistry().getDialectData( "java" );
for (FactType factType : kPackage.getFactTypes()) {
Class<?> c = factType.getFactClass();
String className = c.getName();
String classAsPath = className.replace('.', '/') + ".class";
InputStream stream = c.getClassLoader().getResourceAsStream(classAsPath);
byte[] bytes = IOUtils.toByteArray(stream);
dialect.putClassDefinition(classAsPath, bytes);
}
}
KnowledgeBase kbaseRules = KnowledgeBaseFactory.newKnowledgeBase();
kbaseRules.addKnowledgePackages(packages);
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
11 years, 8 months
[JBoss JIRA] Created: (AS7-1712) Implement an account lockout mechanism for domain management.
by Darran Lofthouse (JIRA)
Implement an account lockout mechanism for domain management.
-------------------------------------------------------------
Key: AS7-1712
URL: https://issues.jboss.org/browse/AS7-1712
Project: Application Server 7
Issue Type: Task
Components: Domain Management, Security
Reporter: Darran Lofthouse
Assignee: Darran Lofthouse
Fix For: 7.1.0.Beta1
One issue to consider is that we are using realms to integrate with existing user stores so may not be able to update the remote store: -
- Consider an option to update the remote store if possible.
- If not cache a backlisted user until an admin unlocks that account
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
11 years, 8 months
[JBoss JIRA] Created: (AS7-977) Dynamic Detection of SPNEGO auth method and adding of NegotiationAuthenticator
by Darran Lofthouse (JIRA)
Dynamic Detection of SPNEGO auth method and adding of NegotiationAuthenticator
------------------------------------------------------------------------------
Key: AS7-977
URL: https://issues.jboss.org/browse/AS7-977
Project: Application Server 7
Issue Type: Task
Components: Security, Web
Reporter: Darran Lofthouse
Assignee: Darran Lofthouse
Fix For: 7.1.0.Alpha1
Previously a mapping for the SPNEGO auth method and the authenticator had to be manually defined, this capability is not present in AS7 however it is suggested that alternatively we can detect the auth method ourselves and dynamically add the valve - this seems cleaner as it potentially allows SPNEGO to be added/removed from a server without manual configuration being required.
It is suggested to look at the following code for an example where a valve has been added dynamically before: -
org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor in the JPA subsystem.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
11 years, 8 months
[JBoss JIRA] Created: (AS7-777) Switchable Nonce Handling Strategy for HTTP DigestAuthenticator
by Darran Lofthouse (JIRA)
Switchable Nonce Handling Strategy for HTTP DigestAuthenticator
---------------------------------------------------------------
Key: AS7-777
URL: https://issues.jboss.org/browse/AS7-777
Project: Application Server 7
Issue Type: Task
Reporter: Darran Lofthouse
Assignee: Darran Lofthouse
Fix For: 7.0.0.CR1
Allow the nonce strategy to be switchable: -
1 - Real 'Number Used Once' - i.e. new nonce for each request.
2 - Nonce per connection i.e. as long as a connection is kept alive allow re-use of nonce - new nonce on new connection.
3 - Timed nonce - Generate a nonce with a server secret and timestamp, nonce will be accepted for a validity period.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
11 years, 8 months
[JBoss JIRA] (AS7-2771) ModelControllerClient operations don't fail on invalud username/password
by Thomas Diesler (Created) (JIRA)
ModelControllerClient operations don't fail on invalud username/password
------------------------------------------------------------------------
Key: AS7-2771
URL: https://issues.jboss.org/browse/AS7-2771
Project: Application Server 7
Issue Type: Bug
Components: Domain Management, JSR-88
Reporter: Thomas Diesler
Assignee: Darran Lofthouse
Priority: Critical
Running org.jboss.as.test.smoke.jsr88.EnterpriseDeploymentTestCase
Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 128.98 sec
There should be a test failure with this
{code}
@Test
public void testListAvailableModulesUnauthorized() throws Exception {
DeploymentManager manager = getDeploymentManager("nobody", "nopass");
Target[] targets = manager.getTargets();
// [TODO] This should fail already
TargetModuleID[] availableModules = manager.getAvailableModules(ModuleType.EAR, targets);
assertNull(availableModules);
ProgressObject progress = jsr88Deploy(manager, getEarArchive());
TargetModuleID[] targetModules = progress.getResultTargetModuleIDs();
try {
availableModules = manager.getAvailableModules(ModuleType.EAR, targets);
assertNotNull(availableModules);
assertEquals(1, availableModules.length);
TargetModuleID targetModuleID = availableModules[0];
String moduleID = targetModuleID.getModuleID();
assertTrue("Ends with deployment-app.ear", moduleID.endsWith("deployment-app.ear"));
// [TODO] verify child modules
} finally {
jsr88Undeploy(manager, targetModules);
}
}
{code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
11 years, 8 months