use of org.guvnor.ala.pipeline.Pipeline in project kie-wb-common by kiegroup.
the class PipelineExecutorTaskManagerImpl method executeSync.
/**
* Executes a task definition in synchronous mode.
* @param taskDef task definition for executing.
* @return the taskId assigned to the executed task.
*/
private String executeSync(final PipelineExecutorTaskDef taskDef) {
final PipelineExecutorTaskImpl task = taskManagerHelper.createTask(taskDef);
storeTaskEntry(TaskEntry.newSyncEntry(task));
final Pipeline pipeline = pipelineRegistry.getPipelineByName(taskDef.getPipeline());
pipelineExecutor.execute(taskDef.getInput(), pipeline, output -> processPipelineOutput(task, output), localListener);
removeTaskEntry(task.getId());
updateExecutorRegistry(task);
return task.getId();
}
use of org.guvnor.ala.pipeline.Pipeline 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.Pipeline in project kie-wb-common by kiegroup.
the class InMemoryPipelineRegistryTest method testGetPipelineByName.
@Test
public void testGetPipelineByName() {
verifyPipelineIsNotRegistered(pipeline);
pipelineRegistry.registerPipeline(pipeline);
Pipeline result = pipelineRegistry.getPipelineByName(PIPELINE_ID);
assertEquals(pipeline, result);
}
use of org.guvnor.ala.pipeline.Pipeline in project kie-wb-common by kiegroup.
the class InMemoryPipelineRegistryTest method testGetPipelines.
@Test
public void testGetPipelines() {
List<Pipeline> result = pipelineRegistry.getPipelines(0, 1000, PipelineRegistry.PIPELINE_NAME_SORT, true);
assertTrue(result.isEmpty());
List<Pipeline> pipelines = mockPipelineList("", ELEMENTS_COUNT);
pipelines.forEach(pipeline -> pipelineRegistry.registerPipeline(pipeline));
result = pipelineRegistry.getPipelines(0, 1000, PipelineRegistry.PIPELINE_NAME_SORT, true);
for (Pipeline pipeline : pipelines) {
assertTrue(result.contains(pipeline));
}
}
use of org.guvnor.ala.pipeline.Pipeline in project kie-wb-common by kiegroup.
the class PageSortUtilTest method pipelinesPagingAndSorting.
@Test
public void pipelinesPagingAndSorting() {
Pipeline pipe1 = mock(Pipeline.class);
when(pipe1.getName()).thenReturn("pipeline 1");
Pipeline pipe2 = mock(Pipeline.class);
when(pipe2.getName()).thenReturn("pipeline 2");
Pipeline pipe3 = mock(Pipeline.class);
when(pipe3.getName()).thenReturn("pipeline 3");
Pipeline pipe4 = mock(Pipeline.class);
when(pipe4.getName()).thenReturn("pipeline 4");
Pipeline pipe5 = mock(Pipeline.class);
when(pipe5.getName()).thenReturn("pipeline 5");
Collection<Pipeline> pipes = new ArrayList<>();
pipes.add(pipe1);
pipes.add(pipe2);
pipes.add(pipe3);
pipes.add(pipe4);
pipes.add(pipe5);
String sort = "name";
// Get the first page (0) with page size 2 and sorting ascending
List<Pipeline> pageSort = PageSortUtil.pageSort(pipes, (Pipeline p1, Pipeline p2) -> {
switch(sort) {
case "name":
return p1.getName().compareTo(p2.getName());
default:
return p1.toString().compareTo(p2.toString());
}
}, 0, 2, sort, true);
assertEquals(2, pageSort.size());
assertEquals("pipeline 1", pageSort.get(0).getName());
assertEquals("pipeline 2", pageSort.get(1).getName());
// Get the first page (0) with page size 2 and sorting descending
pageSort = PageSortUtil.pageSort(pipes, (Pipeline p1, Pipeline p2) -> {
switch(sort) {
case "name":
return p1.getName().compareTo(p2.getName());
default:
return p1.toString().compareTo(p2.toString());
}
}, 0, 2, sort, false);
assertEquals(2, pageSort.size());
assertEquals("pipeline 2", pageSort.get(0).getName());
assertEquals("pipeline 1", pageSort.get(1).getName());
// Get the first page (1) with page size 2 and sorting ascending
pageSort = PageSortUtil.pageSort(pipes, (Pipeline p1, Pipeline p2) -> {
switch(sort) {
case "name":
return p1.getName().compareTo(p2.getName());
default:
return p1.toString().compareTo(p2.toString());
}
}, 1, 2, sort, true);
assertEquals(2, pageSort.size());
assertEquals("pipeline 3", pageSort.get(0).getName());
assertEquals("pipeline 4", pageSort.get(1).getName());
// Get the first page (1) with page size 2 and sorting descending
pageSort = PageSortUtil.pageSort(pipes, (Pipeline p1, Pipeline p2) -> {
switch(sort) {
case "name":
return p1.getName().compareTo(p2.getName());
default:
return p1.toString().compareTo(p2.toString());
}
}, 1, 2, sort, false);
assertEquals(2, pageSort.size());
assertEquals("pipeline 4", pageSort.get(0).getName());
assertEquals("pipeline 3", pageSort.get(1).getName());
// Get the first page (2) with page size 2 and sorting ascending
pageSort = PageSortUtil.pageSort(pipes, (Pipeline p1, Pipeline p2) -> {
switch(sort) {
case "name":
return p1.getName().compareTo(p2.getName());
default:
return p1.toString().compareTo(p2.toString());
}
}, 2, 2, sort, false);
assertEquals(1, pageSort.size());
assertEquals("pipeline 5", pageSort.get(0).getName());
// Get the first page (3) with page size 2 and sorting ascending
pageSort = PageSortUtil.pageSort(pipes, (Pipeline p1, Pipeline p2) -> {
switch(sort) {
case "name":
return p1.getName().compareTo(p2.getName());
default:
return p1.toString().compareTo(p2.toString());
}
}, 3, 2, sort, false);
assertEquals(0, pageSort.size());
// Get the get the first 10 elements without sorting
pageSort = PageSortUtil.pageSort(pipes, (Pipeline p1, Pipeline p2) -> {
switch(sort) {
case "name":
return p1.getName().compareTo(p2.getName());
default:
return p1.toString().compareTo(p2.toString());
}
}, 0, 10, "", false);
assertEquals(5, pageSort.size());
}
Aggregations