3 Replies Latest reply on Sep 9, 2011 1:56 AM by Gary tse

    jBPM5 - Using as a state machine in clustered spring application with a dashboard

    Narayan Singh Newbie

      We're currently investigating to use BPM as a workflow/state machine for process orchestration in a very high volume clustered environment. Orchestration component is Spring application which sends and receives events from other component over MQ/REST and basically events decides process state transition.

       

      Here are some basic requirements for the Orchestration component we have and so far my observations with jBPM5 -

       

      1. Clustering and Server deployment - Multiple instances of orchestration component are deployed to the cluster, hence the process state is maintained across cluster and server instances can drop and join the cluster any time.

       

      Observation: If I use drools-spring to boot-strap my jBPM5 engine then I got 2 options - a) create new session or b) load existing session. But to load existing session I need to specify session id. In other words, I would need to write custom code upfront to decide whether I want to create new session or load existing one based on some thing, and this code needs to be cluster-safe as multiple instances starting up at the same time.

       

      So do you agree we cant use any out-of-the box solution here and one have to write custom boot-strap code?

       

      2. Dashboard support - We have our own platform-wide Dashboard and we want to add process state information to it, ideally using REST interface provided by jBPM. So we're not using any of jBPM console apps provided out-of-the-box.

       

      Observation: currently jBPM console functionality is consists of JBoss BPM modules(ex. org.jboss.bpm:gwt-console-server etc) hooked in with jBPM integration services as provided in jbpm-gwt-xxx modules. we cant use it out-of-the box because -

      1/ some of the jbpm-gwt-xxx modules have got persistence.xml with hard-wired H2 database details

      2/ they are tightly coupled with Human-task and Guvonor, however in our case we are bundling all our processes as part of the application and not using any WS-HT either. In other words state transition of our process is driven by the events.

       

      So as I understand we would need to build our version of "org.jboss.bpm:gwt-console-server" bundled with custom services to expose REST api to be used by dashboard. Would Knowledge api be used to extract current state from the database or am I missing something here?

       

      3. Persistence -  As I understand there are 2 forms of it - runtime state and auditing. Auditing is mainly pluggable using various listeners, and there are some out-of the box audit loggers available. For Runtime state, which is core part of jBPM5, I only see 3 entities -

           <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>

           <class>org.drools.persistence.info.SessionInfo</class>

           <class>org.drools.persistence.info.WorkItemInfo</class>

       

      Observation: Runtime state is stored in binary form and there is no relationship between tables, so merely looking at tables not able to say which process part of which session. So one has to use knowledgeSession to extract the information.

       

      I see loads of potential in jBPM5 and believe it could be used in our case. I would really appreciate any directions here to understand how it can solve our requirements as pointed out above?

        • 1. jBPM5 - Using as a state machine in clustered spring application with a dashboard
          Narayan Singh Newbie

          I think I found some answers after trwaling through the code and user forum. I would like to share them and see if anyone has got any comments:

           

          1. Clustering and Server deployment - Use a Spring bean to bootstrap jBPM using knowledgeBase api and restore Session from Database if it already exists. This bean will act as a Factory for KnowledgeSession.

           

          To benefit from all clustering features, I would ideally need to keep one instance of Session across the cluster.

          Questions:

          a) What is the best way to configure the session, especially when processes instances are not shared?

           

          2. Dashboard support - I would need to build my own Dashboard with our preferred UI technology, however I could use org.jboss.bpm:gwt-console-server for REST api(with plugged-in custom services)

           

          3. Event management - I would need to make use of  tasks(workItems)/events and another business layer to keep mapping between event meta-data to processInstance, workItem/eventId etc.. So when an business event occures I would be able to locate process instance then make following call to move it forward -

          ksession.

          getWorkItemManager().completeWorkItem(workItemId, parameters);

           

           

           

           

          As always any comments are highly appreciated.

           

          • 2. Re: jBPM5 - Using as a state machine in clustered spring application with a dashboard
            Arkady Perepelyuk Newbie

            I think there might be a problem with trying to share the same Knowledge Session across the cluster. I tried doing so and observed the following issue. A node tries to commit a transaction and finds out that entity SessionInfo has been updated by another transaction. The exception looks as follows:

             

             

             

            Hibernate: update SessionInfo set lastModificationDate=?, rulesByteArray=?, startDate=?, OPTLOCK=? where id=? and OPTLOCK=?

            Sep 7, 2011 10:39:34 PM org.drools.persistence.jta.JtaTransactionManager commit

            WARNING: Unable to commit transaction

            javax.persistence.OptimisticLockException

             

             

            : org.hibernate.StaleObjectStateException

            : Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [org.drools.persistence.info.SessionInfo#1]

             

             

             

            It should be noted that it's just a warning, but I'm not sure if the necessary updates are re-attempted in order to persist the state accuratly.

            • 3. Re: jBPM5 - Using as a state machine in clustered spring application with a dashboard
              Gary tse Newbie

              Hi Narayan,

               

              My team happens to be doing very similar stuff -- Orchestration of events using JBPM as a state machine.  The only difference is that we are using vanilla web service. 

               

              >>>

              Questions:

              a) What is the best way to configure the session, especially when processes instances are not shared?

               

              For now, we use a single StatefulKnowledgeSession in a "primary" cluster-node to handle all of the processes eventhough we receive webservice calls from multiple web containers.   If scaling is needed, my plan is to move to multiple StatefulKnowledgeSessions located in different cluster nodes;  then have a mapping/ look up method to find where the actual proceses are.

               

              2. Dashboard support

              Can't comment; we are not using this ... yet.

               

              3. Event management - I would need to make use of  tasks(workItems)/events and another business layer to keep mapping between event meta-data to processInstance, workItem/eventId etc.. So when an business event occures I would be able to locate process instance then make following call to move it forward - ksession.getWorkItemManager().completeWorkItem(workItemId, parameters)

               

              This is one part I find tricky too.  The events are unconditional.  Say, I have 10 instances of the same process type, each tries to receive a unique event to proceed.   Even though I can signal a EventType of 1-10 dynamically, I have no way to find out WHICH of the 10 instances is actually interested in my event.  For now, I just loop through all of the processes and notify each of them.   In the BPMN, I make a "loop" that conditions and loops back to waitfor the event again if the conditions do not match.