use of org.guvnor.ala.pipeline.events.OnErrorStageExecutionEvent in project kie-wb-common by kiegroup.
the class PipelineExecutorTaskManagerImplEventsTest method testOnStageErrorExecutionEvent.
private void testOnStageErrorExecutionEvent(boolean async) {
when(taskEntry.isAsync()).thenReturn(async);
OnErrorStageExecutionEvent event = new OnErrorStageExecutionEvent(TASK_ID, pipeline, stage, error);
taskManager.localListener.onStageError(event);
verify(task, times(1)).setPipelineStatus(PipelineExecutorTask.Status.ERROR);
verify(task, times(1)).setStageStatus(stage.getName(), PipelineExecutorTask.Status.ERROR);
verify(task, times(1)).setStageError(eq(stage.getName()), pipelineExecutorErrorCaptor.capture());
assertEquals(new PipelineExecutorError(ERROR_MESSAGE, error), pipelineExecutorErrorCaptor.getValue());
verifyExecutorRegistryUpdated(async);
verifyExternalListenersNotified(event);
}
use of org.guvnor.ala.pipeline.events.OnErrorStageExecutionEvent in project kie-wb-common by kiegroup.
the class PipelineExecutionListenerTest method testOnStageError.
@Test
public void testOnStageError() {
listener.onStageError(new OnErrorStageExecutionEvent(EXECUTION_ID, pipeline, stage, throwable));
verify(stageStatusChangeEvent, times(1)).fire(new StageStatusChangeEvent(traceKey, STAGE_NAME, PipelineStatus.ERROR));
}
use of org.guvnor.ala.pipeline.events.OnErrorStageExecutionEvent in project kie-wb-common by kiegroup.
the class PipelineExecutor method continuePipeline.
private void continuePipeline(final PipelineContext context, final PipelineEventListener... eventListeners) {
while (!context.isFinished()) {
final Stage<Object, ?> stage = getCurrentStage(context);
final Object newInput = pollOutput(context);
try {
propagateEvent(new BeforeStageExecutionEvent(context.getExecutionId(), context.getPipeline(), stage), eventListeners);
stage.execute(newInput, output -> {
final ConfigExecutor executor = resolve(output.getClass());
if (output instanceof ContextAware) {
((ContextAware) output).setContext(Collections.unmodifiableMap(context.getValues()));
}
final Object newOutput = interpolate(context.getValues(), output);
if (executor == null) {
throw new RuntimeException("Fail to resolve ConfigExecutor for: " + output.getClass());
}
context.getValues().put(executor.inputId(), newOutput);
if (executor instanceof BiFunctionConfigExecutor) {
final Optional result = (Optional) ((BiFunctionConfigExecutor) executor).apply(newInput, newOutput);
context.pushOutput(executor.outputId(), result.get());
} else if (executor instanceof FunctionConfigExecutor) {
final Optional result = (Optional) ((FunctionConfigExecutor) executor).apply(newOutput);
context.pushOutput(executor.outputId(), result.get());
}
propagateEvent(new AfterStageExecutionEvent(context.getExecutionId(), context.getPipeline(), stage), eventListeners);
});
} catch (final Throwable t) {
t.printStackTrace();
final RuntimeException exception = new RuntimeException("An error occurred while executing the " + (stage == null ? "null" : stage.getName()) + " stage.", t);
propagateEvent(new OnErrorStageExecutionEvent(context.getExecutionId(), context.getPipeline(), stage, exception), eventListeners);
propagateEvent(new OnErrorPipelineExecutionEvent(context.getExecutionId(), context.getPipeline(), stage, exception), eventListeners);
throw exception;
}
}
final Object output = pollOutput(context);
while (context.hasCallbacks()) {
context.applyCallbackAndPop(output);
}
}
Aggregations