@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); } }
@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; } }
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())));
@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); } }
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 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); }
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.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));
@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().getTaskId()); assertHasSameInfo(internalTaskEntry.getTask(), pipelineExecutorTraceCaptor.getValue().getTask());
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().getTaskId()); assertHasSameInfo(internalTaskEntry.getTask(), pipelineExecutorTraceCaptor.getValue().getTask());
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); }
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()); } }
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); }
@Override public void delete(final String taskId) throws PipelineExecutorException { final TaskEntry entry = getTaskEntry(taskId); if (entry != null) { throw new PipelineExecutorException("An active PipelineExecutorTask was found for taskId: " + taskId + " delete operation is only available for the following status set: " + deleteEnabledStatus); } final PipelineExecutorTrace trace = pipelineExecutorRegistry.getExecutorTrace(taskId); if (trace == null) { throw new PipelineExecutorException("No PipelineExecutorTask was found for taskId: " + taskId); } else { if (!deleteEnabledStatus.contains(trace.getTask().getPipelineStatus())) { throw new PipelineExecutorException("A PipelineExecutorTask in status: " + trace.getTask().getPipelineStatus().name() + " can not" + " be deleted. Delete operation is available for the following status set: " + deleteEnabledStatus); } else { pipelineExecutorRegistry.deregister(taskId); } } }
@Test public void getExecutorTraceByRuntimeId() { RuntimeIdMock runtimeId = mock(RuntimeIdMock.class); when(runtimeId.getId()).thenReturn(RUNTIME_ID); PipelineExecutorTask task = mock(PipelineExecutorTask.class); when(task.getOutput()).thenReturn(runtimeId); when(trace.getTask()).thenReturn(task); pipelineExecutorRegistry.register(trace); PipelineExecutorTrace result = pipelineExecutorRegistry.getExecutorTrace(runtimeId); assertEquals(trace, result); }
@Override public void delete(final String taskId) throws PipelineExecutorException { final TaskEntry entry = getTaskEntry(taskId); if (entry != null) { throw new PipelineExecutorException("An active PipelineExecutorTask was found for taskId: " + taskId + " delete operation is only available for the following status set: " + deleteEnabledStatus); } final PipelineExecutorTrace trace = pipelineExecutorRegistry.getExecutorTrace(taskId); if (trace == null) { throw new PipelineExecutorException("No PipelineExecutorTask was found for taskId: " + taskId); } else { if (!deleteEnabledStatus.contains(trace.getTask().getPipelineStatus())) { throw new PipelineExecutorException("A PipelineExecutorTask in status: " + trace.getTask().getPipelineStatus().name() + " can not" + " be deleted. Delete operation is available for the following status set: " + deleteEnabledStatus); } else { pipelineExecutorRegistry.deregister(taskId); } } }
@Test public void getExecutorTraceByRuntimeId() { RuntimeIdMock runtimeId = mock(RuntimeIdMock.class); when(runtimeId.getId()).thenReturn(RUNTIME_ID); PipelineExecutorTask task = mock(PipelineExecutorTask.class); when(task.getOutput()).thenReturn(runtimeId); when(trace.getTask()).thenReturn(task); pipelineExecutorRegistry.register(trace); PipelineExecutorTrace result = pipelineExecutorRegistry.getExecutorTrace(runtimeId); assertEquals(trace, result); }
@Test public void testStopAsyncTask() throws PipelineExecutorException { when(taskManagerHelper.generateTaskId()).thenReturn(TASK_ID); taskManager.init(); //prepare the input parameters. prepareExecution(); Future future = mock(Future.class); when(executorService.submit(any(Runnable.class))).thenReturn(future); String result = taskManager.execute(taskDef, PipelineExecutorTaskManager.ExecutionMode.ASYNCHRONOUS); assertEquals(TASK_ID, result); PipelineExecutorTaskManagerImpl.TaskEntry taskEntry = taskManager.currentTasks.get(TASK_ID); taskManager.stop(TASK_ID); verify(future, times(1)).cancel(true); assertFalse(taskManager.currentTasks.containsKey(TASK_ID)); verify(taskManagerHelper, times(1)).setTaskInStoppedStatus(taskEntry.getTask()); //verify the pipeline executor registry was properly updated. verify(pipelineExecutorRegistry, times(2)).register(pipelineExecutorTraceCaptor.capture()); assertHasSameInfo(pipelineExecutorTraceCaptor.getAllValues().get(1).getTask(), pipelineExecutorTraceCaptor.getValue().getTask()); }
@Test public void testStopAsyncTask() throws PipelineExecutorException { when(taskManagerHelper.generateTaskId()).thenReturn(TASK_ID); taskManager.init(); //prepare the input parameters. prepareExecution(); Future future = mock(Future.class); when(executorService.submit(any(Runnable.class))).thenReturn(future); String result = taskManager.execute(taskDef, PipelineExecutorTaskManager.ExecutionMode.ASYNCHRONOUS); assertEquals(TASK_ID, result); PipelineExecutorTaskManagerImpl.TaskEntry taskEntry = taskManager.currentTasks.get(TASK_ID); taskManager.stop(TASK_ID); verify(future, times(1)).cancel(true); assertFalse(taskManager.currentTasks.containsKey(TASK_ID)); verify(taskManagerHelper, times(1)).setTaskInStoppedStatus(taskEntry.getTask()); //verify the pipeline executor registry was properly updated. verify(pipelineExecutorRegistry, times(2)).register(pipelineExecutorTraceCaptor.capture()); assertHasSameInfo(pipelineExecutorTraceCaptor.getAllValues().get(1).getTask(), pipelineExecutorTraceCaptor.getValue().getTask()); }