@Override public boolean test(PipelineExecutorTrace pipelineExecutorTrace) { if (pipelineExecutionId != null) { return pipelineExecutionId.equals(pipelineExecutorTrace.getTaskId()); } if (runtimeId != null) { return (pipelineExecutorTrace.getTask().getOutput() instanceof RuntimeId) && runtimeId.equals(((RuntimeId) pipelineExecutorTrace.getTask().getOutput()).getId()); } if (runtimeName != null) { return (pipelineExecutorTrace.getTask().getOutput() instanceof RuntimeId) && runtimeName.equals(((RuntimeId) pipelineExecutorTrace.getTask().getOutput()).getName()); } if (providerId != null) { if (pipelineExecutorTrace.getTask().getTaskDef().getProviderId() == null) { return false; } else if (!providerId.equals(pipelineExecutorTrace.getTask().getTaskDef().getProviderId().getId())) { return false; } } if (pipelineId != null) { if (!pipelineId.equals(pipelineExecutorTrace.getPipelineId())) { return false; } } return true; } }
@Override public void register(final PipelineExecutorTrace trace) { checkNotNull("trace", trace); recordsMap.put(trace.getTaskId(), trace); }
@Override public PipelineExecutorTrace getExecutorTrace(final RuntimeId runtimeId) { checkNotNull("runtimeId", runtimeId); return recordsMap.values() .stream() .filter(trace -> (trace.getTask().getOutput() instanceof RuntimeId) && runtimeId.getId().equals(((RuntimeId) trace.getTask().getOutput()).getId()) ).findFirst().orElse(null); } }
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())));
@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()); }
@Override public void register(final PipelineExecutorTrace trace) { checkNotNull("trace", trace); recordsMap.put(trace.getTaskId(), trace); }
@Override public PipelineExecutorTrace getExecutorTrace(final RuntimeId runtimeId) { checkNotNull("runtimeId", runtimeId); return recordsMap.values() .stream() .filter(trace -> (trace.getTask().getOutput() instanceof RuntimeId) && runtimeId.getId().equals(((RuntimeId) trace.getTask().getOutput()).getId()) ).findFirst().orElse(null); } }
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())));
@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()); }
if (pipelineExecutorTrace.getTask().getTaskDef().getProviderId() != null) { item.setProviderId(pipelineExecutorTrace.getTask().getTaskDef().getProviderId().getId()); item.setProviderTypeName(pipelineExecutorTrace.getTask().getTaskDef().getProviderId().getProviderType().getProviderTypeName()); item.setProviderVersion(pipelineExecutorTrace.getTask().getTaskDef().getProviderId().getProviderType().getVersion()); item.setPipelineId(pipelineExecutorTrace.getPipelineId()); item.setPipelineExecutionId(pipelineExecutorTrace.getTaskId()); item.setPipelineStatus(pipelineExecutorTrace.getTask().getPipelineStatus().name()); if (pipelineExecutorTrace.getTask().getPipelineError() != null) { item.setPipelineError(pipelineExecutorTrace.getTask().getPipelineError().toString()); List<PipelineStageItem> stageItems = pipelineExecutorTrace.getTask().getTaskDef().getStages().stream() .map(stage -> { String stageError = null; if (pipelineExecutorTrace.getTask().getStageError(stage) != null) { stageError = pipelineExecutorTrace.getTask().getStageError(stage).getMessage(); if (pipelineExecutorTrace.getTask().getStageStatus(stage) != null) { stageStatus = pipelineExecutorTrace.getTask().getStageStatus(stage).name(); item.setPipelineStageItems(new PipelineStageItemList(stageItems)); if (pipelineExecutorTrace.getTask().getOutput() instanceof Runtime) { Runtime runtime = runtimeRegistry.getRuntimeById(((Runtime) pipelineExecutorTrace.getTask().getOutput()).getId()); if (runtime != null) { item.setRuntimeId(runtime.getId()); item.setRuntimeName(pipelineExecutorTrace.getTask().getTaskDef().getInput().get(RuntimeConfig.RUNTIME_NAME));
@Override public void register(final PipelineExecutorTrace trace) { checkNotNull("trace", trace); final Path path = buildTracePath(trace.getTaskId()); try { registryHelper.storeEntry(path, trace); } catch (Exception e) { //uncommon error logger.error("Unexpected error was produced during trace marshalling/storing, trace: " + trace, e); throw new RuntimeException("Unexpected error was produced during trace marshalling/storing, trace: " + trace, e); } super.register(trace); }
@Test public void testDeleteTask() throws Exception { PipelineExecutorTrace trace = mock(PipelineExecutorTrace.class); PipelineExecutorTask task = mock(PipelineExecutorTask.class); PipelineExecutorTask.Status status = PipelineExecutorTask.Status.STOPPED; when(task.getPipelineStatus()).thenReturn(status); when(trace.getTask()).thenReturn(task); when(pipelineExecutorRegistry.getExecutorTrace(TASK_ID)).thenReturn(trace); taskManager.delete(TASK_ID); verify(pipelineExecutorRegistry, times(1)).deregister(TASK_ID); }
pipelineExecutorTraceCaptor.getValue().getPipelineId()); assertEquals(TASK_ID, pipelineExecutorTraceCaptor.getValue().getTaskId()); assertHasSameInfo(internalTaskEntry.getTask(), pipelineExecutorTraceCaptor.getValue().getTask());
@Before public void setUp() { trace = mock(PipelineExecutorTrace.class); when(trace.getTaskId()).thenReturn(PIPELINE_EXECUTION_ID); pipelineExecutorRegistry = new InMemoryPipelineExecutorRegistry(); }
private void verifyExecutorRegistryUpdated(boolean async) { if (async) { //verify the pipeline executor registry was properly updated. verify(pipelineExecutorRegistry, times(1)).register(pipelineExecutorTraceCaptor.capture()); assertHasSameInfo(task, pipelineExecutorTraceCaptor.getValue().getTask()); } else { verify(pipelineExecutorRegistry, never()).register(anyObject()); } }
pipelineExecutorTraceCaptor.getValue().getPipelineId()); assertEquals(TASK_ID, pipelineExecutorTraceCaptor.getValue().getTaskId()); assertHasSameInfo(internalTaskEntry.getTask(), pipelineExecutorTraceCaptor.getValue().getTask());
@Before public void setUp() { trace = mock(PipelineExecutorTrace.class); when(trace.getTaskId()).thenReturn(PIPELINE_EXECUTION_ID); pipelineExecutorRegistry = new InMemoryPipelineExecutorRegistry(); }
@Test public void testDeleteTask() throws Exception { PipelineExecutorTrace trace = mock(PipelineExecutorTrace.class); PipelineExecutorTask task = mock(PipelineExecutorTask.class); PipelineExecutorTask.Status status = PipelineExecutorTask.Status.STOPPED; when(task.getPipelineStatus()).thenReturn(status); when(trace.getTask()).thenReturn(task); when(pipelineExecutorRegistry.getExecutorTrace(TASK_ID)).thenReturn(trace); taskManager.delete(TASK_ID); verify(pipelineExecutorRegistry, times(1)).deregister(TASK_ID); }
@Test public void testGetExecutorTraces() { List<PipelineExecutorTrace> traces = new ArrayList<>(); for (int i = 0; i < TRACES_COUNT; i++) { PipelineExecutorTrace trace = mock(PipelineExecutorTrace.class); when(trace.getTaskId()).thenReturn(PIPELINE_EXECUTION_ID + Integer.toString(i)); traces.add(trace); } traces.forEach(trace -> pipelineExecutorRegistry.register(trace)); Collection<PipelineExecutorTrace> result = pipelineExecutorRegistry.getExecutorTraces(); assertEquals(traces.size(), result.size()); for (PipelineExecutorTrace trace : traces) { assertTrue(result.contains(trace)); } }
private void testDeleteTaskInNonStopeableState(PipelineExecutorTask.Status nonStopeableStatus) throws Exception { PipelineExecutorTask task = mock(PipelineExecutorTask.class); when(task.getPipelineStatus()).thenReturn(nonStopeableStatus); PipelineExecutorTrace trace = mock(PipelineExecutorTrace.class); when(trace.getTask()).thenReturn(task); when(pipelineExecutorRegistry.getExecutorTrace(TASK_ID)).thenReturn(trace); expectedException.expectMessage(new StartsWith("A PipelineExecutorTask in status: " + nonStopeableStatus + " can not" + " be deleted. Delete operation is available for the following status set:")); taskManager.delete(TASK_ID); }