@Override public List<Pair<ExecutableFlow, Optional<Executor>>> getActiveFlowsWithExecutor() throws IOException { final List<Pair<ExecutableFlow, Optional<Executor>>> flows = new ArrayList<>(); try { getActiveFlowsWithExecutorHelper(flows, this.executorLoader.fetchUnfinishedFlows().values()); } catch (final ExecutorManagerException e) { logger.error("Failed to get active flows with executor.", e); } return flows; }
/** * Get execution ids of all running (unfinished) flows from database. */ public List<Integer> getRunningFlowIds() { final List<Integer> allIds = new ArrayList<>(); try { getExecutionIdsHelper(allIds, this.executorLoader.fetchUnfinishedFlows().values()); } catch (final ExecutorManagerException e) { this.logger.error("Failed to get running flow ids.", e); } return allIds; }
/** * Get all running (unfinished) flows from database. {@inheritDoc} */ @Override public List<ExecutableFlow> getRunningFlows() { final ArrayList<ExecutableFlow> flows = new ArrayList<>(); try { getFlowsHelper(flows, this.executorLoader.fetchUnfinishedFlows().values()); } catch (final ExecutorManagerException e) { logger.error("Failed to get running flows.", e); } return flows; }
/** * Checks whether the given flow has an active (running, non-dispatched) execution from * database. {@inheritDoc} */ @Override public boolean isFlowRunning(final int projectId, final String flowId) { boolean isRunning = false; try { isRunning = isFlowRunningHelper(projectId, flowId, this.executorLoader.fetchUnfinishedFlows().values()); } catch (final ExecutorManagerException e) { logger.error( "Failed to check if the flow is running for project " + projectId + ", flow " + flowId, e); } return isRunning; }
/** * Gets a list of all the unfinished (both dispatched and non-dispatched) executions for a * given project and flow {@inheritDoc}. * * @see azkaban.executor.ExecutorManagerAdapter#getRunningFlows(int, java.lang.String) */ @Override public List<Integer> getRunningFlows(final int projectId, final String flowId) { final List<Integer> executionIds = new ArrayList<>(); try { executionIds.addAll(getRunningFlowsHelper(projectId, flowId, this.executorLoader.fetchUnfinishedFlows().values())); } catch (final ExecutorManagerException e) { logger.error("Failed to get running flows for project " + projectId + ", flow " + flowId, e); } return executionIds; }
private void submitFlow(final ExecutableFlow flow, final ExecutionReference ref) throws Exception { when(this.loader.fetchUnfinishedFlows()).thenReturn(this.unfinishedFlows); when(this.loader.fetchExecutableFlow(flow.getExecutionId())).thenReturn(flow); this.controller.submitExecutableFlow(flow, this.user.getUserId()); this.unfinishedFlows.put(flow.getExecutionId(), new Pair<>(ref, flow)); }
private void initializeUnfinishedFlows() throws Exception { this.unfinishedFlows = ImmutableMap .of(this.flow1.getExecutionId(), new Pair<>(this.ref1, this.flow1), this.flow2.getExecutionId(), new Pair<>(this.ref2, this.flow2), this.flow3.getExecutionId(), new Pair<>(this.ref3, this.flow3)); when(this.loader.fetchUnfinishedFlows()).thenReturn(this.unfinishedFlows); } }
/** * If a flow is already dispatched to an executor, cancel by calling Executor. Else if it's still * queued in DB, remove it from DB queue and finalize. {@inheritDoc} */ @Override public void cancelFlow(final ExecutableFlow exFlow, final String userId) throws ExecutorManagerException { synchronized (exFlow) { final Map<Integer, Pair<ExecutionReference, ExecutableFlow>> unfinishedFlows = this.executorLoader .fetchUnfinishedFlows(); if (unfinishedFlows.containsKey(exFlow.getExecutionId())) { final Pair<ExecutionReference, ExecutableFlow> pair = unfinishedFlows .get(exFlow.getExecutionId()); if (pair.getFirst().getExecutor().isPresent()) { // Flow is already dispatched to an executor, so call that executor to cancel the flow. this.apiGateway .callWithReferenceByUser(pair.getFirst(), ConnectorParams.CANCEL_ACTION, userId); } else { // Flow is still queued, need to finalize it and update the status in DB. ExecutionControllerUtils.finalizeFlow(this.executorLoader, this.alerterHolder, exFlow, "Cancelled before dispatching to executor", null); } } else { throw new ExecutorManagerException("Execution " + exFlow.getExecutionId() + " of flow " + exFlow.getFlowId() + " isn't running."); } } }