Search in sources :

Example 6 with MigrationReportInstance

use of org.kie.server.api.model.admin.MigrationReportInstance in project droolsjbpm-integration by kiegroup.

the class ProcessAdminServicesClientImpl method migrateProcessInstance.

@Override
public MigrationReportInstance migrateProcessInstance(String containerId, Long processInstanceId, String targetContainerId, String targetProcessId, Map<String, String> nodeMapping) {
    MigrationReportInstance reportInstance = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(PROCESS_INST_ID, processInstanceId);
        Map<String, String> headers = new HashMap<String, String>();
        String queryString = "?targetContainerId=" + targetContainerId + "&targetProcessId=" + targetProcessId;
        reportInstance = makeHttpPutRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), ADMIN_PROCESS_URI + "/" + MIGRATE_PROCESS_INST_PUT_URI, valuesMap) + queryString, nodeMapping, MigrationReportInstance.class, headers);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("ProcessAdminService", "migrateProcessInstance", serialize(safeMap(nodeMapping)), marshaller.getFormat().getType(), new Object[] { containerId, processInstanceId, targetContainerId, targetProcessId })));
        ServiceResponse<MigrationReportInstance> response = (ServiceResponse<MigrationReportInstance>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM", containerId).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        reportInstance = response.getResult();
    }
    return reportInstance;
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) MigrationReportInstance(org.kie.server.api.model.admin.MigrationReportInstance) HashMap(java.util.HashMap) CommandScript(org.kie.server.api.commands.CommandScript)

Example 7 with MigrationReportInstance

use of org.kie.server.api.model.admin.MigrationReportInstance in project droolsjbpm-integration by kiegroup.

the class KieServerMigrationTest method testProcessStartAndAbort.

@Test
public void testProcessStartAndAbort() {
    // query for all available process definitions
    QueryServicesClient queryClient = kieServicesClient.getServicesClient(QueryServicesClient.class);
    ProcessServicesClient processClient = kieServicesClient.getServicesClient(ProcessServicesClient.class);
    ProcessAdminServicesClient processAdminClient = kieServicesClient.getServicesClient(ProcessAdminServicesClient.class);
    // start process instance
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("employee", "john");
    params.put("reason", "test on spring boot");
    Long processInstanceId = processClient.startProcess(containerId, processId, params);
    assertNotNull(processInstanceId);
    ProcessInstance processInstance = queryClient.findProcessInstanceById(processInstanceId);
    assertNotNull(processInstance);
    assertEquals(1, processInstance.getState().intValue());
    assertEquals(containerId, processInstance.getContainerId());
    try {
        MigrationReportInstance report = processAdminClient.migrateProcessInstance(containerId, processInstanceId, containerId2, processId);
        assertTrue(report.isSuccessful());
        processInstance = queryClient.findProcessInstanceById(processInstanceId);
        assertNotNull(processInstance);
        assertEquals(1, processInstance.getState().intValue());
        assertEquals(containerId2, processInstance.getContainerId());
    } catch (Exception ex) {
        // clean up if failure
        try {
            processClient.abortProcessInstance(containerId, processInstanceId);
        } catch (Exception abortEx) {
            logger.warn("Error aborting process instance over container " + containerId, abortEx);
        }
        fail("Migration failed: " + ex);
        throw ex;
    }
    // abort process instance (outside try/catch), to not hide exception that will certainly occur if  migration fails
    processClient.abortProcessInstance(containerId2, processInstanceId);
    processInstance = queryClient.findProcessInstanceById(processInstanceId);
    assertNotNull(processInstance);
    assertEquals(3, processInstance.getState().intValue());
}
Also used : QueryServicesClient(org.kie.server.client.QueryServicesClient) HashMap(java.util.HashMap) MigrationReportInstance(org.kie.server.api.model.admin.MigrationReportInstance) ProcessAdminServicesClient(org.kie.server.client.admin.ProcessAdminServicesClient) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) ProcessServicesClient(org.kie.server.client.ProcessServicesClient) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with MigrationReportInstance

use of org.kie.server.api.model.admin.MigrationReportInstance in project droolsjbpm-integration by kiegroup.

the class JobServiceMigrationIntegrationTest method testMigrateAndRequeueFailingJob.

@Test(timeout = 60000)
public void testMigrateAndRequeueFailingJob() throws Exception {
    Long pid = processClient.startProcess(CONTAINER_ID1, PROCESS_ID);
    waitForErrors(CONTAINER_ID1, 15000L);
    // first container has a wrong deployment-structure (without CustomWorkItemHandler definition), so job ends up in Error status
    List<RequestInfoInstance> errors = jobServicesClient.getRequestsByContainer(CONTAINER_ID1, singletonList(ERROR.toString()), 0, 10);
    Long jobId = errors.get(0).getId();
    // migrate process instance to container 2 (right deployment-structure containing the CustomWorkItemHandler definition)
    MigrationReportInstance report = processAdminClient.migrateProcessInstance(CONTAINER_ID1, pid, CONTAINER_ID2, PROCESS_ID);
    assertNotNull(report);
    assertTrue(report.isSuccessful());
    jobServicesClient.requeueRequest(jobId);
    KieServerSynchronization.waitForJobToFinish(jobServicesClient, jobId);
    RequestInfoInstance jobRequest = jobServicesClient.getRequestById(jobId, false, false);
    assertNotNull(jobRequest);
    assertEquals(jobId, jobRequest.getId());
    assertEquals("org.jbpm.process.core.async.AsyncSignalEventCommand", jobRequest.getCommandName());
    assertEquals(DONE.toString(), jobRequest.getStatus());
}
Also used : MigrationReportInstance(org.kie.server.api.model.admin.MigrationReportInstance) RequestInfoInstance(org.kie.server.api.model.instance.RequestInfoInstance) Test(org.junit.Test)

