0 Replies Latest reply on Jan 31, 2017 5:41 PM by Manav Bhaykar

    How to resume JBPM process after system crash?

    Manav Bhaykar Newbie

      Hi,

      I have created sample JBPM prosess which contain two script task and two human task as shown below. I am stopping process execution while execution user task 2. After resuming, process should start form usertask 2. When am loading StatefulKnowledgeSession using session_id (session id of session when process execution stopped) and starting process it is starting from script task 1. How to persist complete task information of process and resume process from persisted state.@

       

      JBPM Process

      . Screen Shot 2017-02-01 at 3.51.00 AM.png

      Code for createProcess and ResumeProcess after system crash

       

       

        private static PoolingDataSource ds = new PoolingDataSource();

       

        private static void dataSource() {

             ds.setUniqueName("jdbc/jbpm-ds");

             ds.setClassName("com.mysql.jdbc.jdbc2.optional.MysqlXADataSource");

             ds.setMaxPoolSize(3);

             ds.setAllowLocalTransactions(true);

             ds.getDriverProperties().put("user", "root");

             ds.getDriverProperties().put("password", "root");

             ds.getDriverProperties().put("Url", "jdbc:mysql://localhost:3306/jbpm_db");

             ds.init();

        }

       

        @Test

        public void testCreateProcess() {

             dataSource();

       

             Environment env = EnvironmentFactory.newEnvironment();

             EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");

             env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);

             env.set(EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager());

             KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

       

             kbuilder.add(ResourceFactory.newClassPathResource("sampleProcess.bpmn"), ResourceType.BPMN2);

       

             KnowledgeBase kbase = kbuilder.newKnowledgeBase();

       

             StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);

       

             System.out.println(">>> Session id : " + ksession.getId());

       

             MockAsyncHTWorkItemHandler mockSyncHTWorkItemHandler = new MockAsyncHTWorkItemHandler();

             MockExternalServiceWorkItemHandler mockExternalServiceWorkItemHandler = new MockExternalServiceWorkItemHandler();

             ksession.getWorkItemManager().registerWorkItemHandler("Human Task", mockSyncHTWorkItemHandler);

       

       

             System.out.println(">>> Start process instance");

             ProcessInstance processInstance = ksession.startProcess("sampleProcess");

       

             System.out.println(">>> process id :-" + processInstance.getId());

       

            try {

                  Thread.sleep(5000);

             } catch (InterruptedException e) {

             }

             System.out.println(">>> Completing the first Human Interaction");

             ksession.getWorkItemManager().completeWorkItem(mockSyncHTWorkItemHandler.getId(), null);

       

           //here am stopping the process execution

             try {

                  Thread.sleep(5000);

             } catch (InterruptedException e) {

             }

             System.out.println(">>> Completing the first Human Interaction");

             ksession.getWorkItemManager().completeWorkItem(mockSyncHTWorkItemHandler.getId(), null);

       

        }

       

       

      @Test

        public void testResumeProcess() {

             dataSource();

       

             Environment env = EnvironmentFactory.newEnvironment();

             EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");

             env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);

             env.set(EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager());

             KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

       

             kbuilder.add(ResourceFactory.newClassPathResource("sampleProcess.bpmn"), ResourceType.BPMN2);

       

             KnowledgeBase kbase = kbuilder.newKnowledgeBase();

       

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

       

             ProcessInstance processInstance = ksession.getProcessInstance(4);

             System.out.println(">>>  Process state : " + processInstance.getState());

             ksession.startProcess(processInstance.getProcessId());

       

        }

       

       

      Persistence.xml

       

      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>

       

      <persistence version="1.0"

       

        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence

       

           http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd

       

           http://java.sun.com/xml/ns/persistence/orm

       

           http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"

       

        xmlns:orm="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       

        xmlns="http://java.sun.com/xml/ns/persistence">

       

        <persistence-unit name="org.jbpm.persistence.jpa" transaction-type="JTA">

       

        <provider>org.hibernate.ejb.HibernatePersistence</provider>

       

        <jta-data-source>jdbc/jbpm-ds</jta-data-source>

        <mapping-file>META-INF/JBPMorm.xml</mapping-file>

        <mapping-file>META-INF/ProcessInstanceInfo.hbm.xml</mapping-file>

       

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

       

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

       

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

       

       

        <properties>

       

        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />

       

        <property name="hibernate.max_fetch_depth" value="3" />

       

        <property name="hibernate.hbm2ddl.auto" value="update" />

       

        <property name="hibernate.show_sql" value="true" />

       

        <property name="hibernate.transaction.manager_lookup_class"

       

        value="org.hibernate.transaction.BTMTransactionManagerLookup" />

       

        </properties>

       

        </persistence-unit>

       

      </persistence>

       

       

       

      * for reference attached maven project