Search in sources :

Example 1 with SuspendXCommand

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

the class TestSubWorkflowActionExecutor method testSubWorkflowSuspend.

public void testSubWorkflowSuspend() throws Exception {
    try {
        Path subWorkflowAppPath = getFsTestCaseDir();
        FileSystem fs = getFileSystem();
        Path subWorkflowPath = new Path(subWorkflowAppPath, "workflow.xml");
        Writer writer = new OutputStreamWriter(fs.create(subWorkflowPath));
        writer.write(getLazyWorkflow());
        writer.close();
        String workflowUri = getTestCaseFileUri("workflow.xml");
        String appXml = "<workflow-app xmlns=\"uri:oozie:workflow:0.4\" name=\"workflow\">" + "<start to=\"subwf\"/>" + "<action name=\"subwf\">" + "     <sub-workflow xmlns='uri:oozie:workflow:0.4'>" + "          <app-path>" + subWorkflowAppPath.toString() + "</app-path>" + "     </sub-workflow>" + "     <ok to=\"end\"/>" + "     <error to=\"fail\"/>" + "</action>" + "<kill name=\"fail\">" + "     <message>Sub workflow failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>" + "</kill>" + "<end name=\"end\"/>" + "</workflow-app>";
        writeToFile(appXml, workflowUri);
        LocalOozie.start();
        final OozieClient wfClient = LocalOozie.getClient();
        Properties conf = wfClient.createConfiguration();
        conf.setProperty(OozieClient.APP_PATH, workflowUri);
        conf.setProperty(OozieClient.USER_NAME, getTestUser());
        conf.setProperty("appName", "var-app-name");
        final String jobId = wfClient.submit(conf);
        wfClient.start(jobId);
        waitFor(JOB_TIMEOUT, new Predicate() {

            public boolean evaluate() throws Exception {
                return (wfClient.getJobInfo(jobId).getStatus() == WorkflowJob.Status.RUNNING) && (wfClient.getJobInfo(jobId).getActions().get(1).getStatus() == WorkflowAction.Status.RUNNING);
            }
        });
        WorkflowJob wf = wfClient.getJobInfo(jobId);
        // Suspending subworkflow
        new SuspendXCommand(wf.getActions().get(1).getExternalId()).call();
        // Check suspend for base workflow
        assertEquals(WorkflowJob.Status.SUSPENDED, wfClient.getJobInfo(jobId).getStatus());
        // Check suspend for sub workflow
        assertEquals(WorkflowJob.Status.SUSPENDED, wfClient.getJobInfo(wf.getActions().get(1).getExternalId()).getStatus());
    } finally {
        LocalOozie.stop();
    }
}
Also used : Path(org.apache.hadoop.fs.Path) SuspendXCommand(org.apache.oozie.command.wf.SuspendXCommand) OozieClient(org.apache.oozie.client.OozieClient) FileSystem(org.apache.hadoop.fs.FileSystem) Properties(java.util.Properties) WorkflowJob(org.apache.oozie.client.WorkflowJob)

Example 2 with SuspendXCommand

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

the class CoordSuspendXCommand method suspendChildren.

@Override
public void suspendChildren() throws CommandException {
    try {
        // Get all running actions of a job to suspend them
        List<CoordinatorActionBean> actionList = jpaService.execute(new CoordJobGetActionsRunningJPAExecutor(jobId));
        for (CoordinatorActionBean action : actionList) {
            // queue a SuspendXCommand
            if (action.getExternalId() != null) {
                queue(new SuspendXCommand(action.getExternalId()));
                updateCoordAction(action);
                LOG.debug("Suspend coord action = [{0}], new status = [{1}], pending = [{2}] and queue SuspendXCommand for [{3}]", action.getId(), action.getStatus(), action.getPending(), action.getExternalId());
            } else {
                updateCoordAction(action);
                LOG.debug("Suspend coord action = [{0}], new status = [{1}], pending = [{2}] and external id is null", action.getId(), action.getStatus(), action.getPending());
            }
        }
        LOG.debug("Suspended coordinator actions for the coordinator=[{0}]", jobId);
    } catch (XException ex) {
        exceptionOccured = true;
        throw new CommandException(ex);
    } finally {
        if (exceptionOccured) {
            coordJob.setStatus(CoordinatorJob.Status.FAILED);
            coordJob.resetPending();
            LOG.debug("Exception happened, fail coordinator job id = " + jobId + ", status = " + coordJob.getStatus());
            updateList.add(new UpdateEntry<CoordJobQuery>(CoordJobQuery.UPDATE_COORD_JOB_STATUS_PENDING_TIME, coordJob));
        }
    }
}
Also used : SuspendXCommand(org.apache.oozie.command.wf.SuspendXCommand) CoordJobGetActionsRunningJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetActionsRunningJPAExecutor) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) CoordJobQuery(org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery)

Example 3 with SuspendXCommand

use of org.apache.oozie.command.wf.SuspendXCommand 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)

Aggregations

SuspendXCommand (org.apache.oozie.command.wf.SuspendXCommand)3 Properties (java.util.Properties)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)1 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)1 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)1 XException (org.apache.oozie.XException)1 OozieClient (org.apache.oozie.client.OozieClient)1 WorkflowJob (org.apache.oozie.client.WorkflowJob)1 JobEvent (org.apache.oozie.client.event.JobEvent)1 CommandException (org.apache.oozie.command.CommandException)1 CoordResumeXCommand (org.apache.oozie.command.coord.CoordResumeXCommand)1 ActionKillXCommand (org.apache.oozie.command.wf.ActionKillXCommand)1 ActionStartXCommand (org.apache.oozie.command.wf.ActionStartXCommand)1 KillXCommand (org.apache.oozie.command.wf.KillXCommand)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 CoordJobGetActionsRunningJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetActionsRunningJPAExecutor)1