use of org.kie.server.api.model.admin.MigrationSpecification in project droolsjbpm-integration by kiegroup.
the class ProcessInstanceMigrationIntegrationTest method testUpgradeParentInstanceWithSubprocesses.
@Test
public void testUpgradeParentInstanceWithSubprocesses() {
Long processParentInstanceId = processClient.startProcess(CONTAINER_ID, PARENT_WITH_SUBPROCESSES_ID);
assertNotNull(processParentInstanceId);
assertTrue(processParentInstanceId > 0);
logger.info("Process in container {} has started {}", CONTAINER_ID, processParentInstanceId);
List<ProcessInstance> childrenProcessInstances = processClient.findProcessInstancesByParent(CONTAINER_ID, processParentInstanceId, 0, 10);
assertEquals(2, childrenProcessInstances.size());
assertProcessInstancesInfo(childrenProcessInstances, "subprocess", "1.0", CONTAINER_ID, SUBPROCESS_ID, processParentInstanceId);
List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
assertEquals(2, tasks.size());
assertTasksInfo(tasks, "Evaluate items?", CONTAINER_ID, SUBPROCESS_ID);
MigrationSpecification spec = new MigrationSpecification();
MigrationProcessSpecification pSpecParent = new MigrationProcessSpecification();
pSpecParent.setSourceProcessId(PARENT_WITH_SUBPROCESSES_ID);
pSpecParent.setTargetProcessId(PARENT_WITH_SUBPROCESSES_ID_2);
MigrationProcessSpecification pSpecChild = new MigrationProcessSpecification();
pSpecChild.setSourceProcessId(SUBPROCESS_ID);
pSpecChild.setTargetProcessId(SUBPROCESS_ID_2);
spec.setProcesses(Arrays.asList(pSpecParent, pSpecChild));
ProcessInstance piMigrate = processClient.getProcessInstance(CONTAINER_ID, processParentInstanceId);
assertProcessInstanceInfo(piMigrate, "parentWithSubProcesses", "1.0", CONTAINER_ID, PARENT_WITH_SUBPROCESSES_ID);
logger.info("about to process migration from container {} to {} with process definition {} with id {}", piMigrate.getContainerId(), CONTAINER_ID_2, piMigrate.getProcessId(), processParentInstanceId);
assertMigrateProcessInstanceWithSubprocess(processParentInstanceId, CONTAINER_ID, CONTAINER_ID_2, spec, 3);
piMigrate = processClient.getProcessInstance(CONTAINER_ID_2, processParentInstanceId);
assertNotNull(piMigrate);
assertProcessInstanceInfo(piMigrate, "parentWithSubProcesses2", "1.0.1", CONTAINER_ID_2, PARENT_WITH_SUBPROCESSES_ID_2);
childrenProcessInstances = processClient.findProcessInstancesByParent(CONTAINER_ID_2, processParentInstanceId, 0, 10);
logger.info("children instances from {} fetched", CONTAINER_ID_2);
assertEquals(2, childrenProcessInstances.size());
assertProcessInstancesInfo(childrenProcessInstances, "subprocess2", "1.0.1", CONTAINER_ID_2, SUBPROCESS_ID_2, processParentInstanceId);
// it stays in the same task
tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
assertAndCompleteTasks(tasks, 2, USER_YODA, CONTAINER_ID_2, SUBPROCESS_ID_2);
logger.info("migration tested!");
}
use of org.kie.server.api.model.admin.MigrationSpecification in project droolsjbpm-integration by kiegroup.
the class ProcessAdminServiceBase method migrateProcessInstanceWithAllSubprocess.
public MigrationReportInstanceList migrateProcessInstanceWithAllSubprocess(String containerId, Number processInstanceId, String targetContainerId, String payload, String marshallingType) {
ProcessInstanceDesc pi = runtimeDataService.getProcessInstanceById(processInstanceId.longValue());
if (pi.getParentId() > 0) {
throw new IllegalArgumentException("Only root process can invoke this migration with all subprocesses");
}
MigrationSpecification migrationSpecification = new MigrationSpecification();
if (payload != null) {
logger.debug("About to unmarshal node mapping from payload: '{}' using container {} marshaller", payload, containerId);
migrationSpecification = marshallerHelper.unmarshal(containerId, payload, marshallingType, MigrationSpecification.class);
}
List<Long> processInstancesId = new ArrayList<>(runtimeDataService.getProcessInstancesWithSubprocessByProcessInstanceId(processInstanceId.longValue(), singletonList(ProcessInstance.STATE_ACTIVE), new QueryContext(0, -1)).stream().map(ProcessInstanceDesc::getId).collect(Collectors.toList()));
processInstancesId.add(processInstanceId.longValue());
List<MigrationReport> reports = new ArrayList<>();
for (Long processInstanceToMigrateId : processInstancesId) {
ProcessInstanceDesc piToMigrate = runtimeDataService.getProcessInstanceById(processInstanceToMigrateId);
Optional<MigrationProcessSpecification> spec = migrationSpecification.getProcesses().stream().filter(e -> piToMigrate.getProcessId().equals(e.getSourceProcessId())).findFirst();
if (!spec.isPresent()) {
logger.error("MigrationProcessSpecification is not correct. Process Instance Id " + processInstanceToMigrateId + " won't be migrated");
continue;
}
String targetProcessId = spec.get().getTargetProcessId();
Map<String, String> nodeMapping = spec.get().getNodes();
reports.add(processInstanceMigrationService.migrate(containerId, processInstanceToMigrateId, targetContainerId, targetProcessId, nodeMapping));
}
return convertMigrationReports(reports);
}
use of org.kie.server.api.model.admin.MigrationSpecification in project droolsjbpm-integration by kiegroup.
the class ProcessInstanceMigrationIntegrationTest method testUpgradeParentInstanceWithMultipleSubprocesses.
@Test
public void testUpgradeParentInstanceWithMultipleSubprocesses() {
Long processParentInstanceId = processClient.startProcess(CONTAINER_ID, PARENT_WITH_MULTIPLE_SUBPROCESSES_ID);
assertNotNull(processParentInstanceId);
assertTrue(processParentInstanceId > 0);
logger.info("Process in container {} has started {}", CONTAINER_ID, processParentInstanceId);
List<ProcessInstance> childrenProcessInstance = processClient.findProcessInstancesByParent(CONTAINER_ID, processParentInstanceId, 0, 10);
assertEquals(1, childrenProcessInstance.size());
assertProcessInstancesInfo(childrenProcessInstance, "subprocessCallingAnotherSubProcess", "1.0", CONTAINER_ID, SUBPROCESS_CALLING_ANOTHER_SUBPROCESS_ID, processParentInstanceId);
List<ProcessInstance> childrenSubProcessInstance = processClient.findProcessInstancesByParent(CONTAINER_ID, childrenProcessInstance.get(0).getId(), 0, 10);
assertEquals(1, childrenSubProcessInstance.size());
assertProcessInstancesInfo(childrenSubProcessInstance, "subprocess", "1.0", CONTAINER_ID, SUBPROCESS_ID, childrenSubProcessInstance.get(0).getParentId());
List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
assertEquals(1, tasks.size());
assertTasksInfo(tasks, "Evaluate items?", CONTAINER_ID, SUBPROCESS_ID);
MigrationSpecification spec = new MigrationSpecification();
MigrationProcessSpecification pSpecParent = new MigrationProcessSpecification();
pSpecParent.setSourceProcessId(PARENT_WITH_MULTIPLE_SUBPROCESSES_ID);
pSpecParent.setTargetProcessId(PARENT_WITH_MULTIPLE_SUBPROCESSES_ID_2);
MigrationProcessSpecification pSpecChild = new MigrationProcessSpecification();
pSpecChild.setSourceProcessId(SUBPROCESS_CALLING_ANOTHER_SUBPROCESS_ID);
pSpecChild.setTargetProcessId(SUBPROCESS_CALLING_ANOTHER_SUBPROCESS_ID_2);
MigrationProcessSpecification pSpecSubChild = new MigrationProcessSpecification();
pSpecSubChild.setSourceProcessId(SUBPROCESS_ID);
pSpecSubChild.setTargetProcessId(SUBPROCESS_ID_2);
spec.setProcesses(Arrays.asList(pSpecParent, pSpecChild, pSpecSubChild));
ProcessInstance piMigrate = processClient.getProcessInstance(CONTAINER_ID, processParentInstanceId);
assertProcessInstanceInfo(piMigrate, "parentWithMultipleSubProcesses", "1.0", CONTAINER_ID, PARENT_WITH_MULTIPLE_SUBPROCESSES_ID);
logger.info("about to process migration from container {} to {} with process definition {} with id {}", piMigrate.getContainerId(), CONTAINER_ID_2, piMigrate.getProcessId(), processParentInstanceId);
assertMigrateProcessInstanceWithSubprocess(processParentInstanceId, CONTAINER_ID, CONTAINER_ID_2, spec, 3);
piMigrate = processClient.getProcessInstance(CONTAINER_ID_2, processParentInstanceId);
assertNotNull(piMigrate);
assertProcessInstanceInfo(piMigrate, "parentWithMultipleSubProcesses2", "1.0.1", CONTAINER_ID_2, PARENT_WITH_MULTIPLE_SUBPROCESSES_ID_2);
childrenProcessInstance = processClient.findProcessInstancesByParent(CONTAINER_ID_2, processParentInstanceId, 0, 10);
logger.info("children instance from {} fetched", CONTAINER_ID_2);
assertEquals(1, childrenProcessInstance.size());
assertProcessInstancesInfo(childrenProcessInstance, "subprocessCallingAnotherSubProcess2", "1.0.1", CONTAINER_ID_2, SUBPROCESS_CALLING_ANOTHER_SUBPROCESS_ID_2, processParentInstanceId);
childrenSubProcessInstance = processClient.findProcessInstancesByParent(CONTAINER_ID_2, childrenProcessInstance.get(0).getId(), 0, 10);
logger.info("children instance from {} fetched", CONTAINER_ID_2);
assertEquals(1, childrenSubProcessInstance.size());
assertProcessInstancesInfo(childrenSubProcessInstance, "subprocess2", "1.0.1", CONTAINER_ID_2, SUBPROCESS_ID_2, childrenProcessInstance.get(0).getId());
// it stays in the same task
tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
assertAndCompleteTasks(tasks, 1, USER_YODA, CONTAINER_ID_2, SUBPROCESS_ID_2);
logger.info("migration tested!");
}
use of org.kie.server.api.model.admin.MigrationSpecification in project droolsjbpm-integration by kiegroup.
the class ProcessInstanceMigrationIntegrationTest method testUpgradeInvalidParentInstanceWithSubprocesses.
@Test
public void testUpgradeInvalidParentInstanceWithSubprocesses() {
Long processParentInstanceId = processClient.startProcess(CONTAINER_ID, PARENT_WITH_MULTIPLE_SUBPROCESSES_ID);
try {
assertNotNull(processParentInstanceId);
assertTrue(processParentInstanceId > 0);
logger.info("Process in container {} has started {}", CONTAINER_ID, processParentInstanceId);
List<ProcessInstance> childrenProcessInstance = processClient.findProcessInstancesByParent(CONTAINER_ID, processParentInstanceId, 0, 10);
assertEquals(1, childrenProcessInstance.size());
Long childrenProcessInstanceId = childrenProcessInstance.get(0).getId();
assertNotNull(childrenProcessInstanceId);
assertTrue(childrenProcessInstanceId > 0);
assertProcessInstancesInfo(childrenProcessInstance, "subprocessCallingAnotherSubProcess", "1.0", CONTAINER_ID, SUBPROCESS_CALLING_ANOTHER_SUBPROCESS_ID, processParentInstanceId);
List<ProcessInstance> childrenSubProcessInstance = processClient.findProcessInstancesByParent(CONTAINER_ID, childrenProcessInstanceId, 0, 10);
assertEquals(1, childrenSubProcessInstance.size());
assertProcessInstancesInfo(childrenSubProcessInstance, "subprocess", "1.0", CONTAINER_ID, SUBPROCESS_ID, childrenSubProcessInstance.get(0).getParentId());
List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
assertEquals(1, tasks.size());
assertTasksInfo(tasks, "Evaluate items?", CONTAINER_ID, SUBPROCESS_ID);
MigrationSpecification spec = new MigrationSpecification();
MigrationProcessSpecification pSpecParent = new MigrationProcessSpecification();
pSpecParent.setSourceProcessId(PARENT_WITH_MULTIPLE_SUBPROCESSES_ID);
pSpecParent.setTargetProcessId(PARENT_WITH_MULTIPLE_SUBPROCESSES_ID_2);
MigrationProcessSpecification pSpecChild = new MigrationProcessSpecification();
pSpecChild.setSourceProcessId(SUBPROCESS_CALLING_ANOTHER_SUBPROCESS_ID);
pSpecChild.setTargetProcessId(SUBPROCESS_CALLING_ANOTHER_SUBPROCESS_ID_2);
MigrationProcessSpecification pSpecSubChild = new MigrationProcessSpecification();
pSpecSubChild.setSourceProcessId(SUBPROCESS_ID);
pSpecSubChild.setTargetProcessId(SUBPROCESS_ID_2);
spec.setProcesses(Arrays.asList(pSpecParent, pSpecChild, pSpecSubChild));
assertThrows(KieServicesException.class, () -> processAdminClient.migrateProcessInstanceWithSubprocess(CONTAINER_ID, childrenProcessInstanceId, CONTAINER_ID_2, spec));
} finally {
try {
processClient.getProcessInstance(CONTAINER_ID_2, processParentInstanceId);
processClient.abortProcessInstance(CONTAINER_ID_2, processParentInstanceId);
} catch (KieServicesException e) {
processClient.abortProcessInstance(CONTAINER_ID, processParentInstanceId);
}
}
}
Aggregations