use of org.apache.oozie.sla.SLARegistrationBean in project oozie by apache.
the class TestSLARegistrationQueryExecutor method testGetSelectQuery.
public void testGetSelectQuery() throws Exception {
EntityManager em = jpaService.getEntityManager();
SLARegistrationBean bean = addRecordToSLARegistrationTable("test-application", SLAStatus.MET);
// GET_SLA_REG_ALL
Query query = SLARegistrationQueryExecutor.getInstance().getSelectQuery(SLARegQuery.GET_SLA_REG_ALL, em, bean.getId());
assertEquals(query.getParameterValue("id"), bean.getId());
// GET_WORKFLOW_SUSPEND
query = SLARegistrationQueryExecutor.getInstance().getSelectQuery(SLARegQuery.GET_SLA_REG_ON_RESTART, em, bean.getId());
assertEquals(query.getParameterValue("id"), bean.getId());
}
use of org.apache.oozie.sla.SLARegistrationBean in project oozie by apache.
the class DummySLACalculatorMemory method createDBEntryForStarted.
private SLASummaryBean createDBEntryForStarted(String actionId, Date expectedStartTS, Date expectedEndTS, int eventProcessed) throws Exception {
ArrayList<JsonBean> insertList = new ArrayList<JsonBean>();
Date modTime = new Date();
WorkflowJobBean wf = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING, actionId);
wf.setStatus(wf.getStatus());
wf.setStartTime(expectedStartTS);
wf.setLastModifiedTime(modTime);
WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_START_END, wf);
CoordinatorActionBean coordAction = new CoordinatorActionBean();
coordAction.setId(actionId);
coordAction.setJobId(actionId.split("@", -1)[0]);
coordAction.setStatusStr("RUNNING");
coordAction.setLastModifiedTime(modTime);
coordAction.setExternalId(wf.getId());
CoordinatorJobBean coordJob = new CoordinatorJobBean();
coordJob.setId(actionId.split("@", -1)[0]);
coordJob.setUser("dummy");
coordJob.setAppName("dummy");
coordJob.setStatusStr("RUNNING");
coordJob.setAppNamespace("dummy");
SLASummaryBean sla = new SLASummaryBean();
sla.setId(actionId);
sla.setAppType(AppType.COORDINATOR_ACTION);
sla.setJobStatus("RUNNING");
sla.setSLAStatus(SLAStatus.IN_PROCESS);
sla.setEventProcessed(eventProcessed);
sla.setLastModifiedTime(modTime);
sla.setExpectedStart(expectedStartTS);
sla.setActualStart(expectedStartTS);
sla.setExpectedEnd(expectedEndTS);
sla.setExpectedDuration(10 * 60 * 1000);
SLARegistrationBean reg = new SLARegistrationBean();
reg.setId(actionId);
insertList.add(coordAction);
insertList.add(coordJob);
insertList.add(sla);
insertList.add(reg);
BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, null, null);
return sla;
}
use of org.apache.oozie.sla.SLARegistrationBean in project oozie by apache.
the class DummySLACalculatorMemory method createDBEntry.
private void createDBEntry(String actionId, Date expectedStartTS, Date expectedEndTS) throws Exception {
ArrayList<JsonBean> insertList = new ArrayList<JsonBean>();
CoordinatorActionBean coordAction = new CoordinatorActionBean();
Date modTime = new Date(System.currentTimeMillis() - 1000 * 3600 * 2);
coordAction.setId(actionId);
coordAction.setJobId(actionId.split("@", -1)[0]);
coordAction.setStatusStr("WAITING");
coordAction.setLastModifiedTime(modTime);
CoordinatorJobBean coordJob = new CoordinatorJobBean();
coordJob.setId(actionId.split("@", -1)[0]);
coordJob.setUser("dummy");
coordJob.setAppName("dummy");
coordJob.setStatusStr("RUNNING");
coordJob.setAppNamespace("dummy");
SLASummaryBean sla = new SLASummaryBean();
sla.setId(actionId);
sla.setAppType(AppType.COORDINATOR_ACTION);
sla.setJobStatus("WAITING");
sla.setSLAStatus(SLAStatus.NOT_STARTED);
sla.setEventProcessed(0);
sla.setLastModifiedTime(modTime);
sla.setExpectedStart(expectedStartTS);
sla.setExpectedEnd(expectedEndTS);
sla.setExpectedDuration(10 * 60 * 1000);
SLARegistrationBean reg = new SLARegistrationBean();
reg.setId(actionId);
insertList.add(coordAction);
insertList.add(coordJob);
insertList.add(sla);
insertList.add(reg);
BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, null, null);
}
use of org.apache.oozie.sla.SLARegistrationBean in project oozie by apache.
the class DummySLACalculatorMemory method testSLAFailOverWithHA.
public void testSLAFailOverWithHA() throws Exception {
SLAService slas = Services.get().get(SLAService.class);
SLACalculatorMemory slaCalcMem = (SLACalculatorMemory) slas.getSLACalculator();
EventHandlerService ehs = Services.get().get(EventHandlerService.class);
// start another dummy oozie instance (dummy sla and eventhandler
// services)
DummyZKOozie dummyOozie_1 = null;
try {
dummyOozie_1 = new DummyZKOozie("a", "http://blah");
DummySLACalculatorMemory dummyCalc = new DummySLACalculatorMemory();
EventHandlerService dummyEhs = new EventHandlerService();
dummyCalc.setEventHandlerService(dummyEhs);
dummyEhs.init(Services.get());
dummyCalc.init(Services.get().getConf());
// Case 1 workflow job submitted to dummy server,
// but before start running, the dummy server is down
WorkflowJobBean wfJob1 = createWorkflow("job-1-W");
SLARegistrationBean sla1 = TestSLAService._createSLARegistration("job-1-W", AppType.WORKFLOW_JOB);
// 2 hr before
sla1.setExpectedStart(new Date(System.currentTimeMillis() - 2 * 3600 * 1000));
// 1 hr before
sla1.setExpectedEnd(new Date(System.currentTimeMillis() - 1 * 3600 * 1000));
// 10 mins
sla1.setExpectedDuration(10 * 60 * 1000);
dummyCalc.addRegistration(sla1.getId(), sla1);
dummyCalc.updateAllSlaStatus();
// Case 2. workflow job submitted to dummy server, start running,
// then the dummy server is down
WorkflowJobBean wfJob2 = createWorkflow("job-2-W");
SLARegistrationBean sla2 = TestSLAService._createSLARegistration("job-2-W", AppType.WORKFLOW_JOB);
// 2hr before
sla2.setExpectedStart(new Date(System.currentTimeMillis() - 2 * 3600 * 1000));
// 1hr ahead
sla2.setExpectedEnd(new Date(System.currentTimeMillis() + 1 * 3600 * 1000));
// 10 mins
sla2.setExpectedDuration(10 * 60 * 1000);
dummyCalc.addRegistration(sla2.getId(), sla2);
dummyCalc.addJobStatus(sla2.getId(), WorkflowJob.Status.RUNNING.name(), EventStatus.STARTED, new Date(), new Date());
dummyCalc.updateAllSlaStatus();
dummyEhs.new EventWorker().run();
assertTrue(output.toString().contains(sla2.getId() + " Sla START - MISS!!!"));
// suppose dummy Server is down
dummyCalc.clear();
dummyCalc = null;
dummyOozie_1.teardown();
slaCalcMem.updateAllSlaStatus();
// Job 1 started running on the living server --> start miss
slaCalcMem.addJobStatus(sla1.getId(), WorkflowJob.Status.RUNNING.name(), EventStatus.STARTED, new Date(), new Date());
// job 1 is added to slamap of living oozie server
assertNotNull(slaCalcMem.get(sla1.getId()));
ehs.new EventWorker().run();
assertTrue(output.toString().contains(sla1.getId() + " Sla START - MISS!!!"));
wfJob1.setStatus(WorkflowJob.Status.SUCCEEDED);
wfJob1.setEndTime(new Date());
wfJob1.setStartTime(new Date());
WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_START_END, wfJob1);
// Job 1 succeeded on the living server --> duration met and end miss
slaCalcMem.addJobStatus(sla1.getId(), WorkflowJob.Status.SUCCEEDED.name(), EventStatus.SUCCESS, new Date(), new Date());
ehs.new EventWorker().run();
assertTrue(output.toString().contains(sla1.getId() + " Sla DURATION - MET!!!"));
assertTrue(output.toString().contains(sla1.getId() + " Sla END - MISS!!!"));
wfJob2.setStatus(WorkflowJob.Status.SUCCEEDED);
wfJob2.setEndTime(new Date());
wfJob2.setStartTime(new Date());
WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_START_END, wfJob2);
// Job 2 succeeded on the living server --> duration met and end met
slaCalcMem.addJobStatus(sla2.getId(), WorkflowJob.Status.SUCCEEDED.name(), EventStatus.SUCCESS, new Date(), new Date());
// eventProc >= 7(already processed duration/end met), should be removed from slaMap
assertNull(slaCalcMem.get(sla2.getId()));
ehs.new EventWorker().run();
assertTrue(output.toString().contains(sla2.getId() + " Sla DURATION - MET!!!"));
assertTrue(output.toString().contains(sla2.getId() + " Sla END - MET!!!"));
} finally {
if (dummyOozie_1 != null) {
dummyOozie_1.teardown();
}
}
}
use of org.apache.oozie.sla.SLARegistrationBean in project oozie by apache.
the class TestJMSSLAEventListener method testSLAJobSelectorsNegative.
@Test
public void testSLAJobSelectorsNegative() throws Exception {
JMSSLAEventListener slaListener = new JMSSLAEventListener();
slaListener.init(conf);
String id = "0000000-000000000000001-oozie-wrkf-C@1";
SLACalcStatus startMiss = _createSLACalcStatus(id);
SLARegistrationBean startMissBean = startMiss.getSLARegistrationBean();
startMiss.setId(id);
startMissBean.setAppName("Test-SLA-Start-Miss");
startMissBean.setAppType(AppType.COORDINATOR_ACTION);
startMissBean.setUser("dummyuser");
startMiss.setEventStatus(EventStatus.START_MISS);
startMiss.setSLAStatus(SLAStatus.NOT_STARTED);
startMiss.setMsgType(MessageType.SLA);
ConnectionContext jmsContext = getConnectionContext();
Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
// Pass a selector which does not match and assert for null message
String selector = JMSHeaderConstants.EVENT_STATUS + "='SLA_END_MISS'";
MessageConsumer consumer = jmsContext.createConsumer(session, slaListener.getTopic(startMiss), selector);
slaListener.onStartMiss(startMiss);
TextMessage message = (TextMessage) consumer.receive(5000);
assertNull(message);
}
Aggregations