5 Replies Latest reply on May 18, 2010 3:36 AM by Sergey Telezhnikov

    Process instance migration problem

    Sergey Telezhnikov Newbie

      My problem is that the migration sometimes doesn’t work. And I cannot understand why.

      It would be good if someone could help me.

       

      I deploy two process definitions that are very simple. Both have only sequential activities:

      • First process definition: S-> A-> X-> E
      • Second process definition: S-> A-> X-> B> E.

      Where S is start activity, A, B and E are java activity and X is state activity.


      First use case that works: I deploy two definitions. Then I instantiate and start the first definition. In this case migration works and it migrates in activity X of the second process definition and activity B is executed.

       

      Second use case that doesn’t work: I deploy only the first process definition and then immediately run it. In this case execution waits for signal in activity X. Then I deploy second process definition, migrate instance to new second definition and signal the execution. But it will continue execution of the first definition, although running instance has a process definition Id set to the second definition.

       

      I don’t understand what can be wrong. Can someone explain me how exactly does Deployment works and why it is different, when I deploy two process definitions immediately and start the first or sequentially and start in between the first. I use DefaultMigrationHandler from jBPM 4.2.

      Sorry for my bad English.

        • 1. Re: Process instance migration problem
          Sebastian Schneider Master

          I don't understand the first "use case" as you call it. I think if you want help you'll be in the need to post the actual process definitions and a test case to demonstrate what you are trying to do.

          • 2. Re: Process instance migration problem
            HuiSheng Xu Master

            Hi Sergey,

              I cannot reproduce your scenario, so I make a testcase and upload it to attach.  Maybe you could use it to reproduce this problem for us.

             

              Thank you.

            • 3. Re: Process instance migration problem
              Sergey Telezhnikov Newbie

              Thanks for the answers. But what I do is more complicated. I use DefaultMigrationHandler from external code. My definitions have the different names and the second has not migration tag. Here is my testcase that represent my use case (simplified):

               

                  public void testMigrateRunning()
                    {
                      deployJpdlClasspath("org/uni/stuttgart/iaas/fragments/test/a.jpdl.xml");


                      ProcessInstance processInstance = executionService
                          .startProcessInstanceById("a-1");
                      assertTrue(processInstance.isActive("a"));


                      String id = processInstance.getId();
                      processInstance = executionService.signalExecutionById(id);
                      assertTrue(processInstance.isActive("x"));



                      deployJpdlClasspath("org/uni/stuttgart/iaas/fragments/test/b.jpdl.xml");



                      processInstance = executionService.signalExecutionById(id);
                      assertTrue(processInstance.isActive("b"));
                      processInstance = executionService.signalExecutionById(id);
                      assertTrue(processInstance.isEnded());
                    }


                  public void testMigrateRunningIntern()
                    {
                      deployJpdlClasspath("org/uni/stuttgart/iaas/fragments/test/a.jpdl.xml");


                      ProcessInstance processInstance = executionService
                          .startProcessInstanceById("a-1");
                      assertTrue(processInstance.isActive("a"));


                      String id = processInstance.getId();
                      processInstance = executionService.signalExecutionById(id);
                      assertTrue(processInstance.isActive("x"));



                      String deploymentId = deployJpdlClasspath("org/uni/stuttgart/iaas/fragments/test/c.jpdl.xml");
                      // Get new process definition
                      ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(
                          deploymentId).uniqueResult();
                      assertTrue(processDefinition.getName().equalsIgnoreCase("c"));
                      // Migrate instance here
                      new DefaultMigrationHandler().migrateInstance(processDefinition, processInstance, new MigrationDescriptor());



                      processInstance = executionService.signalExecutionById(id);
                      assertTrue(processInstance.isActive("b"));
                      processInstance = executionService.signalExecutionById(id);
                      assertTrue(processInstance.isEnded());
                    }

               

              The first test is ok, the second is failed.

               

              jpdl definition a:

               

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

               

              <process name="a" xmlns="http://jbpm.org/4.3/jpdl">

               

                <start g="11,99,48,48" name="s">
                   <transition to="a"/>
                </start>

               

                <state g="106,94,110,52" name="a">
                  <transition to="x"/>
                </state>

               

                <state g="279,176,110,52" name="x">
                  <transition to="e"/>
                </state>

               

                <end g="499,99,48,48" name="e"/>

               

              </process>


              jpdl definition b:

               

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

               

              <process name="a" xmlns="http://jbpm.org/4.3/jpdl">

               

                <start g="11,99,48,48" name="s">
                   <transition to="a"/>
                </start>

               

                <state g="106,94,110,52" name="a">
                  <transition to="x"/>
                </state>

               

                <state g="234,185,110,52" name="x">
                  <transition to="b"/>
                </state>

               

                <state g="371,92,110,52" name="b">
                  <transition to="e"/>
                </state>

               

                <end g="549,92,48,48" name="e"/>
                <migrate-instances/>
              </process>


              jpdl definition c:

               

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

               

              <process name="c" xmlns="http://jbpm.org/4.3/jpdl">

               

                <start g="11,99,48,48" name="s">
                   <transition to="a"/>
                </start>

               

                <state g="106,94,110,52" name="a">
                  <transition to="x"/>
                </state>

               

                <state g="234,185,110,52" name="x">
                  <transition to="b"/>
                </state>

               

                <state g="371,92,110,52" name="b">
                  <transition to="e"/>
                </state>

               

                <end g="549,92,48,48" name="e"/>

               

              </process>

               

              Any help would be appreciated.

              • 4. Re: Process instance migration problem
                HuiSheng Xu Master

                Hi Sergey,

                 

                After migrate processinstance to a new processDefinition,  you should update the modifed processInstance to database.  Otherwise database couldn't know the processInstance has changed.  So it seems the migration operation has no effect.

                 

                You could use Command to do this:

                 

                processEngine.execute(new Command() {
                            public Object execute(Environment env) {
                                new DefaultMigrationHandler().migrateInstance(pd,
                                    pi, new MigrationDescriptor());
                                env.get(Session.class).update(pi);
                                return null;
                            }
                        });

                 

                I attached the testcase.  Please have a try.  Thank you.