Search in sources :

Example 1 with AfterStageExecutionEvent

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

the class PipelineExecutorTaskManagerImplEventsTest method testAfterStageExecutionEvent.

private void testAfterStageExecutionEvent(boolean async) {
    when(taskEntry.isAsync()).thenReturn(async);
    AfterStageExecutionEvent event = new AfterStageExecutionEvent(TASK_ID, pipeline, stage);
    taskManager.localListener.afterStageExecution(event);
    verify(task, times(1)).setStageStatus(stage.getName(), PipelineExecutorTask.Status.FINISHED);
    verifyExecutorRegistryUpdated(async);
    verifyExternalListenersNotified(event);
}
Also used : AfterStageExecutionEvent(org.guvnor.ala.pipeline.events.AfterStageExecutionEvent)

Example 2 with AfterStageExecutionEvent

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

the class PipelineExecutionListenerTest method testAfterStageExecution.

@Test
public void testAfterStageExecution() {
    listener.afterStageExecution(new AfterStageExecutionEvent(EXECUTION_ID, pipeline, stage));
    verify(stageStatusChangeEvent, times(1)).fire(new StageStatusChangeEvent(traceKey, STAGE_NAME, PipelineStatus.FINISHED));
}
Also used : AfterStageExecutionEvent(org.guvnor.ala.pipeline.events.AfterStageExecutionEvent) StageStatusChangeEvent(org.guvnor.ala.ui.events.StageStatusChangeEvent) Test(org.junit.Test)

Example 3 with AfterStageExecutionEvent

use of org.guvnor.ala.pipeline.events.AfterStageExecutionEvent 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 4 with AfterStageExecutionEvent

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

the class RestPipelineEventsTest method testEventsPropagation.

@Test
public void testEventsPropagation() {
    List<PipelineConfigStage> configs = new ArrayList<>();
    configs.add(new PipelineConfigStage("GitConfig", new GitConfigImpl()));
    configs.add(new PipelineConfigStage("MavenProjectConfig", new MavenProjectConfigImpl()));
    pipelineService.newPipeline(new PipelineConfigImpl("mypipe", configs));
    Input input = new Input();
    input.put("repo-name", "drools-workshop-events");
    input.put("create-repo", "true");
    input.put("branch", "master");
    input.put("out-dir", tempPath.getAbsolutePath());
    input.put("origin", gitUrl);
    pipelineService.runPipeline("mypipe", input, false);
    assertEquals(6, listener.getEvents().size());
    assertTrue(listener.getEvents().get(0) instanceof BeforePipelineExecutionEvent);
    assertTrue(listener.getEvents().get(1) instanceof BeforeStageExecutionEvent);
    assertTrue(listener.getEvents().get(2) instanceof AfterStageExecutionEvent);
    assertTrue(listener.getEvents().get(3) instanceof BeforeStageExecutionEvent);
    assertTrue(listener.getEvents().get(4) instanceof AfterStageExecutionEvent);
    assertTrue(listener.getEvents().get(5) instanceof AfterPipelineExecutionEvent);
}
Also used : BeforePipelineExecutionEvent(org.guvnor.ala.pipeline.events.BeforePipelineExecutionEvent) Input(org.guvnor.ala.pipeline.Input) AfterStageExecutionEvent(org.guvnor.ala.pipeline.events.AfterStageExecutionEvent) PipelineConfigStage(org.guvnor.ala.pipeline.PipelineConfigStage) MavenProjectConfigImpl(org.guvnor.ala.build.maven.config.impl.MavenProjectConfigImpl) BeforeStageExecutionEvent(org.guvnor.ala.pipeline.events.BeforeStageExecutionEvent) GitConfigImpl(org.guvnor.ala.source.git.config.impl.GitConfigImpl) ArrayList(java.util.ArrayList) AfterPipelineExecutionEvent(org.guvnor.ala.pipeline.events.AfterPipelineExecutionEvent) PipelineConfigImpl(org.guvnor.ala.pipeline.impl.PipelineConfigImpl) Test(org.junit.Test)

Aggregations

AfterStageExecutionEvent (org.guvnor.ala.pipeline.events.AfterStageExecutionEvent)4 BeforeStageExecutionEvent (org.guvnor.ala.pipeline.events.BeforeStageExecutionEvent)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 Optional (java.util.Optional)1 MavenProjectConfigImpl (org.guvnor.ala.build.maven.config.impl.MavenProjectConfigImpl)1 BiFunctionConfigExecutor (org.guvnor.ala.pipeline.BiFunctionConfigExecutor)1 ConfigExecutor (org.guvnor.ala.pipeline.ConfigExecutor)1 ContextAware (org.guvnor.ala.pipeline.ContextAware)1 FunctionConfigExecutor (org.guvnor.ala.pipeline.FunctionConfigExecutor)1 Input (org.guvnor.ala.pipeline.Input)1 PipelineConfigStage (org.guvnor.ala.pipeline.PipelineConfigStage)1 AfterPipelineExecutionEvent (org.guvnor.ala.pipeline.events.AfterPipelineExecutionEvent)1 BeforePipelineExecutionEvent (org.guvnor.ala.pipeline.events.BeforePipelineExecutionEvent)1 OnErrorPipelineExecutionEvent (org.guvnor.ala.pipeline.events.OnErrorPipelineExecutionEvent)1 OnErrorStageExecutionEvent (org.guvnor.ala.pipeline.events.OnErrorStageExecutionEvent)1 PipelineConfigImpl (org.guvnor.ala.pipeline.impl.PipelineConfigImpl)1 GitConfigImpl (org.guvnor.ala.source.git.config.impl.GitConfigImpl)1 StageStatusChangeEvent (org.guvnor.ala.ui.events.StageStatusChangeEvent)1