@SuppressWarnings("unchecked") public JSONObject toJSONObject(String timeZoneId) { JSONObject json = new JSONObject(); json.put(JsonTags.WORKFLOW_APP_PATH, getAppPath()); json.put(JsonTags.WORKFLOW_APP_NAME, getAppName()); json.put(JsonTags.WORKFLOW_ID, getId()); json.put(JsonTags.WORKFLOW_EXTERNAL_ID, getExternalId()); json.put(JsonTags.WORKFLOW_PARENT_ID, getParentId()); json.put(JsonTags.WORKFLOW_CONF, getConf()); json.put(JsonTags.WORKFLOW_STATUS, getStatus().toString()); json.put(JsonTags.WORKFLOW_LAST_MOD_TIME, JsonUtils.formatDateRfc822(getLastModifiedTime(), timeZoneId)); json.put(JsonTags.WORKFLOW_CREATED_TIME, JsonUtils.formatDateRfc822(getCreatedTime(), timeZoneId)); json.put(JsonTags.WORKFLOW_START_TIME, JsonUtils.formatDateRfc822(getStartTime(), timeZoneId)); json.put(JsonTags.WORKFLOW_END_TIME, JsonUtils.formatDateRfc822(getEndTime(), timeZoneId)); json.put(JsonTags.WORKFLOW_USER, getUser()); json.put(JsonTags.WORKFLOW_GROUP, getGroup()); json.put(JsonTags.WORKFLOW_ACL, getAcl()); json.put(JsonTags.WORKFLOW_RUN, (long) getRun()); json.put(JsonTags.WORKFLOW_CONSOLE_URL, getConsoleUrl()); json.put(JsonTags.WORKFLOW_ACTIONS, WorkflowActionBean.toJSONArray(actions, timeZoneId)); json.put(JsonTags.TO_STRING, toString()); return json; }
@SuppressWarnings("unchecked") public JSONObject toJSONObject(String timeZoneId) { JSONObject json = new JSONObject(); json.put(JsonTags.WORKFLOW_APP_PATH, getAppPath()); json.put(JsonTags.WORKFLOW_APP_NAME, getAppName()); json.put(JsonTags.WORKFLOW_ID, getId()); json.put(JsonTags.WORKFLOW_EXTERNAL_ID, getExternalId()); json.put(JsonTags.WORKFLOW_PARENT_ID, getParentId()); json.put(JsonTags.WORKFLOW_CONF, getConf()); json.put(JsonTags.WORKFLOW_STATUS, getStatus().toString()); json.put(JsonTags.WORKFLOW_LAST_MOD_TIME, JsonUtils.formatDateRfc822(getLastModifiedTime(), timeZoneId)); json.put(JsonTags.WORKFLOW_CREATED_TIME, JsonUtils.formatDateRfc822(getCreatedTime(), timeZoneId)); json.put(JsonTags.WORKFLOW_START_TIME, JsonUtils.formatDateRfc822(getStartTime(), timeZoneId)); json.put(JsonTags.WORKFLOW_END_TIME, JsonUtils.formatDateRfc822(getEndTime(), timeZoneId)); json.put(JsonTags.WORKFLOW_USER, getUser()); json.put(JsonTags.WORKFLOW_GROUP, getGroup()); json.put(JsonTags.WORKFLOW_ACL, getAcl()); json.put(JsonTags.WORKFLOW_RUN, (long) getRun()); json.put(JsonTags.WORKFLOW_CONSOLE_URL, getConsoleUrl()); json.put(JsonTags.WORKFLOW_ACTIONS, WorkflowActionBean.toJSONArray(actions, timeZoneId)); json.put(JsonTags.TO_STRING, toString()); return json; }
public WorkflowNotificationXCommand(WorkflowJobBean workflow) { super("job.notification", "job.notification", 0); ParamChecker.notNull(workflow, "workflow"); jobId = workflow.getId(); url = workflow.getWorkflowInstance().getConf().get(OozieClient.WORKFLOW_NOTIFICATION_URL); if (url != null) { url = url.replaceAll(JOB_ID_PATTERN, workflow.getId()); url = url.replaceAll(STATUS_PATTERN, workflow.getStatus().toString()); if (workflow.getParentId() == null) { url = url.replaceAll(PARENT_ID_PATTERN, ""); } else { url = url.replaceAll(PARENT_ID_PATTERN, workflow.getParentId()); } proxyConf = workflow.getWorkflowInstance().getConf() .get(OozieClient.WORKFLOW_NOTIFICATION_PROXY, ConfigurationService.get(NOTIFICATION_PROXY_KEY)); LOG.debug("Proxy :" + proxyConf); } }
WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_START_END, job1); slaCalcMemory.addJobStatus(jobId, WorkflowJob.Status.RUNNING.toString(), EventStatus.STARTED, new Date( System.currentTimeMillis() - 3600 * 1000), null); SLASummaryBean slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId); WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_START_END, job1); slaCalcMemory.addJobStatus(jobId, WorkflowJob.Status.SUCCEEDED.toString(), EventStatus.SUCCESS, new Date( System.currentTimeMillis() - 3600 * 1000), new Date(System.currentTimeMillis())); slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId);
public void testHistoryPurge() throws Exception{ SLACalculatorMemory slaCalcMemory = new SLACalculatorMemory(); slaCalcMemory.init(Services.get().get(ConfigurationService.class).getConf()); WorkflowJobBean job1 = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP); SLARegistrationBean slaRegBean = _createSLARegistration(job1.getId(), AppType.WORKFLOW_JOB); Date startTime = new Date(System.currentTimeMillis() - 1 * 1 * 3600 * 1000); slaRegBean.setExpectedStart(startTime); // 1 hour back slaRegBean.setExpectedDuration(1000); slaRegBean.setExpectedEnd(new Date(System.currentTimeMillis() - 1 * 1 * 3600 * 1000)); String jobId = slaRegBean.getId(); slaCalcMemory.addRegistration(slaRegBean.getId(), slaRegBean); slaCalcMemory.updateJobSla(jobId); job1.setStatusStr("RUNNING"); job1.setLastModifiedTime(new Date()); job1.setStartTime(startTime); WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_START_END, job1); slaCalcMemory.addJobStatus(jobId, WorkflowJob.Status.RUNNING.toString(), EventStatus.STARTED, new Date( System.currentTimeMillis() - 3600 * 1000), null); SLASummaryBean slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId); // The actual end times are not stored, but sla's processed so (111) assertEquals(7, slaSummary.getEventProcessed()); assertTrue(slaCalcMemory.isJobIdInHistorySet(job1.getId())); job1.setStatusStr("SUCCEEDED"); job1.setLastModifiedTime(new Date()); job1.setStartTime(startTime); WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_START_END, job1); slaCalcMemory.new HistoryPurgeWorker().run(); assertFalse(slaCalcMemory.isJobIdInHistorySet(job1.getId())); }
@Test public void testEventOutOfOrder() throws Exception { SLACalculatorMemory slaCalcMemory = new SLACalculatorMemory(); slaCalcMemory.init(Services.get().get(ConfigurationService.class).getConf()); WorkflowJobBean wfJob = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING); SLARegistrationBean slaRegBean = _createSLARegistration(wfJob.getId(), AppType.WORKFLOW_JOB); Date startTime = new Date(System.currentTimeMillis() + 1 * 1 * 3600 * 1000); // 1 hour ahead slaRegBean.setExpectedStart(startTime); slaRegBean.setExpectedDuration(3600 * 1000); slaRegBean.setExpectedEnd(new Date(System.currentTimeMillis() - 1 * 1 * 3600 * 1000)); // 1 hour back String jobId = slaRegBean.getId(); slaCalcMemory.addRegistration(slaRegBean.getId(), slaRegBean); slaCalcMemory.updateJobSla(jobId); SLASummaryBean slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId); slaRegBean = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, jobId); assertEquals(slaSummary.getJobStatus(), WorkflowInstance.Status.RUNNING.toString()); wfJob.setStatus(WorkflowJob.Status.SUCCEEDED); wfJob.setEndTime(new Date(System.currentTimeMillis() + 1 * 1 * 3600 * 1000)); WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_END, wfJob); slaCalcMemory.addJobStatus(jobId, WorkflowJob.Status.SUCCEEDED.toString(), EventStatus.SUCCESS, new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis() + 1 * 1 * 3600 * 1000)); slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId); assertEquals(slaSummary.getJobStatus(), WorkflowInstance.Status.SUCCEEDED.toString()); slaCalcMemory.addJobStatus(jobId, WorkflowJob.Status.RUNNING.toString(), EventStatus.SUCCESS, new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis() + 1 * 1 * 3600 * 1000)); slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId); assertEquals(slaSummary.getJobStatus(), WorkflowInstance.Status.SUCCEEDED.toString()); }
@Test public void testDuplicateStartMiss() throws Exception { // test start-miss EventHandlerService ehs = Services.get().get(EventHandlerService.class); SLACalculatorMemory slaCalcMemory = new SLACalculatorMemory(); slaCalcMemory.init(Services.get().get(ConfigurationService.class).getConf()); WorkflowJobBean job1 = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP); SLARegistrationBean slaRegBean = _createSLARegistration(job1.getId(), AppType.WORKFLOW_JOB); Date startTime = new Date(System.currentTimeMillis() - 1 * 1 * 3600 * 1000); // 1 hour back slaRegBean.setExpectedStart(startTime); slaRegBean.setExpectedDuration(2* 3600 * 1000); //to avoid duration miss slaRegBean.setExpectedEnd(new Date(System.currentTimeMillis() + 1 * 1 * 3600 * 1000)); // 1 hour ahead String jobId = slaRegBean.getId(); slaCalcMemory.addRegistration(slaRegBean.getId(), slaRegBean); slaCalcMemory.updateJobSla(jobId); SLASummaryBean slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId); assertEquals(1, slaSummary.getEventProcessed()); assertEquals(SLAStatus.NOT_STARTED, slaSummary.getSLAStatus()); job1.setStatus(WorkflowJob.Status.RUNNING); job1.setStartTime(startTime); WorkflowJobQueryExecutor.getInstance().executeUpdate( WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_START_END, job1); slaCalcMemory.addJobStatus(jobId, WorkflowJob.Status.RUNNING.toString(), EventStatus.STARTED, new Date(System.currentTimeMillis()), null); slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId); assertEquals(1, slaSummary.getEventProcessed()); assertEquals(SLAStatus.IN_PROCESS, slaSummary.getSLAStatus()); assertEquals(WorkflowJob.Status.RUNNING.toString(), slaSummary.getJobStatus()); assertEquals(1, ehs.getEventQueue().size()); }
@Override protected void verifyPrecondition() throws CommandException, PreconditionException { if (wfJob == null) { throw new PreconditionException(ErrorCode.E0604, jobId); } if (wfAction == null) { throw new PreconditionException(ErrorCode.E0605, actionId); } if (wfAction.isPending() && (wfAction.getStatus() == WorkflowActionBean.Status.DONE || wfAction.getStatus() == WorkflowActionBean.Status.END_RETRY || wfAction.getStatus() == WorkflowActionBean.Status.END_MANUAL)) { if (wfJob.getStatus() != WorkflowJob.Status.RUNNING) { throw new PreconditionException(ErrorCode.E0811, WorkflowJob.Status.RUNNING.toString()); } } else { throw new PreconditionException(ErrorCode.E0812, wfAction.isPending(), wfAction.getStatusStr()); } executor = Services.get().get(ActionService.class).getExecutor(wfAction.getType()); if (executor == null) { throw new CommandException(ErrorCode.E0802, wfAction.getType()); } }
@Override protected void verifyPrecondition() throws CommandException, PreconditionException { if (wfJob == null) { throw new PreconditionException(ErrorCode.E0604, jobId); } if (wfAction == null) { throw new PreconditionException(ErrorCode.E0605, actionId); } if (wfAction.isPending() && (wfAction.getStatus() == WorkflowActionBean.Status.DONE || wfAction.getStatus() == WorkflowActionBean.Status.END_RETRY || wfAction.getStatus() == WorkflowActionBean.Status.END_MANUAL)) { if (wfJob.getStatus() != WorkflowJob.Status.RUNNING) { throw new PreconditionException(ErrorCode.E0811, WorkflowJob.Status.RUNNING.toString()); } } else { throw new PreconditionException(ErrorCode.E0812, wfAction.isPending(), wfAction.getStatusStr()); } executor = Services.get().get(ActionService.class).getExecutor(wfAction.getType()); if (executor == null) { throw new CommandException(ErrorCode.E0802, wfAction.getType()); } }
public void check(Context context, WorkflowAction action) throws ActionExecutorException { try { String subWorkflowId = action.getExternalId(); String oozieUri = action.getTrackerUri(); OozieClient oozieClient = getWorkflowClient(context, oozieUri); WorkflowJob subWorkflow = oozieClient.getJobInfo(subWorkflowId); WorkflowJob.Status status = subWorkflow.getStatus(); switch (status) { case FAILED: case KILLED: case SUCCEEDED: context.setExecutionData(status.toString(), null); break; default: context.setExternalStatus(status.toString()); break; } } catch (Exception ex) { throw convertException(ex); } }
@Override protected void verifyPrecondition() throws CommandException, PreconditionException { if (wfJob == null) { throw new PreconditionException(ErrorCode.E0604, jobId); } if (wfAction == null) { throw new PreconditionException(ErrorCode.E0605, actionId); } if (wfAction.isPending() && (wfAction.getStatus() == WorkflowActionBean.Status.PREP || wfAction.getStatus() == WorkflowActionBean.Status.START_RETRY || wfAction.getStatus() == WorkflowActionBean.Status.START_MANUAL || wfAction.getStatus() == WorkflowActionBean.Status.USER_RETRY )) { if (wfJob.getStatus() != WorkflowJob.Status.RUNNING) { throw new PreconditionException(ErrorCode.E0810, WorkflowJob.Status.RUNNING.toString()); } } else { throw new PreconditionException(ErrorCode.E0816, wfAction.isPending(), wfAction.getStatusStr()); } executor = Services.get().get(ActionService.class).getExecutor(wfAction.getType()); if (executor == null) { throw new CommandException(ErrorCode.E0802, wfAction.getType()); } }
@Override protected void verifyPrecondition() throws CommandException, PreconditionException { if (wfJob == null) { throw new PreconditionException(ErrorCode.E0604, jobId); } if (wfAction == null) { throw new PreconditionException(ErrorCode.E0605, actionId); } if (wfAction.isPending() && (wfAction.getStatus() == WorkflowActionBean.Status.PREP || wfAction.getStatus() == WorkflowActionBean.Status.START_RETRY || wfAction.getStatus() == WorkflowActionBean.Status.START_MANUAL || wfAction.getStatus() == WorkflowActionBean.Status.USER_RETRY )) { if (wfJob.getStatus() != WorkflowJob.Status.RUNNING) { throw new PreconditionException(ErrorCode.E0810, WorkflowJob.Status.RUNNING.toString()); } } else { throw new PreconditionException(ErrorCode.E0816, wfAction.isPending(), wfAction.getStatusStr()); } executor = Services.get().get(ActionService.class).getExecutor(wfAction.getType()); if (executor == null) { throw new CommandException(ErrorCode.E0802, wfAction.getType()); } }
public void check(Context context, WorkflowAction action) throws ActionExecutorException { try { String subWorkflowId = action.getExternalId(); String oozieUri = action.getTrackerUri(); OozieClient oozieClient = getWorkflowClient(context, oozieUri); WorkflowJob subWorkflow = oozieClient.getJobInfo(subWorkflowId); WorkflowJob.Status status = subWorkflow.getStatus(); switch (status) { case FAILED: case KILLED: case SUCCEEDED: context.setExecutionData(status.toString(), null); break; default: context.setExternalStatus(status.toString()); break; } } catch (Exception ex) { throw convertException(ex); } }
public WorkflowNotificationXCommand(WorkflowJobBean workflow) { super("job.notification", "job.notification", 0); ParamChecker.notNull(workflow, "workflow"); jobId = workflow.getId(); url = workflow.getWorkflowInstance().getConf().get(OozieClient.WORKFLOW_NOTIFICATION_URL); if (url != null) { url = url.replaceAll(JOB_ID_PATTERN, workflow.getId()); url = url.replaceAll(STATUS_PATTERN, workflow.getStatus().toString()); if (workflow.getParentId() == null) { url = url.replaceAll(PARENT_ID_PATTERN, ""); } else { url = url.replaceAll(PARENT_ID_PATTERN, workflow.getParentId()); } proxyConf = workflow.getWorkflowInstance().getConf() .get(OozieClient.WORKFLOW_NOTIFICATION_PROXY, ConfigurationService.get(NOTIFICATION_PROXY_KEY)); LOG.debug("Proxy :" + proxyConf); } }
public void setStatus(Status val) { this.statusStr = StringUtils.intern(val.toString()); }
public void testGetWFInfoForTextAndStatus() throws Exception { WorkflowJobBean workflowJob = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP); workflowJob.setAppName("wf-name-1"); WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW, workflowJob); Map<String, List<String>> filter = new HashMap<String, List<String>>(); List<String> textFilterList = new ArrayList<String>(); textFilterList.add("wf-name-1"); List<String> textStatusList = new ArrayList<String>(); textStatusList.add(WorkflowJob.Status.PREP.toString()); filter.put(OozieClient.FILTER_TEXT, textFilterList); filter.put(OozieClient.FILTER_STATUS, textStatusList); JPAService jpaService = Services.get().get(JPAService.class); WorkflowsJobGetJPAExecutor wfGetCmd = new WorkflowsJobGetJPAExecutor(filter, 1, 20); WorkflowsInfo wfInfo = jpaService.execute(wfGetCmd); assertEquals(1, wfInfo.getWorkflows().size()); }
public void setStatus(Status val) { this.statusStr = StringUtils.intern(val.toString()); }
@Override public void onWorkflowJobEvent(WorkflowJobEvent event) { sendEventToSLAService(event, event.getStatus().toString()); }
@Override public void onWorkflowJobEvent(WorkflowJobEvent event) { sendEventToSLAService(event, event.getStatus().toString()); }
@Override public String getJobStatus(String jobId) throws DagEngineException { did = RestConstants.JOB_SHOW_STATUS; int idx = validateWorkflowIdx(jobId); return workflows.get(idx).getStatus().toString(); }