use of org.kie.internal.runtime.error.ExecutionError in project jbpm by kiegroup.
the class ExecutionErrorHandlingRuntimeManagerTest method createEnvironment.
private RuntimeEnvironment createEnvironment() {
ExecutionErrorStorage storage = new ExecutionErrorStorage() {
private List<ExecutionError> errors = new ArrayList<>();
@Override
public ExecutionError store(ExecutionError error) {
this.errors.add(error);
return error;
}
@Override
public List<ExecutionError> listByProcessInstance(Long processInstanceId, Integer page, Integer pageSize) {
return errors;
}
@Override
public List<ExecutionError> listByDeployment(String deploymentId, Integer page, Integer pageSize) {
return errors;
}
@Override
public List<ExecutionError> listByActivity(String activityName, Integer page, Integer pageSize) {
return errors;
}
@Override
public List<ExecutionError> list(Integer page, Integer pageSize) {
return errors;
}
@Override
public ExecutionError get(String errorId) {
return errors.stream().filter(err -> err.getErrorId().equals(errorId)).findFirst().get();
}
@Override
public void acknowledge(String user, String... errorIds) {
for (String errorId : errorIds) {
ExecutionError error = get(errorId);
error.setAcknowledged(true);
error.setAcknowledgedBy(user);
error.setAcknowledgedAt(new Date());
}
}
};
RuntimeEnvironmentBuilder environmentBuilder = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-BrokenScriptTask.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTaskWithRollback.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTaskCustomTask.bpmn2"), ResourceType.BPMN2);
if (testName.getMethodName().contains("InMemoryStorage")) {
environmentBuilder.addEnvironmentEntry("ExecutionErrorStorage", storage);
}
return environmentBuilder.get();
}
use of org.kie.internal.runtime.error.ExecutionError in project jbpm by kiegroup.
the class ProcessInstanceAdminServiceImplTest method testErrorHandlingOnScriptTask.
@Test
public void testErrorHandlingOnScriptTask() {
try {
processService.startProcess(deploymentUnit.getIdentifier(), "BrokenScriptTask");
} catch (Exception e) {
// expected as this is broken script process
}
List<ExecutionError> errors = processAdminService.getErrors(true, new QueryContext());
assertNotNull(errors);
assertEquals(1, errors.size());
ExecutionError error = errors.get(0);
assertNotNull(error);
assertFalse(error.isAcknowledged());
processAdminService.acknowledgeError(error.getErrorId());
errors = processAdminService.getErrors(true, new QueryContext());
assertNotNull(errors);
assertEquals(1, errors.size());
error = errors.get(0);
assertNotNull(error);
assertTrue(error.isAcknowledged());
}
use of org.kie.internal.runtime.error.ExecutionError 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());
}
use of org.kie.internal.runtime.error.ExecutionError in project jbpm by kiegroup.
the class CleanupExecutionErrorCommandWithProcessTest method testRunProcessWithAsyncHandlerDeleteUsingReoccurring.
@Test(timeout = 30000)
public void testRunProcessWithAsyncHandlerDeleteUsingReoccurring() throws Exception {
CountDownAsyncJobListener countDownListener = configureListener(1);
RuntimeEnvironment environment = configureEnvironment();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
ExecutionErrorStorage errorStorage = ((AbstractRuntimeManager) manager).getExecutionErrorManager().getStorage();
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
// schedule log cleanup every 3 seconds for processes with processId ScriptTask
scheduleLogCleanup(null, null, false, "3s", "ScriptTask", null, "yyyy-MM-dd HH:mm:ss", manager.getIdentifier());
// wait for the first cleanup
countDownListener.waitTillCompleted();
List<ExecutionError> errors = errorStorage.list(0, 10);
assertEquals(0, errors.size());
System.out.println("Process starting...");
ProcessInstance processInstance = ksession.startProcess("ScriptTask");
System.out.println("Process started...");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
// wait for the process instance to generate an error
countDownListener.reset(1);
System.out.println("Waiting to generate an error...");
countDownListener.waitTillCompleted();
errors = errorStorage.list(0, 10);
assertEquals(1, errors.size());
// wait for another log cleanup
countDownListener.reset(1);
countDownListener.waitTillCompleted();
System.out.println("Aborting process instance " + processInstance.getId());
processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
assertNotNull(processInstance);
// should not delete any errors as the process instance is still active
errors = errorStorage.list(0, 10);
assertEquals(1, errors.size());
runtime.getKieSession().abortProcessInstance(processInstance.getId());
processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
assertNull(processInstance);
// wait for another log cleanup
countDownListener.reset(1);
countDownListener.waitTillCompleted();
errors = errorStorage.list(0, 10);
assertEquals(0, errors.size());
}
use of org.kie.internal.runtime.error.ExecutionError in project jbpm by kiegroup.
the class ProcessInstanceAdminServiceImpl method acknowledgeError.
@Override
public void acknowledgeError(String... errorId) throws ExecutionErrorNotFoundException {
for (String error : errorId) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("errorId", error);
params.put("ack", new Short("0"));
List<ExecutionError> execErrors = commandService.execute(new QueryNameCommand<List<ExecutionError>>("getErrorById", params));
if (execErrors.isEmpty()) {
throw new ExecutionErrorNotFoundException("No execution error found for id " + errorId);
}
ExecutionError errorInstance = execErrors.get(0);
RuntimeManager runtimeManager = RuntimeManagerRegistry.get().getManager(errorInstance.getDeploymentId());
if (runtimeManager != null) {
((AbstractRuntimeManager) runtimeManager).getExecutionErrorManager().getStorage().acknowledge(identityProvider.getName(), errorInstance.getErrorId());
}
}
}
Aggregations