Upgrade from drools 5.4 to 6.0.0-Beta3 - Legacy API Adapter JAR
by MaverickDrools
Hi,
There is not enough documentation on drools v6.0.0-Beta3, but this is what
I'm trying to do.
Our system was designed with 5.3 but then we encountered the issue with
synchronization (https://issues.jboss.org/browse/JBRULES-3283), so we
upgraded to v 5.4.
Things worked fine until we multithreaded the client code due to which we
faced another issue (https://issues.jboss.org/browse/JBRULES-3675)
So finally now, I'm trying to upgrade to 6.0.0-Beta3 since both those issues
should've been fixed with 6.0.0-Alpha1. The problem I'm facing is, I do not
have enough documentation to look at to see how to convert those things. I
went through the slides etc that were posted on the mailing list for the
conferences, but I'm still unable to figure it out correctly..
So, can someone point me to a JUnit or something that I can look at to
figure this thing out?
static {
KieServices ks = KieServices.Factory.get();
KieRepository kr = ks.getRepository();
Resource res = ks.getResources().newFileSystemResource(
"src/main/resources/rules/abc.drl");
KieModule kModule = kr.addKieModule(res);
kc = ks.newKieContainer(kModule.getReleaseId());
}
throws an exception on kr.addKieModule(res) which says Error in opening zip
file.. I assume we are now expecting a jar instead of a plain drl file. Is
there a way to convert this drl into a jar that the 6.0 code can understand
(for compatibility purposes with the existing system)?
Another thought was to make use of the Legacy API Adapter JAR, but I
couldn't find any examples of the same. Can you point me to a code
sample/JUnit that could explain how this works?
Thanks
--
View this message in context: http://drools.46999.n3.nabble.com/Upgrade-from-drools-5-4-to-6-0-0-Beta3-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 2 months
java.lang.NullPointerException when using a custom operator
by Hezi Stern
Hi all,
I have been working with Drools 5.2.0 on windows xp and I have a stable
project.
I upgraded to windows 8, drools 5.5.0 and upgraded to eclipse Juno (from
Helios).
I have now encountered a strange problem with my existing drools project. I
have a accustom operator called supersetof which now results in the
following error reported in the IDE in any file where the supersetOf is used
(LHS):
Error: java.lang.NullPointerException
After receving this error the drools parser does not work, hence this is the
only error I have.
I have tried to use the Drools 5.2.0 again (on the new windows 8 machine)
but I get the same problem so I guess it has to do with some IDE\eclispe
configuration or compatibility issue.
Obviously not the drools project code as I have not made any changes to the
working project.
I did make sure the custom operator is configured similar to the way it was
on my previous computer.
Any ideas? Is there a different configuration for Juno?
Thanks,
Hezi
12 years, 2 months
5.6.0.CR1 gives a NullPointerException in after evaluator
by abr
Hi everyone,
I tried to switch from 5.5.0.Final to 5.6.0.CR1 and got a null pointer
exception in the evaluation of the after evaluator.
(Exact method is:
/org.drools.base.evaluators.AfterEvaluatorDefinition.AfterEvaluator.evaluate(InternalWorkingMemory,
InternalReadAccessor, InternalFactHandle, InternalReadAccessor,
InternalFactHandle)/ )
When debugging, the exception occurs at the very first line of the method,
in:
/ if ( extractor1.isNullValue( workingMemory, handle1.getObject() ) ||
extractor2.isNullValue( workingMemory, handle2.getObject() ) ) {
return false;
}
/
The cause of the exception is that handle1 is null.
The rule where the exception occurs looks like:
/ MyFact(
fromdate before[ 0d ] $min,
( todate == null || todate after[ 0d ] $max ) )
/
When the exception occurs, /MyFact.fromdate/ is not null, /$min/ is not
null, /MyFact.todate/ is null, /$max/ is not null.
In AfterEvaluator.evaluate : /extractor1/ refers to /MyFact.todate/,
/extractor2/ refers to /$max/, /handle1/ is null, /handle2/ refers to the
fact including the attribute to which /$max/ variable is bound to.
Of course, this worked fine in 5.5.0.Final.
I couldn't test this out in Drools 6.0.0.CR5 because I have dependencies to
drools-spring JAR that does not exist anymore in 6.0.0.CR5.
Is it simple to fix this problem?
Thanks in advance.
Best,
Alexis
--
View this message in context: http://drools.46999.n3.nabble.com/5-6-0-CR1-gives-a-NullPointerException-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 2 months
Incorrect resolution of global symbols in LHS rule constraint (Java dialect)
by mikerod
I upgraded from 5.5.0.Final of Drools (rule engine) to 5.6.0.Final and I am
now seeing errors with globals.
We have rule constraints that access globals in a DRL; like this:
some.classpath.package2.MyType ( global_instance.invoke(this) == true )
I have `some.classpath.package.SomeType global_instance;` declared at the
top of the DRL, but it doesn't seem to be interpeting it as a global in the
rule's restriction.
So, putting this into context within, I have a DRL such as:
package my.package.example;
global some.classpath.package.SomeType global_instance;
****
rule "Example rule"
when
some.classpath.package2.MyType ( global_instance.invoke(this) == true )
then
// do something
end
****
I am getting an error from the package builder originating from the "Example
rule" specifying something like:
"can't find method MyType.global_instance()"
Once, again this did work in 5.5.0.Final, but in 5.6.0.Final I am getting a
failure trying to build the knowledge package.
It looks to me like the `global_instance` symbol is not being recognized as
a global in the DRL and is trying to be
resolved as a method of the MyType class.
So I guess it would be trying to do a
"MyType.global_instance().invoke(this)" or something.
The intent is that `global_instance` will be set for a session with an
immutable function-type of class
(invoke is an instance method though; not static). The rule restriction
uses this function/predicate to determine if some
complex criteria is true for `this` MyType instance.
I would appreciate any insight into what the issue might be. I haven't been
able to find any threads out there on a similar issue.
--
View this message in context: http://drools.46999.n3.nabble.com/Incorrect-resolution-of-global-symbols-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 2 months
Re: [rules-users] kContainer.newKieSession() fails in Apache Karaf
by jhusby
I wasn't subscribed to the mailing list so I don't think my message below
went through. Apologies if it did.
jhusby wrote
> I'm trying to run Drools in an OSGi container (Apache Karaf 2.3.3 to be
> precise). When I try to call newKieSession() on a KieContainer, I get an
> exception as follows:
>
> java.lang.IllegalArgumentException: conflict Resolver
> 'org.drools.core.conflict.DepthConflictResolver' not found
> at
> org.drools.core.RuleBaseConfiguration.determineConflictResolver(RuleBaseConfiguration.java:868)[276:org.drools.core:6.0.1.20131220-0333]
> at
> org.drools.core.RuleBaseConfiguration.init(RuleBaseConfiguration.java:459)[276:org.drools.core:6.0.1.20131220-0333]
> at
> org.drools.core.RuleBaseConfiguration.init(RuleBaseConfiguration.java:415)[276:org.drools.core:6.0.1.20131220-0333]
> at org.drools.core.RuleBaseConfiguration.
> <init>
> (RuleBaseConfiguration.java:402)[276:org.drools.core:6.0.1.20131220-0333]
> at
> org.drools.core.impl.KnowledgeBaseFactoryServiceImpl.newKnowledgeBaseConfiguration(KnowledgeBaseFactoryServiceImpl.java:37)[276:org.drools.core:6.0.1.20131220-0333]
> at
> org.kie.internal.KnowledgeBaseFactory.newKnowledgeBaseConfiguration(KnowledgeBaseFactory.java:125)[275:org.kie.internalapi:6.0.1.20131220-0322]
> at
> org.drools.compiler.kie.builder.impl.KieContainerImpl.getKnowledgeBaseConfiguration(KieContainerImpl.java:323)[277:org.drools.compiler:6.0.1.20131220-0333]
> at
> org.drools.compiler.kie.builder.impl.KieContainerImpl.createKieBase(KieContainerImpl.java:316)[277:org.drools.compiler:6.0.1.20131220-0333]
> at
> org.drools.compiler.kie.builder.impl.KieContainerImpl.getKieBase(KieContainerImpl.java:257)[277:org.drools.compiler:6.0.1.20131220-0333]
> at
> org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:400)[277:org.drools.compiler:6.0.1.20131220-0333]
> at
> org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:349)[277:org.drools.compiler:6.0.1.20131220-0333]
> at
> org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:331)[277:org.drools.compiler:6.0.1.20131220-0333]
>
> As a workaround, I was able to get it working by doing this:
>
> KieBaseConfiguration kbaseConf = KnowledgeBaseFactory
> .newKnowledgeBaseConfiguration(
> null,
> getClass().getClassLoader(),
> RuleBaseConfiguration.class.getClassLoader()
> );
> KieBase kbase = kContainer.newKieBase(kbaseConf);
> kSession = kbase.newKieSession();
>
> but this is obviously less than ideal. Any ideas on how to make this work
> better in OSGi?
>
> Thank you!
>
> Joseph
--
View this message in context: http://drools.46999.n3.nabble.com/kContainer-newKieSession-fails-in-Apach...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 2 months
Inconsistency in Drools' Performance (Version 5.5.0)
by Harpreet Singh
Hi,
I have been trying to measure Drools' 5.5.0 performance for quite some time. I see that Drools' perform inconsistently in terms of CPU time.
Please see the below code (modification of DroolsTest example):
/*Code start*/
public class DroolsTest {
public static final void main(String[] args) {
try {
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
// go !
for (int i = 0; i < 20; i++) {
Message message = new Message();
message.setMessage("Hello World");
message.setStatus(Message.HELLO);
long startTime = System.nanoTime();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
FactHandle handle = ksession.insert(message);
ksession.fireAllRules();
ksession.retract(handle);
System.out.println("Time taken is: " + (System.nanoTime()-startTime)/1000);
ksession.dispose();
}
} catch (Throwable t) {
t.printStackTrace();
}
}
private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("Sample.drl"), ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error: errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge.");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
return kbase;
}
public static class Message {
public static final int HELLO = 0;
public static final int GOODBYE = 1;
private String message;
private int status;
public String getMessage() {
return this.message;
}
public void setMessage(String message) {
this.message = message;
}
public int getStatus() {
return this.status;
}
public void setStatus(int status) {
this.status = status;
}
}
}
/** Code end**/
I have just added timing code to the DroolsTest.java program (provided by JBoss) and I am using Sample.drl file (provided by JBoss). The rules get executed correctly but the timings that I see are:
Iteration 1: 103753 (we can ignore this as the classes get loaded during the first iteration)
Iteration 2: 861
Iteration 3: 744
Iteration 4: 1350
Iteration 5: 718
Iteration 6: 651
Iteration 7: 661
Iteration 8: 668
Iteration 9: 648
Iteration 10: 3564
Iteration 11: 911
Iteration 12: 689
Iteration 13: 682
Iteration 14: 796
Iteration 15: 4236
Iteration 16: 774
Iteration 17: 772
Iteration 18: 722
Iteration 19: 713
Iteration 20: 697
I profiled it with Yourkit Profiler and the increase in time does not correspond to garbage collection. I also timed individual calls and found out that:
- ksession.insert: takes consistent time
- ksession.fireAllRules: inconsistent
- kbase.newStatefulKnowledgeSession: inconsistent
I see same inconsistency in performance when I integrate Drools with original project (which I can't share here). I also found that this has nothing to do with compiler optimizations.
Why is there inconsistent performance? Is there anything that I am missing?
Thank you.
12 years, 2 months
permgen error for simple rule stress test
by anjana.ackroyd
We are running a simple stress test (whose code I will paste below) for a
numbercompare rule file)
We get the following error before the test finishes. Which seems odd for one
rule
javax.servlet.ServletException: java.lang.OutOfMemoryError: PermGen space
This test is run against 3 loablanced tomcat servers
Here is my JVM_OPTS for each of those tomcat
JVM_OPTS="-Xms4096m -Xmx4096m -XX:NewSize=2048m -XX:PermSize=512m
-XX:MaxPermSize=512m -Xss1024K -XX:+UseCodeCacheFlushing
-XX:-UseSplitVerifier"
Here is
I have a simple rule file deployed on guvnor on my abc with JVM_OPTS on the
guvnor being
JVM_OPTS="-Xms4096m -Xmx4096m -XX:NewSize=2048m -XX:PermSize=512m
-XX:MaxPermSize=512m -Xss1024K
Here is my stress test that we are running
package DroolsTest;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import confident.guppy.tools.Caller;
public class DroolsSpeedTest {
public static void main(String[] args) {
HttpURLConnection httpURLConnection = null;
InputStream inputStream = null;
BufferedReader bufferedReader = null;
long t1 = System.currentTimeMillis();
for (int i = 0; i < 10000; i++) {
try {
long start =
System.currentTimeMillis();
// Three
boxes
String url =
"https://abc-uat2.xyz.com/ces/v2.0/rules/10/compare/10";
httpURLConnection = (HttpURLConnection) ( new URL(url).openConnection());
if
(httpURLConnection != null) {
inputStream = httpURLConnection.getInputStream();
bufferedReader = new BufferedReader(new InputStreamReader(
inputStream));
String results = "";
String info = "";
while ((info = bufferedReader.readLine()) != null) {
results += info;
}
//caller.log(results);
} else {
System.out.println("Unable to create the HTTP connection with the required
server...");
}
if (i % 20
== 0 && i != 0 ) {
System.out.println(" passing " + i + " ms " + (
System.currentTimeMillis() - start ));
}
} catch (Exception boom) {
boom.printStackTrace();
System.out.println("It died on the " + i + " attempt because " +
boom.getMessage());
}
}
long t2 = System.currentTimeMillis() - t1 ;
System.out.println("I took ms : "+ t2 );
}
}
Here is my rules defined on guvnor
package org.numbercompare;
declare NumberCompare
message : String
numberone: Integer
numbertwo: Integer
end
rule "numberone is equals to numbertwo"
when
n: NumberCompare(numberone == numbertwo);
then
n.setMessage("numberone is equals to numbertwo");
end
rule "numberone is greater than numbertwo"
when
n: NumberCompare(numberone > numbertwo);
then
n.setMessage("numberone is greater than numbertwo");
end
rule "numberone is less than numbertwo"
when
n: NumberCompare(numberone < numbertwo);
then
n.setMessage("numberone is less than numbertwo");
end
Here is my code that updates the rule file
public KnowledgeBase readKnowledgeBase() throws Exception {
ResourceFactory.getResourceChangeNotifierService().start();
ResourceFactory.getResourceChangeScannerService().start();
ResourceChangeScannerConfiguration sconf =
ResourceFactory.getResourceChangeScannerService().newResourceChangeScannerConfiguration();
sconf.setProperty("drools.resource.scanner.interval", "2");
ResourceFactory.getResourceChangeScannerService().configure(sconf);
KnowledgeAgentConfiguration kaconf =
KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
kaconf.setProperty("drools.agent.scanDirectories", "true");
kaconf.setProperty("drools.agent.scanResources", "true");
kaconf.setProperty("drools.agent.newInstance", "false");
KnowledgeAgent kagent =
KnowledgeAgentFactory.newKnowledgeAgent("CS", kaconf);
kagent.applyChangeSet(ResourceFactory.newClassPathResource("ChangeSet.xml"));
KnowledgeBase kbase = kagent.getKnowledgeBase();
return kbase;
}
@Override
public DroolsDTO getDroolsDTO(int numberone, int numbertwo) throws
Exception {
DroolsDTO droolsDTO = new DroolsDTO();
KnowledgeBase kb = readKnowledgeBase();
FactType factType = kb.getFactType("org.numbercompare",
"NumberCompare");
Object nc = factType.newInstance();
factType.set(nc, "numberone", numberone);
factType.set(nc, "numbertwo", numbertwo);
StatefulKnowledgeSession ksession =
kb.newStatefulKnowledgeSession();
ksession.insert(nc);
ksession.fireAllRules();
ksession.dispose();
droolsDTO.setMessage(factType.get(nc, "message").toString());
return droolsDTO;
}
My changeset.xml
<change-set xmlns='http://drools.org/drools-5.0/change-set'
xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'
xs:schemaLocation='http://drools.org/drools-5.0/change-set
http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-api/src/...'
>
<add>
<resource
source='http://abc:8082/guvnor/org.drools.guvnor.Guvnor/package/org.numbercompare...'
type='PKG' basicAuthentication="enabled" username="admin" password="admin"/>
</add>
</change-set>
Also in the guvnor logs during the test I see
, I see thousands of these: WARN 28-01 11:50:55,551
(RulesRepositoryManager.java:getRulesRepository:70) Creating RulesRepository
with default username. =============== session-guest-864931
and the session-guest numbers keep climbing.
and admin user logging in about every second.
--
View this message in context: http://drools.46999.n3.nabble.com/permgen-error-for-simple-rule-stress-te...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 2 months