@Override public Map<Integer, Pair<ExecutionReference, ExecutableFlow>> fetchActiveFlows() throws ExecutorManagerException { return this.fetchActiveFlowDao.fetchActiveFlows(); }
@Override public Pair<ExecutionReference, ExecutableFlow> fetchActiveFlowByExecId(final int execId) throws ExecutorManagerException { return this.fetchActiveFlowDao.fetchActiveFlowByExecId(execId); }
@Override public Map<Integer, Pair<ExecutionReference, ExecutableFlow>> fetchUnfinishedFlows() throws ExecutorManagerException { return this.fetchActiveFlowDao.fetchUnfinishedFlows(); }
@Override public Map<Integer, Pair<ExecutionReference, ExecutableFlow>> fetchUnfinishedFlowsMetadata() throws ExecutorManagerException { return this.fetchActiveFlowDao.fetchUnfinishedFlowsMetadata(); }
private static Pair<ExecutionReference, ExecutableFlow> getExecutableFlowHelper( final ResultSet rs) throws SQLException { final int id = rs.getInt("exec_id"); final int encodingType = rs.getInt("enc_type"); final byte[] data = rs.getBytes("flow_data"); if (data == null) { logger.warn("Execution id " + id + " has flow_data = null. To clean up, update status to " + "FAILED manually, eg. " + "SET status = " + Status.FAILED.getNumVal() + " WHERE id = " + id); } else { final EncodingType encType = EncodingType.fromInteger(encodingType); final ExecutableFlow exFlow; try { exFlow = ExecutableFlow.createExecutableFlowFromObject( GZIPUtils.transformBytesToObject(data, encType)); } catch (final IOException e) { throw new SQLException("Error retrieving flow data " + id, e); } return getPairWithExecutorInfo(rs, exFlow); } return null; }
@Before public void setup() { this.executionFlowDao = new ExecutionFlowDao(dbOperator); this.executorDao = new ExecutorDao(dbOperator); this.assignExecutor = new AssignExecutorDao(dbOperator, this.executorDao); this.fetchActiveFlowDao = new FetchActiveFlowDao(dbOperator); this.executionJobDao = new ExecutionJobDao(dbOperator); this.loader = new JdbcProjectImpl(props, dbOperator); }
@Test public void testFetchUnfinishedFlowsMetadata() throws Exception { final List<ExecutableFlow> flows = createExecutions(); final Map<Integer, Pair<ExecutionReference, ExecutableFlow>> unfinishedFlows = this.fetchActiveFlowDao.fetchUnfinishedFlowsMetadata(); 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), false); assertTwoFlowSame(unfinishedFlows.get(flows.get(1).getExecutionId()).getSecond(), flows.get(1), false); assertTwoFlowSame(unfinishedFlows.get(flows.get(2).getExecutionId()).getSecond(), flows.get(2), false); }
private static Pair<ExecutionReference, ExecutableFlow> getExecutableFlowMetadataHelper( final ResultSet rs) throws SQLException { final Flow flow = new Flow(rs.getString("flow_id")); final Project project = new Project(rs.getInt("project_id"), null); project.setVersion(rs.getInt("version")); final ExecutableFlow exFlow = new ExecutableFlow(project, flow); exFlow.setExecutionId(rs.getInt("exec_id")); exFlow.setStatus(Status.fromInteger(rs.getInt("status"))); exFlow.setSubmitTime(rs.getLong("submit_time")); exFlow.setStartTime(rs.getLong("start_time")); exFlow.setEndTime(rs.getLong("end_time")); exFlow.setSubmitUser(rs.getString("submit_user")); return getPairWithExecutorInfo(rs, exFlow); }
@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 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 testFetchActiveFlowByExecId() throws Exception { final List<ExecutableFlow> flows = createExecutions(); assertTwoFlowSame( this.fetchActiveFlowDao.fetchActiveFlowByExecId(flows.get(0).getExecutionId()).getSecond(), flows.get(0)); assertThat(this.fetchActiveFlowDao.fetchActiveFlowByExecId(flows.get(1).getExecutionId())) .isNull(); assertTwoFlowSame( this.fetchActiveFlowDao.fetchActiveFlowByExecId(flows.get(2).getExecutionId()).getSecond(), flows.get(2)); assertThat(this.fetchActiveFlowDao.fetchActiveFlowByExecId(flows.get(3).getExecutionId())) .isNull(); assertTwoFlowSame( this.fetchActiveFlowDao.fetchActiveFlowByExecId(flows.get(4).getExecutionId()).getSecond(), flows.get(4)); }
@Test public void testFetchActiveFlowsStatusChanged() throws Exception { final ExecutableFlow flow1 = TestUtils.createTestExecutableFlow("exectest1", "exec1"); this.executionFlowDao.uploadExecutableFlow(flow1); final Executor executor = this.executorDao.addExecutor("test", 1); this.assignExecutor.assignExecutor(executor.getId(), flow1.getExecutionId()); Map<Integer, Pair<ExecutionReference, ExecutableFlow>> activeFlows1 = this.fetchActiveFlowDao.fetchActiveFlows(); assertThat(activeFlows1.containsKey(flow1.getExecutionId())).isTrue(); // When flow status becomes SUCCEEDED/KILLED/FAILED, it should not be in active state flow1.setStatus(Status.SUCCEEDED); this.executionFlowDao.updateExecutableFlow(flow1); activeFlows1 = this.fetchActiveFlowDao.fetchActiveFlows(); assertThat(activeFlows1.containsKey(flow1.getExecutionId())).isFalse(); flow1.setStatus(Status.KILLED); this.executionFlowDao.updateExecutableFlow(flow1); activeFlows1 = this.fetchActiveFlowDao.fetchActiveFlows(); assertThat(activeFlows1.containsKey(flow1.getExecutionId())).isFalse(); flow1.setStatus(Status.FAILED); this.executionFlowDao.updateExecutableFlow(flow1); activeFlows1 = this.fetchActiveFlowDao.fetchActiveFlows(); assertThat(activeFlows1.containsKey(flow1.getExecutionId())).isFalse(); }
@Override public Map<Integer, Pair<ExecutionReference, ExecutableFlow>> fetchActiveFlows() throws ExecutorManagerException { return this.fetchActiveFlowDao.fetchActiveFlows(); }