understanding working of Drools guvnor - drools

can any one plz let me know that how drool guvnor work i went to guvnor documentation but couldn't understand the core logic of how rules are processed and how we can use drools guvnor in coherence with java code
Basically i want to know how java code interacts with drools guvnor api.

There is very less documentation about latest drool 6.
I suggest you watch this presentation by Mark Proctor on drools 6 (Drools Project Lead at Red Hat) and visit his Youtube Channel to watch screencasts of drools workbench and tutorials on building example applications.

Related

It is possible to Integrate Activiti with Drools rule engin

I am working on a project and trying to evaluate Drools vs Activiti.
I know there is jBPM support but my client needs Activiti for managing the business flow and I need to use rule engin for evaluating some cases.
So is it possible to integrate drools and activity. Any pointer would help.
As I mention in the Gitter channel this is totally possible.
I will recommend you to do a small PoC (Proof of Concept) to really understand the details of it. People usually underestimate the complexity of a Rule Engine like Drools. Don't get me wrong, I love Drools, but I recommend you to check the docs and one of their books ;)
Check out the chapter in Tijs Rademaker's book "Activiti in Action". It describes the drools integration for version 5.x of Activiti very completely. The concepts are still valid for Activiti 6 as well.

Drools on Spark with Scala

I am starting a project where we have a lot of business rules. I have strongly been considering using the JBoss rules engine, Drools.
My project uses Scala and uses the Spark engine. I am wondering if anyone has experience, or advice, using Drools with Spark/Scala.
If you looked into Drools and decided against it, I would like to know that too.
I have read several blogs on how people integrate Drools with Spark, or Drools with Scala, but I didn't find any good examples explaining Drools on Spark with Scala. I have seen this with a mixture of Scala and Java, but never pure Scala. I am not sure if this is possible.
Update: Clarifying Question
Would you recommend Drools?
How about with Spark/Scala?
If you looked into Drools and decided against it, I would like to know
that too.
I would not advise that. We are forced to use drools in one of our components and all developers in a team find this solution full of cons:
Java 8 support: scala is moving towards java 8 (see this and
this regarding runtime). Drools started to support java 8 only
in 2 years after its release.
IDE support: eclipse only. We were not able to get it done in
Intellij idea.
General purpose: we did come up with the idea, that whatever you
write using drools rules engine could be written in java/scala
easily. You would say that business logic can get too technical?
Possibly, but you would not have to learn some kind of scripting language
to create business rules.
1) Yes, I would recommend Drools. I have no experience with other rule engines, but the projects I have developed using Drools have worked perfectly so far. Truth be told, I have only used the basic functionality of Drools (never used salience explicitly, Agendas, etc). However, the functionality I have used has solved my requirements perfectly.
2) I have used Drools with both Java 7 and Scala 2.11. I haven't found any particular thing I was able to do with Java but not in Scala. My latest project is using Apache Spark with Scala and Drools, and everything fits together nicely.
If you are going to use Scala, then your facts (the objects that model your domain; aka the 'bean') should have public access modifiers on the val or var you are going to access within the rules. If you need static methods or attributes, then use Objects and import them in the rule file.
Hope this helps

drools 5.0.1 vs 6.0.1 API changes?

We are upgrading our application from drools 5.0.1 to drools 6.0.1 Final. I noticed there are some API changes. Many classes that used to be in org.drools appear to be now in org.drools.core. Also, the class DebugRuleFlowEventListener appears to no longer exist.
My question is: is there a documentation somewhere explaining the API differences between the two versions? Unless I'm missing something, it seems like they are significant and should be documented. Also, thought I was tasked with the upgrade I wasn't the one who developed so I'm far from being an expert on drools.
If there is no such documentation - can anyone advise what to do about DebugRuleflowEventListener?
Thanks, Thomas
A big focus for 6.0 was streamlining the build, deploy and loading(utilization) aspects of the system. Building and deploying now align with Maven and the utilization is now convention and configuration oriented, instead of programmatic, with sane default to minimise the configuration.
Two primary distributions consist of:
KIE Drools Workbench
Drools Editors, for rules and supporting assets.
jBPM Designer, for Rule Flow and supporting assets.
KIE Workbench
Drools Editors, for rules and supporting assets.
jBPM Designer, for BPMN2 and supporting assets.
jBPM Console, runtime and Human Task support.
jBPM Form Builder.
BAM.
Regarding API would suggest looking at OFFICIAL DOCS
There are three debug classes:
DebugAgendaEventListener
DebugRuleRuntimeEventListener
DebugWorkingMemoryEventListener
Some of the methods afterRuleFlowGroupActivated(RuleFlowGroupActivatedEvent event) and afterRuleFlowGroupDeactivated(RuleFlowGroupDeactivatedEvent event) which existed in DebugRuleFlowEventListener are moved to DebugAgendaEventListener
Hoping was able to help to some extent.
Cheers !!

Maintaining drl (technical) rules in Drools Guvnor

