private void getActiveFlowHelper(final ArrayList<ExecutableFlow> flows, final Collection<Pair<ExecutionReference, ExecutableFlow>> collection) { for (final Pair<ExecutionReference, ExecutableFlow> ref : collection) { flows.add(ref.getSecond()); } }
/** * Helper method to get all flows from collection. */ private void getFlowsHelper(final ArrayList<ExecutableFlow> flows, final Collection<Pair<ExecutionReference, ExecutableFlow>> collection) { collection.stream().forEach(ref -> flows.add(ref.getSecond())); }
/** * Fetch flow for an execution. Returns null, if execution not in queue */ public ExecutableFlow getFlow(final int executionId) { if (hasExecution(executionId)) { return this.queuedFlowMap.get(executionId).getSecond(); } return null; }
private boolean isFlowRunningHelper(final int projectId, final String flowId, final Collection<Pair<ExecutionReference, ExecutableFlow>> collection) { for (final Pair<ExecutionReference, ExecutableFlow> ref : collection) { if (ref.getSecond().getProjectId() == projectId && ref.getSecond().getFlowId().equals(flowId)) { return true; } } return false; }
private boolean isFlowRunningHelper(final int projectId, final String flowId, final Collection<Pair<ExecutionReference, ExecutableFlow>> collection) { for (final Pair<ExecutionReference, ExecutableFlow> ref : collection) { if (ref.getSecond().getProjectId() == projectId && ref.getSecond().getFlowId().equals(flowId)) { return true; } } return false; }
private void getRunningFlowsIdsHelper(final List<Integer> allIds, final Collection<Pair<ExecutionReference, ExecutableFlow>> collection) { for (final Pair<ExecutionReference, ExecutableFlow> ref : collection) { allIds.add(ref.getSecond().getExecutionId()); } }
private List<Integer> getRunningFlowsHelper(final int projectId, final String flowId, final Collection<Pair<ExecutionReference, ExecutableFlow>> collection) { final List<Integer> executionIds = new ArrayList<>(); for (final Pair<ExecutionReference, ExecutableFlow> ref : collection) { if (ref.getSecond().getFlowId().equals(flowId) && ref.getSecond().getProjectId() == projectId) { executionIds.add(ref.getFirst().getExecId()); } } return executionIds; }
private List<Integer> getRunningFlowsHelper(final int projectId, final String flowId, final Collection<Pair<ExecutionReference, ExecutableFlow>> collection) { final List<Integer> executionIds = new ArrayList<>(); for (final Pair<ExecutionReference, ExecutableFlow> ref : collection) { if (ref.getSecond().getFlowId().equals(flowId) && ref.getSecond().getProjectId() == projectId) { executionIds.add(ref.getFirst().getExecId()); } } return executionIds; }
private void getActiveFlowsWithExecutorHelper( final List<Pair<ExecutableFlow, Optional<Executor>>> flows, final Collection<Pair<ExecutionReference, ExecutableFlow>> collection) { for (final Pair<ExecutionReference, ExecutableFlow> ref : collection) { flows.add(new Pair<>(ref.getSecond(), ref .getFirst().getExecutor())); } }
private void loadQueuedFlows() throws ExecutorManagerException { final List<Pair<ExecutionReference, ExecutableFlow>> retrievedExecutions = this.executorLoader.fetchQueuedFlows(); if (retrievedExecutions != null) { for (final Pair<ExecutionReference, ExecutableFlow> pair : retrievedExecutions) { this.queuedFlows.enqueue(pair.getSecond(), pair.getFirst()); } } }
@Override public Map<Integer, Pair<ExecutionReference, ExecutableFlow>> fetchUnfinishedFlowsMetadata() throws ExecutorManagerException { return this.activeFlows.entrySet().stream() .collect(Collectors.toMap(Entry::getKey, e -> { final ExecutableFlow metadata = getExecutableFlowMetadata(e.getValue().getSecond()); return new Pair<>(e.getValue().getFirst(), metadata); })); }
@Test public void testFetchAllActiveFlows() throws Exception { initializeUnfinishedFlows(); final List<ExecutableFlow> flows = this.controller.getRunningFlows(); this.unfinishedFlows.values() .forEach(pair -> assertThat(flows.contains(pair.getSecond())).isTrue()); }
@Test public void testFetchActiveFlowWithExecutor() throws Exception { initializeUnfinishedFlows(); final List<Pair<ExecutableFlow, Optional<Executor>>> activeFlowsWithExecutor = this.controller.getActiveFlowsWithExecutor(); this.unfinishedFlows.values().forEach(pair -> assertThat(activeFlowsWithExecutor .contains(new Pair<>(pair.getSecond(), pair.getFirst().getExecutor()))).isTrue()); }
@Test public void testFetchUnfinishedFlows() throws Exception { final List<ExecutableFlow> flows = createExecutions(); final Map<Integer, Pair<ExecutionReference, ExecutableFlow>> unfinishedFlows = this.fetchActiveFlowDao.fetchUnfinishedFlows(); assertFound(unfinishedFlows, flows.get(0), true); assertFound(unfinishedFlows, flows.get(1), false); assertFound(unfinishedFlows, flows.get(2), true); assertNotFound(unfinishedFlows, flows.get(3), "Returned an execution with a finished status"); assertFound(unfinishedFlows, flows.get(4), false); assertTwoFlowSame(unfinishedFlows.get(flows.get(0).getExecutionId()).getSecond(), flows.get(0)); }
@Test public void testFetchActiveFlowsExecutorAssigned() throws Exception { final List<ExecutableFlow> flows = createExecutions(); final Map<Integer, Pair<ExecutionReference, ExecutableFlow>> activeFlows = this.fetchActiveFlowDao .fetchActiveFlows(); assertFound(activeFlows, flows.get(0), true); assertNotFound(activeFlows, flows.get(1), "Returned a queued execution"); assertFound(activeFlows, flows.get(2), true); assertNotFound(activeFlows, flows.get(3), "Returned an execution with a finished status"); assertFound(activeFlows, flows.get(4), false); assertTwoFlowSame(activeFlows.get(flows.get(0).getExecutionId()).getSecond(), flows.get(0)); }
@Test(expected = ExecutorManagerException.class) public void testEnqueueDuplicateExecution() throws IOException, ExecutorManagerException { final Pair<ExecutionReference, ExecutableFlow> pair1 = createExecutablePair("exec1", 1); final QueuedExecutions queue = new QueuedExecutions(5); queue.enqueue(pair1.getSecond(), pair1.getFirst()); queue.enqueue(pair1.getSecond(), pair1.getFirst()); }
@Test(expected = ExecutorManagerException.class) public void testEnqueueOverflow() throws IOException, ExecutorManagerException { final Pair<ExecutionReference, ExecutableFlow> pair1 = createExecutablePair("exec1", 1); final QueuedExecutions queue = new QueuedExecutions(1); queue.enqueue(pair1.getSecond(), pair1.getFirst()); queue.enqueue(pair1.getSecond(), pair1.getFirst()); }
@Test public void testEnqueueHappyCase() throws IOException, ExecutorManagerException { final QueuedExecutions queue = new QueuedExecutions(5); final List<Pair<ExecutionReference, ExecutableFlow>> dataList = getDummyData(); for (final Pair<ExecutionReference, ExecutableFlow> pair : dataList) { queue.enqueue(pair.getSecond(), pair.getFirst()); } Assert.assertTrue(queue.getAllEntries().containsAll(dataList)); Assert.assertTrue(dataList.containsAll(queue.getAllEntries())); }
@Test public void testGetFlow() throws IOException, ExecutorManagerException, InterruptedException { final QueuedExecutions queue = new QueuedExecutions(2); final List<Pair<ExecutionReference, ExecutableFlow>> dataList = getDummyData(); queue.enqueueAll(dataList); for (final Pair<ExecutionReference, ExecutableFlow> pair : dataList) { Assert.assertEquals(pair.getSecond(), queue.getFlow(pair.getFirst().getExecId())); } }