Search in sources :

Example 1 with ConfigExecutor

use of org.guvnor.ala.pipeline.ConfigExecutor 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);
    }
}
Also used : FunctionConfigExecutor(org.guvnor.ala.pipeline.FunctionConfigExecutor) BiFunctionConfigExecutor(org.guvnor.ala.pipeline.BiFunctionConfigExecutor) Optional(java.util.Optional) ConfigExecutor(org.guvnor.ala.pipeline.ConfigExecutor) FunctionConfigExecutor(org.guvnor.ala.pipeline.FunctionConfigExecutor) BiFunctionConfigExecutor(org.guvnor.ala.pipeline.BiFunctionConfigExecutor) AfterStageExecutionEvent(org.guvnor.ala.pipeline.events.AfterStageExecutionEvent) BeforeStageExecutionEvent(org.guvnor.ala.pipeline.events.BeforeStageExecutionEvent) ContextAware(org.guvnor.ala.pipeline.ContextAware) OnErrorStageExecutionEvent(org.guvnor.ala.pipeline.events.OnErrorStageExecutionEvent) OnErrorPipelineExecutionEvent(org.guvnor.ala.pipeline.events.OnErrorPipelineExecutionEvent) BiFunctionConfigExecutor(org.guvnor.ala.pipeline.BiFunctionConfigExecutor)

Example 2 with ConfigExecutor

use of org.guvnor.ala.pipeline.ConfigExecutor in project kie-wb-common by kiegroup.

the class DataModelServiceConstructorTest method getConfigExecutors.

private Collection<ConfigExecutor> getConfigExecutors(KieModuleService moduleService, BuildHelper buildHelper) {
    Collection<ConfigExecutor> configs = new ArrayList<>();
    configs.add(new LocalSourceConfigExecutor());
    configs.add(new LocalModuleConfigExecutor(moduleService));
    configs.add(new LocalBuildConfigExecutor());
    configs.add(new LocalBuildExecConfigExecutor(buildHelper));
    return configs;
}
Also used : LocalBuildExecConfigExecutor(org.kie.workbench.common.services.backend.builder.ala.LocalBuildExecConfigExecutor) ArrayList(java.util.ArrayList) LocalModuleConfigExecutor(org.kie.workbench.common.services.backend.builder.ala.LocalModuleConfigExecutor) LocalSourceConfigExecutor(org.kie.workbench.common.services.backend.builder.ala.LocalSourceConfigExecutor) LocalModuleConfigExecutor(org.kie.workbench.common.services.backend.builder.ala.LocalModuleConfigExecutor) LocalBuildConfigExecutor(org.kie.workbench.common.services.backend.builder.ala.LocalBuildConfigExecutor) ConfigExecutor(org.guvnor.ala.pipeline.ConfigExecutor) LocalBuildExecConfigExecutor(org.kie.workbench.common.services.backend.builder.ala.LocalBuildExecConfigExecutor) LocalSourceConfigExecutor(org.kie.workbench.common.services.backend.builder.ala.LocalSourceConfigExecutor) LocalBuildConfigExecutor(org.kie.workbench.common.services.backend.builder.ala.LocalBuildConfigExecutor)

Aggregations

ConfigExecutor (org.guvnor.ala.pipeline.ConfigExecutor)2 ArrayList (java.util.ArrayList)1 Optional (java.util.Optional)1 BiFunctionConfigExecutor (org.guvnor.ala.pipeline.BiFunctionConfigExecutor)1 ContextAware (org.guvnor.ala.pipeline.ContextAware)1 FunctionConfigExecutor (org.guvnor.ala.pipeline.FunctionConfigExecutor)1 AfterStageExecutionEvent (org.guvnor.ala.pipeline.events.AfterStageExecutionEvent)1 BeforeStageExecutionEvent (org.guvnor.ala.pipeline.events.BeforeStageExecutionEvent)1 OnErrorPipelineExecutionEvent (org.guvnor.ala.pipeline.events.OnErrorPipelineExecutionEvent)1 OnErrorStageExecutionEvent (org.guvnor.ala.pipeline.events.OnErrorStageExecutionEvent)1 LocalBuildConfigExecutor (org.kie.workbench.common.services.backend.builder.ala.LocalBuildConfigExecutor)1 LocalBuildExecConfigExecutor (org.kie.workbench.common.services.backend.builder.ala.LocalBuildExecConfigExecutor)1 LocalModuleConfigExecutor (org.kie.workbench.common.services.backend.builder.ala.LocalModuleConfigExecutor)1 LocalSourceConfigExecutor (org.kie.workbench.common.services.backend.builder.ala.LocalSourceConfigExecutor)1