Search in sources :

Example 6 with ExecutionErrorManager

use of org.kie.internal.runtime.error.ExecutionErrorManager in project jbpm by kiegroup.

the class ExecutionErrorHandlingRuntimeManagerTest method testDataBaseFailureInMemoryStorage.

@Test
public void testDataBaseFailureInMemoryStorage() {
    RuntimeEngine runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession1 = runtime1.getKieSession();
    assertNotNull(ksession1);
    ksession1.addEventListener(new DefaultProcessEventListener() {

        @Override
        public void afterProcessStarted(ProcessStartedEvent event) {
            pds.close();
        }
    });
    try {
        ksession1.startProcess("UserTaskWithRollback");
        fail("Start process should fail due to data base error");
    } catch (Throwable e) {
    // expected
    }
    int expectedErrors = 1;
    try {
        manager.disposeRuntimeEngine(runtime1);
    } catch (Exception e) {
        // expected to fail for some strategies due to data source being down
        expectedErrors++;
    }
    ExecutionErrorManager errorManager = ((AbstractRuntimeManager) manager).getExecutionErrorManager();
    ExecutionErrorStorage storage = errorManager.getStorage();
    List<ExecutionError> errors = storage.list(0, 10);
    assertNotNull(errors);
    assertEquals(expectedErrors, errors.size());
    assertExecutionError(errors.get(0), "DB", "UserTaskWithRollback", "Hello");
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) ExecutionError(org.kie.internal.runtime.error.ExecutionError) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) TaskExecutionException(org.jbpm.services.task.exception.TaskExecutionException) ExecutionErrorManager(org.kie.internal.runtime.error.ExecutionErrorManager) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ExecutionErrorStorage(org.kie.internal.runtime.error.ExecutionErrorStorage) KieSession(org.kie.api.runtime.KieSession) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 7 with ExecutionErrorManager

use of org.kie.internal.runtime.error.ExecutionErrorManager in project jbpm by kiegroup.

the class ExecutionErrorHandlingRuntimeManagerTest method testUserTaskFailure.

@SuppressWarnings("unchecked")
@Test
public void testUserTaskFailure() {
    RuntimeEngine runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession1 = runtime1.getKieSession();
    assertNotNull(ksession1);
    ksession1.startProcess("UserTaskWithRollback");
    TaskService taskService = runtime1.getTaskService();
    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals(1, tasks.size());
    long taskId = tasks.get(0).getId();
    try {
        ((EventService<TaskLifeCycleEventListener>) taskService).registerTaskEventListener(new DefaultTaskEventListener() {

            @Override
            public void afterTaskStartedEvent(TaskEvent event) {
                throw new TaskExecutionException("On purpose");
            }
        });
        taskService.start(taskId, "john");
        fail("Start task should fail due to broken script");
    } catch (Throwable e) {
    // expected
    }
    manager.disposeRuntimeEngine(runtime1);
    ExecutionErrorManager errorManager = ((AbstractRuntimeManager) manager).getExecutionErrorManager();
    ExecutionErrorStorage storage = errorManager.getStorage();
    List<ExecutionError> errors = storage.list(0, 10);
    assertNotNull(errors);
    assertEquals(1, errors.size());
    assertExecutionError(errors.get(0), "Task", "UserTaskWithRollback", "Hello");
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) ExecutionError(org.kie.internal.runtime.error.ExecutionError) TaskService(org.kie.api.task.TaskService) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) EventService(org.kie.internal.task.api.EventService) DefaultTaskEventListener(org.jbpm.services.task.events.DefaultTaskEventListener) TaskExecutionException(org.jbpm.services.task.exception.TaskExecutionException) ExecutionErrorManager(org.kie.internal.runtime.error.ExecutionErrorManager) TaskSummary(org.kie.api.task.model.TaskSummary) TaskEvent(org.kie.api.task.TaskEvent) ExecutionErrorStorage(org.kie.internal.runtime.error.ExecutionErrorStorage) KieSession(org.kie.api.runtime.KieSession) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 8 with ExecutionErrorManager

use of org.kie.internal.runtime.error.ExecutionErrorManager in project jbpm by kiegroup.

the class AsyncWorkItemHandlerTest method testRunProcessWithAsyncHandlerRecordExecutionErrorTaskAutoAck.

