use of org.apache.oozie.WorkflowJobBean in project oozie by apache.
the class TestSLACalculatorMemory method createWorkflow.
private void createWorkflow(List<String> idList) throws Exception {
List<JsonBean> insertList = new ArrayList<JsonBean>();
for (String id : idList) {
WorkflowJobBean workflow = new WorkflowJobBean();
workflow.setId(id);
workflow.setStatusStr("PREP");
workflow.setStartTime(new Date());
insertList.add(workflow);
}
BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, null, null);
}
use of org.apache.oozie.WorkflowJobBean in project oozie by apache.
the class TestSLACalculatorMemory method testWFEndNotCoord.
public void testWFEndNotCoord() throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
SLACalculatorMemory slaCalcMemory = new SLACalculatorMemory();
slaCalcMemory.init(Services.get().get(ConfigurationService.class).getConf());
SLARegistrationBean slaRegBean = _createSLARegistration("job-C@1", AppType.COORDINATOR_ACTION);
String coordActionId = slaRegBean.getId();
slaRegBean.setExpectedEnd(sdf.parse("2013-03-07"));
slaRegBean.setExpectedStart(sdf.parse("2012-03-07"));
slaCalcMemory.addRegistration(coordActionId, slaRegBean);
SLACalcStatus calc1 = slaCalcMemory.get(coordActionId);
calc1.setEventProcessed(1);
calc1.setSLAStatus(SLAEvent.SLAStatus.IN_PROCESS);
calc1.setJobStatus(WorkflowAction.Status.RUNNING.name());
calc1.setLastModifiedTime(new Date());
SLASummaryBean slaSummaryBean = new SLASummaryBean(calc1);
SLASummaryQueryExecutor.getInstance().executeUpdate(SLASummaryQuery.UPDATE_SLA_SUMMARY_ALL, slaSummaryBean);
// Simulate a lost failed event
CoordinatorActionBean coordAction = new CoordinatorActionBean();
coordAction.setId(coordActionId);
coordAction.setStatus(CoordinatorAction.Status.RUNNING);
coordAction.setLastModifiedTime(sdf.parse("2013-02-07"));
coordAction.setExternalId("wf_job-W");
CoordActionInsertJPAExecutor caInsertCmd = new CoordActionInsertJPAExecutor(coordAction);
jpaService.execute(caInsertCmd);
WorkflowJobBean wjb = new WorkflowJobBean();
wjb.setId("wf_job-W");
wjb.setStartTime(sdf.parse("2012-02-07"));
wjb.setLastModifiedTime(new Date());
wjb.setStatus(WorkflowJob.Status.SUCCEEDED);
WorkflowJobQueryExecutor.getInstance().insert(wjb);
calc1 = slaCalcMemory.get(coordActionId);
slaCalcMemory.updateJobSla(coordActionId);
slaSummaryBean = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, coordActionId);
// cord action is running and wf job is completed
assertEquals(slaSummaryBean.getJobStatus(), WorkflowInstance.Status.RUNNING.name());
coordAction.setStatus(CoordinatorAction.Status.SUCCEEDED);
CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, coordAction);
slaCalcMemory.addJobStatus(coordActionId, WorkflowJob.Status.SUCCEEDED.toString(), EventStatus.SUCCESS, sdf.parse("2012-02-07"), sdf.parse("2012-03-07"));
slaSummaryBean = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, coordActionId);
assertEquals(slaSummaryBean.getJobStatus(), WorkflowInstance.Status.SUCCEEDED.toString());
}
use of org.apache.oozie.WorkflowJobBean in project oozie by apache.
the class TestSLACalculatorMemory method testCoordinatorActionSLAStatusOnRestart.
@Test
public void testCoordinatorActionSLAStatusOnRestart() throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
SLACalculatorMemory slaCalcMemory = new SLACalculatorMemory();
slaCalcMemory.init(Services.get().get(ConfigurationService.class).getConf());
SLARegistrationBean slaRegBean1 = _createSLARegistration("job-C@1", AppType.COORDINATOR_ACTION);
String jobId1 = slaRegBean1.getId();
slaRegBean1.setExpectedEnd(sdf.parse("2013-03-07"));
slaRegBean1.setExpectedStart(sdf.parse("2012-03-07"));
slaCalcMemory.addRegistration(jobId1, slaRegBean1);
SLACalcStatus calc1 = slaCalcMemory.get(jobId1);
calc1.setEventProcessed(1);
calc1.setSLAStatus(SLAEvent.SLAStatus.IN_PROCESS);
calc1.setJobStatus(WorkflowAction.Status.RUNNING.name());
calc1.setLastModifiedTime(new Date());
SLASummaryBean slaSummaryBean = new SLASummaryBean(calc1);
SLASummaryQueryExecutor.getInstance().executeUpdate(SLASummaryQuery.UPDATE_SLA_SUMMARY_ALL, slaSummaryBean);
// Simulate a lost failed event
CoordinatorActionBean cab = new CoordinatorActionBean();
cab.setId(jobId1);
cab.setStatus(CoordinatorAction.Status.FAILED);
cab.setLastModifiedTime(sdf.parse("2013-02-07"));
cab.setExternalId("wf_job-W");
CoordActionInsertJPAExecutor caInsertCmd = new CoordActionInsertJPAExecutor(cab);
jpaService.execute(caInsertCmd);
WorkflowJobBean wjb = new WorkflowJobBean();
wjb.setId("wf_job-W");
wjb.setStartTime(sdf.parse("2012-02-07"));
wjb.setLastModifiedTime(new Date());
WorkflowJobQueryExecutor.getInstance().insert(wjb);
slaCalcMemory = new SLACalculatorMemory();
slaCalcMemory.init(Services.get().get(ConfigurationService.class).getConf());
slaCalcMemory.updateAllSlaStatus();
// As job succeeded, it should not be in memory
assertEquals(0, slaCalcMemory.size());
SLASummaryBean slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId1);
assertEquals("job-C@1", slaSummary.getId());
assertEquals(8, slaSummary.getEventProcessed());
assertEquals(AppType.COORDINATOR_ACTION, slaSummary.getAppType());
assertEquals("FAILED", slaSummary.getJobStatus());
assertEquals(SLAEvent.SLAStatus.MISS, slaSummary.getSLAStatus());
assertEquals(sdf.parse("2012-02-07"), slaSummary.getActualStart());
assertEquals(sdf.parse("2013-02-07"), slaSummary.getActualEnd());
assertEquals(sdf.parse("2013-02-07").getTime() - sdf.parse("2012-02-07").getTime(), slaSummary.getActualDuration());
}
use of org.apache.oozie.WorkflowJobBean in project oozie by apache.
the class TestSLACalculatorMemory method testHistoryPurge.
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);
// 1 hour back
slaRegBean.setExpectedStart(startTime);
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()));
}
use of org.apache.oozie.WorkflowJobBean in project oozie by apache.
the class TestSLACalculatorMemory method testSLAEvents1.
@Test
public void testSLAEvents1() throws Exception {
SLACalculatorMemory slaCalcMemory = new SLACalculatorMemory();
EventHandlerService ehs = Services.get().get(EventHandlerService.class);
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);
// 1 hour
slaRegBean.setExpectedStart(new Date(System.currentTimeMillis() - 1 * 1 * 3600 * 1000));
slaRegBean.setExpectedDuration(2 * 3600 * 1000);
// 1 hour
slaRegBean.setExpectedEnd(new Date(System.currentTimeMillis() - 1 * 1 * 3600 * 1000));
String jobId = slaRegBean.getId();
slaCalcMemory.addRegistration(jobId, slaRegBean);
assertEquals(1, slaCalcMemory.size());
SLASummaryBean slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId);
assertEquals(SLAStatus.NOT_STARTED, slaSummary.getSLAStatus());
assertEquals("PREP", slaSummary.getJobStatus());
slaCalcMemory.updateJobSla(jobId);
assertEquals(2, ehs.getEventQueue().size());
slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId);
// both start miss and end miss (101)
assertEquals(5, slaSummary.getEventProcessed());
assertEquals(SLAEvent.EventStatus.END_MISS, slaSummary.getEventStatus());
assertEquals(SLAStatus.MISS, slaSummary.getSLAStatus());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
assertEquals(SLAStatus.MISS, slaSummary.getSLAStatus());
job1.setStatusStr(WorkflowJob.Status.SUSPENDED.toString());
job1.setLastModifiedTime(new Date());
WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_MODTIME, job1);
slaCalcMemory.addJobStatus(jobId, WorkflowJob.Status.SUSPENDED.toString(), EventStatus.SUSPEND, sdf.parse("2012-01-01"), null);
slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId);
assertEquals(WorkflowJob.Status.SUSPENDED.toString(), slaSummary.getJobStatus());
assertEquals(5, slaSummary.getEventProcessed());
job1.setStatusStr(WorkflowJob.Status.SUCCEEDED.toString());
job1.setLastModifiedTime(new Date());
job1.setStartTime(sdf.parse("2012-01-01"));
job1.setEndTime(sdf.parse("2012-01-02"));
WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_START_END, job1);
slaCalcMemory.addJobStatus(jobId, WorkflowJob.Status.SUCCEEDED.toString(), EventStatus.SUCCESS, sdf.parse("2012-01-01"), sdf.parse("2012-01-02"));
assertEquals(3, ehs.getEventQueue().size());
slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId);
// All events processed and actual times stored (1000)
assertEquals(8, slaSummary.getEventProcessed());
assertEquals(SLAStatus.MET, slaSummary.getSLAStatus());
assertEquals(WorkflowJob.Status.SUCCEEDED.toString(), slaSummary.getJobStatus());
assertEquals(SLAEvent.EventStatus.DURATION_MISS, slaSummary.getEventStatus());
assertEquals(sdf.parse("2012-01-01").getTime(), slaSummary.getActualStart().getTime());
assertEquals(sdf.parse("2012-01-02").getTime(), slaSummary.getActualEnd().getTime());
assertEquals(sdf.parse("2012-01-02").getTime() - sdf.parse("2012-01-01").getTime(), slaSummary.getActualDuration());
assertEquals(0, slaCalcMemory.size());
}
Aggregations