Search in sources :

Example 1 with MigrationReportInstanceList

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);
    }
}
Also used : RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) RestUtils.createCorrectVariant(org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant) Variant(javax.ws.rs.core.Variant) DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) MigrationReportInstanceList(org.kie.server.api.model.admin.MigrationReportInstanceList) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) NodeInstanceNotFoundException(org.jbpm.services.api.NodeInstanceNotFoundException) DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) ExecutionErrorNotFoundException(org.jbpm.services.api.admin.ExecutionErrorNotFoundException) NodeNotFoundException(org.jbpm.services.api.NodeNotFoundException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) PUT(javax.ws.rs.PUT)

Example 2 with MigrationReportInstanceList

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);
    }
}
Also used : RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) RestUtils.createCorrectVariant(org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant) Variant(javax.ws.rs.core.Variant) DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) MigrationReportInstanceList(org.kie.server.api.model.admin.MigrationReportInstanceList) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) NodeInstanceNotFoundException(org.jbpm.services.api.NodeInstanceNotFoundException) DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) ExecutionErrorNotFoundException(org.jbpm.services.api.admin.ExecutionErrorNotFoundException) NodeNotFoundException(org.jbpm.services.api.NodeNotFoundException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) PUT(javax.ws.rs.PUT)

Example 3 with MigrationReportInstanceList

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();
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) HashMap(java.util.HashMap) MigrationReportInstanceList(org.kie.server.api.model.admin.MigrationReportInstanceList) CommandScript(org.kie.server.api.commands.CommandScript)

Example 4 with MigrationReportInstanceList

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();
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) HashMap(java.util.HashMap) MigrationReportInstanceList(org.kie.server.api.model.admin.MigrationReportInstanceList) CommandScript(org.kie.server.api.commands.CommandScript)

Example 5 with MigrationReportInstanceList

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

Aggregations

MigrationReportInstanceList (org.kie.server.api.model.admin.MigrationReportInstanceList)7 MigrationReport (org.jbpm.services.api.admin.MigrationReport)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 HashMap (java.util.HashMap)2 Consumes (javax.ws.rs.Consumes)2 PUT (javax.ws.rs.PUT)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Variant (javax.ws.rs.core.Variant)2 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)2 NodeInstanceNotFoundException (org.jbpm.services.api.NodeInstanceNotFoundException)2 NodeNotFoundException (org.jbpm.services.api.NodeNotFoundException)2 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)2 ExecutionErrorNotFoundException (org.jbpm.services.api.admin.ExecutionErrorNotFoundException)2 CommandScript (org.kie.server.api.commands.CommandScript)2 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)2 KieServerCommand (org.kie.server.api.model.KieServerCommand)2 ServiceResponse (org.kie.server.api.model.ServiceResponse)2 MigrationReportInstance (org.kie.server.api.model.admin.MigrationReportInstance)2