Friday, 15 January 2010

Blending Processes And Rules With jBPM

This integration with rules and processes is a first important step to facilitate all aspects of Business Process Management (BPM) into jBPM. From a runtime engine perspective, we'll be expanding further in this direction to cover all artefact types that are involved automating business processes to for example services. On the other hand, we'll also be expanding towards linking these BPM related artefacts to the business users. More on that topic soon.

The rules deployer is a convenience integration between jBPM and Drools. It allows for unified deployment of processes, rules together with forms and other process resources in a .bar business archive. jBPM creates a KnowledgeBase based on all .drl files that are included in a business archive deployment. Activities like the rules and rules-decision leverage this KnowledgeBase.

A rules-decision will take a single outgoing transition based on the evaluation of rules. Let's first look at a rules-decision example process:

This is the RulesDecision jPDL process file (click to enlarge) :
Now all you have to do is deploy the following .drl file together with the process in a .bar business archive and deploy it to jBPM (click to enlarge)
For your convenience, the process variables are made available as global variables in the rules. Then you can start a new process instance with jBPM like this (click to enlarge):
And your rules will be used to evaluate which outgoing transition will be taken in the process execution. Voila. That's all there is to it.

Similarly, a rules activity will evaluate rules, allowing them to update process variables or perform other actions. Let's look at a rules example process:
The Rules jPDL process file looks like this (click to enlarge):
Imagine a process variable of type Room (click to enlarge)
And a rule like this (click to enlarge)
Then starting a new process instance like this (click to enlarge):
will execute the activity, evaluate the rule and update the room process variable.

