Search in sources :

Example 1 with KillXCommand

use of org.apache.oozie.command.wf.KillXCommand 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 2 with KillXCommand

use of org.apache.oozie.command.wf.KillXCommand in project oozie by apache.

the class TestEventGeneration method testWorkflowJobEvent.

@Test
public void testWorkflowJobEvent() throws Exception {
    assertEquals(0, queue.size());
    WorkflowApp app = new LiteWorkflowApp("testApp", "<workflow-app/>", new StartNodeDef(LiteWorkflowStoreService.LiteControlNodeHandler.class, "fs-node")).addNode(new ActionNodeDef("fs-node", "", TestLiteWorkflowLib.TestActionNodeHandler.class, "end", "end")).addNode(new EndNodeDef("end", LiteWorkflowStoreService.LiteControlNodeHandler.class));
    WorkflowJobBean job = addRecordToWfJobTable(app, WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
    // Starting job
    new StartXCommand(job.getId()).call();
    WorkflowJobGetJPAExecutor wfJobGetCmd = new WorkflowJobGetJPAExecutor(job.getId());
    job = jpaService.execute(wfJobGetCmd);
    assertEquals(WorkflowJob.Status.RUNNING, job.getStatus());
    assertEquals(1, queue.size());
    JobEvent event = (JobEvent) queue.poll();
    assertNotNull(event);
    assertEquals(EventStatus.STARTED, event.getEventStatus());
    assertEquals(AppType.WORKFLOW_JOB, event.getAppType());
    assertEquals(job.getId(), event.getId());
    assertEquals(job.getUser(), event.getUser());
    assertEquals(job.getAppName(), event.getAppName());
    assertEquals(job.getStartTime(), event.getStartTime());
    assertEquals(0, queue.size());
    // Suspending job
    new SuspendXCommand(job.getId()).call();
    job = jpaService.execute(wfJobGetCmd);
    assertEquals(WorkflowJob.Status.SUSPENDED, job.getStatus());
    assertEquals(1, queue.size());
    event = (JobEvent) queue.poll();
    assertNotNull(event);
    assertEquals(EventStatus.SUSPEND, event.getEventStatus());
    assertEquals(AppType.WORKFLOW_JOB, event.getAppType());
    assertEquals(job.getId(), event.getId());
    assertEquals(job.getUser(), event.getUser());
    assertEquals(job.getAppName(), event.getAppName());
    assertEquals(0, queue.size());
    // Resuming job
    new ResumeXCommand(job.getId()).call();
    job = jpaService.execute(wfJobGetCmd);
    assertEquals(WorkflowJob.Status.RUNNING, job.getStatus());
    assertEquals(1, queue.size());
    event = (JobEvent) queue.poll();
    assertNotNull(event);
    assertEquals(AppType.WORKFLOW_JOB, event.getAppType());
    assertEquals(job.getId(), event.getId());
    assertEquals(job.getUser(), event.getUser());
    assertEquals(job.getAppName(), event.getAppName());
    assertEquals(job.getStartTime(), event.getStartTime());
    assertEquals(0, queue.size());
    // Killing job
    new KillXCommand(job.getId()).call();
    job = jpaService.execute(wfJobGetCmd);
    assertEquals(WorkflowJob.Status.KILLED, job.getStatus());
    assertEquals(1, queue.size());
    event = (JobEvent) queue.poll();
    assertNotNull(event);
    assertEquals(EventStatus.FAILURE, event.getEventStatus());
    assertEquals(AppType.WORKFLOW_JOB, event.getAppType());
    assertEquals(job.getId(), event.getId());
    assertEquals(job.getUser(), event.getUser());
    assertEquals(job.getAppName(), event.getAppName());
    assertEquals(job.getStartTime(), event.getStartTime());
    assertEquals(job.getEndTime(), event.getEndTime());
    assertEquals(0, queue.size());
    // Successful job (testing SignalX)
    job = _createWorkflowJob();
    LiteWorkflowInstance wfInstance = (LiteWorkflowInstance) job.getWorkflowInstance();
    wfInstance.start();
    job.setWorkflowInstance(wfInstance);
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MODIFIED, job);
    WorkflowActionBean wfAction = jpaService.execute(new WorkflowActionGetJPAExecutor(job.getId() + "@one"));
    new SignalXCommand(job.getId(), wfAction.getId()).call();
    job = jpaService.execute(new WorkflowJobGetJPAExecutor(job.getId()));
    assertEquals(WorkflowJob.Status.SUCCEEDED, job.getStatus());
    assertEquals(1, queue.size());
    event = (JobEvent) queue.poll();
    assertNotNull(event);
    assertEquals(AppType.WORKFLOW_JOB, event.getAppType());
    assertEquals(job.getId(), event.getId());
    assertEquals(job.getUser(), event.getUser());
    assertEquals(job.getAppName(), event.getAppName());
    assertEquals(job.getStartTime(), event.getStartTime());
    assertEquals(job.getEndTime(), event.getEndTime());
}
Also used : WorkflowApp(org.apache.oozie.workflow.WorkflowApp) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) EndNodeDef(org.apache.oozie.workflow.lite.EndNodeDef) WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) SignalXCommand(org.apache.oozie.command.wf.SignalXCommand) ActionNodeDef(org.apache.oozie.workflow.lite.ActionNodeDef) ActionKillXCommand(org.apache.oozie.command.wf.ActionKillXCommand) KillXCommand(org.apache.oozie.command.wf.KillXCommand) StartXCommand(org.apache.oozie.command.wf.StartXCommand) ActionStartXCommand(org.apache.oozie.command.wf.ActionStartXCommand) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) StartNodeDef(org.apache.oozie.workflow.lite.StartNodeDef) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) SuspendXCommand(org.apache.oozie.command.wf.SuspendXCommand) JobEvent(org.apache.oozie.client.event.JobEvent) TestLiteWorkflowLib(org.apache.oozie.workflow.lite.TestLiteWorkflowLib) ResumeXCommand(org.apache.oozie.command.wf.ResumeXCommand) CoordResumeXCommand(org.apache.oozie.command.coord.CoordResumeXCommand) WorkflowActionGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor) Test(org.junit.Test)

