Search in sources :

Example 1 with MigrationSpecification

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!");
}
Also used : MigrationProcessSpecification(org.kie.server.api.model.admin.MigrationProcessSpecification) TaskSummary(org.kie.server.api.model.instance.TaskSummary) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) MigrationSpecification(org.kie.server.api.model.admin.MigrationSpecification) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 2 with MigrationSpecification

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);
}
Also used : MigrationProcessSpecification(org.kie.server.api.model.admin.MigrationProcessSpecification) MigrationReport(org.jbpm.services.api.admin.MigrationReport) ExecutionErrorInstanceList(org.kie.server.api.model.admin.ExecutionErrorInstanceList) LoggerFactory(org.slf4j.LoggerFactory) MarshallerHelper(org.kie.server.services.impl.marshal.MarshallerHelper) TimerInstance(org.jbpm.services.api.admin.TimerInstance) ProcessInstanceAdminService(org.jbpm.services.api.admin.ProcessInstanceAdminService) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) ExecutionErrorInstance(org.kie.server.api.model.admin.ExecutionErrorInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessNodeList(org.kie.server.api.model.admin.ProcessNodeList) Map(java.util.Map) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) ConvertUtils.convertToErrorInstance(org.kie.server.services.jbpm.ConvertUtils.convertToErrorInstance) MigrationEntry(org.jbpm.services.api.admin.MigrationEntry) NodeInstanceList(org.kie.server.api.model.instance.NodeInstanceList) ConvertUtils(org.kie.server.services.jbpm.ConvertUtils) ConvertUtils.convertToErrorInstanceList(org.kie.server.services.jbpm.ConvertUtils.convertToErrorInstanceList) Logger(org.slf4j.Logger) Collection(java.util.Collection) MigrationReportInstanceList(org.kie.server.api.model.admin.MigrationReportInstanceList) TimerInstanceList(org.kie.server.api.model.admin.TimerInstanceList) ProcessInstanceMigrationService(org.jbpm.services.api.admin.ProcessInstanceMigrationService) QueryContext(org.kie.api.runtime.query.QueryContext) Collectors(java.util.stream.Collectors) ProcessNode(org.jbpm.services.api.admin.ProcessNode) KieServerRegistry(org.kie.server.services.api.KieServerRegistry) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) List(java.util.List) ConvertUtils.buildQueryContext(org.kie.server.services.jbpm.ConvertUtils.buildQueryContext) ExecutionError(org.kie.internal.runtime.error.ExecutionError) RuntimeDataService(org.jbpm.services.api.RuntimeDataService) MigrationReportInstance(org.kie.server.api.model.admin.MigrationReportInstance) Optional(java.util.Optional) MigrationSpecification(org.kie.server.api.model.admin.MigrationSpecification) Collections(java.util.Collections) MigrationProcessSpecification(org.kie.server.api.model.admin.MigrationProcessSpecification) ArrayList(java.util.ArrayList) MigrationReport(org.jbpm.services.api.admin.MigrationReport) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) MigrationSpecification(org.kie.server.api.model.admin.MigrationSpecification) QueryContext(org.kie.api.runtime.query.QueryContext) ConvertUtils.buildQueryContext(org.kie.server.services.jbpm.ConvertUtils.buildQueryContext)

Example 3 with MigrationSpecification

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!");
}
Also used : MigrationProcessSpecification(org.kie.server.api.model.admin.MigrationProcessSpecification) TaskSummary(org.kie.server.api.model.instance.TaskSummary) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) MigrationSpecification(org.kie.server.api.model.admin.MigrationSpecification) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 4 with MigrationSpecification

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);
        }
    }
}
Also used : MigrationProcessSpecification(org.kie.server.api.model.admin.MigrationProcessSpecification) TaskSummary(org.kie.server.api.model.instance.TaskSummary) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) MigrationSpecification(org.kie.server.api.model.admin.MigrationSpecification) KieServicesException(org.kie.server.api.exception.KieServicesException) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Aggregations

MigrationProcessSpecification (org.kie.server.api.model.admin.MigrationProcessSpecification)4 MigrationSpecification (org.kie.server.api.model.admin.MigrationSpecification)4 Test (org.junit.Test)3 ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)3 TaskSummary (org.kie.server.api.model.instance.TaskSummary)3 JbpmKieServerBaseIntegrationTest (org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)3 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 RuntimeDataService (org.jbpm.services.api.RuntimeDataService)1 MigrationEntry (org.jbpm.services.api.admin.MigrationEntry)1 MigrationReport (org.jbpm.services.api.admin.MigrationReport)1 ProcessInstanceAdminService (org.jbpm.services.api.admin.ProcessInstanceAdminService)1 ProcessInstanceMigrationService (org.jbpm.services.api.admin.ProcessInstanceMigrationService)1 ProcessNode (org.jbpm.services.api.admin.ProcessNode)1