Search in sources :

Example 1 with PipelineExecutorTaskDef

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

the class RestPipelineServiceImpl method runPipeline.

@Override
public String runPipeline(final String pipelineId, final Input input, final boolean async) throws BusinessException {
    final Pipeline pipeline = pipelineRegistry.getPipelineByName(pipelineId);
    if (pipeline == null) {
        throw new BusinessException("Pipeline: " + pipelineId + " was not found.");
    }
    String providerName = input.get(ProviderConfig.PROVIDER_NAME);
    Provider provider = null;
    ProviderType providerType = null;
    PipelineExecutorTaskDef taskDef;
    if (providerName != null && !providerName.isEmpty()) {
        provider = runtimeRegistry.getProvider(providerName);
    }
    if (provider == null) {
        providerType = pipelineRegistry.getProviderType(pipelineId);
    }
    if (provider != null) {
        taskDef = new PipelineExecutorTaskDefImpl(pipeline, input, provider);
    } else if (providerType != null) {
        taskDef = new PipelineExecutorTaskDefImpl(pipeline, input, providerType);
    } else {
        taskDef = new PipelineExecutorTaskDefImpl(pipeline, input);
    }
    return executorTaskManager.execute(taskDef, async ? PipelineExecutorTaskManager.ExecutionMode.ASYNCHRONOUS : PipelineExecutorTaskManager.ExecutionMode.SYNCHRONOUS);
}
Also used : PipelineExecutorTaskDefImpl(org.guvnor.ala.pipeline.execution.impl.PipelineExecutorTaskDefImpl) BusinessException(org.guvnor.ala.services.exceptions.BusinessException) ProviderType(org.guvnor.ala.runtime.providers.ProviderType) ConfigBasedPipeline(org.guvnor.ala.pipeline.ConfigBasedPipeline) Pipeline(org.guvnor.ala.pipeline.Pipeline) Provider(org.guvnor.ala.runtime.providers.Provider) PipelineExecutorTaskDef(org.guvnor.ala.pipeline.execution.PipelineExecutorTaskDef)

Example 2 with PipelineExecutorTaskDef

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

the class PipelineExecutorTaskManagerImplExecutionTest method testDestroy.

