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;
}
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());
}
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());
}
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);
}
}
}
}
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);
}
Aggregations