cancel
Showing results for 
Search instead for 
Did you mean: 

Process instances migration

penusila611621
Champ in-the-making
Champ in-the-making
Is there any way in Activit to migrate in flight instances onto newer version of process definition.
1 ACCEPTED ANSWER

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi.

code snippet from activiti sources:

    // start process instance
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("receiveTask");

    // check that receive task has been reached
    Execution execution = runtimeService.createExecutionQuery()
      .processInstanceId(pi.getId())
      .activityId("waitState1")
      .singleResult();
    assertNotNull(execution);
   
    // deploy new version of the process definition
    org.activiti.engine.repository.Deployment deployment = repositoryService
      .createDeployment()
      .addClasspathResource(TEST_PROCESS)
      .deploy();
    assertEquals(2, repositoryService.createProcessDefinitionQuery().count());

    // migrate process instance to new process definition version
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
    commandExecutor.execute(new SetProcessDefinitionVersionCmd(pi.getId(), 2));

    // signal process instance
    runtimeService.signal(execution.getId());

    // check that the instance now uses the new process definition version
    ProcessDefinition newProcessDefinition = repositoryService
      .createProcessDefinitionQuery()
      .processDefinitionVersion(2)
      .singleResult();
    pi = runtimeService
      .createProcessInstanceQuery()
      .processInstanceId(pi.getId())
      .singleResult();
    assertEquals(newProcessDefinition.getId(), pi.getProcessDefinitionId());
   
    // check history
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
      HistoricProcessInstance historicPI = historyService
        .createHistoricProcessInstanceQuery()
        .processInstanceId(pi.getId())
        .singleResult();
      assertEquals(newProcessDefinition.getId(), historicPI.getProcessDefinitionId());
    }

    // undeploy "manually" deployed process definition
    repositoryService.deleteDeployment(deployment.getId(), true);

Regards
Martin

View answer in original post

15 REPLIES 15

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi.

There is SetProcessDefinitionVersionCmd.
In general there is no automatic way how to upgrade running process instances to newer process definition. In the case of need you can do that manually.

Regards
Martin.

penusila611621
Champ in-the-making
Champ in-the-making
Would you please elobarate how to use this command. Since I am very new to activiti.

penusila611621
Champ in-the-making
Champ in-the-making
Also..i am using moduler and not eclipse plug in. please let me know how to use above command

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,
This question is not new. Try to read following threads:
http://forums.activiti.org/search/node/SetProcessDefinitionVersionCmd

It can help to understand How/Why/Why not…. .
Regards
Martin

penusila611621
Champ in-the-making
Champ in-the-making
After going thorugh the threads the link lead you posed. I have written a java class as below to test instances migration.

package com.mindtree.cps.common;

import org.activiti.engine.ActivitiException;
import org.activiti.engine.impl.cmd.SetProcessDefinitionVersionCmd;
import org.activiti.engine.impl.interceptor.CommandExecutor;
import org.activiti.engine.impl.test.PluggableActivitiTestCase;

public class MigrateInstances extends PluggableActivitiTestCase{

   public void testSetProcessDefinitionVersionNonExistingPI() {
   
      System.out.print("About to get command executor object");
     
      try {
       CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
       if(commandExecutor != null){
       
        commandExecutor.execute(new SetProcessDefinitionVersionCmd("14811", 14816)); //23 is a random number
        System.out.println("————- object commandExecutor is not null ————-");
       
       }
       else System.out.println("————- object commandExecutor is null ————-");
       
       //fail("ActivitiException expected");
       
      } catch (ActivitiException ae) {
      
        //assertTextPresent("No process instance found for id = '42'.", ae.getMessage());
        System.out.println("————- Exception thrown ————-" + ae.getLocalizedMessage());
       
      }
    }
}


When I try to test this class, I am getting the errors as attched.Am I missing something here. Since I am new to activiti not able to trace reason behind this error.

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

Do you use jUnit test in war deployment?
Use jUnit tests outside of you web application for testing purposes. They are usually not  part of production code.

Regards
Martin

I am not using JUnit test. Any help how to use JUnit test case. No clue on out side war deployment. I am using JBOSS server and Activiti modeler and not eclipse plugin. I do not want to use eclise plugin since modeler us quite easy for me since I am IBM BPM backgroud.

penusila611621
Champ in-the-making
Champ in-the-making
Hi Martin,

Let me know how to found Junit test suit present inside war deployment, if so how to remove them.

martin_grofcik
Confirmed Champ
Confirmed Champ
I think it is not good practice to use jUnit test inside war.
I would propose to make this special DB changes outside of war. (simple program with command line interface)