Create kieBase programmatically: WARN "No files found for KieBase defaultKieBase"?
by Frank Langelage
Hello,
I need your help!
I'm trying to migrate from Drools 5.5.0 to 6.0.1, creating the
KnowledgeBase programmatically.
But buildAll gives me WARN "No files found for KieBase defaultKieBase".
What's missing? My code is based on the example found in documentation.
fileName is pointing to an xls file with decision table.
Writing it to kieFileSystem seemed to work correct, as
kieFileSystem.read( fileName ).length is showing the right number of bytes.
Logging output:
DEBUG [RuleBuilder#buildKieBase] Get kieServices
DEBUG [RuleBuilder#buildKieBase] Get kieRepository
DEBUG [RuleBuilder#buildKieBase] Get new kieFileSystem
DEBUG [RuleBuilder#buildKieBase] Add
/mbi/etc/MailFilter_hgm2e-langfr-sb2000-ipc.xls to kieFileSystem
DEBUG [RuleBuilder#buildKieBase] Get new kieBuilder
DEBUG [RuleBuilder#buildKieBase] 22016
DEBUG [RuleBuilder#buildKieBase] Build all Rules
WARN
[org.drools.compiler.kie.builder.impl.AbstractKieModule#buildKnowledgePackages]
No files found for KieBase defaultKieBase
INFO
[org.drools.compiler.kie.builder.impl.KieRepositoryImpl#addKieModule]
KieModule was added:MemoryKieModule[
ReleaseId=org.default:artifact:1.0.0-SNAPSHOT]
DEBUG [RuleBuilder#buildKieBase] Get new kieContainer
DEBUG [RuleBuilder#buildKieBase] Get kieBase
Code:
RuleBuilder.LOGGER.debug( "Get kieServices" );
KieServices kieServices = KieServices.Factory.get();
RuleBuilder.LOGGER.debug( "Get kieRepository" );
KieRepository kieRepository = kieServices.getRepository();
RuleBuilder.LOGGER.debug( "Get new kieFileSystem" );
KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
XADiskConnection connection = null;
try {
connection = this.xaDisk.getConnection();
XAFileInputStream fis = connection.createXAFileInputStream( new File(
fileName ) );
try ( InputStream is = new XAFileInputStreamWrapper( fis ) ) {
RuleBuilder.LOGGER.debug( "Add " + fileName + " to kieFileSystem" );
kieFileSystem.write( fileName,
kieServices.getResources().newInputStreamResource( is ) );
} catch ( IOException e ) {
// ignore
}
fis.close();
} catch ( FileNotExistsException e ) {
// Datei '%s' nicht gefunden
ServiceStringResponse ssr = this.mbiFxtxtFacade.getTranslation(
Integer.valueOf( 215421 ), locales );
throw new MbiException( e, RuleBuilder.LOGGER, String.format(
ssr.getValue(), fileName ) );
} catch ( InsufficientPermissionOnFileException | LockingFailedException
| NoTransactionAssociatedException e ) {
throw new MbiException( e, RuleBuilder.LOGGER );
} catch ( ResourceException | InterruptedException e ) {
throw new MbiException( e, RuleBuilder.LOGGER );
} finally {
if ( connection != null ) {
connection.close();
}
}
RuleBuilder.LOGGER.debug( "Get new kieBuilder" );
KieBuilder kieBuilder = kieServices.newKieBuilder( kieFileSystem );
RuleBuilder.LOGGER.debug( kieFileSystem.read( fileName ).length );
RuleBuilder.LOGGER.debug( "Build all Rules" );
kieBuilder.buildAll();
RuleBuilder.LOGGER.debug( "Get new kieContainer" );
KieContainer kieContainer = kieServices.newKieContainer(
kieRepository.getDefaultReleaseId() );
RuleBuilder.LOGGER.debug( "Get kieBase" );
KieBase kieBase = kieContainer.getKieBase();
12 years, 2 months
NPE when combining rules
by sumantp
Hi again,
I had previously posted an issue with event re-evaluation when using
accumulate -
http://drools.46999.n3.nabble.com/Prevent-re-evaluation-of-events-in-stre...
I resolved the issue by using a flag to ensure that an event is evaluated
just once. I used two rules, one that would match the condition I'm
interested in and the second to set the flag on all events that did not
match the condition. I used salience to control the order. Here are the
rules:
rule "Rule 1: Amount exceeds average"
salience 2
when
$event : Transaction(!isProcessed(), $sequence : sequence, $account :
account, $amount : amount)
Number($avg : doubleValue, $amount > $avg) from
accumulate(Transaction(account == $account, $amount_ : amount) over
window:length(100), average($amount_))
then
System.out.println("\t***ALERT***: Amount exceeds average = " + $avg + ",
Amount = " + $amount + ", Sequence = " + $sequence);
$event.setProcessed();
update($event)
end
rule "(Prune rule 1) Amount exceeds average"
salience 1
when
$event : Transaction(!isProcessed())
then
$event.setProcessed();
update($event)
end
These rules work great!
Next, I created another rule that checks if a metric exceeds a threshold but
suppresses consecutive repeating violations. Here's the rule:
rule "Rule 2: Suppress repeating violations"
when
$prevevent : Transaction($account : account, !(amount > 150))
$thisevent : Transaction($sequence : sequence, account == $account, this
after $prevevent, $amount : amount, $amount > 150)
not (Transaction(account == $account, this after $prevevent, this before
$thisevent))
then
System.out.println("\t***ALERT***: Amount exceeds threshold
(non-repeating) = " + $amount + ", Sequence = " + $sequence);
end
This rule, when used by itself (the only rule in the drl), works great!
The problem happens when I include all 3 rules in the drl file. I get a NPE.
Here's the output:
Inserting: (Average = 100.0) : Sequence = 1, Account = 1, Amount = 100.0
Inserting: (Average = 100.0) : Sequence = 2, Account = 1, Amount = 100.0
Inserting: (Average = 133.33333333333334) : Sequence = 3, Account = 1,
Amount = 200.0
***ALERT***: Amount exceeds average = 133.33333333333334, Amount = 200.0,
Sequence = 3
java.lang.NullPointerException
at
org.drools.core.time.impl.JDKTimerService.removeJob(JDKTimerService.java:132)
at
org.drools.core.phreak.PhreakTimerNode.doLeftUpdates(PhreakTimerNode.java:124)
at org.drools.core.phreak.PhreakTimerNode.doNode(PhreakTimerNode.java:65)
at
org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:357)
at
org.drools.core.phreak.RuleNetworkEvaluator.outerEval(RuleNetworkEvaluator.java:161)
at
org.drools.core.phreak.RuleNetworkEvaluator.evaluateNetwork(RuleNetworkEvaluator.java:116)
at
org.drools.core.phreak.RuleExecutor.reEvaluateNetwork(RuleExecutor.java:194)
at
org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:67)
at
org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:937)
at
org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1201)
at
org.drools.core.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:958)
at
org.drools.core.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:932)
at
org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:256)
at com.sample.BankRules.main(BankRules.java:26)
The sequence of amounts I'm inserting is: 100, 100, 200, 200, 200, 100, 200,
200, 200, 100
I'm using 6.0.0.Final. The java code is essentially the same as in the link
above.
Help!
--
View this message in context: http://drools.46999.n3.nabble.com/NPE-when-combining-rules-tp4027267.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 2 months
help with drools 6
by dwipin
Hi,
I am trying to create a project using Drools 6 with Spring.
I have drools-spring-6.0.0.Beta2 as the dependency as
drools-spring-6.0.0.Final is not available.
I am unable to get the <kie:kmodule> tag to bind in the spring
application-context file. Can some one post a sample appCtx file with the
kmodule xsd schema location specified ?
Also, is there a working sample of using Spring with Drools 6 anywhere ?
Thanks,
Dwipin Chandran.
--
View this message in context: http://drools.46999.n3.nabble.com/help-with-drools-6-tp4027460.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 2 months
Re: [rules-users] Unable to have KBase recognize our DRL files
by P. Vinod Kiran
Mayank,
Can you try adding the ksession tag?
<kie:kmodule id="kieModule">
<kie:kbase name="validationRulesKBase" packages="com.acme.rules">
<kie:ksession name="ksession1" type="stateless"/>
</kie:kbase>
</kie:kmodule>
Also, can you post the relevant sections of the console log?
- Vinod
> From: Mayank <mayank.kumar(a)gmail.com>
> Subject: [rules-users] Unable to have KBase recognize our DRL files
> Date: 27 December 2013 02:50:59 GMT
> To: rules-users(a)lists.jboss.org
> Reply-To: Rules Users List <rules-users(a)lists.jboss.org>
>
> Hi,
>
> We are in the process of upgrading Drools in our application. Until 5.x the
following spring configuration used to work well for us:
>
> <drools:kbase id="validationRulesKBase">
> <drools:resources>
> <drools:resource type="DRL"
source="classpath:rules/trade/rule1.drl" />
> <drools:resource type="DRL"
source="classpath:rules/trade/rule2.drl" />
> </drools:resources>
> </drools:kbase>
>
> With an inejection of this KnowledgeBase, we would create a stateless
session and fire all rules after inserting appropriate facts and globals.
>
> After upgrading to Drools 6, our DRL files don't seem to be getting picked
up in the knowledge base - we are using the following spring configuration:
>
> <bean id="kiePostProcessor"
class="org.kie.spring.KModuleBeanFactoryPostProcessor"/>
>
> <kie:kmodule id="kieModule">
> <kie:kbase name="validationRulesKBase" packages="com.acme.rules"/>
> </kie:kmodule>
>
> This KnowledgeBase gets injected in our code but it doesn't seem to pick up
the DRL files in the specified package. We have ensure that the drl files are
under src/main/resources/com/acme/rules and that package is specified in each
DRL file at the top.
>
> Am I missing something in this new configuration?
>
> thnx,
> -mayank
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
12 years, 2 months
JBPM : How to Listen Once ResourceChangeScanner Modifies the package after Changes
by Zahid Ahmed
Hi,
I want to upgrade my process instances using WorkflowProcessInstanceUpgrader. To trigger the upgrade after any change I wanted to listen for changes completed by ResourceChangeScanner. To listen the completion of changes I was looking to configure KnowledgeBaseEventListener. I have drools-spring-integration in place which uses drools-spring.xsd to configure beans and event listeners. I am getting KBase and Ksession from spring. I was trying to register my KnowledgeBaseEventListener in my spring configurations. But, The issue is that drools-spring.xsd only registers 3 kind of listeners
1. ProcessEventListener
2. AgendaEventListener
3. WorkingMemoryEventListener
Solution Required :
1. I need to know how to configure the KnowledgeBaseEventListener in my spring configurations ?
Example for ksession we have following config to register listeners.
<drools:ksession id="knowledgeSession" type="stateful" kbase="knowledgeBase">
<drools:agendaEventListener ref="agendaEventListener"/>
<drools:workingMemoryEventListener ref="wmEventListener"/>
</drools:ksession>
2. Is this the best place to trigger a batch process upgrade ? From within the KBaseEventListener ?
3. Shall I add KBaseEventListener using knowledgebase.addEventListener() ?
Environment
1. Drools-5.5.0.Final
a. Guvnor
b. Jbpm
12 years, 2 months