Search in sources :

Example 1 with ProcessError

use of org.kie.kogito.process.ProcessError in project kogito-runtimes by kiegroup.

the class PublishEventIT method testServiceTaskProcessWithError.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testServiceTaskProcessWithError() throws Exception {
    Application app = generateCodeProcessesOnly("servicetask/ServiceProcessDifferentOperations.bpmn2");
    assertThat(app).isNotNull();
    TestEventPublisher publisher = new TestEventPublisher();
    app.unitOfWorkManager().eventManager().setService("http://myhost");
    app.unitOfWorkManager().eventManager().addPublisher(publisher);
    UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    Process<? extends Model> p = app.get(Processes.class).processById("ServiceProcessDifferentOperations");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    m.fromMap(parameters);
    ProcessInstance processInstance = p.createInstance(m);
    processInstance.start();
    uow.end();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ERROR);
    List<DataEvent<?>> events = publisher.extract();
    assertThat(events).isNotNull().hasSize(1);
    ProcessInstanceEventBody body = assertProcessInstanceEvent(events.get(0), "ServiceProcessDifferentOperations", "Service Process", 5);
    assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("StartNode", "WorkItemNode");
    assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
    // human task is active thus null for leave time
    assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
    assertThat(body.getError()).isNotNull();
    assertThat(body.getError().getErrorMessage()).contains("java.lang.NullPointerException");
    assertThat(body.getError().getNodeDefinitionId()).isEqualTo("_38E04E27-3CCA-47F9-927B-E37DC4B8CE25");
    parameters.put("s", "john");
    m.fromMap(parameters);
    uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    processInstance.updateVariables(m);
    uow.end();
    events = publisher.extract();
    assertThat(events).isNotNull().hasSize(1);
    body = assertProcessInstanceEvent(events.get(0), "ServiceProcessDifferentOperations", "Service Process", 5);
    assertThat(body.getError()).isNotNull();
    assertThat(body.getError().getErrorMessage()).contains("java.lang.NullPointerException");
    assertThat(body.getError().getNodeDefinitionId()).isEqualTo("_38E04E27-3CCA-47F9-927B-E37DC4B8CE25");
    uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    if (processInstance.error().isPresent()) {
        ((ProcessError) processInstance.error().get()).retrigger();
    }
    uow.end();
    events = publisher.extract();
    assertThat(events).isNotNull().hasSize(1);
    body = assertProcessInstanceEvent(events.get(0), "ServiceProcessDifferentOperations", "Service Process", 2);
    assertThat(body.getError()).isNull();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).hasSize(1).containsKeys("s");
    assertThat(result.toMap().get("s")).isNotNull().isEqualTo("Goodbye Hello john!!");
}
Also used : UnitOfWork(org.kie.kogito.uow.UnitOfWork) HashMap(java.util.HashMap) ProcessInstanceEventBody(org.kie.kogito.services.event.impl.ProcessInstanceEventBody) UserTaskInstanceDataEvent(org.kie.kogito.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(org.kie.kogito.services.event.ProcessInstanceDataEvent) DataEvent(org.kie.kogito.event.DataEvent) VariableInstanceDataEvent(org.kie.kogito.services.event.VariableInstanceDataEvent) Processes(org.kie.kogito.process.Processes) ProcessError(org.kie.kogito.process.ProcessError) Model(org.kie.kogito.Model) ProcessInstance(org.kie.kogito.process.ProcessInstance) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Example 2 with ProcessError

use of org.kie.kogito.process.ProcessError in project kogito-runtimes by kiegroup.

the class MockCacheProcessInstancesTest method testBasicFlowWithError.

private void testBasicFlowWithError(Consumer<ProcessInstance<BpmnVariables>> op) {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask-Script.bpmn2")).get(0);
    // workaround as BpmnProcess does not compile the scripts but just reads the xml
    for (Node node : ((WorkflowProcess) process.get()).getNodes()) {
        if (node instanceof ActionNode) {
            DroolsAction a = ((ActionNode) node).getAction();
            a.setMetaData("Action", (Action) kcontext -> {
                System.out.println("The variable value is " + kcontext.getVariable("s") + " about to call toString on it");
                kcontext.getVariable("s").toString();
            });
        }
    }
    process.setProcessInstancesFactory(new CacheProcessInstancesFactory(cacheManager));
    process.configure();
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create());
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(STATE_ERROR);
    Optional<ProcessError> errorOp = processInstance.error();
    assertThat(errorOp).isPresent();
    assertThat(errorOp.get().failedNodeId()).isEqualTo("ScriptTask_1");
    assertThat(errorOp.get().errorMessage()).isNotNull().contains("java.lang.NullPointerException");
    op.accept(processInstance);
    assertThat(processInstance.error()).isNotPresent();
    WorkItem workItem = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john"))).get(0);
    assertThat(workItem).isNotNull();
    assertThat(workItem.getParameters().get("ActorId")).isEqualTo("john");
    processInstance.completeWorkItem(workItem.getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
    assertThat(processInstance.status()).isEqualTo(STATE_COMPLETED);
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) MetadataValueImpl(org.infinispan.client.hotrod.impl.MetadataValueImpl) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) WorkflowProcess(org.jbpm.workflow.core.WorkflowProcess) STATE_ACTIVE(org.kie.kogito.internal.process.runtime.KogitoProcessInstance.STATE_ACTIVE) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RemoteCache(org.infinispan.client.hotrod.RemoteCache) ProcessInstances(org.kie.kogito.process.ProcessInstances) RemoteCacheManager(org.infinispan.client.hotrod.RemoteCacheManager) STATE_COMPLETED(org.kie.kogito.internal.process.runtime.KogitoProcessInstance.STATE_COMPLETED) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) DroolsAction(org.jbpm.workflow.core.DroolsAction) RemoteCacheManagerAdmin(org.infinispan.client.hotrod.RemoteCacheManagerAdmin) ActionNode(org.jbpm.workflow.core.node.ActionNode) BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) StaticIdentityProvider(org.kie.kogito.services.identity.StaticIdentityProvider) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SecurityPolicy(org.kie.kogito.auth.SecurityPolicy) Mockito.when(org.mockito.Mockito.when) Assertions.entry(org.assertj.core.api.Assertions.entry) KogitoProcessInstancesFactory(org.kie.kogito.persistence.KogitoProcessInstancesFactory) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) List(java.util.List) ProcessInstance(org.kie.kogito.process.ProcessInstance) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Node(org.kie.api.definition.process.Node) ProcessError(org.kie.kogito.process.ProcessError) ProcessInstanceReadMode(org.kie.kogito.process.ProcessInstanceReadMode) STATE_ERROR(org.kie.kogito.internal.process.runtime.KogitoProcessInstance.STATE_ERROR) Optional(java.util.Optional) Action(org.jbpm.process.instance.impl.Action) Collections(java.util.Collections) WorkItem(org.kie.kogito.process.WorkItem) ProcessInstanceNotFoundException(org.kie.kogito.process.ProcessInstanceNotFoundException) Mockito.mock(org.mockito.Mockito.mock) StaticIdentityProvider(org.kie.kogito.services.identity.StaticIdentityProvider) BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) ActionNode(org.jbpm.workflow.core.node.ActionNode) Node(org.kie.api.definition.process.Node) ActionNode(org.jbpm.workflow.core.node.ActionNode) WorkItem(org.kie.kogito.process.WorkItem) ClassPathResource(org.drools.core.io.impl.ClassPathResource) ProcessError(org.kie.kogito.process.ProcessError) WorkflowProcess(org.jbpm.workflow.core.WorkflowProcess) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables)

