Skip to content

Commit

Permalink
[incubator-kie-issues-861] Process instance migration (apache#2005)
Browse files Browse the repository at this point in the history
* [incubator-kie-issues-916] Process Instance Migration
  • Loading branch information
elguardian authored and rgdoliveira committed Apr 16, 2024
1 parent 2ad3dd7 commit 30b05f3
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,10 @@ public void testProcessGatewayAPI() throws IOException {
.statusCode(200)
.body("data.ProcessInstances[0].nodeDefinitions", notNullValue())
.body("data.ProcessInstances[0].nodeDefinitions.size()", is(4))
.body("data.ProcessInstances[0].nodeDefinitions[0].id", is("1"))
.body("data.ProcessInstances[0].nodeDefinitions[0].id", is("_8B62D3CA-5D03-4B2B-832B-126469288BB4"))
.body("data.ProcessInstances[0].nodeDefinitions[0].name", is("First Line Approval"))
.body("data.ProcessInstances[0].nodeDefinitions[0].type", is("HumanTaskNode"))
.body("data.ProcessInstances[0].nodeDefinitions[0].uniqueId", is("1"))
.body("data.ProcessInstances[0].nodeDefinitions[0].uniqueId", is("_8B62D3CA-5D03-4B2B-832B-126469288BB4"))
.body("data.ProcessInstances[0].nodeDefinitions[0].metadata.UniqueId", is("_8B62D3CA-5D03-4B2B-832B-126469288BB4"))
.body("data.ProcessInstances[0].nodes.size()", is(2))
.body("data.ProcessInstances[0].nodes.name", hasItem("First Line Approval"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.kie.kogito.event.process.ProcessInstanceNodeEventBody;
import org.kie.kogito.event.process.ProcessInstanceSLADataEvent;
import org.kie.kogito.event.process.ProcessInstanceStateDataEvent;
import org.kie.kogito.event.process.ProcessInstanceStateEventBody;
import org.kie.kogito.event.process.ProcessInstanceVariableDataEvent;
import org.kie.kogito.event.usertask.UserTaskInstanceAssignmentDataEvent;
import org.kie.kogito.event.usertask.UserTaskInstanceAttachmentDataEvent;
Expand All @@ -64,7 +65,6 @@
import org.kie.kogito.event.usertask.UserTaskInstanceDeadlineDataEvent;
import org.kie.kogito.event.usertask.UserTaskInstanceStateDataEvent;
import org.kie.kogito.event.usertask.UserTaskInstanceVariableDataEvent;
import org.kie.kogito.internal.process.runtime.KogitoProcessInstance;
import org.kie.kogito.jobs.service.model.ScheduledJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -95,29 +95,17 @@ public void storeProcessInstanceDataEvent(DataAuditContext context, ProcessInsta
log.setRoles(event.getData().getRoles());

EntityManager entityManager = context.getContext();
switch (event.getData().getState()) {
case KogitoProcessInstance.STATE_ACTIVE:
switch (event.getData().getEventType()) {
case ProcessInstanceStateEventBody.EVENT_TYPE_STARTED:
log.setEventType(ProcessStateLogType.ACTIVE);
entityManager.persist(log);
break;
case KogitoProcessInstance.STATE_ABORTED:
log.setEventType(ProcessStateLogType.ABORTED);
entityManager.persist(log);
break;
case KogitoProcessInstance.STATE_COMPLETED:
case ProcessInstanceStateEventBody.EVENT_TYPE_ENDED:
log.setEventType(ProcessStateLogType.COMPLETED);
entityManager.persist(log);
break;
case KogitoProcessInstance.STATE_PENDING:
log.setEventType(ProcessStateLogType.PENDING);
entityManager.persist(log);
break;
case KogitoProcessInstance.STATE_SUSPENDED:
log.setEventType(ProcessStateLogType.SUSPENDING);
entityManager.persist(log);
break;
case KogitoProcessInstance.STATE_ERROR:
log.setEventType(ProcessStateLogType.ERROR);
case ProcessInstanceStateEventBody.EVENT_TYPE_MIGRATED:
log.setEventType(ProcessStateLogType.MIGRATED);
entityManager.persist(log);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,9 @@ public class ProcessInstanceStateLog extends AbstractProcessInstanceLog {

public enum ProcessStateLogType {
ACTIVE,
STARTED,
COMPLETED,
ABORTED,
MIGRATED,
SLA_VIOLATION,
PENDING,
SUSPENDING,
ERROR
}

@Id
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE Process_Instance_State_Log DROP CONSTRAINT Process_Instance_State_Log_event_type_check;
ALTER TABLE Process_Instance_State_Log ADD CONSTRAINT Process_Instance_State_Log_event_type_check CHECK (event_type IN ( 'ACTIVE','COMPLETED','SLA_VIOLATION', 'MIGRATED' ));
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE Process_Instance_State_Log DROP CONSTRAINT Process_Instance_State_Log_event_type_check;
ALTER TABLE Process_Instance_State_Log ADD CONSTRAINT Process_Instance_State_Log_event_type_check CHECK (event_type IN ( 'ACTIVE','COMPLETED','SLA_VIOLATION', 'MIGRATED' ));
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public CompletableFuture<List<Node>> getProcessDefinitionNodes(String serviceURL
List<org.kie.api.definition.process.Node> nodes = ((KogitoWorkflowProcess) ((AbstractProcess<?>) process).get()).getNodesRecursively();
List<Node> list = nodes.stream().map(n -> {
Node data = new Node();
data.setId(String.valueOf(n.getId()));
data.setId(n.getId().toExternalFormat());
data.setUniqueId(((org.jbpm.workflow.core.Node) n).getUniqueId());
data.setMetadata(n.getMetaData() == null ? null : mapMetadata(n));
data.setType(n.getClass().getSimpleName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ void testDataIndexAddon() {
.body("data.ProcessDefinitions[0].addons", hasItem("infinispan-persistence"))
.body("data.ProcessDefinitions[0].source", is(not(emptyOrNullString())))
.body("data.ProcessDefinitions[0].nodes.size()", is(2))
.body("data.ProcessDefinitions[0].nodes[0].id", is("1"))
.body("data.ProcessDefinitions[0].nodes[0].id", is("_B3241ACF-97BE-443B-A49F-964AB3DD006C"))
.body("data.ProcessDefinitions[0].nodes[0].name", is("End"))
.body("data.ProcessDefinitions[0].nodes[0].type", is("EndNode"))
.body("data.ProcessDefinitions[0].nodes[0].uniqueId", is("1"))
.body("data.ProcessDefinitions[0].nodes[0].uniqueId", is("_B3241ACF-97BE-443B-A49F-964AB3DD006C"))
.body("data.ProcessDefinitions[0].nodes[0].metadata.UniqueId", is("_B3241ACF-97BE-443B-A49F-964AB3DD006C"));

given().contentType(ContentType.JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void testDataIndexAddon() {
.body("data.ProcessDefinitions[0].nodes[0].name", is("Start"))
.body("data.ProcessDefinitions[0].nodes[0].type", is("StartNode"))
.body("data.ProcessDefinitions[0].nodes[0].uniqueId", is("1"))
.body("data.ProcessDefinitions[0].nodes[0].metadata.UniqueId", is("_jbpm-unique-0"))
.body("data.ProcessDefinitions[0].nodes[0].metadata.UniqueId", is("1"))
.extract().path("data.ProcessDefinitions[0].source");

assertThat(JsonPath.from(source).getString("id")).isEqualTo("greet");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ void testDataIndexAddon() {
.body("data.ProcessDefinitions[0].addons", hasItem("mongodb-persistence"))
.body("data.ProcessDefinitions[0].source", is(not(emptyOrNullString())))
.body("data.ProcessDefinitions[0].nodes.size()", is(2))
.body("data.ProcessDefinitions[0].nodes[0].id", is("1"))
.body("data.ProcessDefinitions[0].nodes[0].id", is("_B3241ACF-97BE-443B-A49F-964AB3DD006C"))
.body("data.ProcessDefinitions[0].nodes[0].name", is("End"))
.body("data.ProcessDefinitions[0].nodes[0].type", is("EndNode"))
.body("data.ProcessDefinitions[0].nodes[0].uniqueId", is("1"))
.body("data.ProcessDefinitions[0].nodes[0].uniqueId", is("_B3241ACF-97BE-443B-A49F-964AB3DD006C"))
.body("data.ProcessDefinitions[0].nodes[0].metadata.UniqueId", is("_B3241ACF-97BE-443B-A49F-964AB3DD006C"));

given().contentType(ContentType.JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void testDataIndexAddon() {
.body("data.ProcessDefinitions[0].nodes[0].name", is("Start"))
.body("data.ProcessDefinitions[0].nodes[0].type", is("StartNode"))
.body("data.ProcessDefinitions[0].nodes[0].uniqueId", is("1"))
.body("data.ProcessDefinitions[0].nodes[0].metadata.UniqueId", is("_jbpm-unique-0"))
.body("data.ProcessDefinitions[0].nodes[0].metadata.UniqueId", is("1"))
.extract().path("data.ProcessDefinitions[0].source");

assertThat(JsonPath.from(source).getString("id")).isEqualTo("greet");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ void testDataIndexAddon() {
.body("data.ProcessDefinitions[0].addons", hasItem("jdbc-persistence"))
.body("data.ProcessDefinitions[0].source", is(not(emptyOrNullString())))
.body("data.ProcessDefinitions[0].nodes.size()", is(2))
.body("data.ProcessDefinitions[0].nodes[0].id", is("1"))
.body("data.ProcessDefinitions[0].nodes[0].id", is("_B3241ACF-97BE-443B-A49F-964AB3DD006C"))
.body("data.ProcessDefinitions[0].nodes[0].name", is("End"))
.body("data.ProcessDefinitions[0].nodes[0].type", is("EndNode"))
.body("data.ProcessDefinitions[0].nodes[0].uniqueId", is("1"))
.body("data.ProcessDefinitions[0].nodes[0].uniqueId", is("_B3241ACF-97BE-443B-A49F-964AB3DD006C"))
.body("data.ProcessDefinitions[0].nodes[0].metadata.UniqueId", is("_B3241ACF-97BE-443B-A49F-964AB3DD006C"));

given().contentType(ContentType.JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void testDataIndexAddon() {
.body("data.ProcessDefinitions[0].nodes[0].name", is("Start"))
.body("data.ProcessDefinitions[0].nodes[0].type", is("StartNode"))
.body("data.ProcessDefinitions[0].nodes[0].uniqueId", is("1"))
.body("data.ProcessDefinitions[0].nodes[0].metadata.UniqueId", is("_jbpm-unique-0"))
.body("data.ProcessDefinitions[0].nodes[0].metadata.UniqueId", is("1"))
.extract().path("data.ProcessDefinitions[0].source");

assertThat(JsonPath.from(source).getString("id")).isEqualTo("greet");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.kie.kogito.jobs.embedded;

import java.util.Optional;

import org.kie.kogito.Application;
import org.kie.kogito.Model;
import org.kie.kogito.jobs.service.api.Recipient;
Expand Down Expand Up @@ -53,12 +55,21 @@ public Uni<JobExecutionResponse> execute(JobDetails jobDetails) {
RecipientInstance recipientModel = (RecipientInstance) jobDetails.getRecipient();
InVMRecipient recipient = (InVMRecipient) recipientModel.getRecipient();
String timerId = recipient.getPayload().getData().timerId();
String processId = recipient.getPayload().getData().processId();
Process<? extends Model> process = processes.processById(processId);
String processInstanceId = recipient.getPayload().getData().processInstanceId();
Optional<Process<? extends Model>> process = processes.processByProcessInstanceId(processInstanceId);
if (process.isEmpty()) {
return Uni.createFrom().item(
JobExecutionResponse.builder()
.code("401")
.jobId(jobDetails.getId())
.now()
.message("job does not belong to this container")
.build());
}

Integer limit = jobDetails.getRetries();

TriggerJobCommand command = new TriggerJobCommand(processInstanceId, correlationId, timerId, limit, process, application.unitOfWorkManager());
TriggerJobCommand command = new TriggerJobCommand(processInstanceId, correlationId, timerId, limit, process.get(), application.unitOfWorkManager());

return Uni.createFrom().item(command::execute)
.onFailure()
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">


<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down

0 comments on commit 30b05f3

Please sign in to comment.