@Override protected Object clone() throws CloneNotSupportedException { PipelineExecutorTaskImpl clone = new PipelineExecutorTaskImpl(taskDef, executionId); clone.setPipelineStatus(this.getPipelineStatus()); stageStatus.forEach(clone::setStageStatus); stageError.forEach(clone::setStageError); clone.setPipelineError(pipelineError); clone.setOutput(output); return clone; } }
private void updateExecutorRegistry(final PipelineExecutorTaskImpl task) { try { PipelineExecutorTaskImpl clone = (PipelineExecutorTaskImpl) task.clone(); pipelineExecutorRegistry.register(new PipelineExecutorTraceImpl(clone)); } catch (Exception e) { //clone is supported by construction, since PipelineExecutorTaskImpl is clonable. logger.error("Unexpected error: " + e.getMessage(), e); } }
private synchronized void storeTaskEntry(final TaskEntry entry) { currentTasks.put(entry.task.getId(), entry); }
public void setTaskInStoppedStatus(final PipelineExecutorTaskImpl task) { task.setPipelineStatus(PipelineExecutorTask.Status.STOPPED); task.getTaskDef().getStages() .stream() .filter(stage -> PipelineExecutorTask.Status.RUNNING.equals(task.getStageStatus(stage)) || PipelineExecutorTask.Status.SCHEDULED.equals(task.getStageStatus(stage))) .forEach(stage -> task.setStageStatus(stage, PipelineExecutorTask.Status.STOPPED)); task.clearErrors(); task.setOutput(null); } }
@Override public PipelineExecutorTraceImpl getValue() { //only the stage names are used by the taskDef, so the pipeline can be mocked. List<Stage> stages = mockStages(STAGE_COUNT); Pipeline pipeline = new BasePipeline(PIPELINE_NAME, stages) { }; Input input = mockInput(PIPELINE_INPUT_SIZE); PipelineExecutorTaskDefImpl taskDef = new PipelineExecutorTaskDefImpl(pipeline, input); PipelineExecutorTaskImpl taskImpl = new PipelineExecutorTaskImpl(taskDef, PIPELINE_EXECUTION_ID); taskImpl.setPipelineStatus(PipelineExecutorTask.Status.SCHEDULED); taskImpl.setPipelineError(mockError(PIPELINE_ERROR, PIPELINE_ERROR_DETAIL)); taskImpl.getTaskDef().getStages().forEach(stage -> taskImpl.setStageError(stage, mockStageError(stage))); taskImpl.setOutput(new MockPipelineOutput(PIPELINE_OUTPUT)); return new PipelineExecutorTraceImpl(taskImpl); }
private void onStageError(final OnErrorStageExecutionEvent oesee, final TaskEntry taskEntry) { taskEntry.getTask().setPipelineStatus(PipelineExecutorTask.Status.ERROR); taskEntry.getTask().setStageStatus(oesee.getStage().getName(), PipelineExecutorTask.Status.ERROR); taskEntry.getTask().setStageError(oesee.getStage().getName(), new PipelineExecutorError(oesee.getError().getMessage(), oesee.getError())); if (taskEntry.isAsync()) { updateExecutorRegistry(taskEntry.getTask()); } }
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)); capture.getTask())); tasks.forEach(task -> assertHasSameInfo(task, registeredTasks.get(task.getId())));
when(taskDef.getStages()).thenReturn(stages); PipelineExecutorTaskImpl task = new PipelineExecutorTaskImpl(taskDef, "executionId"); task.setPipelineStatus(PipelineExecutorTask.Status.RUNNING); task.getPipelineStatus());
private void onPipelineError(final OnErrorPipelineExecutionEvent oepee, final TaskEntry taskEntry) { taskEntry.getTask().setPipelineStatus(PipelineExecutorTask.Status.ERROR); taskEntry.getTask().setPipelineError(new PipelineExecutorException(oepee.getError().getMessage(), oepee.getError())); if (taskEntry.isAsync()) { updateExecutorRegistry(taskEntry.getTask()); } }
entrySet.addAll(currentTasks.values()); entrySet.forEach(entry -> { currentTasks.remove(entry.getTask().getId()); if (entry.isAsync()) { final PipelineExecutorTaskImpl task = entry.getTask(); if (stopEnabledStatus.contains(task.getPipelineStatus())) { try { taskManagerHelper.setTaskInStoppedStatus(task); updateExecutorRegistry(task); } catch (Exception e) { logger.error("It was not possible to update task: " + task.getId() + " during " + " PipelineExecutorTaskManager finalization. " + e.getMessage(), e);
private void beforePipelineExecution(final BeforePipelineExecutionEvent bpee, final TaskEntry taskEntry) { taskEntry.getTask().setPipelineStatus(PipelineExecutorTask.Status.RUNNING); if (taskEntry.isAsync()) { updateExecutorRegistry(taskEntry.getTask()); } }
private void verifyInternalTask(PipelineExecutorTaskManagerImpl.TaskEntry taskEntry, boolean isAsync) { //verify that the generated internal task has the expect settings assertNotNull(taskEntry); assertEquals(TASK_ID, taskEntry.getTask().getId()); assertEquals(taskDef, taskEntry.getTask().getTaskDef()); assertEquals(isAsync, taskEntry.isAsync()); } }
private void assertStagesInStatus(final PipelineExecutorTaskImpl task, final List<String> stages, final PipelineExecutorTask.Status status) { stages.forEach(stage -> assertEquals(status, task.getStageStatus(stage))); } }
private void setId(final String executionId) { this.executionId = executionId; getTaskDef().getInput().put(PIPELINE_EXECUTION_ID, executionId); }
private void processPipelineOutput(final PipelineExecutorTask task, final Object output) { if (output instanceof RegistrableOutput) { ((PipelineExecutorTaskImpl) task).setOutput((RegistrableOutput) output); } else { //uncommon case logger.debug("Only pipeline outputs of type RegistrableOutput will be registered" + ", current output value won't be registered: " + output); } }
public PipelineExecutorTaskImpl createTask(final PipelineExecutorTaskDef taskDef, final String executionId) { PipelineExecutorTaskImpl task = new PipelineExecutorTaskImpl(taskDef, executionId); return task; }
@Override public void stop(final String taskId) throws PipelineExecutorException { final TaskEntry entry = getTaskEntry(taskId); if (entry == null) { throw new PipelineExecutorException("No PipelineExecutorTask was found for taskId: " + taskId); } if (!entry.isAsync()) { throw new PipelineExecutorException("Stop operation is not available for taskId: " + taskId + " running in SYNCHRONOUS mode"); } final PipelineExecutorTask.Status currentStatus = entry.getTask().getPipelineStatus(); if (!stopEnabledStatus.contains(currentStatus)) { throw new PipelineExecutorException("A PipelineExecutorTask in status: " + currentStatus.name() + " can not" + " be stopped. Stop operation is available for the following status set: " + stopEnabledStatus); } destroyFutureTask(taskId); removeTaskEntry(taskId); taskManagerHelper.setTaskInStoppedStatus(entry.getTask()); updateExecutorRegistry(entry.getTask()); }
@Override public PipelineExecutorTraceImpl getValue() { //only the stage names are used by the taskDef, so the pipeline can be mocked. List<Stage> stages = mockStages(STAGE_COUNT); Pipeline pipeline = new BasePipeline(PIPELINE_NAME, stages); Input input = mockInput(PIPELINE_INPUT_SIZE); PipelineExecutorTaskDefImpl taskDef = new PipelineExecutorTaskDefImpl(pipeline, input); PipelineExecutorTaskImpl taskImpl = new PipelineExecutorTaskImpl(taskDef, PIPELINE_EXECUTION_ID); taskImpl.setPipelineStatus(PipelineExecutorTask.Status.SCHEDULED); taskImpl.setPipelineError(mockError(PIPELINE_ERROR)); taskImpl.getTaskDef().getStages().forEach(stage -> taskImpl.setStageError(stage, mockStageError(stage))); taskImpl.setOutput(new MockPipelineOutput(PIPELINE_OUTPUT)); return new PipelineExecutorTraceImpl(taskImpl); }
public void setTaskInStoppedStatus(final PipelineExecutorTaskImpl task) { task.setPipelineStatus(PipelineExecutorTask.Status.STOPPED); task.getTaskDef().getStages() .stream() .filter(stage -> PipelineExecutorTask.Status.RUNNING.equals(task.getStageStatus(stage)) || PipelineExecutorTask.Status.SCHEDULED.equals(task.getStageStatus(stage))) .forEach(stage -> task.setStageStatus(stage, PipelineExecutorTask.Status.STOPPED)); task.clearErrors(); task.setOutput(null); } }
private void onStageError(final OnErrorStageExecutionEvent oesee, final TaskEntry taskEntry) { taskEntry.getTask().setPipelineStatus(PipelineExecutorTask.Status.ERROR); taskEntry.getTask().setStageStatus(oesee.getStage().getName(), PipelineExecutorTask.Status.ERROR); taskEntry.getTask().setStageError(oesee.getStage().getName(), new PipelineExecutorException(oesee.getError().getMessage(), oesee.getError())); if (taskEntry.isAsync()) { updateExecutorRegistry(taskEntry.getTask()); } }