private void setId(final String executionId) { this.executionId = executionId; getTaskDef().getInput().put(PIPELINE_EXECUTION_ID, executionId); }
private void setId(final String executionId) { this.executionId = executionId; getTaskDef().getInput().put(PIPELINE_EXECUTION_ID, executionId); }
private void prepareExecution() { //mock the execution inputs pipeline = mock(Pipeline.class); stages = mockStages(PIPELINE_STAGES_SIZE); when(pipeline.getStages()).thenReturn(stages); when(pipeline.getName()).thenReturn(PIPELINE_ID); when(pipelineRegistry.getPipelineByName(PIPELINE_ID)).thenReturn(pipeline); taskDef = mock(PipelineExecutorTaskDef.class); input = mock(Input.class); when(taskDef.getInput()).thenReturn(input); when(taskDef.getPipeline()).thenReturn(PIPELINE_ID); }
private void prepareExecution() { //mock the execution inputs pipeline = mock(Pipeline.class); stages = mockStages(PIPELINE_STAGES_SIZE); when(pipeline.getStages()).thenReturn(stages); when(pipeline.getName()).thenReturn(PIPELINE_ID); when(pipelineRegistry.getPipelineByName(PIPELINE_ID)).thenReturn(pipeline); taskDef = mock(PipelineExecutorTaskDef.class); input = mock(Input.class); when(taskDef.getInput()).thenReturn(input); when(taskDef.getPipeline()).thenReturn(PIPELINE_ID); }
@Before public void setUp() { super.setUp(); error = mock(Throwable.class); when(error.getMessage()).thenReturn(ERROR_MESSAGE); pipelineExecutorExceptionCaptor = ArgumentCaptor.forClass(PipelineExecutorException.class); pipeline = mock(Pipeline.class); stages = mockStages(PIPELINE_STAGES_SIZE); when(pipeline.getStages()).thenReturn(stages); when(pipeline.getName()).thenReturn(PIPELINE_ID); when(pipelineRegistry.getPipelineByName(PIPELINE_ID)).thenReturn(pipeline); //pick an arbitrary stage for events testing. stage = stages.get(0); taskDef = mock(PipelineExecutorTaskDef.class); input = mock(Input.class); when(taskDef.getInput()).thenReturn(input); when(taskDef.getPipeline()).thenReturn(PIPELINE_ID); task = spy(taskManagerHelper.createTask(taskDef, TASK_ID)); taskEntry = mock(PipelineExecutorTaskManagerImpl.TaskEntry.class); when(taskEntry.getTask()).thenReturn(task); //emulate there's a running task. taskManager.currentTasks.put(TASK_ID, taskEntry); taskManager.init(); }
@Before public void setUp() { super.setUp(); error = mock(Throwable.class); when(error.getMessage()).thenReturn(ERROR_MESSAGE); pipelineExecutorErrorCaptor = ArgumentCaptor.forClass(PipelineExecutorError.class); pipeline = mock(Pipeline.class); stages = mockStages(PIPELINE_STAGES_SIZE); when(pipeline.getStages()).thenReturn(stages); when(pipeline.getName()).thenReturn(PIPELINE_ID); when(pipelineRegistry.getPipelineByName(PIPELINE_ID)).thenReturn(pipeline); //pick an arbitrary stage for events testing. stage = stages.get(0); taskDef = mock(PipelineExecutorTaskDef.class); input = mock(Input.class); when(taskDef.getInput()).thenReturn(input); when(taskDef.getPipeline()).thenReturn(PIPELINE_ID); task = spy(taskManagerHelper.createTask(taskDef, TASK_ID)); taskEntry = mock(PipelineExecutorTaskManagerImpl.TaskEntry.class); when(taskEntry.getTask()).thenReturn(task); //emulate there's a running task. taskManager.currentTasks.put(TASK_ID, taskEntry); taskManager.init(); }
@Test public void testExecuteSync() { when(taskManagerHelper.generateTaskId()).thenReturn(TASK_ID); taskManager.init(); //prepare the input parameters. prepareExecution(); String result = taskManager.execute(taskDef, PipelineExecutorTaskManager.ExecutionMode.SYNCHRONOUS); assertEquals(TASK_ID, result); //verify the task to execute was properly initialized. verify(taskManagerHelper, times(1)).createTask(taskDef); //verify the pipeline was properly executed. verify(pipelineExecutor, times(1)).execute(eq(taskDef.getInput()), eq(pipeline), any(Consumer.class), eq(taskManager.localListener)); //verify the pipeline executor registry was properly updated. verify(pipelineExecutorRegistry, times(1)).register(pipelineExecutorTraceCaptor.capture()); assertEquals(PIPELINE_ID, pipelineExecutorTraceCaptor.getValue().getPipelineId()); assertEquals(TASK_ID, pipelineExecutorTraceCaptor.getValue().getTaskId()); }
@Test public void testExecuteSync() { when(taskManagerHelper.generateTaskId()).thenReturn(TASK_ID); taskManager.init(); //prepare the input parameters. prepareExecution(); String result = taskManager.execute(taskDef, PipelineExecutorTaskManager.ExecutionMode.SYNCHRONOUS); assertEquals(TASK_ID, result); //verify the task to execute was properly initialized. verify(taskManagerHelper, times(1)).createTask(taskDef); //verify the pipeline was properly executed. verify(pipelineExecutor, times(1)).execute(eq(taskDef.getInput()), eq(pipeline), any(Consumer.class), eq(taskManager.localListener)); //verify the pipeline executor registry was properly updated. verify(pipelineExecutorRegistry, times(1)).register(pipelineExecutorTraceCaptor.capture()); assertEquals(PIPELINE_ID, pipelineExecutorTraceCaptor.getValue().getPipelineId()); assertEquals(TASK_ID, pipelineExecutorTraceCaptor.getValue().getTaskId()); }
/** * Executes a task in asynchronous mode. * @param task the task for execute. * @return the taskId of the task. */ private synchronized void startAsyncTask(final PipelineExecutorTask task) { final Future<?> future = executor.submit(() -> { final Pipeline pipeline = pipelineRegistry.getPipelineByName(task.getTaskDef().getPipeline()); try { pipelineExecutor.execute(task.getTaskDef().getInput(), pipeline, output -> processPipelineOutput(task, output), localListener); } catch (Exception e) { logger.error("An error was produced during pipeline execution for PipelineExecutorTask: " + task.getId(), e); } finally { removeTaskEntry(task.getId()); removeFutureTask(task.getId()); } }); storeFutureTask(task.getId(), future); }
/** * Executes a task in asynchronous mode. * @param task the task for execute. * @return the taskId of the task. */ private synchronized void startAsyncTask(final PipelineExecutorTask task) { final Future<?> future = executor.submit(() -> { final Pipeline pipeline = pipelineRegistry.getPipelineByName(task.getTaskDef().getPipeline()); try { pipelineExecutor.execute(task.getTaskDef().getInput(), pipeline, output -> processPipelineOutput(task, output), localListener); } catch (Exception e) { logger.error("An error was produced during pipeline execution for PipelineExecutorTask: " + task.getId(), e); } finally { removeTaskEntry(task.getId()); removeFutureTask(task.getId()); } }); storeFutureTask(task.getId(), future); }
protected void assertHasSameInfo(PipelineExecutorTaskDef expectedTaskDef, PipelineExecutorTaskDef taskDef) { assertEquals(expectedTaskDef.getInput(), taskDef.getInput()); assertEquals(expectedTaskDef.getPipeline(), taskDef.getPipeline()); assertEquals(expectedTaskDef.getProviderId(), taskDef.getProviderId()); assertEquals(expectedTaskDef.getProviderType(), taskDef.getProviderType()); } }
protected void assertHasSameInfo(PipelineExecutorTaskDef expectedTaskDef, PipelineExecutorTaskDef taskDef) { assertEquals(expectedTaskDef.getInput(), taskDef.getInput()); assertEquals(expectedTaskDef.getPipeline(), taskDef.getPipeline()); assertEquals(expectedTaskDef.getProviderId(), taskDef.getProviderId()); assertEquals(expectedTaskDef.getProviderType(), taskDef.getProviderType()); } }
/** * 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(); }
/** * 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(); }
when(taskDef.getInput()).thenReturn(input); when(taskDef.getStages()).thenReturn(stages);
when(taskDef.getInput()).thenReturn(input); when(taskDef.getStages()).thenReturn(stages);
item.setRuntimeName(pipelineExecutorTrace.getTask().getTaskDef().getInput().get(RuntimeConfig.RUNTIME_NAME));