Example 3 with ProcessError

use of org.kie.kogito.process.ProcessError in project kogito-runtimes by kiegroup.

the class ActivityGenerationModelTest method testExclusiveSplitRetriggerAfterError.

@Test
public void testExclusiveSplitRetriggerAfterError() throws Exception {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-ExclusiveSplit.bpmn2")).get(0);
    ProcessMetaData metaData = ProcessToExecModelGenerator.INSTANCE.generate((WorkflowProcess) process.get());
    String content = metaData.getGeneratedClassModel().toString();
    assertThat(content).isNotNull();
    log(content);
    Map<String, String> classData = new HashMap<>();
    classData.put("org.drools.bpmn2.TestProcess", content);
    SystemOutWorkItemHandler workItemHandler = new SystemOutWorkItemHandler();
    Map<String, BpmnProcess> processes = createProcesses(classData, Collections.singletonMap("Email", workItemHandler));
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "First1");
    params.put("y", "Second1");
    ProcessInstance<BpmnVariables> processInstance = processes.get("com.sample.test").createInstance(BpmnVariables.create(params));
    processInstance.start();
    assertEquals(KogitoProcessInstance.STATE_ERROR, processInstance.status());
    Optional<ProcessError> errorOptional = processInstance.error();
    assertThat(errorOptional).isPresent();
    ProcessError error = errorOptional.get();
    assertThat(error.failedNodeId()).isEqualTo("_2");
    assertThat(error.errorMessage()).contains("XOR split could not find at least one valid outgoing connection for split Split");
    params.put("x", "First");
    processInstance.updateVariables(BpmnVariables.create(params));
    error.retrigger();
    assertEquals(STATE_COMPLETED, processInstance.status());
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) HashMap(java.util.HashMap) ClassPathResource(org.drools.core.io.impl.ClassPathResource) ProcessError(org.kie.kogito.process.ProcessError) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) ProcessMetaData(org.jbpm.compiler.canonical.ProcessMetaData) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 4 with ProcessError

