2018/10/11

Handle service exceptions via subprocess

Interacting with services as part of your business process (or in more general business automation) is a common requirement. Though we all know that services tend to fail from time to time and business automation solutions should be able to cope with that. A worth reading article was recently published by Donato Marrazzo and can be found here Reducing data inconsistencies with Red Hat Process Automation Manager

Described feature in this article was actually inspired by discussion with Donato so all credit goes to him!

BPMN2 has already a construct for similar thing - error boundary events that can be easily attached to service tasks to deal with exceptions and perform additional processing or decision taking. This approach has some drawbacks in more advanced scenarios

  • error handling needs to be done on individual task level
  • retry of the same service call needs to be done via process modelling - usually a loop
  • each error type needs to be handled separately and by that makes the process definition too verbose

The first point from the above list can be addressed by using even based subprocess that starts with error event but that still suffers from the two other points.

To address this an additional error handling is introduced (in jBPM version 7.13) that allows the work item handlers (that implement the logic responsible for service interaction) to throw special type of exception org.kie.api.runtime.process.ProcessWorkItemHandlerException

This exception requires three parameters
  • process id that should be created to deal with this exception
  • selected handling strategy to be applied when exception handling process is completed
  • root cause exception
When such exception is thrown from work item handler it triggers automatic error handling by starting subprocess instance with the definition identified by process id set on the exception. If the process is straight through (meaning does not have any wait states) service task that failed will apply the handling strategy directly, otherwise it puts the service task in a wait state until the subprocess instance is completed. Then the strategy is applied on the service task.

Supported strategies

There are four predefined strategies 
  • COMPLETE - it completes the service task with the variables from the completed subprocess instance - these variables will be given to the service task as output of the service interaction and thus mapped to main process instance variables
  • ABORT - it aborts the service task and moves on the process without setting any variables
  • RETRY - it retries the service task logic (calls the work item handler again) with variables from both the original service task parameters and the variables from subprocess instance - variables from subprocess instance overrides any variables of the same name
  • RETHROW - it simply throws the error back to the caller - this strategy should not be used with wait state subprocesses as it will simply rollback the transaction and thus the completion of the subprocess instance
With this feature service implementors (those who implement work item handlers) can simply decide how the exception should be handled and what strategy it should apply to the failing service tasks once the error was evaluated and fixed.

Out of the box handlers and exception handling

Three major out of the box work item handlers are equipped with this handling automatically as soon as they are created with process id to handle exception and strategy. This takes over the regular error handling that will be applied when RETHROW strategy is selected.

  • RESTWorkItemHandler
  • WebServiceWorkItemHandler
  • EmailWorkItemHandler

Sample registration for RESTWorkItemHandler via deployment descriptor would be

new org.jbpm.process.workitem.rest.RESTWorkItemHandler("username", "password", classLoader, "handlingProcessId", "handlingStrategy")

Look at available constructors of given handler class to see all possible options. Similar way email and Webservice handlers can be configured to handle the exceptions via subprocess.

Use cases

Here are few examples that could be implemented
  • report to administrator that service task failed - this would have to be via subprocess that has user task assigned to administrators 
  • use a timer based sub process to introduce some delay in retries
  • ask business users to provide the information in case system is down in time critical situations 
There can be many more use cases implemented by that and one of the most important things with this is it does not have to be modelled for each and every task that could fail. It is up to the service handler to instruct what and how should be done in case of errors.

In action...

A short screencast showing this in action, simple process with custom service task that has a work item handler that throws ProcessWorkItemHandlerException exception and starts user focused subprocess to provide expected values and then apply COMPLETE strategy.



Here is the complete sample repository shown in the above screencast.

Hopefully you will find this useful and that will allow you to better automate your business to avoid any repetitive actions ...

Visit jbpm.org to download latest version of the jBPM project

2018/10/09

jBPM Business Apps - dashboard demo



This is first part of the "What do after I generate my business app?" series where we show demos that are supposed to give you ideas on how to get started on your own to build really cool business apps.

In this demo we very quickly (seriously less than 20 lines of code) create a dashboard through which we can interact with business processes in our business app. You can follow the steps shown in the video below and get this up and running. 

Here are the links:

* Youtube Video:



* Kie Server Dialect project used in the video (note this location may change soon so look there for a link to the projects new home once its moved).

Happy jBPM Business App coding

