4 Replies Latest reply on Nov 11, 2010 5:57 PM by km wen

    Question about process instance migration

    km wen Newbie

      I have made two following process definition, the older named pd1, A->B->C, and instantiated as inscance1, the newer named pd2,  A->B.

       

      I'd like to know whether I can migrate the instance1 to the process definition pd2?

       

      thanks

        • 1. Re: Question to process instance migration
          Kris Verlaenen Master

          What version of jBPM are you talking about?

          • 2. Re: Question to process instance migration
            km wen Newbie

            Hi Kris, i am using  jBPM4.4

            • 3. Re: Question about process instance migration
              Michael Wohlfart Expert

              check out org.jbpm.test.migration.InstanceMigratorTest

              something like:

                [...]

                <migrate-instances>
                      <activity-mapping old-name='C' new-name='B'/>
                 </migrate-instances>

                [...]

               

              in your pd2 process definition should do the trick

              • 4. Re: Question to process instance migration
                km wen Newbie

                thanks, michael,

                it works, if i deploy new process definition from the same .xml file with different version as following:

                 

                ProcessDefinition pd1 = deployProcessDefinitionFromClasspath("org/jbpm/testMigration/a.jpdl.xml"); 
                  ProcessInstance pi1 = startAndSignal(pd1, "aa");
                  ProcessInstance pi2 = startAndSignal(pd1,"b");
                  ProcessInstance pi3 = startAndSignal(pd1,"c");
                 
                  assertTrue(pi3.isActive("c"));
                 
                  // here get new process definition
                  ProcessDefinition pd2 = deployProcessDefinitionFromClasspath("org/jbpm/testMigration/a.jpdl.xml");
                  assertEquals(pd2.getId(),"a-2");
                  pi3 = executionService.findProcessInstanceById(pi3.getId());
                  assertEquals(pd2.getId(),pi3.getProcessDefinitionId());
                 
                  // here the instances of the previously deployed process definition
                  //that are waiting in node "c" will be placed in the node "b".
                  assertTrue(pi3.isActive("b"));

                __________________________________________________________________________________________

                I have wrote following code, but it's failed. I want to get the new definition from another process .xml file.

                 

                  ProcessDefinition pd1 = deployProcessDefinitionFromClasspath("org/jbpm/testMigration/a.jpdl.xml"); 
                  ProcessInstance pi1 = startAndSignal(pd1, "aa");
                  ProcessInstance pi2 = startAndSignal(pd1,"b");
                ProcessInstance pi3 = startAndSignal(pd1,"c");
                 
                  assertTrue(pi3.isActive("c"));
                 
                  // here get new process definition
                  final ProcessDefinition pd2 = deployProcessDefinitionFromClasspath("org/jbpm/testMigration/a1.jpdl.xml");

                  final ProcessInstance pi = pi3;

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

                  });
                  assertTrue(pi3.isActive("b"));
                  }

                the error comes out:"org.jbpm.api.JbpmException: the activity null could not be found in the new process definition."

                 

                __________________________________________________________________________________________________

                 

                following is process definition .xml file:

                 

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

                <process name="a" xmlns="http://jbpm.org/4.4/jpdl">
                   <start g="33,107,48,48" name="s">
                      <transition to="aa"/>
                   </start>
                   <task g="138,107,92,52" name="aa">
                      <transition to="b"/>
                   </task>
                   <task g="274,108,92,52" name="b">
                      <transition to="c"/>
                   </task>
                   <task g="407,107,92,52" name="c">
                      <transition to="e"/>
                   </task>
                   <end g="549,109,48,48" name="e"/>
                  <migrate-instances>
                      <activity-mapping old-name="c" new-name="b"/>
                     </migrate-instances>
                </process>

                ________________________________-

                 

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

                <process name="a1" xmlns="http://jbpm.org/4.4/jpdl">    
                <start g="11,99,48,48" name="s">     
                  <transition to="aa"/>  
                   </start>     
                   <state g="106,94,110,52" name="aa">     
                   <transition to="x"/>   
                   </state>     
                   <state g="290,96,110,52" name="x">    
                    <transition to="e"/>   
                    </state>    
                     <end g="499,99,48,48" name="e"/>
                    
                </process>