Saturday, November 19, 2011

10 things a programmer should know about Liferay Kaleo Workflow Engine

Liferay developers decided to create their own workflow engine called Kaleo 2 years ago. It's a flexible lightweight workflow engine similar to other open-source engines out there. It is a plugin built on Liferay's ServiceBuilder and it needs to be deployed before you can use it (it is not a part of portal).

The principle consists in defining workflow for resources as an xml definition containing states, tasks, conditions, forks & joins and timer. Apart from timer, all of them contains transition nodes (where to go next). And apart from condition, fork&join all of them may contain actions (what to do) and hereby orchestrate a sequence of events and actions. It is especially useful for content reviewing, validation, approving and quality evaluation.

It is quite easy to use and design workflows in xml directly. But there are definitely use cases that makes you investigate its internal working and modify it or add something that you need.

Following summary lists a few things you should be aware of as a developer :
  • Liferay has it's own simple messaging implementation that is meant only for internal usage, it doesn't allow remote messaging. Kaleo uses it from two reasons :
    • Because it is an external plugin, portal context needs to communicate with it via messaging
    • Because messaging is a suitable choice for workflow engine implementation
  • A workflow definition is always associated with a corresponding resource. There are 2 key entities. For instance, in case of document library :  KaleoDefinition (definition itself) and WorkflowDefinitionLink (association between the definition and folder and file types that will be "workflow aware").
  • You cannot undeploy a definition if such an association exists. So that you first delete the link ( this corresponds to removing workflow from a resource in administration) and then you can deactivate it and undeploy it.
  • When you deploy a workflow definition, it is parsed in XMLWorkflowModelParser into an object model and for each node type (mentioned in 2. paragraph) there is a NodeExecutor type with methods enter, execute and exit
  • Everytime you add a resource, that has a workflow definition link, a workflow instance is created and its execution context is associated with it.
  • Consequently KaleoSignaler ( class that sends messages about entering, executing and exiting ) either call a corresponding NodeExecutor in case of timer node or sends a message to liferay/kaleo_graph_walker destination about entering or leaving a node (transitions). The destination is associated with DefaultGraphWalker, that steps into target nodes and call corresponding NodeExecutors. The methods are implemented differently based on type of the node.
  • Execution context contains so called Instance Token that is carrying information about current position within the workflow node model and and its state. It also holds a reference to workflow and service contexts.
  • Task nodes contain assignment element that determines recipients (content reviewers for instance) based on Role, User or just an email address. You can even dynamically determine this in runtime in scripted-assignment, which is a matter of setting a user or a role that you want in the scripting context. I wrote a blog post about improving scripting experience.
  • Actions are either notifications or whatever you need to be done. For a java developer the obvious choice would be writing groovy scripts.
  • KaleoLog entity contains information like duration, user comments etc. 

I hope this post helped you with getting grasp of Liferay Kaleo Engine's internal working. Cheers


Keyur said...

I have created one workflow in my project. I am done with the workflow but i need to make some changes in that. In this when anyone click on Assign to Me button then it will display one pop-up for comments. Now here i need to make some validation. Currently if you don't write any comment then also it allows but i need to make the comments mandatory. How can i achieve this? please kindly help me if you have any idea.

Anonymous said...

It took me a couple of hours before I came across your site.Well, this post would be of great help to anyone who would come to read this one. Thanks a lot for sharing your thoughts. play tetris free

Anonymous said...

You really have a way of words. Great style of delivering the information and I could relate to it. Such a great information for me. Thanks for this. Damiana

Anonymous said...

I implemented this one. I download Kaleo plugina and deploy into liferay. It works correctly. Kaleo have two states. Either Accept or Reject. Now I have to give functionality like
1) Accept
2) Reject
3) Review - Re-Submit

Can you please tell me how can I achieve this one????

Thanksssssss in Advance...

Pradip Bhatt

Skype : pradip.aspire
email :