Let's embed forms ... rendered by KIE Server

jBPM comes with rather sophisticated form modeller that allows to graphically build forms for processes and tasks. These forms can then be used to interact with process engine to start new instances or complete user tasks.

One of the biggest advantages of using forms built in workbench is that they share the same life cycle as your business assets (processes and user tasks). By that they are versioned exactly the same way - so if you have another version of a process that requires more information to start you simply create new version of the project and make changes to both process definition and form. Once deployed you can start different versions of the process using dedicated forms.

Although to be able to take advantage of these forms users have to be logged into workbench as the only way to render the content is ... through workbench itself. These days are now over ... KIE Server provides pluggable renderers for forms created in workbench. That means you can solely interact with kie server to perform all the needed operations. So what does this brings:
  • renders process forms - used to start new instances
  • renders case forms - used to start new case instances - includes both data and role assignments
  • renders user task forms - used to interact with user tasks - includes life cycle operations

Worth noting is that rendered forms are fully operational, meaning they come with buttons to perform all the operations that are based on the context - e.g. if user task is in in progress state there are buttons to stop, release, save and complete.

Here are few screenshots on how the forms look like, these are taken from the sample projects that come out of the box with jBPM distribution



Evaluation start process form

Mortgage start process form



IT Orders start case form
As it was mentioned, form renderers are pluggable and out of the box there are two implementations

  • based on PatternFly - this is the default renderer that keeps the look and feel consistent with workbench
  • based on Bootstrap
Renderers can be switched per each form rendering request by simply appending query parameter
?renderer=patternfly or ?renderer=boostrap if not given patternfly is the default one.

Here are few examples of the REST endpoints that illustrate how to get these forms rendered

http://localhost:8080/kie-server/services/rest/server/containers/evaluation/forms/processes/evaluation/content
http://localhost:8080/kie-server/services/rest/server/containers/evaluation/forms/tasks/1/content


http://localhost:8080/kie-server/services/rest/server/containers/mortgage-process/forms/processes/Mortgage_Process.MortgageApprovalProcess/content
http://localhost:8080/kie-server/services/rest/server/containers/mortgage-process/forms/tasks/2/content


http://localhost:8080/kie-server/services/rest/server/containers/itorders/forms/cases/itorders.orderhardware/content
http://localhost:8080/kie-server/services/rest/server/containers/itorders/forms/tasks/3/content

Note that containers are given as alias so that brings in additional benefits when working with forms and multiple project versions.

And at the end few short screen casts showing this feature in action

Evaluation process


Mortgage process


IT Orders case


Multi Sub Form - dealing with list of items in forms



More technical information will be provided in the next article as this one is just a quick preview of what's coming. Hope you like it and don't forget to provide feedback!

2018/09/25

Business Applications by jBPM - League of Legends Stats Demo

A lot of our development focus recently has been around business applications, specifically rapid creation/development of business apps that include the full power of jBPM, are easily deployable to the cloud, and are fun and easy to work with.
We are at a point currently where we can start showcasing our work and what better way than with a demo.

This demo shows off the power of business app generation with jBPM and shows how easy it is to then extend it to create a unique and fun app for your users/customers.


The youtube video for the demo can be found here (or click on the image below).

Feel free to leave any comments/questions/ideas on the video itself or here if you like. The video shows how we generated the business app with start.jbpm.org, extend it and gives alot of good info on how to get up and running with all this.

And also here are some important links to get you started:
And some images of the demo app that you can build easily yourself:

Demo app - Summoner Search


Demo app - Match Results

Let us know what you think. A lot more info about this is coming your way so stay tuned and have fun generating your business apps!

2018/07/26

jBPM Workitems Spotlight - GitHub and Slack


So far we have posted a number of articles describing the jBPM Workitem Repository and its features but there was little mention about its actual content and the powerful integration capabilities it brings to your business processes.

Currently the workitem repository includes 25 different workitem groups and a total of 57 individual workitem handlers. These include various integration services with Google,  Dropbox, IBM, Twitter and many more. New workitems can easily be added as was described in this previous article.  Given that the number of workitems in growing at a steady pace we thought to start showcasing them with simple working examples that you can take and use to start implementing your custom integration solutions.

In this article we will focus on two workitem groups, namely GitHub and Slack:




