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);
}
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())));
}
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());
}
Aggregations