use of org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry 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.BatchQueryExecutor.UpdateEntry in project oozie by apache.
the class CoordActionsKillXCommand method updateJob.
@Override
public void updateJob() throws CommandException {
coordJob.setPending();
updateList.add(new UpdateEntry(CoordJobQuery.UPDATE_COORD_JOB_STATUS_PENDING, coordJob));
}
use of org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry in project oozie by apache.
the class CoordActionsKillXCommand method killChildren.
@Override
public void killChildren() throws CommandException {
InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
for (CoordinatorActionBean coordAction : coordActions) {
coordAction.setStatus(CoordinatorAction.Status.KILLED);
coordAction.setLastModifiedTime(new Date());
// kill Workflow job associated with this Coord action
if (coordAction.getExternalId() != null) {
queue(new KillXCommand(coordAction.getExternalId()));
coordAction.incrementAndGetPending();
} else {
coordAction.setPending(0);
}
updateList.add(new UpdateEntry(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, coordAction));
if (EventHandlerService.isEnabled()) {
CoordinatorXCommand.generateEvent(coordAction, coordJob.getUser(), coordJob.getAppName(), coordAction.getCreatedTime());
}
queue(new CoordActionNotificationXCommand(coordAction), 100);
}
CoordinatorActionInfo coordInfo = new CoordinatorActionInfo(coordActions);
ret = coordInfo;
}
use of org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry in project oozie by apache.
the class KillXCommand method execute.
@Override
protected Void execute() throws CommandException {
LOG.info("STARTED WorkflowKillXCommand for jobId=" + wfId);
wfJob.setEndTime(new Date());
if (wfJob.getStatus() != WorkflowJob.Status.FAILED) {
InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
wfJob.setStatus(WorkflowJob.Status.KILLED);
SLAEventBean slaEvent = SLADbXOperations.createStatusEvent(wfJob.getSlaXml(), wfJob.getId(), Status.KILLED, SlaAppType.WORKFLOW_JOB);
if (slaEvent != null) {
insertList.add(slaEvent);
}
try {
wfJob.getWorkflowInstance().kill();
} catch (WorkflowException e) {
throw new CommandException(ErrorCode.E0725, e.getMessage(), e);
}
WorkflowInstance wfInstance = wfJob.getWorkflowInstance();
((LiteWorkflowInstance) wfInstance).setStatus(WorkflowInstance.Status.KILLED);
wfJob.setWorkflowInstance(wfInstance);
}
try {
for (WorkflowActionBean action : actionList) {
if (action.getStatus() == WorkflowActionBean.Status.RUNNING || action.getStatus() == WorkflowActionBean.Status.DONE) {
if (!(actionService.getExecutor(action.getType()) instanceof ControlNodeActionExecutor)) {
action.setPending();
}
action.setStatus(WorkflowActionBean.Status.KILLED);
updateList.add(new UpdateEntry<WorkflowActionQuery>(WorkflowActionQuery.UPDATE_ACTION_STATUS_PENDING, action));
queue(new ActionKillXCommand(action.getId(), action.getType()));
} else if (action.getStatus() == WorkflowActionBean.Status.PREP || action.getStatus() == WorkflowActionBean.Status.START_RETRY || action.getStatus() == WorkflowActionBean.Status.START_MANUAL || action.getStatus() == WorkflowActionBean.Status.END_RETRY || action.getStatus() == WorkflowActionBean.Status.END_MANUAL || action.getStatus() == WorkflowActionBean.Status.USER_RETRY) {
action.setStatus(WorkflowActionBean.Status.KILLED);
action.resetPending();
SLAEventBean slaEvent = SLADbXOperations.createStatusEvent(action.getSlaXml(), action.getId(), Status.KILLED, SlaAppType.WORKFLOW_ACTION);
if (slaEvent != null) {
insertList.add(slaEvent);
}
updateList.add(new UpdateEntry<WorkflowActionQuery>(WorkflowActionQuery.UPDATE_ACTION_STATUS_PENDING, action));
if (EventHandlerService.isEnabled() && !(actionService.getExecutor(action.getType()) instanceof ControlNodeActionExecutor)) {
generateEvent(action, wfJob.getUser());
}
}
}
wfJob.setLastModifiedTime(new Date());
updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_END, wfJob));
BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, updateList, null);
if (EventHandlerService.isEnabled()) {
generateEvent(wfJob);
}
queue(new WorkflowNotificationXCommand(wfJob));
} catch (JPAExecutorException e) {
throw new CommandException(e);
} finally {
if (wfJob.getStatus() == WorkflowJob.Status.KILLED) {
// To delete the WF temp dir
new WfEndXCommand(wfJob).call();
}
updateParentIfNecessary(wfJob);
}
LOG.info("ENDED WorkflowKillXCommand for jobId=" + wfId);
return null;
}
use of org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry in project oozie by apache.
the class TestBatchQueryExecutor method testExecuteBatchUpdateInsertDeleteRollBack.
public void testExecuteBatchUpdateInsertDeleteRollBack() throws Exception {
BatchQueryExecutor executor = BatchQueryExecutor.getInstance();
WorkflowJobBean job = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
WorkflowActionBean action1 = createWorkflowAction(job.getId(), "1", WorkflowAction.Status.PREP);
WorkflowActionBean action2 = createWorkflowAction(job.getId(), "2", WorkflowAction.Status.PREP);
job.setStatus(WorkflowJob.Status.RUNNING);
Collection<JsonBean> insertList = new ArrayList<JsonBean>();
insertList.add(action1);
insertList.add(action2);
List<UpdateEntry> updateList = new ArrayList<UpdateEntry>();
// Add two actions to insert list
updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW, job));
// set fault injection to true, so transaction is roll backed
setSystemProperty(FaultInjection.FAULT_INJECTION, "true");
setSystemProperty(SkipCommitFaultInjection.ACTION_FAILOVER_FAULT_INJECTION, "true");
FaultInjection.activate("org.apache.oozie.command.SkipCommitFaultInjection");
try {
executor.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
WorkflowJobBean wfBean = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW, job.getId());
// status should not be RUNNING
assertEquals("PREP", wfBean.getStatusStr());
WorkflowActionBean waBean;
try {
waBean = WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQuery.GET_ACTION, action1.getId());
fail("Expected exception but didnt get any");
} catch (JPAExecutorException jpaee) {
assertEquals(ErrorCode.E0605, jpaee.getErrorCode());
}
try {
waBean = WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQuery.GET_ACTION, action2.getId());
fail("Expected exception but didnt get any");
} catch (JPAExecutorException jpaee) {
assertEquals(ErrorCode.E0605, jpaee.getErrorCode());
}
}
Aggregations