For our simple example to showcase these workitems we will create a business process which fetches all open issues from one of your GitHub repositories, accumulate them into a message and then send this message to a specified channel on Slack notifying you of these open issues and give you simple links to each so you can start addressing them.

First let's look at the pre-requisites for each of the workitems. To start using GitHub workitems the required information is your login data, namely your username and password. For this example we will use the FetchIssuesWorkitemHandler where you will also need to know the name of the repository where you want to fetch the issues from.

To start using the Slack workitem handlers you need to first create a Slack App. Follow this link to get started with that. Once you create your app make sure to enable OAuth so Slack will create an access token for it. This access token is then passed to the workitem handler as it needs it for authentication with the Slack service. The workitem handler we will use here is PostMessageToChannelWorkitemHandler which also needs the name of one of the channels your slack app has access posting messages to.

To follow this example we also assume that you have the KIE workbench+server set up and ready but if you don't you can follow this article to do that literally in minutes. We also assume that you have an existing GitHub repository set up with some real or test issues defined. If you don't you could use this test one. 

Test GitHub repo with some test issues

With our KIE worbench running log in and create a new project. Within this project create a new business process (with legacy editor as it's currently only one capable of installing workitems from a repository).  Click on the repository icon in the process editor menu bar and connect to your running service repository
Installing workitems from workbench legacy bpmn2 editor
Find the two workitem handlers we mentioned earlier, namely FetchIssuesWorkitemHandler and PostMessageToChannelWorkitemHandler and click on the little wrench icon next to each to install them into your workbench. Note that the install also updates your project pom with all necessary maven dependencies to execute these workitems as well as your projects deployment descriptor xml. 

To finish the setup we do need to edit the projects deployment descriptor slightly, passing in our login information to the github workitem as well as the Slack access token created to the slack workitem so they can authenticate with their respective services correctly:

For this in the project explorer navigate to your projects /src/main/resources/META-INF directory and edit the kie-deployment-descriptor.xml file. Note that under the work-item-handlers element in this xml file the workitem installer has already added the definitions of two workitem handlers we want to use, however it needs to be slightly changed to add the sensitive info we talked about:

So for the GitHub handler we need to add:

<identifier>new org.jbpm.process.workitem.github.FetchIssuesWorkitemHandler("YOUR_GITHUB_LOGIN_NAME", "YOUR_GITHUB_LOGIN_PASSWORD")</identifier>

and for the Slack handler:

<identifier>new org.jbpm.process.workitem.slack.PostMessageToChannelWorkitemHandler("YOUR_SLACK_APP_ACCESS_TOKEN")</identifier>

Note that in the image below I have cut off the sensitive info as I used my personal login information when making the demo

Modifying the kie deployment descriptor

            
Now we should be all set up to create our business process. You can download or import the one used in this example from this Gist.

Our test business process

The example process first fetches all open issues from our testrepo GitHub repository. This list is then saved in a process variable which the script task iterates to create a message. The created message is then used by the Slack workitem to connect to your defined channel and create a new post to it.

You can now build and deploy your worbench process and start and instance of our example process


Starting new instance of the example process

Process instance completed info panel

Once the process has completed execution you should see in your Slack channel the result message:



And that's it :) Let us know what other workitems you would like to see featured next. 







2018/07/19

Easy Workitem installation (jBPM WorkItem Repository)

We added the ability to install workitems hosted by the  jBPM Workitem Repository on any running KIE Worbench instance directly from the repository. itself This lifts some limitations of installing workitems which was so far only possible from within process editors inside each running workbench. It also allows for future integrations with other runtime systems that can take advantage of the hosted workitems.

When browsing workitems inside the repository you will now find the "Install" column:

Install column - Repository homepage

Selecting "Kie Workbench" will trigger the installation modal:

Workitem installation modal

Here you can enter specific information about the running KIE Workbench instance such as URL, Username, Password, Space name, and Project info where this workitem should be installed in.

Clicking the Install button will install all workitem handlers from the selected workitem group to your workbench instance. Upon successful installation you should be able to see the installed workitem handlers inside the selected workbench project.

Install success message

Archive workitem installed in "myproject"


Once installed you can start using your workitems when modeling your business processes:

Start using the installed workitem!

Note that this feature is available only if you are running the workitem repository in "hosted" mode, so by hosting it via the repository-springboot, or the repository-wildfly modules. When serving the repository content from the file system the Install column will not be displayed. 

Another thing to note is that since in almost all cases your hosted repository will have a different origin(domain) than the running workbench instances you are installing workitems to we need to enable CORS on the servers the workbench is running on. If you are running on Wildfly, this can simply be done inside your standalone.xml config:

Wildfly CORS config

Don't forget to change the value of the "Access-Control-Allow-Origin" header to the domain where you are hosting your workitem repository. In this case we use the default http://localhost:8090 which is used when running spring-boot repository setup. 

Last thing to mention is that currently the KIE Workbench servlet filters do not handle CORS preflight requests unfortunately (hopefully this will be changed in the future). Because of this by default the workitem repository is not able to issue CORS requests to the workbench intances. To lift this limitation add this filter definition to your workbench web.xml and restart the server:

Filter definition within KIE workbench


As always feel free to leave any comments and suggestions. Enjoy!





2018/07/17

Performance baseline for jBPM 7 (7.8.0)

The aim of this article is to show a base information about performance of the jBPM to set a baseline and to answer basic question how good jBPM performs when it comes to execution. This is not to be seen as competitive information or show jBPM is faster or slower than other engines but more for setting a stage and open the door for more performance tests that can be performed in different types of environments.

Overview

The performance test is executed on KIE Server so it actually measures performance of the jBPM as a running service instead of focusing on raw execution of the APIs. So anyone can perform this tests by following the instructions at the end of this article.

Environment

The test has been executed on:
  • community 7.8.0 single zip distribution that you can download on jbpm.org
    • WildFly 11
    • Postgres data base 
  • hardware
    • macOS 10.13.4
    • Processor Intel Core i7 2,3 GHz
    • Memory 16GB
  • JMeter as the test client
All components (client, application server and database) are on the same hardware, meaning they share the resources.

Scenarios

There are three scenarios selected for this test that are executed with various concurrency settings.

Script task

Most basic process definition that runs directly from the beginning till the end without persisting any state in between.
This test consists of just single call to KIE Server.

User task

User task based process that will persist its state when reaching user task activity. Completion of the task is done in another call. 
This test consists of three calls to KIE Server
  • start process
  • get tasks for given process instance
  • complete first task


Parallel script and user tasks

More advanced process definition that combines both user and script tasks with parallel gateways.

This test consists of five calls to KIE Server
  • start process
  • get tasks for given process instance
  • complete first task
  • get tasks for given process instance
  • complete second task

Performance test

Tests are separated per scenario and then number of concurrent threads. The test is designed to run fixed number of process instances (1000) in the shortest possible time.

Script task execution results


Actual figures
  • 1 thread - 11 421 ms
  • 4 threads - 4 428 ms
  • 8 threads - 3 124 ms

Throughput: 
  • 1 thread - 91 instances/s
  • 4 threads - 240 instances/s
  • 8 threads - 361 instances/s

User task execution results



Actual figures
  • 1 thread - 64 439 ms
  • 4 threads - 18 397 ms
  • 8 threads - 13 927 ms

Throughput: 
  • 1 thread - 16 instances/s
  • 4 threads - 52 instances/s
  • 8 threads - 72 instances/s

NOTE: throughput is for complete process instance execution including completion of user task


Parallel script and user tasks execution results



Actual figures
  • 1 thread - 153 543 ms
  • 4 threads - 34 769 ms
  • 8 threads - 20 426 ms

Throughput: 
  • 1 thread - 11 instances/s
  • 4 threads - 45 instances/s
  • 8 threads - 70 instances/s

NOTE: throughput is for complete process instance execution including completion of user tasks

Conclusion

These performance results show the base performance of the jBPM execution through KIE Server - meaning it adds network and marshalling overhead. The application server or hardware has not been tuned in anyway and the sample processes are simple as well. So with that said, it's not meant to provide complete performance report but rather a base line. More advanced performance tests can be performed on dedicated hardware and with tuned application server and database for optimal performance.


Instruction for execution

In case someone would like to try these tests themselves, here are few steps one how to do it.

  1. Download and install jBPM 7.8.0 (or newer)
    1. download 
    2. getting started 
  2. Change data base to PostgreSQL or MySQL - see getting started (bottom of the page)
  3. Import this project into workbench on your running jBPM server
  4. Download and start JMeter
  5. Open this script in JMeter
  6. Run the selected scenario.