use of org.apache.oozie.sla.SLARegistrationBean in project oozie by apache.
the class CoordChangeXCommand method deleteAction.
/**
* Delete coordinator action
*
* @param actionNum coordinator action number
*/
private Date deleteAction(int actionNum, Date afterDate) throws CommandException {
try {
if (actionNum <= 0) {
return null;
}
String actionId = jobId + "@" + actionNum;
CoordinatorActionBean bean = CoordActionQueryExecutor.getInstance().getIfExist(CoordActionQueryExecutor.CoordActionQuery.GET_COORD_ACTION, actionId);
if (bean == null) {
return null;
}
if (afterDate.compareTo(bean.getNominalTime()) <= 0) {
if (bean.getStatus() == CoordinatorAction.Status.WAITING || bean.getStatus() == CoordinatorAction.Status.READY) {
// delete SLA registration entry (if any) for action
if (SLAService.isEnabled()) {
Services.get().get(SLAService.class).removeRegistration(actionId);
}
SLARegistrationBean slaReg = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, actionId);
if (slaReg != null) {
LOG.debug("Deleting registration bean corresponding to action " + slaReg.getId());
deleteList.add(slaReg);
}
SLASummaryBean slaSummaryBean = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, actionId);
if (slaSummaryBean != null) {
LOG.debug("Deleting summary bean corresponding to action " + slaSummaryBean.getId());
deleteList.add(slaSummaryBean);
}
deleteList.add(bean);
} else {
throw new CommandException(ErrorCode.E1022, bean.getId());
}
return bean.getNominalTime();
} else {
return null;
}
} catch (JPAExecutorException e) {
throw new CommandException(e);
}
}
use of org.apache.oozie.sla.SLARegistrationBean 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.sla.SLARegistrationBean in project oozie by apache.
the class SLARegistrationQueryExecutor method get.
@Override
public SLARegistrationBean get(SLARegQuery namedQuery, Object... parameters) throws JPAExecutorException {
JPAService jpaService = Services.get().get(JPAService.class);
EntityManager em = jpaService.getEntityManager();
Query query = getSelectQuery(namedQuery, em, parameters);
Object ret = jpaService.executeGet(namedQuery.name(), query, em);
if (ret == null && !namedQuery.equals(SLARegQuery.GET_SLA_REG_ALL)) {
throw new JPAExecutorException(ErrorCode.E0604, query.toString());
}
SLARegistrationBean bean = constructBean(namedQuery, ret, parameters);
return bean;
}
use of org.apache.oozie.sla.SLARegistrationBean in project oozie by apache.
the class TestCoordChangeXCommand method testCoordChangePauseTime.
/**
* test pause time change : pending should mark false if job is running with
* pending true. two actions should be removed for pause time changes.
*
* @throws Exception
*/
public void testCoordChangePauseTime() throws Exception {
Date startTime = DateUtils.parseDateOozieTZ("2013-08-01T00:00Z");
Date endTime = DateUtils.parseDateOozieTZ("2013-08-01T04:59Z");
// 2 hrs
Date pauseTime = new Date(startTime.getTime() + (3 * HOURS_IN_MS));
String pauseTimeChangeStr = "pausetime=" + DateUtils.formatDateOozieTZ(pauseTime);
final CoordinatorJobBean job = addRecordToCoordJobTableForPauseTimeTest(CoordinatorJob.Status.RUNNING, startTime, endTime, endTime, true, false, 4);
CoordinatorActionBean ca1 = addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
CoordinatorActionBean ca2 = addRecordToCoordActionTable(job.getId(), 2, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-01T02:00Z"));
CoordinatorActionBean ca3 = addRecordToCoordActionTable(job.getId(), 3, CoordinatorAction.Status.WAITING, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-01T03:00Z"));
CoordinatorActionBean ca4 = addRecordToCoordActionTable(job.getId(), 4, CoordinatorAction.Status.WAITING, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-01T04:00Z"));
SLARegistrationBean slaRegBean1 = new SLARegistrationBean();
slaRegBean1.setId(ca1.getId());
SLARegistrationBean slaRegBean2 = new SLARegistrationBean();
slaRegBean2.setId(ca2.getId());
SLARegistrationBean slaRegBean3 = new SLARegistrationBean();
slaRegBean3.setId(ca3.getId());
SLARegistrationBean slaRegBean4 = new SLARegistrationBean();
slaRegBean4.setId(ca4.getId());
SLASummaryBean slaSummaryBean1 = new SLASummaryBean();
slaSummaryBean1.setId(ca1.getId());
SLASummaryBean slaSummaryBean3 = new SLASummaryBean();
slaSummaryBean3.setId(ca3.getId());
List<JsonBean> insertList = new ArrayList<JsonBean>();
insertList.add(slaRegBean1);
insertList.add(slaRegBean2);
insertList.add(slaRegBean3);
insertList.add(slaRegBean4);
insertList.add(slaSummaryBean1);
insertList.add(slaSummaryBean3);
JPAService jpaService = Services.get().get(JPAService.class);
BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, null, null);
new CoordChangeXCommand(job.getId(), pauseTimeChangeStr).call();
CoordJobGetJPAExecutor coordGetCmd = new CoordJobGetJPAExecutor(job.getId());
CoordinatorJobBean coordJob = jpaService.execute(coordGetCmd);
assertEquals(DateUtils.formatDateOozieTZ(coordJob.getPauseTime()), DateUtils.formatDateOozieTZ(pauseTime));
assertEquals(Job.Status.RUNNING, coordJob.getStatus());
assertEquals(2, coordJob.getLastActionNumber());
try {
jpaService.execute(new CoordJobGetActionByActionNumberJPAExecutor(job.getId(), 3));
fail("Expected to fail as action 3 should have been deleted");
} catch (JPAExecutorException jpae) {
assertEquals(ErrorCode.E0603, jpae.getErrorCode());
}
try {
jpaService.execute(new CoordJobGetActionByActionNumberJPAExecutor(job.getId(), 4));
fail("Expected to fail as action 4 should have been deleted");
} catch (JPAExecutorException jpae) {
assertEquals(ErrorCode.E0603, jpae.getErrorCode());
}
slaRegBean1 = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, slaRegBean1.getId());
assertNotNull(slaRegBean1);
slaRegBean2 = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, slaRegBean2.getId());
assertNotNull(slaRegBean2);
slaRegBean3 = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, slaRegBean3.getId());
assertNull(slaRegBean3);
slaRegBean4 = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, slaRegBean4.getId());
assertNull(slaRegBean4);
slaSummaryBean3 = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, slaSummaryBean3.getId());
assertNull(slaSummaryBean3);
slaSummaryBean1 = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, slaSummaryBean1.getId());
assertNotNull(slaSummaryBean1);
}
use of org.apache.oozie.sla.SLARegistrationBean in project oozie by apache.
the class TestSLARegistrationQueryExecutor method testGet.
public void testGet() throws Exception {
SLARegistrationBean bean = addRecordToSLARegistrationTable("test-application", SLAStatus.MET);
// GET_SLA_REG_ON_RESTART
SLARegistrationBean retBean = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ON_RESTART, bean.getId());
assertEquals(bean.getJobData(), retBean.getJobData());
assertEquals(bean.getSlaConfig(), retBean.getSlaConfig());
assertEquals(bean.getUpstreamApps(), retBean.getUpstreamApps());
assertEquals(bean.getNotificationMsg(), retBean.getNotificationMsg());
assertNull(retBean.getAppName());
assertNull(retBean.getExpectedEnd());
assertNull(retBean.getExpectedStart());
assertNull(retBean.getCreatedTime());
assertNull(retBean.getNominalTime());
assertNull(retBean.getUser());
assertNull(retBean.getParentId());
// GET_SLA_REG_ALL
retBean = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, bean.getId());
assertEquals(bean.getId(), retBean.getId());
assertEquals(bean.getAppName(), retBean.getAppName());
assertEquals(bean.getAppType(), retBean.getAppType());
assertEquals(bean.getExpectedDuration(), retBean.getExpectedDuration());
assertEquals(bean.getExpectedStart().getTime(), retBean.getExpectedStart().getTime());
assertEquals(bean.getExpectedEnd().getTime(), retBean.getExpectedEnd().getTime());
assertEquals(bean.getCreatedTime().getTime(), retBean.getCreatedTime().getTime());
assertEquals(bean.getNominalTime().getTime(), retBean.getNominalTime().getTime());
assertEquals(bean.getNotificationMsg(), retBean.getNotificationMsg());
assertEquals(bean.getJobData(), retBean.getJobData());
assertEquals(bean.getParentId(), retBean.getParentId());
assertEquals(bean.getSlaConfig(), retBean.getSlaConfig());
assertEquals(bean.getUpstreamApps(), retBean.getUpstreamApps());
assertEquals(bean.getUser(), retBean.getUser());
}
Aggregations