use of org.kie.kogito.process.ProcessError in project kogito-runtimes by kiegroup.

the class AbstractProcessInstance method buildProcessError.

protected ProcessError buildProcessError() {
    WorkflowProcessInstance pi = processInstance();
    final String errorMessage = pi.getErrorMessage();
    final String nodeInError = pi.getNodeIdInError();
    final Throwable errorCause = pi.getErrorCause().orElse(null);
    return new ProcessError() {

        @Override
        public String failedNodeId() {
            return nodeInError;
        }

        @Override
        public String errorMessage() {
            return errorMessage;
        }

        @Override
        public Throwable errorCause() {
            return errorCause;
        }

        @Override
        public void retrigger() {
            WorkflowProcessInstanceImpl pInstance = (WorkflowProcessInstanceImpl) processInstance();
            NodeInstance ni = pInstance.getByNodeDefinitionId(nodeInError, pInstance.getNodeContainer());
            pInstance.setState(STATE_ACTIVE);
            pInstance.internalSetErrorNodeId(null);
            pInstance.internalSetErrorMessage(null);
            ni.trigger(null, Node.CONNECTION_DEFAULT_TYPE);
            removeOnFinish();
        }

        @Override
        public void skip() {
            WorkflowProcessInstanceImpl pInstance = (WorkflowProcessInstanceImpl) processInstance();
            NodeInstance ni = pInstance.getByNodeDefinitionId(nodeInError, pInstance.getNodeContainer());
            pInstance.setState(STATE_ACTIVE);
            pInstance.internalSetErrorNodeId(null);
            pInstance.internalSetErrorMessage(null);
            ((NodeInstanceImpl) ni).triggerCompleted(Node.CONNECTION_DEFAULT_TYPE, true);
            removeOnFinish();
        }
    };
}
Also used : NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) ProcessError(org.kie.kogito.process.ProcessError) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) NodeInstance(org.jbpm.workflow.instance.NodeInstance) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance)

Example 5 with ProcessError

use of org.kie.kogito.process.ProcessError in project kogito-runtimes by kiegroup.

the class BaseProcessInstanceManagementResource method doGetInstanceInError.

public T doGetInstanceInError(String processId, String processInstanceId) {
    return executeOnInstanceInError(processId, processInstanceId, processInstance -> {
        ProcessError error = processInstance.error().get();
        Map<String, String> data = new HashMap<>();
        data.put("id", processInstance.id());
        data.put("failedNodeId", error.failedNodeId());
        data.put("message", error.errorMessage());
        return buildOkResponse(data);
    });
}
Also used : ProcessError(org.kie.kogito.process.ProcessError) HashMap(java.util.HashMap)

Aggregations

ProcessError (org.kie.kogito.process.ProcessError)5 HashMap (java.util.HashMap)3 Test (org.junit.jupiter.api.Test)3 ClassPathResource (org.drools.core.io.impl.ClassPathResource)2 ProcessInstance (org.kie.kogito.process.ProcessInstance)2 BpmnProcess (org.kie.kogito.process.bpmn2.BpmnProcess)2 BpmnVariables (org.kie.kogito.process.bpmn2.BpmnVariables)2 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Consumer (java.util.function.Consumer)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1 Assertions.entry (org.assertj.core.api.Assertions.entry)1 RemoteCache (org.infinispan.client.hotrod.RemoteCache)1 RemoteCacheManager (org.infinispan.client.hotrod.RemoteCacheManager)1 RemoteCacheManagerAdmin (org.infinispan.client.hotrod.RemoteCacheManagerAdmin)1 MetadataValueImpl (org.infinispan.client.hotrod.impl.MetadataValueImpl)1