use of org.apache.oozie.executor.jpa.SLASummaryQueryExecutor.SLASummaryQuery in project oozie by apache.
the class SLACalculatorMemory method updateDBSlaExpectedValues.
@SuppressWarnings("rawtypes")
private void updateDBSlaExpectedValues(SLACalcStatus slaCalc, List<UpdateEntry> updateList) throws JPAExecutorException {
slaCalc.setLastModifiedTime(new Date());
updateList.add(new UpdateEntry<SLARegQuery>(SLARegQuery.UPDATE_SLA_EXPECTED_VALUE, slaCalc.getSLARegistrationBean()));
updateList.add(new UpdateEntry<SLASummaryQuery>(SLASummaryQuery.UPDATE_SLA_SUMMARY_FOR_EXPECTED_TIMES, new SLASummaryBean(slaCalc)));
}
use of org.apache.oozie.executor.jpa.SLASummaryQueryExecutor.SLASummaryQuery in project oozie by apache.
the class SLACalculatorMemory method updateDBSlaConfig.
@SuppressWarnings("rawtypes")
private void updateDBSlaConfig(SLACalcStatus slaCalc, List<UpdateEntry> updateList) throws JPAExecutorException {
updateList.add(new UpdateEntry<SLARegQuery>(SLARegQuery.UPDATE_SLA_CONFIG, slaCalc.getSLARegistrationBean()));
slaCalc.setLastModifiedTime(new Date());
updateList.add(new UpdateEntry<SLASummaryQuery>(SLASummaryQuery.UPDATE_SLA_SUMMARY_LAST_MODIFIED_TIME, new SLASummaryBean(slaCalc)));
}
use of org.apache.oozie.executor.jpa.SLASummaryQueryExecutor.SLASummaryQuery in project oozie by apache.
the class TestSLACalculationJPAExecutor method testRollback.
/**
* Test inserts and updates rollback
*
* @throws Exception
*/
@Test
public void testRollback() throws Exception {
JPAService jpaService = Services.get().get(JPAService.class);
assertNotNull(jpaService);
String wfId1 = "workflow-1";
String wfId2 = "workflow-2";
// initial insert
SLASummaryBean bean1 = _createSLASummaryBean(wfId1, "RUNNING", EventStatus.START_MISS, new Date(), new Date(), 1000, null, null, 2000, 0, null);
List<JsonBean> list = new ArrayList<JsonBean>();
list.add(bean1);
BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(list, null, null);
// update existing record and insert another
Date newDate = new Date();
bean1 = new SLASummaryBean();
bean1.setId(wfId1);
bean1.setActualEnd(newDate);
List<UpdateEntry> updateList = new ArrayList<UpdateEntry>();
updateList.add(new UpdateEntry<SLASummaryQuery>(SLASummaryQuery.UPDATE_SLA_SUMMARY_ALL, bean1));
SLASummaryBean bean2 = _createSLASummaryBean(wfId2, "RUNNING", EventStatus.END_MISS, new Date(), new Date(), 1000, null, null, 2000, 0, null);
List<JsonBean> insertList = new ArrayList<JsonBean>();
insertList.add(bean2);
// set fault injection to true, so transaction is roll backed
setSystemProperty(FaultInjection.FAULT_INJECTION, "true");
setSystemProperty(SkipCommitFaultInjection.ACTION_FAILOVER_FAULT_INJECTION, "true");
try {
BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, updateList, null);
fail("Expected exception due to commit failure but didn't get any");
} catch (Exception e) {
}
FaultInjection.deactivate("org.apache.oozie.command.SkipCommitFaultInjection");
// Check whether transactions are rolled back or not
SLASummaryBean sBean = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, wfId1);
// isSlaProcessed should NOT be changed to 1
// actualEnd should be null as before
assertNull(sBean.getActualEnd());
sBean = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, wfId2);
// new bean should not have been inserted due to rollback
assertNull(sBean);
}
use of org.apache.oozie.executor.jpa.SLASummaryQueryExecutor.SLASummaryQuery in project oozie by apache.
the class BatchQueryExecutor method executeBatchInsertUpdateDelete.
@SuppressWarnings("rawtypes")
public void executeBatchInsertUpdateDelete(Collection<JsonBean> insertList, Collection<UpdateEntry> updateList, Collection<JsonBean> deleteList) throws JPAExecutorException {
List<QueryEntry> queryList = new ArrayList<QueryEntry>();
JPAService jpaService = Services.get().get(JPAService.class);
EntityManager em = jpaService.getEntityManager();
if (updateList != null) {
for (UpdateEntry entry : updateList) {
Query query = null;
JsonBean bean = entry.getBean();
if (bean instanceof WorkflowJobBean) {
query = WorkflowJobQueryExecutor.getInstance().getUpdateQuery((WorkflowJobQuery) entry.getQueryName(), (WorkflowJobBean) entry.getBean(), em);
} else if (bean instanceof WorkflowActionBean) {
query = WorkflowActionQueryExecutor.getInstance().getUpdateQuery((WorkflowActionQuery) entry.getQueryName(), (WorkflowActionBean) entry.getBean(), em);
} else if (bean instanceof CoordinatorJobBean) {
query = CoordJobQueryExecutor.getInstance().getUpdateQuery((CoordJobQuery) entry.getQueryName(), (CoordinatorJobBean) entry.getBean(), em);
} else if (bean instanceof CoordinatorActionBean) {
query = CoordActionQueryExecutor.getInstance().getUpdateQuery((CoordActionQuery) entry.getQueryName(), (CoordinatorActionBean) entry.getBean(), em);
} else if (bean instanceof BundleJobBean) {
query = BundleJobQueryExecutor.getInstance().getUpdateQuery((BundleJobQuery) entry.getQueryName(), (BundleJobBean) entry.getBean(), em);
} else if (bean instanceof BundleActionBean) {
query = BundleActionQueryExecutor.getInstance().getUpdateQuery((BundleActionQuery) entry.getQueryName(), (BundleActionBean) entry.getBean(), em);
} else if (bean instanceof SLARegistrationBean) {
query = SLARegistrationQueryExecutor.getInstance().getUpdateQuery((SLARegQuery) entry.getQueryName(), (SLARegistrationBean) entry.getBean(), em);
} else if (bean instanceof SLASummaryBean) {
query = SLASummaryQueryExecutor.getInstance().getUpdateQuery((SLASummaryQuery) entry.getQueryName(), (SLASummaryBean) entry.getBean(), em);
} else {
throw new JPAExecutorException(ErrorCode.E0603, "BatchQueryExecutor failed to construct a query");
}
queryList.add(new QueryEntry(entry.getQueryName(), query));
}
}
jpaService.executeBatchInsertUpdateDelete(insertList, queryList, deleteList, em);
}
use of org.apache.oozie.executor.jpa.SLASummaryQueryExecutor.SLASummaryQuery in project oozie by apache.
the class TestSLACalculatorMemory method testLoadOnRestart.
@Test
public void testLoadOnRestart() throws Exception {
SLACalculatorMemory slaCalcMemory = new SLACalculatorMemory();
slaCalcMemory.init(Services.get().get(ConfigurationService.class).getConf());
SLARegistrationBean slaRegBean1 = _createSLARegistration("job-1-W", AppType.WORKFLOW_JOB);
String jobId1 = slaRegBean1.getId();
SLARegistrationBean slaRegBean2 = _createSLARegistration("job-2-W", AppType.WORKFLOW_JOB);
String jobId2 = slaRegBean2.getId();
SLARegistrationBean slaRegBean3 = _createSLARegistration("job-3-W", AppType.WORKFLOW_JOB);
String jobId3 = slaRegBean3.getId();
List<String> idList = new ArrayList<String>();
idList.add(slaRegBean1.getId());
idList.add(slaRegBean2.getId());
idList.add(slaRegBean3.getId());
createWorkflow(idList);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
slaRegBean1.setAppName("app-name");
slaRegBean1.setExpectedDuration(123);
slaRegBean1.setExpectedEnd(sdf.parse("2012-02-07"));
slaRegBean1.setExpectedStart(sdf.parse("2011-02-07"));
slaRegBean1.setNominalTime(sdf.parse("2012-01-06"));
slaRegBean1.setUser("user");
slaRegBean1.setParentId("parentId");
slaRegBean1.setUpstreamApps("upstreamApps");
slaRegBean1.setNotificationMsg("notificationMsg");
slaRegBean1.setAlertContact("a@abc.com");
slaRegBean1.setAlertEvents("MISS");
slaRegBean1.setJobData("jobData");
// 1 hour back
Date startTime = new Date(System.currentTimeMillis() - 1 * 1 * 3600 * 1000);
// 1 hour back
Date endTime = new Date(System.currentTimeMillis() + 2 * 1 * 3600 * 1000);
slaRegBean3.setExpectedStart(startTime);
slaRegBean3.setExpectedEnd(endTime);
slaCalcMemory.addRegistration(jobId1, slaRegBean1);
slaCalcMemory.addRegistration(jobId2, slaRegBean2);
slaCalcMemory.addRegistration(jobId3, slaRegBean3);
slaCalcMemory.updateAllSlaStatus();
SLACalcStatus calc1 = slaCalcMemory.get(jobId1);
SLACalcStatus calc2 = slaCalcMemory.get(jobId2);
SLACalcStatus calc3 = slaCalcMemory.get(jobId3);
calc1.setEventStatus(SLAEvent.EventStatus.END_MISS);
calc1.setSLAStatus(SLAEvent.SLAStatus.MISS);
calc1.setJobStatus(WorkflowJob.Status.FAILED.toString());
// set last modified time 5 days back
Date lastModifiedTime = new Date(System.currentTimeMillis() - 5 * 24 * 60 * 60 * 1000);
calc1.setLastModifiedTime(lastModifiedTime);
List<UpdateEntry> updateList = new ArrayList<UpdateEntry>();
WorkflowJobBean wf1 = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW, jobId1);
wf1.setId(jobId1);
wf1.setStatus(WorkflowJob.Status.SUCCEEDED);
wf1.setStartTime(sdf.parse("2011-03-09"));
wf1.setEndTime(sdf.parse("2011-03-10"));
wf1.setLastModifiedTime(new Date());
WorkflowJobBean wf2 = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW, jobId2);
wf2.setId(jobId2);
wf2.setStatus(WorkflowJob.Status.RUNNING);
wf2.setStartTime(sdf.parse("2011-03-09"));
wf2.setEndTime(null);
wf2.setLastModifiedTime(new Date());
WorkflowJobBean wf3 = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW, jobId3);
wf3.setId(jobId3);
wf3.setStatus(WorkflowJob.Status.RUNNING);
wf3.setStartTime(startTime);
wf3.setEndTime(null);
wf3.setLastModifiedTime(new Date());
updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW, wf1));
updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW, wf2));
updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW, wf3));
updateList.add(new UpdateEntry<SLASummaryQuery>(SLASummaryQuery.UPDATE_SLA_SUMMARY_ALL, new SLASummaryBean(calc2)));
updateList.add(new UpdateEntry<SLASummaryQuery>(SLASummaryQuery.UPDATE_SLA_SUMMARY_ALL, new SLASummaryBean(calc3)));
BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(null, updateList, null);
slaCalcMemory = new SLACalculatorMemory();
slaCalcMemory.init(Services.get().get(ConfigurationService.class).getConf());
slaCalcMemory.updateAllSlaStatus();
SLACalcStatus calc = new SLACalcStatus(SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId1), SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ON_RESTART, jobId1));
assertEquals("job-1-W", calc.getId());
assertEquals(AppType.WORKFLOW_JOB, calc.getAppType());
assertEquals("app-name", calc.getAppName());
assertEquals(123, calc.getExpectedDuration());
assertEquals(sdf.parse("2012-02-07"), calc.getExpectedEnd());
assertEquals(sdf.parse("2011-02-07"), calc.getExpectedStart());
assertEquals(sdf.parse("2012-01-06"), calc.getNominalTime());
assertEquals("user", calc.getUser());
assertEquals("parentId", calc.getParentId());
assertEquals("upstreamApps", calc.getUpstreamApps());
assertEquals("notificationMsg", calc.getNotificationMsg());
assertEquals("a@abc.com", calc.getAlertContact());
assertEquals("MISS", calc.getAlertEvents());
assertEquals("jobData", calc.getJobData());
assertEquals(sdf.parse("2011-03-09"), calc.getActualStart());
assertEquals(sdf.parse("2011-03-10"), calc.getActualEnd());
assertEquals(SLAEvent.EventStatus.END_MISS, calc1.getEventStatus());
assertEquals(SLAEvent.SLAStatus.MISS, calc1.getSLAStatus());
assertEquals(WorkflowJob.Status.FAILED.toString(), calc1.getJobStatus());
assertEquals(lastModifiedTime, calc1.getLastModifiedTime());
calc2 = new SLACalcStatus(SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId2), SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ON_RESTART, jobId2));
assertEquals(8, calc.getEventProcessed());
assertEquals(7, calc2.getEventProcessed());
// jobId2 should be in history set as eventprocessed is 7 (111)
// job3 will be in slamap
// 1 out of 3 jobs in map
assertEquals(1, slaCalcMemory.size());
WorkflowJobBean wf = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW, jobId3);
wf.setId(jobId3);
wf.setStatus(WorkflowJob.Status.SUCCEEDED);
wf.setEndTime(endTime);
wf.setStartTime(startTime);
WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_START_END, wf);
slaCalcMemory.addJobStatus(jobId3, WorkflowJob.Status.SUCCEEDED.toString(), EventStatus.SUCCESS, startTime, endTime);
SLASummaryBean slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId3);
assertEquals(8, slaSummary.getEventProcessed());
assertEquals(startTime, slaSummary.getActualStart());
assertEquals(endTime, slaSummary.getActualEnd());
assertEquals(WorkflowJob.Status.SUCCEEDED.toString(), slaSummary.getJobStatus());
}
Aggregations