8 Replies Latest reply: Sep 19, 2012 4:14 AM by nbd RSS

Restart JBPM5 Process after system crash

Swaminathan Bhaskar Newbie

I am using JBPM5 V5.2 and exploring the basic BPM functionality. I have a simple persistent process definition - a script task and a signal task that converge on a AND gateway and finally execute a script task before the process ends. I am testing the persistence capabilities by killing the process (to simulate system crash) before the signal (after the first script task). I want to restart the process and continue with the signal and the second script task. How does one load process instances that have not yet completed (crash) ? Any help or pointers appreciated.

  • 1. Re: Restart JBPM5 Process after system crash
    Jimmy dong Newbie

    Do you use yourself app? not use console? if so, I hava the same problem with you.

    And do you mind share your bpmn file and code? I want to study how to use

    signal task ,thanks!!

  • 2. Re: Restart JBPM5 Process after system crash
    Swaminathan Bhaskar Newbie

    After some searching looks like we will have to get the sessionId and save it aside and use it later to restart the process. Is this correct ? Is there a know pattern for managing the sessionId ? Anyone solved this ? Can anyone help ?. Thanks

  • 3. Re: Restart JBPM5 Process after system crash
    Swaminathan Bhaskar Newbie

    Is this the correct way to identify and restart a crashed process instance ?

     

                        ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, null, env);
                        if (ksession != null) {
                             Collection instances = ksession.getProcessInstances();
                             if (instances != null && instances.size() > 0) {
                                  for (ProcessInstance processInstance : instances) {
                                       System.out.printf("\n*** Restarting old Business process [%s]\n", processInstance.getProcessId());
                                       
                                       // Start the BPM process
                                       ksession.startProcessInstance(processInstance.getId());
                                       
                                       // Trigger the signal
                                       ksession.signalEvent("Trigger", null);
                                       
                                       // Did the process instance complete successfully ?
                                       if (processInstance.getState() == ProcessInstance.STATE_COMPLETED) {
                                            System.out.printf("\nBusiness process [%s] successfully completed after restart\n", processInstance.getProcessId());
                                       }
                                  }
                             }
                        }
                        else {
                             System.out.println("***** WARNING: No session found for session-id " + sessionId);
                        }
    
    

    This is not working and I get the following exception:

     

    Hibernate: select sessioninf0_.id as id1_0_, sessioninf0_.lastModificationDate as lastModi2_1_0_, sessioninf0_.rulesByteArray as rulesByt3_1_0_, sessioninf0_.startDate as startDate1_0_, sessioninf0_.OPTLOCK as OPTLOCK1_0_ from SessionInfo s

    essioninf0_ where sessioninf0_.id=?

    0    11/06 20:43:55,210[main] ERROR drools.persistence.SingleSessionCommandService.rollbackTransaction  - Could not commit session

    java.lang.NullPointerException

            at org.jbpm.persistence.processinstance.JPAProcessInstanceManager.getProcessInstances(JPAProcessInstanceManager.java:97)

            at org.jbpm.process.instance.ProcessRuntimeImpl.getProcessInstances(ProcessRuntimeImpl.java:200)

            at org.drools.common.AbstractWorkingMemory.getProcessInstances(AbstractWorkingMemory.java:1093)

            at org.drools.impl.StatefulKnowledgeSessionImpl.getProcessInstances(StatefulKnowledgeSessionImpl.java:292)

            at org.drools.command.runtime.process.GetProcessInstancesCommand.execute(GetProcessInstancesCommand.java:35)

            at org.drools.command.runtime.process.GetProcessInstancesCommand.execute(GetProcessInstancesCommand.java:28)

            at org.drools.command.impl.DefaultCommandService.execute(DefaultCommandService.java:36)

            at org.drools.persistence.SingleSessionCommandService.execute(SingleSessionCommandService.java:345)

            at org.drools.command.impl.CommandBasedStatefulKnowledgeSession.getProcessInstances(CommandBasedStatefulKnowledgeSession.java:139)

     

    Any ideas ?

  • 4. Re: Restart JBPM5 Process after system crash
    Demian Calcaprina Master

    Hey,

     

    at the moment of the "crash", the processes has been persisted? A process is persisted when it reaches a "wait state". I catching signal event is a wait state.

     

    If so, you can simply do,

    ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, null, env);

    ksession.signalEvent("Trigger", null);

     

    as the processes are already persisted in db.

     

    Demian

  • 5. Re: Restart JBPM5 Process after system crash
    Swaminathan Bhaskar Newbie

    Thank for the useful tip Demian. This means I need to keep track of the sessiin ID as well as the process ID so that I can recreate the session and check the process status.

  • 6. Re: Restart JBPM5 Process after system crash
    nbd Newbie

    Hi,

     

    Did you solve it? I'm having the same problem. My process instances are persisted - I can look them up in the database. After server restart I reload the previous session,

    but the process instances don't continue. What ksession.signalEvent("Trigger", null); is supposed to do here? My process instances are not waiting for any event and even

    if they were, they wouldn't react as the instances are not being executed.

  • 7. Re: Restart JBPM5 Process after system crash
    hansi007 Newbie

    Another option could be to remember the work_item / work_item_id that you stopped at without completing it. Than you can continue that process by completing that workitem:

     

    int workitemId = ... //From the work item that you remembered.
    StatefulKnowledgeSession ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, config, env );
    WorkItemManager wManager =  ksession.getWorkItemManager();
    wManager.completeWorkItem(workitemId,null);
    
  • 8. Re: Restart JBPM5 Process after system crash
    nbd Newbie

    Yes, but I would like to execute the unfinished workitem, and calling wManager.completeWorkItem(workitemId,null); will just complete it without executing workitemhandlercode