@SuppressWarnings("unchecked")
@Test(timeout = 20000)
public void testRunProcessWithAsyncHandlerRecordExecutionErrorTaskAutoAck() throws Exception {
    CountDownAsyncJobListener countDownListener = new CountDownAsyncJobListener(1);
    ((ExecutorServiceImpl) executorService).addAsyncJobListener(countDownListener);
    ((ExecutorServiceImpl) executorService).setRetries(0);
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTaskWithRollback.bpmn2"), ResourceType.BPMN2).get();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    ProcessInstance processInstance = ksession.startProcess("UserTaskWithRollback");
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
    assertNotNull(processInstance);
    manager.disposeRuntimeEngine(runtime);
    runtime = manager.getRuntimeEngine(EmptyContext.get());
    TaskService taskService = runtime.getTaskService();
    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals(1, tasks.size());
    long taskId = tasks.get(0).getId();
    TaskLifeCycleEventListener listener = new DefaultTaskEventListener() {

        @Override
        public void afterTaskStartedEvent(TaskEvent event) {
            throw new TaskExecutionException("On purpose");
        }
    };
    try {
        ((EventService<TaskLifeCycleEventListener>) taskService).registerTaskEventListener(listener);
        taskService.start(taskId, "john");
        fail("Start task should fail due to broken script");
    } catch (Throwable e) {
    // expected
    }
    manager.disposeRuntimeEngine(runtime);
    ExecutionErrorManager errorManager = ((AbstractRuntimeManager) manager).getExecutionErrorManager();
    assertNotNull("ErrorManager is null", errorManager);
    ExecutionErrorStorage errorStorage = errorManager.getStorage();
    assertNotNull("ErrorStorage is null", errorStorage);
    List<ExecutionError> errors = errorStorage.list(0, 10);
    assertEquals(1, errors.size());
    ExecutionError error = errors.get(0);
    assertNotNull(error);
    assertEquals("Task", error.getType());
    assertEquals("UserTaskWithRollback", error.getProcessId());
    assertEquals("Hello", error.getActivityName());
    assertEquals(manager.getIdentifier(), error.getDeploymentId());
    assertNotNull(error.getError());
    assertNotNull(error.getErrorMessage());
    assertNotNull(error.getActivityId());
    assertNotNull(error.getProcessInstanceId());
    assertNull(error.getAcknowledgedAt());
    assertNull(error.getAcknowledgedBy());
    assertFalse(error.isAcknowledged());
    countDownListener.reset(1);
    // first run should not ack the job as it's in error state
    CommandContext ctx = new CommandContext();
    ctx.setData("SingleRun", "true");
    ctx.setData("EmfName", "org.jbpm.persistence.complete");
    executorService.scheduleRequest(TaskAutoAckErrorCommand.class.getName(), ctx);
    countDownListener.waitTillCompleted();
    errors = errorStorage.list(0, 10);
    assertEquals(1, errors.size());
    error = errors.get(0);
    assertNotNull(error);
    assertFalse(error.isAcknowledged());
    runtime = manager.getRuntimeEngine(EmptyContext.get());
    tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals(1, tasks.size());
    taskId = tasks.get(0).getId();
    ((EventService<TaskLifeCycleEventListener>) taskService).removeTaskEventListener(listener);
    taskService.start(taskId, "john");
    Map<String, Object> results = new HashMap<>();
    results.put("output1", "ok");
    taskService.complete(taskId, "john", results);
    manager.disposeRuntimeEngine(runtime);
    countDownListener.reset(1);
    // since task was completed auto ack should work
    executorService.scheduleRequest(TaskAutoAckErrorCommand.class.getName(), ctx);
    countDownListener.waitTillCompleted();
    errors = errorStorage.list(0, 10);
    assertEquals(1, errors.size());
    error = errors.get(0);
    assertNotNull(error);
    assertTrue(error.isAcknowledged());
}
Also used : ExecutionError(org.kie.internal.runtime.error.ExecutionError) CommandContext(org.kie.api.executor.CommandContext) HashMap(java.util.HashMap) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) TaskAutoAckErrorCommand(org.jbpm.executor.commands.error.TaskAutoAckErrorCommand) DefaultTaskEventListener(org.jbpm.services.task.events.DefaultTaskEventListener) CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) ExecutionErrorManager(org.kie.internal.runtime.error.ExecutionErrorManager) ExecutionErrorStorage(org.kie.internal.runtime.error.ExecutionErrorStorage) KieSession(org.kie.api.runtime.KieSession) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) TaskService(org.kie.api.task.TaskService) EventService(org.kie.internal.task.api.EventService) TaskExecutionException(org.jbpm.services.task.exception.TaskExecutionException) TaskSummary(org.kie.api.task.model.TaskSummary) TaskEvent(org.kie.api.task.TaskEvent) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) TaskLifeCycleEventListener(org.kie.api.task.TaskLifeCycleEventListener) AbstractExecutorBaseTest(org.jbpm.test.util.AbstractExecutorBaseTest) Test(org.junit.Test)

