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

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

Would you please provide me the sample migration process which can be run in modeler.

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

Modeler does not provide this functionality. Modeler models process definitions. I thought your process upgrade question was "How to upgrade process definition in the running process instance?"

Regards
Martin

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

My requriement is how to migrate in flight instances of running for process def (Ex: A) onto newer version of same process definition.

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

penusila611621
Champ in-the-making
Champ in-the-making
Great & Many thanks Martin.

jperez11
Champ in-the-making
Champ in-the-making
Hello Martin,

Is it possible to invoke SetProcessDefinitionVersionCmd from inside an event? I've been trying, but I'm affraid is not possible because the new deployment has not been created yet. Thanks.

Kind regards,
Jonathan.