Search in sources :

Example 1 with UpdateEntry

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);
}
Also used : JsonBean(org.apache.oozie.client.rest.JsonBean) UpdateEntry(org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry) ArrayList(java.util.ArrayList) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date) SLASummaryQuery(org.apache.oozie.executor.jpa.SLASummaryQueryExecutor.SLASummaryQuery) Test(org.junit.Test)

Example 2 with UpdateEntry

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));
}
Also used : UpdateEntry(org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry)

Example 3 with UpdateEntry

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;
}
Also used : CoordinatorActionInfo(org.apache.oozie.CoordinatorActionInfo) UpdateEntry(org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) KillXCommand(org.apache.oozie.command.wf.KillXCommand) Date(java.util.Date)

Example 4 with UpdateEntry

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;
}
Also used : WorkflowActionQuery(org.apache.oozie.executor.jpa.WorkflowActionQueryExecutor.WorkflowActionQuery) UpdateEntry(org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry) WorkflowException(org.apache.oozie.workflow.WorkflowException) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) CommandException(org.apache.oozie.command.CommandException) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) WorkflowInstance(org.apache.oozie.workflow.WorkflowInstance) Date(java.util.Date) SLAEventBean(org.apache.oozie.SLAEventBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) WorkflowJobQuery(org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery) ControlNodeActionExecutor(org.apache.oozie.action.control.ControlNodeActionExecutor)

Example 5 with UpdateEntry

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());
    }
}
Also used : JsonBean(org.apache.oozie.client.rest.JsonBean) UpdateEntry(org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry) WorkflowJobQuery(org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery) ArrayList(java.util.ArrayList) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Aggregations

UpdateEntry (org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry)15 Date (java.util.Date)11 WorkflowJobQuery (org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery)9 ArrayList (java.util.ArrayList)7 JsonBean (org.apache.oozie.client.rest.JsonBean)7 CommandException (org.apache.oozie.command.CommandException)7 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)7 WorkflowActionQuery (org.apache.oozie.executor.jpa.WorkflowActionQueryExecutor.WorkflowActionQuery)6 SLAEventBean (org.apache.oozie.SLAEventBean)5 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)4 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)4 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)4 ControlNodeActionExecutor (org.apache.oozie.action.control.ControlNodeActionExecutor)4 JPAService (org.apache.oozie.service.JPAService)4 Instrumentation (org.apache.oozie.util.Instrumentation)4 Configuration (org.apache.hadoop.conf.Configuration)3 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)3 PreconditionException (org.apache.oozie.command.PreconditionException)3 Test (org.junit.Test)3 IOException (java.io.IOException)2