@Test
public void testDestroy() throws Exception {
    int runningTasks = 5;
    List<PipelineExecutorTaskImpl> tasks = new ArrayList<>();
    // emulate a set of currently running tasks
    for (int i = 0; i < runningTasks; i++) {
        String taskId = TASK_ID + i;
        PipelineExecutorTaskImpl task = mock(PipelineExecutorTaskImpl.class);
        when(task.clone()).thenReturn(task);
        when(task.getId()).thenReturn(taskId);
        when(task.getPipelineStatus()).thenReturn(PipelineExecutorTask.Status.RUNNING);
        PipelineExecutorTaskDef taskDef = mock(PipelineExecutorTaskDef.class);
        when(task.getTaskDef()).thenReturn(taskDef);
        Pipeline pipeline = mock(Pipeline.class);
        when(pipeline.getStages()).thenReturn(mock(List.class));
        when(taskDef.getPipeline()).thenReturn(PIPELINE_ID);
        PipelineExecutorTaskManagerImpl.TaskEntry taskEntry = mock(PipelineExecutorTaskManagerImpl.TaskEntry.class);
        when(taskEntry.isAsync()).thenReturn(true);
        when(taskEntry.getTask()).thenReturn(task);
        taskManager.currentTasks.put(taskId, taskEntry);
        tasks.add(task);
    }
    taskManager.destroy();
    tasks.forEach(task -> verify(taskManagerHelper, times(1)).setTaskInStoppedStatus(task));
    verify(pipelineExecutorRegistry, times(5)).register(pipelineExecutorTraceCaptor.capture());
    Map<String, PipelineExecutorTask> registeredTasks = new HashMap<>();
    pipelineExecutorTraceCaptor.getAllValues().forEach(capture -> registeredTasks.put(capture.getTaskId(), capture.getTask()));
    tasks.forEach(task -> assertHasSameInfo(task, registeredTasks.get(task.getId())));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Pipeline(org.guvnor.ala.pipeline.Pipeline) PipelineExecutorTask(org.guvnor.ala.pipeline.execution.PipelineExecutorTask) ArrayList(java.util.ArrayList) List(java.util.List) PipelineExecutorTaskDef(org.guvnor.ala.pipeline.execution.PipelineExecutorTaskDef) Test(org.junit.Test)

Example 3 with PipelineExecutorTaskDef

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

the class PipelineExecutorTaskManagerImplHelperTest method testSetTaskInStoppedStatus.

@Test
public void testSetTaskInStoppedStatus() {
    List<String> scheduledStages = mockStages(STAGES_COUNT, "scheduled");
    List<String> runningStages = mockStages(STAGES_COUNT, "running");
    List<String> finishedStages = mockStages(STAGES_COUNT, "finished");
    List<String> errorStages = mockStages(STAGES_COUNT, "error");
    List<String> stoppedStages = mockStages(STAGES_COUNT, "stopped");
    List<String> stages = new ArrayList<>();
    stages.addAll(scheduledStages);
    stages.addAll(runningStages);
    stages.addAll(finishedStages);
    stages.addAll(errorStages);
    stages.addAll(stoppedStages);
    PipelineExecutorTaskDef taskDef = mock(PipelineExecutorTaskDef.class);
    Input input = mock(Input.class);
    when(taskDef.getInput()).thenReturn(input);
    when(taskDef.getStages()).thenReturn(stages);
    PipelineExecutorTaskImpl task = new PipelineExecutorTaskImpl(taskDef, "executionId");
    // set the pipeline e.g. in running status
    task.setPipelineStatus(PipelineExecutorTask.Status.RUNNING);
    // set the stages in the corresponding status
    setStagesInStatus(task, scheduledStages, PipelineExecutorTask.Status.SCHEDULED);
    setStagesInStatus(task, runningStages, PipelineExecutorTask.Status.RUNNING);
    setStagesInStatus(task, finishedStages, PipelineExecutorTask.Status.FINISHED);
    setStagesInStatus(task, errorStages, PipelineExecutorTask.Status.ERROR);
    setStagesInStatus(task, stoppedStages, PipelineExecutorTask.Status.STOPPED);
    taskManagerHelper.setTaskInStoppedStatus(task);
    // verify all stages were set in the expected status.
    // the scheduled stages must have been set to STOPPED
    assertStagesInStatus(task, scheduledStages, PipelineExecutorTask.Status.STOPPED);
    // the running stages must have been set to STOPPED
    assertStagesInStatus(task, runningStages, PipelineExecutorTask.Status.STOPPED);
    // the finished stages must remain in FINISHED status
    assertStagesInStatus(task, finishedStages, PipelineExecutorTask.Status.FINISHED);
    // the error stages must remain in ERROR status
    assertStagesInStatus(task, errorStages, PipelineExecutorTask.Status.ERROR);
    // the stopped stages must remain in STOPPED status
    assertStagesInStatus(task, stoppedStages, PipelineExecutorTask.Status.STOPPED);
    // the pipeline must have been stopped
    assertEquals(PipelineExecutorTask.Status.STOPPED, task.getPipelineStatus());
}
Also used : Input(org.guvnor.ala.pipeline.Input) ArrayList(java.util.ArrayList) PipelineExecutorTaskDef(org.guvnor.ala.pipeline.execution.PipelineExecutorTaskDef) Test(org.junit.Test)

Aggregations

PipelineExecutorTaskDef (org.guvnor.ala.pipeline.execution.PipelineExecutorTaskDef)3 ArrayList (java.util.ArrayList)2 Pipeline (org.guvnor.ala.pipeline.Pipeline)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 List (java.util.List)1 ConfigBasedPipeline (org.guvnor.ala.pipeline.ConfigBasedPipeline)1 Input (org.guvnor.ala.pipeline.Input)1 PipelineExecutorTask (org.guvnor.ala.pipeline.execution.PipelineExecutorTask)1 PipelineExecutorTaskDefImpl (org.guvnor.ala.pipeline.execution.impl.PipelineExecutorTaskDefImpl)1 Provider (org.guvnor.ala.runtime.providers.Provider)1 ProviderType (org.guvnor.ala.runtime.providers.ProviderType)1 BusinessException (org.guvnor.ala.services.exceptions.BusinessException)1