Maintaining drl (technical) rules in Drools Guvnor - drools

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.

Related

Use drools as the underlying rule engine for a saas solution offering complex, editable rules

I'm in the process of designing a new saas solution that lets users configure relatively complex business rules in a web based environment. I'm leaning towards drools, but the web authoring application that ships with drools is way to complex and 'geeky' to show to the average user.
My idea is to create a simplified web authoring application that connects to drools, but having no experience with drools I have a hard time figuring out if this can be done. So that's my question:
Can this be done?
Secondly, do you think this is a good approach? (I know the 2nd question is a bit too generic for stackoverflow, but I'd appreciate it if you guys could share some quick pointers)
So you expect "relatively complex rules" but the existing authoring tool is too complex? The authoring of "complex rules" is a complex process, and no simple tool will be sufficient. (At least, I haven't seen or heard of one, so far.)
You don't need to "connect to Drools" for an authoring tool. All it has to do is to produce DRL (Drools' native rule language) text which is then compiled.
It would be a good approach, but only if you have an answer to the issue of how to create complexity with simple means.

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

How To Create a Flexible Plug-In Architecture?

A repeating theme in my development work has been the use of or creation of an in-house plug-in architecture. I've seen it approached many ways - configuration files (XML, .conf, and so on), inheritance frameworks, database information, libraries, and others. In my experience:
A database isn't a great place to store your configuration information, especially co-mingled with data
Attempting this with an inheritance hierarchy requires knowledge about the plug-ins to be coded in, meaning the plug-in architecture isn't all that dynamic
Configuration files work well for providing simple information, but can't handle more complex behaviors
Libraries seem to work well, but the one-way dependencies have to be carefully created.
As I seek to learn from the various architectures I've worked with, I'm also looking to the community for suggestions. How have you implemented a SOLID plug-in architecture? What was your worst failure (or the worst failure you've seen)? What would you do if you were going to implement a new plug-in architecture? What SDK or open source project that you've worked with has the best example of a good architecture?
A few examples I've been finding on my own:
Perl's Module::Plugable and IOC for dependency injection in Perl
The various Spring frameworks (Java, .NET, Python) for dependency injection.
An SO question with a list for Java (including Service Provider Interfaces)
An SO question for C++ pointing to a Dr. Dobbs article
An SO question regarding a specific plugin idea for ASP.NET MVC
These examples seem to play to various language strengths. Is a good plugin architecture necessarily tied to the language? Is it best to use tools to create a plugin architecture, or to do it on one's own following models?
This is not an answer as much as a bunch of potentially useful remarks/examples.
One effective way to make your application extensible is to expose its internals as a scripting language and write all the top level stuff in that language. This makes it quite modifiable and practically future proof (if your primitives are well chosen and implemented). A success story of this kind of thing is Emacs. I prefer this to the eclipse style plugin system because if I want to extend functionality, I don't have to learn the API and write/compile a separate plugin. I can write a 3 line snippet in the current buffer itself, evaluate it and use it. Very smooth learning curve and very pleasing results.
One application which I've extended a little is Trac. It has a component architecture which in this situation means that tasks are delegated to modules that advertise extension points. You can then implement other components which would fit into these points and change the flow. It's a little like Kalkie's suggestion above.
Another one that's good is py.test. It follows the "best API is no API" philosophy and relies purely on hooks being called at every level. You can override these hooks in files/functions named according to a convention and alter the behaviour. You can see the list of plugins on the site to see how quickly/easily they can be implemented.
A few general points.
Try to keep your non-extensible/non-user-modifiable core as small as possible. Delegate everything you can to a higher layer so that the extensibility increases. Less stuff to correct in the core then in case of bad choices.
Related to the above point is that you shouldn't make too many decisions about the direction of your project at the outset. Implement the smallest needed subset and then start writing plugins.
If you are embedding a scripting language, make sure it's a full one in which you can write general programs and not a toy language just for your application.
Reduce boilerplate as much as you can. Don't bother with subclassing, complex APIs, plugin registration and stuff like that. Try to keep it simple so that it's easy and not just possible to extend. This will let your plugin API be used more and will encourage end users to write plugins. Not just plugin developers. py.test does this well. Eclipse as far as I know, does not.
In my experience I've found there are really two types of plug-in Architectures.
One follows the Eclipse model which is meant to allow for freedom and is open-ended.
The other usually requires plugins to follow a narrow API because the plugin will fill a specific function.
To state this in a different way, one allows plugins to access your application while the other allows your application to access plugins.
The distinction is subtle, and sometimes there is no distiction... you want both for your application.
I do not have a ton of experience with Eclipse/Opening up your App to plugins model (the article in Kalkie's post is great). I've read a bit on the way eclipse does things, but nothing more than that.
Yegge's properties blog talks a bit about how the use of the properties pattern allows for plugins and extensibility.
Most of the work I've done has used a plugin architecture to allow my app to access plugins, things like time/display/map data, etc.
Years ago I would create factories, plugin managers and config files to manage all of it and let me determine which plugin to use at runtime.
Now I usually just have a DI framework do most of that work.
I still have to write adapters to use third party libraries, but they usually aren't that bad.
One of the best plug-in architectures that I have seen is implemented in Eclipse. Instead of having an application with a plug-in model, everything is a plug-in. The base application itself is the plug-in framework.
http://www.eclipse.org/articles/Article-Plug-in-architecture/plugin_architecture.html
I'll describe a fairly simple technique that I have use in the past. This approach uses C# reflection to help in the plugin loading process. This technique can be modified so it is applicable to C++ but you lose the convenience of being able to use reflection.
An IPlugin interface is used to identify classes that implement plugins. Methods are added to the interface to allow the application to communicate with the plugin. For example the Init method that the application will use to instruct the plugin to initialize.
To find plugins the application scans a plugin folder for .Net assemblies. Each assembly is loaded. Reflection is used to scan for classes that implement IPlugin. An instance of each plugin class is created.
(Alternatively, an Xml file might list the assemblies and classes to load. This might help performance but I never found an issue with performance).
The Init method is called for each plugin object. It is passed a reference to an object that implements the application interface: IApplication (or something else named specific to your app, eg ITextEditorApplication).
IApplication contains methods that allows the plugin to communicate with the application. For instance if you are writing a text editor this interface would have an OpenDocuments property that allows plugins to enumerate the collection of currently open documents.
This plugin system can be extended to scripting languages, eg Lua, by creating a derived plugin class, eg LuaPlugin that forwards IPlugin functions and the application interface to a Lua script.
This technique allows you to iteratively implement your IPlugin, IApplication and other application-specific interfaces during development. When the application is complete and nicely refactored you can document your exposed interfaces and you should have a nice system for which users can write their own plugins.
I once worked on a project that had to be so flexible in the way each customer could setup the system, which the only good design we found was to ship the customer a C# compiler!
If the spec is filled with words like:
Flexible
Plug-In
Customisable
Ask lots of questions about how you will support the system (and how support will be charged for, as each customer will think their case is the normal case and should not need any plug-ins.), as in my experience
The support of customers (or
fount-line support people) writing
Plug-Ins is a lot harder than the
Architecture
Usualy I use MEF. The Managed Extensibility Framework (or MEF for short) simplifies the creation of extensible applications. MEF offers discovery and composition capabilities that you can leverage to load application extensions.
If you are interested read more...
In my experience, the two best ways to create a flexible plugin architecture are scripting languages and libraries. These two concepts are in my mind orthogonal; the two can be mixed in any proportion, rather like functional and object-oriented programming, but find their greatest strengths when balanced. A library is typically responsible for fulfilling a specific interface with dynamic functionality, whereas scripts tend to emphasise functionality with a dynamic interface.
I have found that an architecture based on scripts managing libraries seems to work the best. The scripting language allows high-level manipulation of lower-level libraries, and the libraries are thus freed from any specific interface, leaving all of the application-level interaction in the more flexible hands of the scripting system.
For this to work, the scripting system must have a fairly robust API, with hooks to the application data, logic, and GUI, as well as the base functionality of importing and executing code from libraries. Further, scripts are usually required to be safe in the sense that the application can gracefully recover from a poorly-written script. Using a scripting system as a layer of indirection means that the application can more easily detach itself in case of Something Badâ„¢.
The means of packaging plugins depends largely on personal preference, but you can never go wrong with a compressed archive with a simple interface, say PluginName.ext in the root directory.
I think you need to first answer the question: "What components are expected to be plugins?"
You want to keep this number to an absolute minimum or the number of combinations which you must test explodes. Try to separate your core product (which should not have too much flexibility) from plugin functionality.
I've found that the IOC (Inversion of Control) principal (read springframework) works well for providing a flexible base, which you can add specialization to to make plugin development simpler.
You can scan the container for the "interface as a plugin type advertisement" mechanism.
You can use the container to inject common dependencies which plugins may require (i.e. ResourceLoaderAware or MessageSourceAware).
The Plug-in Pattern is a software pattern for extending the behaviour of a class with a clean interface. Often behaviour of classes is extended by class inheritance, where the derived class overwrites some of the virtual methods of the class. A problem with this solution is that it conflicts with implementation hiding. It also leads to situations where derived class become a gathering places of unrelated behaviour extensions. Also, scripting is used to implement this pattern as mentioned above "Make internals as a scripting language and write all the top level stuff in that language. This makes it quite modifiable and practically future proof". Libraries use script managing libraries. The scripting language allows high-level manipulation of lower level libraries. (Also as mentioned above)

What are all the open standards related to Rule Engine?

If we need to use plugaable rule engine, what are all the open standards related to it.
How to migrate rule engine "without rewriting rules" for every platform?
JSR-94 is the only standard in wide use but, sadly, won't help you with rewriting rules as it is only a standard for calling the engine. If you want to avoid re-writing rules while either supporting multiple rule engines or moving from one to another then you need to look into a couple of other standards:
Production Rule Representation (PRR) is a standard under development at OMG. This defines the basic structure of rules and rulesets in rule engines so that an XML structure can be passed around containing rules. This is in beta and is being supported by most of the major rule vendors (though I don't think any have released support yet).
Rule Interchange Format (RIF) is a standard under development at W3C. This is being kept synchronized with PRR and is focused on the syntax of the rules - how to specify conditions etc. This is also widely supported but similarly support is not yet released.
The idea, and the reason the two teams work together, is to allow rules to be structured according to PRR (allowing them to be shared between modeling tools and rule engines) while exporting the rule engine-specific syntax to RIF so that specific rules can be moved from syntax to syntax.
Wikipedia says
Most Java-based rules engines provide
a technical call-level interface,
based on the JSR-94 application
programming interface (API) standard,
in order to allow for integration with
different applications, and many rule
engines allow for service-oriented
integrations through Web-based
standards such as WSDL and SOAP.
In general, it's still an early stage and I don't think there's still a dominating standard on the field. Also see The Rule Markup Initiative (RuleML). Besides JSR-94 and RuleML, Business Rule Management System mentions OMG Business Motivation Model (BMM), OMG SBVR, OMG Production Rule Representation (PRR), W3C RIF, and PMML.
You may also be interested in topics like BPEL, workflow engine, workflow application, and business process management.

What is scaffolding? Is it a term for a particular platform?

Scaffolding, what is it? Is it a Rails-only thing?
Scaffolding generally refers to a quickly set up skeleton for an app. It's not rails-only since other platforms have it as well. It's also not generally meant to be a "final" system; merely the first, smallest way to do it.
From Wikipedia:
Scaffolding is a meta-programming
method of building database-backed
software applications. It is a
technique supported by some
model-view-controller frameworks, in
which the programmer may write a
specification that describes how the
application database may be used. The
compiler uses this specification to
generate code that the application can
use to create, read, update and delete
database entries, effectively treating
the template as a "scaffold" on which
to build a more powerful application.
Just like a real scaffolding in a building construction site, scaffolding gives you some kind of a (fast, simplified, temporary) structure for your project, on which you can rely to build the real project.
It can be (and is today) used to describe many things - from abstracting DB layers, to web apps folder structures, and to generating and managing project dependencies .
It is not something that is specific to any language / technology, just like the term skeleton or boilerplate is platform agnostic.
It is just a term borrowed from real scaffolding (like mentioned above).
You build some fast, simplified, (sometimes external, sometimes temporary) structure that will help you to build the real, more complex, finalized structure under, above, inside or outside of that temporary structure .
.. And just like the real scaffolding, the scaffolding structure is meant to support the building process of the project, rather than the project itself (with some exceptions).
Scafolding is usually some type of code generation where you point it at a database, and the technology creates basic CRUD (create, read, update, delete) screens.
I believe that Wikipedia and some answers here provides a narrow and restricted view. Scaffolding is not just for CRUD operations on top of a database. Scaffolding has a broader objective to give you a skeleton app for any kind of technology.
Yeoman is a modern and useful tool for scaffolding. Using their own words:
The web's scaffolding tool for modern webapps
What's Yeoman?
Yeoman helps you to kickstart new projects, prescribing best practices
and tools to help you stay productive.
To do so, we provide a generator ecosystem. A generator is basically a
plugin that can be run with the yo command to scaffold complete
projects or useful parts.
Through our official Generators, we promote the "Yeoman workflow".
This workflow is a robust and opinionated client-side stack,
comprising tools and frameworks that can help developers quickly build
beautiful web applications. We take care of providing everything
needed to get started without any of the normal headaches associated
with a manual setup.
With a modular architecture that can scale out of the box, we leverage
the success and lessons learned from several open-source communities
to ensure the stack developers use is as intelligent as possible.
As firm believers in good documentation and well thought out build
processes, Yeoman includes support for linting, testing, minification
and much more, so developers can focus on solutions rather than
worrying about the little things.
That's it. Use scaffolding to create a quick-start application to work as an example or the foundation of your solution. It makes you productive faster them building things from scratch.
It is not a rails only term although I think it originated there (at least that is where I first heard it.)
Scaffolding is a framework that allows you to do basic CRUD operations against your database with little or no code. Generally, you then go through and add the code to manage the data the way you want replacing the scaffolding. It is generally only intended to get you up and running quickly.
No it is used in other technologies also such as ASP.NET MVC
it creates a basic layout from some predefined code which programmers uses in almost every project , Eg: for database data access it can make a crud method for create, read, update, delete operations
OR you might use it to create layout for your View/Html Code
Scaffolding is writing any piece of code that would not be part of the business logic but would help in unit testing and integration testing.
This is a software engineering term and not bound to any framework or programming language.
No, scaffolding is not the term for the specific platform, however many know this term in the context of Ruby on Rails or .NET
There are also plenty of tools that perform javascript scaffolding:
divjoy.com
flatlogic.com
scaffoldhub.com
yeoman.io
Those tools are also known as code-generators
Scaffolding is the term used when you don't want to create all parts of the structure such as models, views, etc. and want to generate them all in one go. A lot of frameworks use this technique, I studied about it while doing odoo but most of the references given were to ruby on rails :)