I'm new to the world of business rules, but I think I've understood the concepts of Drools Expert and Drools Guvnor, yet I'm still a bit confused how/when/why exactly use Guvnor in comparison to Expert. And also, whether they rule each other out or are capable or even prefered to work side-by-side. Below are some highlighted topics that puzzle and a bit of explanation behind my concerns, mainly concentrating in application maintainability.
Does Guvnor have all the functionality that is available in Expert plus more?
I know that Guvnor is Business Rule Management System (BRMS) that takes control of storing(including versioning) the rules and exposing services to use of other apps. Guvnor contains UIs (text and graphical) for generating the rules and an engine for running them, so in this sense I guess it contains all functionality of the Expert system. Based on my requirements, I'm quite sure Guvnor is what I need, but do I need Drools Expert for anything after that?
Or in other words, does Drools Expert offer something that is not present in Guvnor?
Testing rules in Guvnor
Many tutorials on Drools I've seen start with TDD example where the rules are tested with simple jUnit tests. Once a rule is imported to Guvnor (or just generated there), is there any way to use/write unit tests for it?
Should the testing be done via exposed interfaces (REST) only?
If the users of the system are to develop their own rules, I don't expect them to write any tests. Mainly interested in 'core' rules and their maintainability here.
In case of 'core' rules, should they be stored in a version controlling system and imported to Guvnor on scheduled updates for the complete system? In this case the unit tests could be written for these rules and automatically executed as part of build cycle.
Thanks in advance.
Based on one of your questions, there's something I should clear up first. In essence:
Expert is a rules engine runtime.
Guvnor is a tool for writing and storing rules, which will subsequently be executed in Expert.
Guvnor doesn't provide a runtime for your rules, other than what is required for the test harnesses. You will always need Expert for your runtime environment. Guvnor enables you to manage the rules and store them. It also provides some handy GUI tools such as the guided editor and web decision tables. However, you can also edit rules in an IDE such as Eclipse and push them to Guvnor using the Guvnor WebDav Eclipse plugins.
Typically, you will have a Guvnor web application on one server and your application(s) on elsewhere. You can download the compiled rules from Guvnor into your application build, and deploy them with your application. Alternatively, you can define a URL resource in your code to create your knowledge base, pointing at the Guvnor package URL. In that case, your application can load the knowledge base on start-up and reload it at runtime.
For example the following code will download a package snapshot called "Approved" as a resource for building a knowledge base.
UrlResource urlResource =
(UrlResource) ResourceFactory.newUrlResource(
"http://my.guvnor.local/.../package/mypackage/Approved");
urlResource.setBasicAuthentication("enabled");
urlResource.setUsername("myusername");
urlResource.setPassword("mypassword");
KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
builder.add(urlResource, resource.getType());
Edit - Take a look at KnowledgeAgent if you wish to have rules reloaded at runtime when they are changed in Guvnor.
My main reason for using Guvnor is to enable non-technical users to author rules using decision tables and DSL-based guided editors.
I like to edit technical rules in Eclipse, where I can easily write unit tests around them and evaluate that they are behaving as I expect. I find that much easier than the testing capabilities in Guvnor. And although Guvnor provides some version control, I much prefer Subversion/Git as version control for my technical rules.
I also write DSL in Eclipse, which I then deploy to Guvnor. This makes guided rules much simpler to work with for non-technical users.
Testing rules
With regards testing, there are a few options. There is testing functionality in Guvnor, which enables you to write expectations based on various inputs. However, I personally find that way too clunky and limiting to use. I far prefer to write tests in Java/JUnit.
First of all, you can write simple unit tests, which load one or two technical rules, written in DRL and evaluate that they are activating when you think they should, and generating inferred facts where appropriate.
For more complex testing, I write tests which create a knowledge base using a package in Guvnor, insert facts and fire rules, in order to evaluate that the package as a whole is working correctly, including those rules which have been built in guided editors or decision tables.
Other uses for Guvnor
It's worth noting that the Guvnor editor functionality is becoming much richer, and it is becoming an editor and repository for more than just rules. For instance, there is rich tooling for BPM processes, which should soon be better than what you can get in an IDE such as Eclipse.
Summary
If all your rules are written by yourself and other developers in DRL, then there is little benefit to using Guvnor. In fact I would find it a hindrance. However, if you wish to take advantage of the guided editors or decision tables, or you wish to have 'business' users manage some of the rules, then you should take a deeper look at Guvnor.

Sample Application Using Drools5

I am working on the Drools5.I am new to this Drools.I need a sample working example for this Drools.For this i have googled it alot but i did not find the correct one.If anyone has an idea can give me the reply.
Since I'm on the same boat as you are, I've searched for learning material quite a bit. Here are my resources:
http://www.jboss.org/drools For the general portal for the project.
Since this project has nicely modularized submodules, here they are:
Drools Guvnor for the Management Module that is used to manage packages of rules and POJOs with versions and also for deployment of snapshots for external usage.
Drools Expert for the expert systems core of the project. Here you can get a first look at how rule processing works under drools.
Drools jBPM5 for business workflow process modeling and integration.
Drools Fusion for Complex Event Processing (CEP) with which you can do all timeconstraint sorts of pattern matching you could think of (my favorite by the way ;).
Drools Planner for planning and business resource optimization.
For each of them, there is a complete and in my opinion high quality documentation out. In there you can really get a hands on an start digging in. You could also start working through one or the other of my personal list:
Getting started with drools fusion, by TheJavaDude
Creating Category, Package, Declarative Model, Rules And Snapshot In Drools Guvnor[Video]
Mark Proctors introduction to drools at FOSDEM[Video]
I hope this helps.
Greetings,
Kjellski