Example 9 with MigrationReportInstance

use of org.kie.server.api.model.admin.MigrationReportInstance in project droolsjbpm-integration by kiegroup.

the class ProcessInstanceMigrationIntegrationTest method testUpgradeProcessInstancesWithNodeMapping.

@Test
public void testUpgradeProcessInstancesWithNodeMapping() {
    List<Long> ids = new ArrayList<Long>();
    for (int i = 0; i < 5; i++) {
        Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_EVALUATION);
        ids.add(processInstanceId);
    }
    try {
        List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
        assertEquals(5, tasks.size());
        for (TaskSummary task : tasks) {
            assertEquals("Evaluate items?", tasks.get(0).getName());
            assertEquals(CONTAINER_ID, task.getContainerId());
            assertEquals(PROCESS_ID_EVALUATION, task.getProcessId());
        }
        Map<String, String> nodeMapping = new HashMap<String, String>();
        nodeMapping.put("_4E8E7545-FB70-494E-9136-2B9ABE655889", "_56FB3E50-DEDD-415B-94DD-0357C91836B9");
        // migrate process instance to evaluation 2 in container 2
        List<MigrationReportInstance> reports = processAdminClient.migrateProcessInstances(CONTAINER_ID, ids, CONTAINER_ID_2, PROCESS_ID_EVALUATION_2, nodeMapping);
        assertNotNull(reports);
        assertEquals(5, reports.size());
        for (MigrationReportInstance report : reports) {
            assertTrue(report.isSuccessful());
        }
        // but next task should be Approve user task
        tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
        assertEquals(5, tasks.size());
        for (TaskSummary task : tasks) {
            assertEquals("Approve", task.getName());
            assertEquals(CONTAINER_ID_2, task.getContainerId());
            assertEquals(PROCESS_ID_EVALUATION_2, task.getProcessId());
        }
    } finally {
        for (Long processInstanceId : ids) {
            try {
                processClient.getProcessInstance(CONTAINER_ID_2, processInstanceId);
                processClient.abortProcessInstance(CONTAINER_ID_2, processInstanceId);
            } catch (KieServicesException e) {
                processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) MigrationReportInstance(org.kie.server.api.model.admin.MigrationReportInstance) ArrayList(java.util.ArrayList) TaskSummary(org.kie.server.api.model.instance.TaskSummary) KieServicesException(org.kie.server.api.exception.KieServicesException) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 10 with MigrationReportInstance

use of org.kie.server.api.model.admin.MigrationReportInstance in project droolsjbpm-integration by kiegroup.

the class ProcessAdminServiceBase method convertMigrationReports.

/*
     * helper methods
     */
protected MigrationReportInstanceList convertMigrationReports(List<MigrationReport> reports) {
    if (reports == null) {
        return new MigrationReportInstanceList();
    }
    MigrationReportInstance[] reportInstances = new MigrationReportInstance[reports.size()];
    int index = 0;
    for (MigrationReport report : reports) {
        MigrationReportInstance instance = convertMigrationReport(report);
        reportInstances[index] = instance;
        index++;
    }
    return new MigrationReportInstanceList(reportInstances);
}
Also used : MigrationReportInstance(org.kie.server.api.model.admin.MigrationReportInstance) MigrationReportInstanceList(org.kie.server.api.model.admin.MigrationReportInstanceList) MigrationReport(org.jbpm.services.api.admin.MigrationReport)

Aggregations

MigrationReportInstance (org.kie.server.api.model.admin.MigrationReportInstance)12 Test (org.junit.Test)6 HashMap (java.util.HashMap)4 KieServicesException (org.kie.server.api.exception.KieServicesException)4 TaskSummary (org.kie.server.api.model.instance.TaskSummary)4 JbpmKieServerBaseIntegrationTest (org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)4 MigrationReport (org.jbpm.services.api.admin.MigrationReport)3 ArrayList (java.util.ArrayList)2 CaseMigrationReport (org.jbpm.casemgmt.api.admin.CaseMigrationReport)2 MigrationReportInstanceList (org.kie.server.api.model.admin.MigrationReportInstanceList)2 CaseMigrationReportInstance (org.kie.server.api.model.cases.CaseMigrationReportInstance)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Variant (javax.ws.rs.core.Variant)1 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)1 NodeInstanceNotFoundException (org.jbpm.services.api.NodeInstanceNotFoundException)1