Search in sources :

Example 1 with LiteWorkflowInstance

use of org.apache.oozie.workflow.lite.LiteWorkflowInstance in project oozie by apache.

the class TestCoordActionsKillXCommand method createDBRecords.

private String[] createDBRecords() throws Exception {
    JPAService jpaService = services.get(JPAService.class);
    Date startTime = DateUtils.parseDateOozieTZ("2013-08-01T23:59Z");
    Date endTime = DateUtils.parseDateOozieTZ("2013-08-02T23:59Z");
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, false, true, 0);
    CoordinatorActionBean action1 = addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
    CoordinatorActionBean action2 = addRecordToCoordActionTable(job.getId(), 2, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
    action2.setNominalTime(DateUtils.parseDateOozieTZ("2009-12-15T02:00Z"));
    action2.setExternalId(null);
    CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION, action2);
    WorkflowJobBean wf = new WorkflowJobBean();
    WorkflowApp app = new LiteWorkflowApp("testApp", "<workflow-app/>", new StartNodeDef(LiteWorkflowStoreService.LiteControlNodeHandler.class, "end")).addNode(new EndNodeDef("end", LiteWorkflowStoreService.LiteControlNodeHandler.class));
    wf.setId(action1.getExternalId());
    wf.setStatus(WorkflowJob.Status.RUNNING);
    WorkflowLib workflowLib = Services.get().get(WorkflowStoreService.class).getWorkflowLibWithNoDB();
    WorkflowInstance wfInstance = workflowLib.createInstance(app, new XConfiguration());
    ((LiteWorkflowInstance) wfInstance).setStatus(WorkflowInstance.Status.RUNNING);
    wf.setWorkflowInstance(wfInstance);
    jpaService.execute(new WorkflowJobInsertJPAExecutor(wf));
    return new String[] { job.getId(), action1.getId(), action2.getId(), wf.getId() };
}
Also used : WorkflowApp(org.apache.oozie.workflow.WorkflowApp) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) EndNodeDef(org.apache.oozie.workflow.lite.EndNodeDef) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) WorkflowLib(org.apache.oozie.workflow.WorkflowLib) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) WorkflowStoreService(org.apache.oozie.service.WorkflowStoreService) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) WorkflowJobInsertJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobInsertJPAExecutor) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) WorkflowInstance(org.apache.oozie.workflow.WorkflowInstance) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) StartNodeDef(org.apache.oozie.workflow.lite.StartNodeDef) XConfiguration(org.apache.oozie.util.XConfiguration) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) JPAService(org.apache.oozie.service.JPAService)

Example 2 with LiteWorkflowInstance

use of org.apache.oozie.workflow.lite.LiteWorkflowInstance in project oozie by apache.

the class TestPurgeXCommand method createWorkflow.

@Override
protected WorkflowJobBean createWorkflow(WorkflowApp app, Configuration conf, WorkflowJob.Status jobStatus, WorkflowInstance.Status instanceStatus) throws Exception {
    WorkflowAppService wps = Services.get().get(WorkflowAppService.class);
    Configuration protoActionConf = wps.createProtoActionConf(conf, true);
    WorkflowLib workflowLib = Services.get().get(WorkflowStoreService.class).getWorkflowLibWithNoDB();
    WorkflowInstance wfInstance = workflowLib.createInstance(app, conf);
    ((LiteWorkflowInstance) wfInstance).setStatus(instanceStatus);
    WorkflowJobBean workflow = new WorkflowJobBean();
    workflow.setId(Services.get().get(UUIDService.class).generateId(ApplicationType.WORKFLOW));
    workflow.setAppName(app.getName());
    workflow.setAppPath(conf.get(OozieClient.APP_PATH));
    workflow.setConf(XmlUtils.prettyPrint(conf).toString());
    workflow.setProtoActionConf(XmlUtils.prettyPrint(protoActionConf).toString());
    workflow.setCreatedTime(new Date());
    workflow.setLogToken(conf.get(OozieClient.LOG_TOKEN, ""));
    workflow.setStatus(jobStatus);
    workflow.setRun(0);
    workflow.setUser(conf.get(OozieClient.USER_NAME));
    workflow.setGroup(conf.get(OozieClient.GROUP_NAME));
    workflow.setWorkflowInstance(wfInstance);
    workflow.setStartTime(DateUtils.parseDateOozieTZ("2009-12-18T01:00Z"));
    workflow.setEndTime(DateUtils.parseDateOozieTZ("2009-12-18T03:00Z"));
    return workflow;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) WorkflowLib(org.apache.oozie.workflow.WorkflowLib) WorkflowAppService(org.apache.oozie.service.WorkflowAppService) WorkflowStoreService(org.apache.oozie.service.WorkflowStoreService) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) WorkflowInstance(org.apache.oozie.workflow.WorkflowInstance) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date)

