Search in sources :

Example 66 with WorkflowActionBean

use of org.apache.oozie.WorkflowActionBean in project oozie by apache.

the class TestDBWorkflowStore method _testSaveAction.

private void _testSaveAction() throws StoreException, SQLException {
    WorkflowActionBean a11 = new WorkflowActionBean();
    store.beginTrx();
    StringBuilder str = new StringBuilder();
    str.append(System.currentTimeMillis());
    str.append("11");
    this.actionId = str.toString();
    a11.setId(actionId);
    a11.setJobId(wfBean1.getId());
    a11.setName("a11");
    a11.setStatus(WorkflowAction.Status.PREP);
    store.insertAction(a11);
    store.commitTrx();
/*
 * WorkflowActionBean a12 = new WorkflowActionBean(); store.beginTrx();
 * a12.setId("12"); a12.setName("a12"); a12.setJobId(wfBean1.getId());
 * a12.setStatus(WorkflowAction.Status.PREP); store.insertAction(a12);
 * store.commitTrx();
 *
 * WorkflowActionBean a21 = new WorkflowActionBean(); store.beginTrx();
 * a21.setId("21"); a21.setName("a21"); a21.setJobId(wfBean2.getId());
 * a21.setStatus(WorkflowAction.Status.PREP); store.insertAction(a21);
 * store.commitTrx();
 *
 * WorkflowActionBean a22 = new WorkflowActionBean(); store.beginTrx();
 * a22.setId("22"); a22.setName("a22"); a22.setJobId(wfBean2.getId());
 * a22.setStatus(WorkflowAction.Status.PREP); store.insertAction(a22);
 * store.commitTrx();
 */
/*
 * SqlStatement s = getCount(OozieTable.ACTIONS); ResultSet rs =
 * s.prepareAndSetValues(conn).executeQuery(); rs.next(); assertEquals(4,
 * rs.getInt(1)); rs.close();
 *
 * s = getCount(OozieTable.ACTIONS).where(isEqual(ACTIONS_wfId,
 * wfBean1.getId())); rs = s.prepareAndSetValues(conn).executeQuery();
 * rs.next(); assertEquals(2, rs.getInt(1)); rs.close();
 *
 * s = getCount(OozieTable.ACTIONS).where(isEqual(ACTIONS_wfId,
 * wfBean2.getId())); rs = s.prepareAndSetValues(conn).executeQuery();
 * rs.next(); assertEquals(2, rs.getInt(1)); rs.close();
 *
 * s = getCount(OozieTable.ACTIONS).where(isEqual(ACTIONS_id, "11")); rs =
 * s.prepareAndSetValues(conn).executeQuery(); rs.next(); assertEquals(1,
 * rs.getInt(1)); rs.close();
 *
 * s = getCount(OozieTable.ACTIONS).where(isEqual(ACTIONS_id, "12")); rs =
 * s.prepareAndSetValues(conn).executeQuery(); rs.next(); assertEquals(1,
 * rs.getInt(1)); rs.close();
 */
}
Also used : WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 67 with WorkflowActionBean

use of org.apache.oozie.WorkflowActionBean in project oozie by apache.

the class TestDBWorkflowStore method _testPurge.

private void _testPurge() throws Exception {
    store.beginTrx();
    wfBean1.setEndTime(new Date(System.currentTimeMillis() - (31 * 24 * 60 * 60 * 1000l)));
    wfBean2.setEndTime(new Date(System.currentTimeMillis() - (31 * 24 * 60 * 60 * 1000l)));
    WorkflowApp app = new LiteWorkflowApp("testApp", "<workflow-app/>", new StartNodeDef(LiteWorkflowStoreService.LiteControlNodeHandler.class, "end")).addNode(new EndNodeDef("end", LiteWorkflowStoreService.LiteControlNodeHandler.class));
    Configuration conf2 = new Configuration();
    conf2.set(OozieClient.APP_PATH, "testPath");
    conf2.set(OozieClient.LOG_TOKEN, "testToken");
    conf2.set(OozieClient.USER_NAME, getTestUser2());
    WorkflowJobBean wfBean3 = createWorkflow(app, conf2, "auth");
    store.insertWorkflow(wfBean3);
    store.updateWorkflow(wfBean2);
    store.updateWorkflow(wfBean1);
    store.commitTrx();
    WorkflowActionBean a31 = new WorkflowActionBean();
    StringBuilder str = new StringBuilder();
    str.append(System.currentTimeMillis());
    str.append("31");
    a31.setId(str.toString());
    a31.setJobId(wfBean3.getId());
    a31.setStatus(WorkflowAction.Status.PREP);
    store.beginTrx();
    store.insertAction(a31);
    store.commitTrx();
    store.beginTrx();
    store.purge(30, 10000);
    store.commitTrx();
/*
 * SqlStatement s = getCount(OozieTable.WF_JOBS); ResultSet rs =
 * s.prepareAndSetValues(conn).executeQuery(); rs.next(); assertEquals(3,
 * rs.getInt(1)); rs.close();
 *
 * s = getCount(OozieTable.WF_ACTIONS); rs =
 * s.prepareAndSetValues(conn).executeQuery(); rs.next(); assertEquals(4,
 * rs.getInt(1)); rs.close();
 *
 * store.purge(30); store.commit();
 *
 * s = getCount(OozieTable.WF_JOBS); rs =
 * s.prepareAndSetValues(conn).executeQuery(); rs.next(); assertEquals(1,
 * rs.getInt(1)); rs.close();
 *
 * WorkflowJobBean tmp = store.getWorkflow(wfBean3.getId(), false);
 * assertEquals(tmp.getId(), wfBean3.getId());
 *
 * s = getCount(OozieTable.WF_ACTIONS); rs =
 * s.prepareAndSetValues(conn).executeQuery(); rs.next(); assertEquals(1,
 * rs.getInt(1)); rs.close();
 *
 * WorkflowActionBean tmpa = store.getAction("31", false); assertEquals("31",
 * tmpa.getId());
 */
}
Also used : WorkflowApp(org.apache.oozie.workflow.WorkflowApp) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) EndNodeDef(org.apache.oozie.workflow.lite.EndNodeDef) Configuration(org.apache.hadoop.conf.Configuration) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) StartNodeDef(org.apache.oozie.workflow.lite.StartNodeDef) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 68 with WorkflowActionBean

use of org.apache.oozie.WorkflowActionBean in project oozie by apache.

the class TestDBWorkflowStore method _testLoadAction.

private void _testLoadAction() throws StoreException {
    store.beginTrx();
    WorkflowActionBean a11 = store.getAction(actionId, false);
    assertEquals(a11.getId(), actionId);
    assertEquals(a11.getJobId(), wfBean1.getId());
    assertEquals(a11.getStatus(), WorkflowAction.Status.PREP);
    store.commitTrx();
}
Also used : WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 69 with WorkflowActionBean

use of org.apache.oozie.WorkflowActionBean in project oozie by apache.

the class ReRunXCommand method eagerVerifyPrecondition.

/**
 * Checks the pre-conditions that are required for workflow to recover - Last run of Workflow should be completed -
 * The nodes that are to be skipped are to be completed successfully in the base run.
 *
 * @throws CommandException
 * @throws PreconditionException On failure of pre-conditions
 */
@Override
protected void eagerVerifyPrecondition() throws CommandException, PreconditionException {
    // through conf.
    if (wfBean.getParentId() != null && !conf.getBoolean(SubWorkflowActionExecutor.SUBWORKFLOW_RERUN, false) && ConfigurationService.getBoolean(DISABLE_CHILD_RERUN)) {
        throw new CommandException(ErrorCode.E0755, " Rerun is not allowed through child workflow, please" + " re-run through the parent " + wfBean.getParentId());
    }
    if (!(wfBean.getStatus().equals(WorkflowJob.Status.FAILED) || wfBean.getStatus().equals(WorkflowJob.Status.KILLED) || wfBean.getStatus().equals(WorkflowJob.Status.SUCCEEDED))) {
        throw new CommandException(ErrorCode.E0805, wfBean.getStatus());
    }
    Set<String> unmachedNodes = new HashSet<String>(nodesToSkip);
    for (WorkflowActionBean action : actions) {
        if (nodesToSkip.contains(action.getName())) {
            if (!action.getStatus().equals(WorkflowAction.Status.OK) && !action.getStatus().equals(WorkflowAction.Status.ERROR)) {
                throw new CommandException(ErrorCode.E0806, action.getName());
            }
            unmachedNodes.remove(action.getName());
        }
    }
    if (unmachedNodes.size() > 0) {
        StringBuilder sb = new StringBuilder();
        String separator = "";
        for (String s : unmachedNodes) {
            sb.append(separator).append(s);
            separator = ",";
        }
        throw new CommandException(ErrorCode.E0807, sb);
    }
}
Also used : CommandException(org.apache.oozie.command.CommandException) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) HashSet(java.util.HashSet)

Example 70 with WorkflowActionBean

use of org.apache.oozie.WorkflowActionBean 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)

Aggregations

WorkflowActionBean (org.apache.oozie.WorkflowActionBean)249 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)164 XConfiguration (org.apache.oozie.util.XConfiguration)84 JPAService (org.apache.oozie.service.JPAService)79 Configuration (org.apache.hadoop.conf.Configuration)56 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)51 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)51 Path (org.apache.hadoop.fs.Path)48 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)42 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)32 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)32 ArrayList (java.util.ArrayList)30 Date (java.util.Date)29 Element (org.jdom.Element)29 FileSystem (org.apache.hadoop.fs.FileSystem)25 Writer (java.io.Writer)22 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)21 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)21 IOException (java.io.IOException)20 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)18