/** * Check if the flow status is finished. * * @param flow the executable flow * @return the boolean */ public static boolean isFinished(final ExecutableFlow flow) { switch (flow.getStatus()) { case SUCCEEDED: case FAILED: case KILLED: return true; default: return false; } } }
@Override public void doAction() throws Exception { final ExecutableFlow exFlow = executorManagerAdapter.getExecutableFlow(this.execId); logger.info("ready to kill execution " + this.execId); if (!Status.isStatusFinished(exFlow.getStatus())) { logger.info("Killing execution " + this.execId); executorManagerAdapter.cancelFlow(exFlow, Constants.AZKABAN_SLA_CHECKER_USERNAME); } }
private void ajaxRestartFailed(final HttpServletRequest req, final HttpServletResponse resp, final HashMap<String, Object> ret, final User user, final ExecutableFlow exFlow) throws ServletException { final Project project = getProjectAjaxByPermission(ret, exFlow.getProjectId(), user, Type.EXECUTE); if (project == null) { return; } if (exFlow.getStatus() == Status.FAILED || exFlow.getStatus() == Status.SUCCEEDED) { ret.put("error", "Flow has already finished. Please re-execute."); return; } try { this.executorManagerAdapter.retryFailures(exFlow, user.getUserId()); } catch (final ExecutorManagerException e) { ret.put("error", e.getMessage()); } }
private void ajaxFetchExecutableFlowUpdate(final HttpServletRequest req, final HttpServletResponse resp, final HashMap<String, Object> ret, final User user, final ExecutableFlow exFlow) throws ServletException { final Long lastUpdateTime = Long.parseLong(getParam(req, "lastUpdateTime")); logger.info("Fetching " + exFlow.getExecutionId()); final Project project = getProjectAjaxByPermission(ret, exFlow.getProjectId(), user, Type.READ); if (project == null) { return; } final Map<String, Object> map = getExecutableFlowUpdateInfo(exFlow, lastUpdateTime); map.put("status", exFlow.getStatus()); map.put("startTime", exFlow.getStartTime()); map.put("endTime", exFlow.getEndTime()); map.put("updateTime", exFlow.getUpdateTime()); ret.putAll(map); }
flowInfo.put("flowId", flow.getFlowId()); flowInfo.put("projectId", flow.getProjectId()); flowInfo.put("status", flow.getStatus().toString()); flowInfo.put("submitTime", flow.getSubmitTime()); flowInfo.put("startTime", flow.getStartTime());
+ execId + " is expected to FINISH within " + duration + " from " + fmt.print(new DateTime(flow.getStartTime())) + "<br/>"; final String actual = "Actual flow status is " + flow.getStatus(); return basicinfo + expected + actual; } else if (type.equals(SlaOption.TYPE_FLOW_SUCCEED)) { + execId + " expected to FINISH within " + duration + " from " + fmt.print(new DateTime(flow.getStartTime())) + "<br/>"; final String actual = "Actual flow status is " + flow.getStatus(); return basicinfo + expected + actual; } else if (type.equals(SlaOption.TYPE_JOB_FINISH)) {
private Status getFlowStatus(final ExecutableFlow flow) throws Exception { return fetchFlow(flow) != null ? fetchFlow(flow).getStatus() : null; }
/** * Test running flow is finalized when its executor is removed from DB. */ @Test public void checkExecutorHealthExecutorIdRemoved() throws Exception { this.activeFlows.put(EXECUTION_ID_11, new Pair<>( new ExecutionReference(EXECUTION_ID_11, null), this.flow1)); when(this.loader.fetchExecutableFlow(EXECUTION_ID_11)).thenReturn(this.flow1); this.executorHealthChecker.checkExecutorHealth(); verify(this.loader).updateExecutableFlow(this.flow1); assertThat(this.flow1.getStatus()).isEqualTo(Status.FAILED); }
@Test public void testKillQueuedFlow() throws Exception { // Flow1 is not assigned to any executor and is in PREPARING status. submitFlow(this.flow1, this.ref1); this.flow1.setStatus(Status.PREPARING); this.controller.cancelFlow(this.flow1, this.user.getUserId()); // Verify that the status of flow1 is finalized. assertThat(this.flow1.getStatus()).isEqualTo(Status.FAILED); this.flow1.getExecutableNodes().forEach(node -> { assertThat(node.getStatus()).isEqualTo(Status.KILLING); }); }
/** * Test running flow is not finalized and alert email is not sent when executor is alive. */ @Test public void checkExecutorHealthAlive() throws Exception { this.activeFlows.put(EXECUTION_ID_11, new Pair<>( new ExecutionReference(EXECUTION_ID_11, this.executor1), this.flow1)); when(this.apiGateway.callWithExecutionId(this.executor1.getHost(), this.executor1.getPort(), ConnectorParams.PING_ACTION, null, null)).thenReturn(ImmutableMap.of(ConnectorParams .STATUS_PARAM, ConnectorParams.RESPONSE_ALIVE)); this.executorHealthChecker.checkExecutorHealth(); assertThat(this.flow1.getStatus()).isEqualTo(Status.RUNNING); verifyZeroInteractions(this.alerterHolder); }
private void assertTwoFlowSame(final ExecutableFlow flow1, final ExecutableFlow flow2, final boolean compareFlowData) { assertThat(flow1.getExecutionId()).isEqualTo(flow2.getExecutionId()); assertThat(flow1.getStatus()).isEqualTo(flow2.getStatus()); assertThat(flow1.getEndTime()).isEqualTo(flow2.getEndTime()); assertThat(flow1.getStartTime()).isEqualTo(flow2.getStartTime()); assertThat(flow1.getSubmitTime()).isEqualTo(flow2.getSubmitTime()); assertThat(flow1.getFlowId()).isEqualTo(flow2.getFlowId()); assertThat(flow1.getProjectId()).isEqualTo(flow2.getProjectId()); assertThat(flow1.getVersion()).isEqualTo(flow2.getVersion()); assertThat(flow1.getSubmitUser()).isEqualTo(flow2.getSubmitUser()); if (compareFlowData) { assertThat(flow1.getExecutionOptions().getFailureAction()) .isEqualTo(flow2.getExecutionOptions().getFailureAction()); assertThat(new HashSet<>(flow1.getEndNodes())).isEqualTo(new HashSet<>(flow2.getEndNodes())); } }
@Override public Object eval() { final ExecutableFlow exflow; try { exflow = executorManagerAdapter.getExecutableFlow(this.execId); } catch (final ExecutorManagerException e) { e.printStackTrace(); return Boolean.FALSE; } if (this.jobName != null) { final ExecutableNode job = exflow.getExecutableNode(this.jobName); if (job != null) { return job.getStatus().equals(this.wantedStatus); } else { return Boolean.FALSE; } } else { return exflow.getStatus().equals(this.wantedStatus); } }
private ExecutableFlow createExecution(final Status status) throws IOException, ExecutorManagerException { final ExecutableFlow flow = TestUtils.createTestExecutableFlow("exectest1", "exec1"); this.executionFlowDao.uploadExecutableFlow(flow); assertEquals(Status.PREPARING, flow.getStatus()); flow.setStatus(status); this.executionFlowDao.updateExecutableFlow(flow); return flow; }
@Test public void testNotFoundFlows() throws Exception { testSetUpForRunningFlows(); this.manager.start(); final ExecutableFlow flow1 = TestUtils.createTestExecutableFlow("exectest1", "exec1"); when(this.loader.fetchExecutableFlow(-1)).thenReturn(flow1); mockFlowDoesNotExist(); this.manager.submitExecutableFlow(flow1, this.user.getUserId()); final ExecutableFlow fetchedFlow = waitFlowFinished(flow1); Assert.assertEquals(fetchedFlow.getStatus(), Status.FAILED); }
private void updateExecutableFlow(final ExecutableFlow flow, final EncodingType encType) throws ExecutorManagerException { final String UPDATE_EXECUTABLE_FLOW_DATA = "UPDATE execution_flows " + "SET status=?,update_time=?,start_time=?,end_time=?,enc_type=?,flow_data=? " + "WHERE exec_id=?"; final String json = JSONUtils.toJSON(flow.toObject()); byte[] data = null; try { final byte[] stringData = json.getBytes("UTF-8"); data = stringData; // Todo kunkun-tang: use a common method to transform stringData to data. if (encType == EncodingType.GZIP) { data = GZIPUtils.gzipBytes(stringData); } } catch (final IOException e) { throw new ExecutorManagerException("Error encoding the execution flow."); } try { this.dbOperator.update(UPDATE_EXECUTABLE_FLOW_DATA, flow.getStatus() .getNumVal(), flow.getUpdateTime(), flow.getStartTime(), flow .getEndTime(), encType.getNumVal(), data, flow.getExecutionId()); } catch (final SQLException e) { throw new ExecutorManagerException("Error updating flow.", e); } }
@Test public void testKillQueuedFlow() throws Exception { final ExecutorManager manager = createMultiExecutorManagerInstance(); final ExecutableFlow flow1 = TestUtils.createTestExecutableFlow("exectest1", "exec1"); final User testUser = TestUtils.getTestUser(); manager.submitExecutableFlow(flow1, testUser.getUserId()); manager.cancelFlow(flow1, testUser.getUserId()); final ExecutableFlow fetchedFlow = this.loader.fetchExecutableFlow(flow1.getExecutionId()); Assert.assertEquals(fetchedFlow.getStatus(), Status.FAILED); Assert.assertFalse(manager.getRunningFlows().contains(flow1)); }
+ Utils.formatDuration(flow.getStartTime(), flow.getEndTime()) + "</td></tr>"); message.println("<tr><td>Status</td><td>" + flow.getStatus() + "</td></tr>"); message.println("</table>"); message.println("");
+ Utils.formatDuration(flow.getStartTime(), flow.getEndTime()) + "</td></tr>"); message.println("<tr><td>Status</td><td>" + flow.getStatus() + "</td></tr>"); message.println("</table>"); message.println("");
private ExecutableFlow getExecutableFlowMetadata( ExecutableFlow fullExFlow) { final Flow flow = new Flow(fullExFlow.getId()); final Project project = new Project(fullExFlow.getProjectId(), null); project.setVersion(fullExFlow.getVersion()); flow.setVersion(fullExFlow.getVersion()); final ExecutableFlow metadata = new ExecutableFlow(project, flow); metadata.setExecutionId(fullExFlow.getExecutionId()); metadata.setStatus(fullExFlow.getStatus()); metadata.setSubmitTime(fullExFlow.getSubmitTime()); metadata.setStartTime(fullExFlow.getStartTime()); metadata.setEndTime(fullExFlow.getEndTime()); metadata.setSubmitUser(fullExFlow.getSubmitUser()); return metadata; }