Example 9 with ExecutionErrorManager

use of org.kie.internal.runtime.error.ExecutionErrorManager in project jbpm by kiegroup.

the class AsyncWorkItemHandlerCmdCallback method closeErrorHandler.

private void closeErrorHandler(RuntimeManager manager) {
    ExecutionErrorManager errorManager = ((AbstractRuntimeManager) manager).getExecutionErrorManager();
    if (errorManager == null) {
        return;
    }
    ((ExecutionErrorManagerImpl) errorManager).closeHandler();
}
Also used : ExecutionErrorManager(org.kie.internal.runtime.error.ExecutionErrorManager) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) ExecutionErrorManagerImpl(org.jbpm.runtime.manager.impl.error.ExecutionErrorManagerImpl)

Example 10 with ExecutionErrorManager

use of org.kie.internal.runtime.error.ExecutionErrorManager in project jbpm by kiegroup.

the class AutoAckErrorCommand method execute.

@Override
public ExecutionResults execute(CommandContext ctx) throws Exception {
    ExecutionResults executionResults = new ExecutionResults();
    String emfName = (String) ctx.getData("EmfName");
    if (emfName == null) {
        emfName = "org.jbpm.domain";
    }
    String singleRun = (String) ctx.getData("SingleRun");
    if ("true".equalsIgnoreCase(singleRun)) {
        // disable rescheduling
        this.nextScheduleTimeAdd = -1;
    }
    String nextRun = (String) ctx.getData("NextRun");
    if (nextRun != null) {
        nextScheduleTimeAdd = DateTimeUtils.parseDateAsDuration(nextRun);
    }
    // get hold of persistence and create instance of audit service
    EntityManagerFactory emf = EntityManagerFactoryManager.get().getOrCreate(emfName);
    EntityManager em = emf.createEntityManager();
    try {
        List<ExecutionErrorInfo> errorsToAck = findErrorsToAck(em);
        logger.debug("Found {} jobs that can be auto ack", errorsToAck.size());
        errorsToAck.forEach(error -> {
            AbstractRuntimeManager manager = (AbstractRuntimeManager) RuntimeManagerRegistry.get().getManager(error.getDeploymentId());
            if (manager != null) {
                ExecutionErrorManager errorManager = manager.getExecutionErrorManager();
                errorManager.getStorage().acknowledge("SYSTEM", error.getErrorId());
                logger.debug("Error {} has been auto acknowledged by system based on {}", error.getErrorId(), getAckRule());
            } else {
                logger.warn("Unable to ack error {} due missing runtime manager for '{}'", error.getErrorId(), error.getDeploymentId());
            }
        });
    } finally {
        em.close();
    }
    return executionResults;
}
Also used : EntityManager(javax.persistence.EntityManager) ExecutionErrorInfo(org.jbpm.runtime.manager.impl.jpa.ExecutionErrorInfo) ExecutionResults(org.kie.api.executor.ExecutionResults) ExecutionErrorManager(org.kie.internal.runtime.error.ExecutionErrorManager) EntityManagerFactory(javax.persistence.EntityManagerFactory) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager)

Aggregations

AbstractRuntimeManager (org.jbpm.runtime.manager.impl.AbstractRuntimeManager)12 ExecutionErrorManager (org.kie.internal.runtime.error.ExecutionErrorManager)12 Test (org.junit.Test)10 KieSession (org.kie.api.runtime.KieSession)10 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)10 ExecutionError (org.kie.internal.runtime.error.ExecutionError)10 ExecutionErrorStorage (org.kie.internal.runtime.error.ExecutionErrorStorage)10 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)7 HashMap (java.util.HashMap)5 ExecutorServiceImpl (org.jbpm.executor.impl.ExecutorServiceImpl)5 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)5 AbstractExecutorBaseTest (org.jbpm.test.util.AbstractExecutorBaseTest)5 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)5 TaskService (org.kie.api.task.TaskService)5 TaskSummary (org.kie.api.task.model.TaskSummary)5 CountDownAsyncJobListener (org.jbpm.executor.test.CountDownAsyncJobListener)4 DefaultRegisterableItemsFactory (org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory)3 TaskExecutionException (org.jbpm.services.task.exception.TaskExecutionException)3 CommandContext (org.kie.api.executor.CommandContext)3 RequestInfo (org.kie.api.executor.RequestInfo)3