25 comments:

  1. I implemented something along this in jBPM3 with a few hacks, but is functional and in production.
    Having it integrated in jBPM 4 is very logical and will save me some work.

    ReplyDelete
  2. Nice, I miss one thing though in the example. The mapping of the name to the drl file. I assume name of the drl file should be identical to what is in the name attribute minus the .drl extension right?

    ReplyDelete
  3. kukeltje,

    at this stage, all .drls are scanned in a .bar deployment and a single KnowledgeBase is compiled for all of those combined. in the future, if practical experience learns that this is too coarse grained, then we can consider to introduce scoping to have multiple KnowledgeBases. of course then you'll have to enter a lot more details on how the .drls are assembled into KnowlledgeBases and which KnowledgeBase to use in the rules. i think for most use cases, it should be sufficient to have a single KnowledgeBase per deployment. but emperical usage date will tell... eagerly awaiting your feedback :-)

    ReplyDelete
  4. I am currently evaluating/examining jBPM4 and Drools Rule Flow for my company.
    We provide technology to financial institutions to facilitate front/middle/back office processing. As such we provide a lot of automatic processing, but need to adapt around customers existing manual and automated processes. We are therefore looking for a technology which allows our customers and our field staff to define workflows and also to implement custom (domain specific) automated processes around our existing (domain specific) services. Due to their nature many of these processes are better delivered as integrated Java rather than over a pure Web Services based approach.
    We have an existing homegrown technology in use, but are looking at replacement.
    I like the look of Drools Rule Flow - it offers the right kind of support for domain specific processes (and we already use Drools).

    However I have to say that the whole jBPM / Drools picture leaves me with concerns. I don't feel confident that Drools Rule Flow will continue to exist. I can't understand why it would not be merged with jBPM, and am somewhat confused what might happen if it does, given that features seem to have been removed between jBPM3 and jBPM4.

    Tom can you offer any clarity on the story with the two 'competing' JBoss workflow offerings?

    ReplyDelete
  5. Jason,

    jBPM is the only supported workflow and BPM offering from JBoss.

    jason: "I can't understand why it would not be merged with jBPM"

    me neither. at least not with the argumentats in the discussions we had (even very recently).

    Jason: "am somewhat confused what might happen if it does, given that features seem to have been removed between jBPM3 and jBPM4."

    some were filtered because they were considered bad. and a couple are not yet implemented cause of prioritization (e.g. nested tasks). if there is an important feature missing in jBPM that you need, file a jira issue: https://jira.jboss.org/jira/secure/CreateIssue.jspa?pid=10052&issuetype=2

    ReplyDelete
  6. Tom, thanks for the rapid response - that clarifies the matter.

    Guess my concern is that we are looking specifically for a tool which is appropriate for low/non-tech resources to use to tweak a system constituted of a set of services. jBPM strikes me as having rather a higher tech-knowledge requirement, while Drools Rule Flow suits us as is.

    Hence if we adopt and Drools Rule Flow is subsumed onto the PVM and into jBPM we might find the platform moving in the wrong direction for us.

    Thanks for the suggestion - will peruse JIRA. Have you given any thought to opening up the jBPM engine & IDE to provide extension points to allow definition of custom tasks which are cleanly integrated?

    ReplyDelete
  7. Jason: "Have you given any thought to opening up the jBPM engine & IDE to provide extension points to allow definition of custom tasks which are cleanly integrated?"

    of course. in jPDL it only takes 1 line in a configuration file to add your own activity to the jPDL language. if you're ok with including the full classname instead of a custom activityname, then you don't have to configure jPDL at all. extending the designer is also possible but that takes longer. there are still a one or two places where the activity types are hard coded. it's in our strategy to have those pluggable. currently it is possible, but requires coding. it remains to be seen when going for full pluggability makes it in the designer.

    ReplyDelete
  8. Thanks Tom - this may be silly question but could you point me to the doc section covering addition of custom task (by name)?

    The (6.2.8) 'custom' tag doesn't seem to me to be that; it allows me to invoke a custom implementation of ExternalActivityBehaviour but I can't attach any configuration with it which I would like to do.

    ReplyDelete
  9. Tom, would it be possible to indicate where the jPDL one-line change is explained. I would very much like to consider using that approach.

    Also you mention that the UI requires some tweaking rather than being pluggable. Are the tweaks listed anywhere (comment/blog etc)? Useful to know.

    Thanks a lot.

    ReplyDelete
  10. Jason,
    Activities and event-listener parsers are read from 2 resource files: 'jbpm.jpdl.bindings.xml' and 'jbpm.user.bindings.xml'

    jbpm.jar already includes the jbpm.jpdl.bindings.xml resource file. There you can see the format. In your classpath, put a file called 'jbpm.user.bindings.xml' and add your activities to it.

    You might have to remove the schema reference. Not sure if we already made the schema fully aware or possible user extensions. By removing the schema reference, the validation during deployment will be skipped.

    ReplyDelete
  11. Thanks again Tom - think the files in jBPM4 are:

    jbpm.jpdl.activities.xml
    jbpm.jpdl.eventlisteners.xml

    I see how it works.

    ReplyDelete
  12. Jason,

    I was looking at trunk of jBPM 4. So you might need to update your solution for those files if you upgrade.

    ReplyDelete
  13. Why was the decision node changed to be a big X ? There's no label shown explaining what the decision is - all you can see is the names of the outgoing transitions. Would be much easier to understand the graph if the decision had a label describing what the decision was, shown clearly on the graph.

    Btw, i'm trying to get jbpm/spring/gwt working together and for the life of me can't seem to get the processdefinitions loading. Any suggestions ?

    repositoryService.createDeployment().addResourceFromClasspath("simple.jpdl.xml").deploy()

    followed by

    repositoryService.createProcessDefinitionQuery().list()

    which just returns an empty list. Confusing.

    ReplyDelete
  14. Just to answer my own question. The problem disappeared after I changed my jbpm.cfg.xml. Instead of hacking together one from various "spring+gwt" blogs posts on the net, I took the jbpm.default.cfg.xml and added two additional resource imports - one for jbpm.tx.spring.cfg.xml and one for jbpm.jpdl.cfg.xml. I still have another problem but at least the process deployment is now working.

    ReplyDelete
  15. The subsequent problem I was having, with a test jpdl xml which consisted merely of 3 java tasks printing out a message, was that I was getting:

    org.hibernate.exception.ConstraintViolationException: could not delete: [org.jbpm.pvm.internal.model.ExecutionImpl ...

    If I switched to an HSQLDB instead of MySQL the problem is not there and the test process completes successfully. This leads me to conclude the constraints specified when hibernate creates the tables are badly determined (probably an error in the hibernate mapping file for the Execution table).

    ReplyDelete
  16. db, try to use as much as possible the ant scripts for installation that ship with jBPM. they are tested in all kinds of configurations.

    ReplyDelete
  17. You mean create the jbpm database tables up front using ant tasks instead of the hibernate mappings plus auto create property ?

    Btw, back to my original question, why was the decision node changed to be a big X ? Don't you agree the graphs were much easier to read with the old "box plus text" format for a decision ?

    ReplyDelete
  18. db,

    the graphical notation (the big X for a decision) is specified by the BPMN standardization committee.

    regards, tom.

    ReplyDelete
  19. Hi your blog is very interesante.Soy cubano,I understand this part

    "Now all you have to do is deploy the following .drl file together with the process in a .bar business archive and deploy it to jBPM"
    Como despligo el proceso y el drl en un archivo .bar

    ReplyDelete
  20. SOLVED!

    I created the schema in mysql using the provided scripts but _IT DID NOT HELP_.

    The solution to the simple problem (just a couple of linked java tasks in a process definition) which for mysql database (but not hsqldb) was giving:

    org.hibernate.exception.ConstraintViolationException: could not delete: [org.jbpm.pvm.internal.model.ExecutionImpl#7]

    was to set continue="async" on the end node. I have no idea why it fixes it and don't care (for now).

    ReplyDelete
  21. estoy probando la integracion de jbpm con drolls,y me surgio un problema.como yo puedo acceder desde mi archivo de reglas(drl) a un objeto de mi dominio que esta en mis variables de proceso
    Gracias de ante mano

    'm testing the integration of jbpm with drolls, and I came a problema.como I can access with my rule file (drl) to an object in my domain that is in my process variables
    Thanks beforehand

    ReplyDelete
  22. 'm testing the integration of jbpm with drolls, and I came a problema.como I can access with my rule file (drl) to an object in my domain that is in my process variables
    Thanks beforehand

    ReplyDelete
  23. Ok last post on the matter. The problem I was having with the constraint violation seems to be a bug in jBPM imo, because in my example process, the created jbpm4_execution entry ends containing a self-referencing INSTANCE_ value (ie it has the same value as the ID_ field).

    Due to the FK_EXEC_INSTANCE constraint, the MySQL engine does not allow this row to be deleted.

    I guess there are two solutions:
    1) Patch the ExecutionImpl code to set the INSTANCE_ value to null prior to deletion if it matches the ID_ value (Tom you wrote that code!)
    2) Remove the constraint from the jbpm4_Execution table with:
    alter table jbpm4_execution drop foreign key FK_EXEC_INSTANCE;
    then make sure if you regenerate your database at some point you remove the constraint again.

    Since I couldn't even find the relevent ant task to build jbpm.jar I went for option 2.

    ReplyDelete
  24. In this advancing world where technology is every time going on and you can't keep up with it, you have to learn as much as you can and this readings help a lot.

    ReplyDelete
  25. In my project i have to develop the jbpm work-flow using some web-based editor. I have downloaded oryx editor. but, i couldn't export as jPDL.

    I have some idea about GWT.Is it possible to design the jbpm work-flow process using gwt?
    Possible means, i need GWT source code. Please help me..

    ReplyDelete