use of org.kie.server.api.model.admin.MigrationReportInstanceList in project droolsjbpm-integration by kiegroup.
the class ProcessAdminResource method migrateProcessInstanceWithSubprocess.
@ApiOperation(value = "Migrates a specified process instance with all subprocesses to process definition in another KIE container.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Process instance or Container Id not found"), @ApiResponse(code = 404, message = "Container Id not found"), @ApiResponse(code = 201, response = MigrationReportInstanceList.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = GET_MIGRATION_REPORTS_RESPONSE_JSON) })) })
@PUT
@Path(MIGRATE_PROCESS_SUBPROCESS_INST_PUT_URI)
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response migrateProcessInstanceWithSubprocess(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "container id that process instances belongs to", required = true, example = "evaluation_1.0.0-SNAPSHOT") @PathParam(CONTAINER_ID) String containerId, @ApiParam(value = "list of identifiers of process instance to be migrated", required = true) @PathParam(PROCESS_INST_ID) Long processInstanceId, @ApiParam(value = "container id that new process definition belongs to", required = true) @QueryParam("targetContainerId") String targetContainerId, @ApiParam(value = "process definition that process instances should be migrated to", required = true) @QueryParam("targetProcessId") String targetProcessId, @ApiParam(value = "migration specifcation. It contains process mapping and node mapping - unique ids of old definition to new definition given as Map", required = false, examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = MIGRATION_VAR_MAP_JSON), @ExampleProperty(mediaType = XML, value = MIGRATION_VAR_MAP_XML) })) String payload) {
Variant v = getVariant(headers);
String type = getContentType(headers);
Header conversationIdHeader = buildConversationIdHeader(containerId, context, headers);
try {
MigrationReportInstanceList reportInstances = processAdminServiceBase.migrateProcessInstanceWithAllSubprocess(containerId, processInstanceId, targetContainerId, payload, type);
return createCorrectVariant(reportInstances, headers, Response.Status.CREATED, conversationIdHeader);
} catch (ProcessInstanceNotFoundException e) {
return notFound(MessageFormat.format(PROCESS_INSTANCE_NOT_FOUND, processInstanceId), v, conversationIdHeader);
} catch (DeploymentNotFoundException e) {
return notFound(MessageFormat.format(CONTAINER_NOT_FOUND, containerId), v, conversationIdHeader);
} catch (Exception e) {
logger.error("Unexpected error during processing {}", e.getMessage(), e);
return internalServerError(errorMessage(e), v, conversationIdHeader);
}
}
use of org.kie.server.api.model.admin.MigrationReportInstanceList in project droolsjbpm-integration by kiegroup.
the class ProcessAdminResource method migrateProcessInstances.
@ApiOperation(value = "Migrates multiple process instances to process definition in another KIE container.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Process instance or Container Id not found"), @ApiResponse(code = 404, message = "Container Id not found"), @ApiResponse(code = 201, response = MigrationReportInstanceList.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = GET_MIGRATION_REPORTS_RESPONSE_JSON) })) })
@PUT
@Path(MIGRATE_PROCESS_INSTANCES_PUT_URI)
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response migrateProcessInstances(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "container id that process instances belongs to", required = true, example = "evaluation_1.0.0-SNAPSHOT") @PathParam(CONTAINER_ID) String containerId, @ApiParam(value = "list of identifiers of process instance to be migrated", required = true) @QueryParam(PROCESS_INST_ID) List<Long> processInstanceIds, @ApiParam(value = "container id that new process definition belongs to", required = true) @QueryParam("targetContainerId") String targetContainerId, @ApiParam(value = "process definition that process instances should be migrated to", required = true) @QueryParam("targetProcessId") String targetProcessId, @ApiParam(value = "node mapping - unique ids of old definition to new definition given as Map", required = false, examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = SIMPLE_VAR_MAP_JSON), @ExampleProperty(mediaType = XML, value = SIMPLE_VAR_MAP_XML) })) String payload) {
Variant v = getVariant(headers);
String type = getContentType(headers);
Header conversationIdHeader = buildConversationIdHeader(containerId, context, headers);
try {
MigrationReportInstanceList reportInstances = processAdminServiceBase.migrateProcessInstances(containerId, processInstanceIds, targetContainerId, targetProcessId, payload, type);
return createCorrectVariant(reportInstances, headers, Response.Status.CREATED, conversationIdHeader);
} catch (ProcessInstanceNotFoundException e) {
return notFound(MessageFormat.format(PROCESS_INSTANCE_NOT_FOUND, processInstanceIds), v, conversationIdHeader);
} catch (DeploymentNotFoundException e) {
return notFound(MessageFormat.format(CONTAINER_NOT_FOUND, containerId), v, conversationIdHeader);
} catch (Exception e) {
logger.error("Unexpected error during processing {}", e.getMessage(), e);
return internalServerError(errorMessage(e), v, conversationIdHeader);
}
}
use of org.kie.server.api.model.admin.MigrationReportInstanceList in project droolsjbpm-integration by kiegroup.
the class ProcessAdminServicesClientImpl method migrateProcessInstances.
@Override
public List<MigrationReportInstance> migrateProcessInstances(String containerId, List<Long> processInstancesId, String targetContainerId, String targetProcessId, Map<String, String> nodeMapping) {
MigrationReportInstanceList reportInstanceList = null;
if (config.isRest()) {
Map<String, Object> valuesMap = new HashMap<String, Object>();
valuesMap.put(CONTAINER_ID, containerId);
Map<String, String> headers = new HashMap<String, String>();
String queryStringBase = buildQueryString(PROCESS_INST_ID, processInstancesId);
String queryString = queryStringBase + "&targetContainerId=" + targetContainerId + "&targetProcessId=" + targetProcessId;
reportInstanceList = makeHttpPutRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), ADMIN_PROCESS_URI + "/" + MIGRATE_PROCESS_INSTANCES_PUT_URI, valuesMap) + queryString, nodeMapping, MigrationReportInstanceList.class, headers);
} else {
CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("ProcessAdminService", "migrateProcessInstances", serialize(safeMap(nodeMapping)), marshaller.getFormat().getType(), new Object[] { containerId, processInstancesId, targetContainerId, targetProcessId })));
ServiceResponse<MigrationReportInstanceList> response = (ServiceResponse<MigrationReportInstanceList>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM", containerId).getResponses().get(0);
throwExceptionOnFailure(response);
if (shouldReturnWithNullResponse(response)) {
return null;
}
reportInstanceList = response.getResult();
}
if (reportInstanceList != null) {
return reportInstanceList.getItems();
}
return Collections.emptyList();
}
use of org.kie.server.api.model.admin.MigrationReportInstanceList in project droolsjbpm-integration by kiegroup.
the class ProcessAdminServicesClientImpl method migrateProcessInstanceWithSubprocess.
@Override
public List<MigrationReportInstance> migrateProcessInstanceWithSubprocess(String containerId, Long processInstanceId, String targetContainerId, MigrationSpecification migrationSpecification) {
MigrationReportInstanceList reportInstanceList = null;
if (config.isRest()) {
Map<String, Object> valuesMap = new HashMap<>();
valuesMap.put(CONTAINER_ID, containerId);
valuesMap.put(PROCESS_INST_ID, processInstanceId);
Map<String, String> headers = new HashMap<>();
String queryString = "?targetContainerId=" + targetContainerId;
reportInstanceList = makeHttpPutRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), ADMIN_PROCESS_URI + "/" + MIGRATE_PROCESS_SUBPROCESS_INST_PUT_URI, valuesMap) + queryString, migrationSpecification, MigrationReportInstanceList.class, headers);
} else {
CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("ProcessAdminService", "migrateProcessInstanceWithAllSubprocess", serialize(migrationSpecification), marshaller.getFormat().getType(), new Object[] { containerId, processInstanceId, targetContainerId })));
ServiceResponse<MigrationReportInstanceList> response = (ServiceResponse<MigrationReportInstanceList>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM", containerId).getResponses().get(0);
throwExceptionOnFailure(response);
if (shouldReturnWithNullResponse(response)) {
return null;
}
reportInstanceList = response.getResult();
}
if (reportInstanceList != null) {
return reportInstanceList.getItems();
}
return Collections.emptyList();
}
use of org.kie.server.api.model.admin.MigrationReportInstanceList 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);
}
Aggregations