Example 3 with LiteWorkflowInstance

use of org.apache.oozie.workflow.lite.LiteWorkflowInstance in project oozie by apache.

the class XDataTestCase method createWorkflow.

/**
 * Create workflow job bean
 *
 * @param app workflow app
 * @param conf workflow configuration
 * @param authToken auth token
 * @param jobStatus workflow job status
 * @param instanceStatus workflow instance status
 * @return workflow job bean
 * @throws Exception thrown if unable to create workflow job bean
 */
protected WorkflowJobBean createWorkflow(WorkflowApp app, Configuration conf, WorkflowJob.Status jobStatus, WorkflowInstance.Status instanceStatus) throws Exception {
    WorkflowAppService wps = Services.get().get(WorkflowAppService.class);
    Configuration protoActionConf = wps.createProtoActionConf(conf, true);
    WorkflowLib workflowLib = Services.get().get(WorkflowStoreService.class).getWorkflowLibWithNoDB();
    WorkflowInstance wfInstance = workflowLib.createInstance(app, conf);
    ((LiteWorkflowInstance) wfInstance).setStatus(instanceStatus);
    WorkflowJobBean workflow = new WorkflowJobBean();
    workflow.setId(wfInstance.getId());
    workflow.setExternalId("extid");
    workflow.setAppName(app.getName());
    workflow.setAppPath(conf.get(OozieClient.APP_PATH));
    workflow.setConf(XmlUtils.prettyPrint(conf).toString());
    workflow.setProtoActionConf(XmlUtils.prettyPrint(protoActionConf).toString());
    workflow.setCreatedTime(new Date());
    workflow.setLogToken(conf.get(OozieClient.LOG_TOKEN, ""));
    workflow.setStatus(jobStatus);
    workflow.setRun(0);
    workflow.setUser(conf.get(OozieClient.USER_NAME));
    workflow.setGroup(conf.get(OozieClient.GROUP_NAME));
    workflow.setWorkflowInstance(wfInstance);
    workflow.setSlaXml("<sla></sla>");
    return workflow;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) WorkflowLib(org.apache.oozie.workflow.WorkflowLib) WorkflowAppService(org.apache.oozie.service.WorkflowAppService) WorkflowStoreService(org.apache.oozie.service.WorkflowStoreService) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) WorkflowInstance(org.apache.oozie.workflow.WorkflowInstance) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date)

Example 4 with LiteWorkflowInstance

use of org.apache.oozie.workflow.lite.LiteWorkflowInstance 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 LiteWorkflowInstance

use of org.apache.oozie.workflow.lite.LiteWorkflowInstance 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

LiteWorkflowInstance (org.apache.oozie.workflow.lite.LiteWorkflowInstance)16 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)13 WorkflowInstance (org.apache.oozie.workflow.WorkflowInstance)12 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)10 XConfiguration (org.apache.oozie.util.XConfiguration)9 EndNodeDef (org.apache.oozie.workflow.lite.EndNodeDef)9 LiteWorkflowApp (org.apache.oozie.workflow.lite.LiteWorkflowApp)9 StartNodeDef (org.apache.oozie.workflow.lite.StartNodeDef)9 ELService (org.apache.oozie.service.ELService)7 LiteWorkflowStoreService (org.apache.oozie.service.LiteWorkflowStoreService)7 ELEvaluator (org.apache.oozie.util.ELEvaluator)7 Date (java.util.Date)6 Configuration (org.apache.hadoop.conf.Configuration)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 CommandException (org.apache.oozie.command.CommandException)4 Test (org.junit.Test)4 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)3 WorkflowStoreService (org.apache.oozie.service.WorkflowStoreService)3 WorkflowLib (org.apache.oozie.workflow.WorkflowLib)3 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)2