Example 3 with KillXCommand

use of org.apache.oozie.command.wf.KillXCommand in project oozie by apache.

the class DagEngine method kill.

/**
 * Kill a job.
 *
 * @param jobId job Id.
 * @throws DagEngineException thrown if the job could not be killed.
 */
@Override
public void kill(String jobId) throws DagEngineException {
    // failure.
    try {
        new KillXCommand(jobId).call();
        LOG.info("User " + user + " killed the WF job " + jobId);
    } catch (CommandException e) {
        throw new DagEngineException(e);
    }
}
Also used : KillXCommand(org.apache.oozie.command.wf.KillXCommand) CommandException(org.apache.oozie.command.CommandException)

Example 4 with KillXCommand

use of org.apache.oozie.command.wf.KillXCommand in project oozie by apache.

the class CoordKillXCommand method killChildren.

@Override
public void killChildren() throws CommandException {
    if (actionList != null) {
        for (CoordinatorActionBean action : actionList) {
            // queue a WorkflowKillXCommand to delete the workflow job and actions
            if (action.getExternalId() != null) {
                queue(new KillXCommand(action.getExternalId()));
                // As the kill command for children is queued, set pending flag for coord action to be true
                updateCoordAction(action, true);
                LOG.debug("Killed coord action = [{0}], new status = [{1}], pending = [{2}] and queue KillXCommand for [{3}]", action.getId(), action.getStatus(), action.getPending(), action.getExternalId());
            } else {
                // As killing children is not required, set pending flag for coord action to be false
                updateCoordAction(action, false);
                LOG.debug("Killed coord action = [{0}], current status = [{1}], pending = [{2}]", action.getId(), action.getStatus(), action.getPending());
            }
            String pushMissingDeps = action.getPushMissingDependencies();
            if (pushMissingDeps != null) {
                CoordPushDependencyCheckXCommand.unregisterMissingDependencies(Arrays.asList(DependencyChecker.dependenciesAsArray(pushMissingDeps)), action.getId());
            }
        }
    }
    coordJob.setDoneMaterialization();
    coordJob.setLastModifiedTime(new Date());
    LOG.debug("Killed coord actions for the coordinator=[{0}]", jobId);
}
Also used : CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) KillXCommand(org.apache.oozie.command.wf.KillXCommand) Date(java.util.Date)

Example 5 with KillXCommand

use of org.apache.oozie.command.wf.KillXCommand in project oozie by apache.

the class TestEventGeneration method testWorkflowJobEventError.

@Test
public void testWorkflowJobEventError() throws Exception {
    final WorkflowJobBean job = addRecordToWfJobTable(WorkflowJob.Status.FAILED, WorkflowInstance.Status.FAILED);
    // create event with error code and message
    WorkflowXCommand<Void> myCmd = new KillXCommand(job.getId()) {

        @Override
        protected Void execute() {
            WorkflowXCommand.generateEvent(job, "errorCode", "errorMsg");
            return null;
        }
    };
    myCmd.call();
    WorkflowJobEvent event = (WorkflowJobEvent) queue.poll();
    assertNotNull(event);
    assertEquals("errorCode", event.getErrorCode());
    assertEquals("errorMsg", event.getErrorMessage());
    assertEquals(EventStatus.FAILURE, event.getEventStatus());
}
Also used : ActionKillXCommand(org.apache.oozie.command.wf.ActionKillXCommand) KillXCommand(org.apache.oozie.command.wf.KillXCommand) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Test(org.junit.Test)

Aggregations

KillXCommand (org.apache.oozie.command.wf.KillXCommand)6 Date (java.util.Date)3 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)2 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)2 ActionKillXCommand (org.apache.oozie.command.wf.ActionKillXCommand)2 Test (org.junit.Test)2 CoordinatorActionInfo (org.apache.oozie.CoordinatorActionInfo)1 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)1 JobEvent (org.apache.oozie.client.event.JobEvent)1 CommandException (org.apache.oozie.command.CommandException)1 CoordKillXCommand (org.apache.oozie.command.coord.CoordKillXCommand)1 CoordResumeXCommand (org.apache.oozie.command.coord.CoordResumeXCommand)1 CoordSubmitXCommand (org.apache.oozie.command.coord.CoordSubmitXCommand)1 ActionStartXCommand (org.apache.oozie.command.wf.ActionStartXCommand)1 ResumeXCommand (org.apache.oozie.command.wf.ResumeXCommand)1 SignalXCommand (org.apache.oozie.command.wf.SignalXCommand)1 StartXCommand (org.apache.oozie.command.wf.StartXCommand)1 SubmitXCommand (org.apache.oozie.command.wf.SubmitXCommand)1 SuspendXCommand (org.apache.oozie.command.wf.SuspendXCommand)1 UpdateEntry (org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry)1