Search in sources :

Example 46 with WorkflowActionGetJPAExecutor

use of org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor in project oozie by apache.

the class TestWorkflowKillXCommand method testWfKillSuccess1.

/**
 * Test : kill RUNNING job and PREP action successfully.
 *
 * @throws Exception
 */
public void testWfKillSuccess1() throws Exception {
    WorkflowJobBean job = this.addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    WorkflowActionBean action = this.addRecordToWfActionTable(job.getId(), "1", WorkflowAction.Status.PREP);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    WorkflowJobGetJPAExecutor wfJobGetCmd = new WorkflowJobGetJPAExecutor(job.getId());
    WorkflowActionGetJPAExecutor wfActionGetCmd = new WorkflowActionGetJPAExecutor(action.getId());
    job = jpaService.execute(wfJobGetCmd);
    action = jpaService.execute(wfActionGetCmd);
    assertEquals(job.getStatus(), WorkflowJob.Status.RUNNING);
    assertEquals(action.getStatus(), WorkflowAction.Status.PREP);
    WorkflowInstance wfInstance = job.getWorkflowInstance();
    assertEquals(wfInstance.getStatus(), WorkflowInstance.Status.RUNNING);
    new KillXCommand(job.getId()).call();
    job = jpaService.execute(wfJobGetCmd);
    action = jpaService.execute(wfActionGetCmd);
    assertEquals(job.getStatus(), WorkflowJob.Status.KILLED);
    assertEquals(action.getStatus(), WorkflowAction.Status.KILLED);
    wfInstance = job.getWorkflowInstance();
    assertEquals(wfInstance.getStatus(), WorkflowInstance.Status.KILLED);
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) WorkflowActionGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) WorkflowInstance(org.apache.oozie.workflow.WorkflowInstance) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 47 with WorkflowActionGetJPAExecutor

use of org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor in project oozie by apache.

the class TestWorkflowKillXCommand method testWfKillSuccessAfterNodeDefUpgrade.

/**
 * Test : kill RUNNING job after NodeDef upgrade.
 *
 * @throws Exception
 */
public void testWfKillSuccessAfterNodeDefUpgrade() throws Exception {
    services.destroy();
    setSystemProperty(LiteWorkflowStoreService.CONF_NODE_DEF_VERSION, LiteWorkflowStoreService.NODE_DEF_VERSION_0);
    services = new Services();
    services.init();
    WorkflowJobBean job = this.addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    WorkflowActionBean action = this.addRecordToWfActionTable(job.getId(), "1", WorkflowAction.Status.PREP);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    WorkflowJobGetJPAExecutor wfJobGetCmd = new WorkflowJobGetJPAExecutor(job.getId());
    WorkflowActionGetJPAExecutor wfActionGetCmd = new WorkflowActionGetJPAExecutor(action.getId());
    job = jpaService.execute(wfJobGetCmd);
    action = jpaService.execute(wfActionGetCmd);
    assertEquals(job.getStatus(), WorkflowJob.Status.RUNNING);
    assertEquals(action.getStatus(), WorkflowAction.Status.PREP);
    WorkflowInstance wfInstance = job.getWorkflowInstance();
    assertEquals(wfInstance.getStatus(), WorkflowInstance.Status.RUNNING);
    services.destroy();
    sleep(5000);
    setSystemProperty(LiteWorkflowStoreService.CONF_NODE_DEF_VERSION, LiteWorkflowStoreService.NODE_DEF_VERSION_1);
    services = new Services();
    services.init();
    sleep(5000);
    new KillXCommand(job.getId()).call();
    jpaService = Services.get().get(JPAService.class);
    job = jpaService.execute(wfJobGetCmd);
    action = jpaService.execute(wfActionGetCmd);
    assertEquals(job.getStatus(), WorkflowJob.Status.KILLED);
    assertEquals(action.getStatus(), WorkflowAction.Status.KILLED);
    wfInstance = job.getWorkflowInstance();
    assertEquals(wfInstance.getStatus(), WorkflowInstance.Status.KILLED);
    services.destroy();
    sleep(5000);
    setSystemProperty(LiteWorkflowStoreService.CONF_NODE_DEF_VERSION, LiteWorkflowStoreService.NODE_DEF_VERSION_2);
    services = new Services();
    services.init();
    sleep(5000);
    jpaService = Services.get().get(JPAService.class);
    job = jpaService.execute(wfJobGetCmd);
    action = jpaService.execute(wfActionGetCmd);
    assertEquals(job.getStatus(), WorkflowJob.Status.KILLED);
    assertEquals(action.getStatus(), WorkflowAction.Status.KILLED);
    wfInstance = job.getWorkflowInstance();
    assertEquals(wfInstance.getStatus(), WorkflowInstance.Status.KILLED);
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) Services(org.apache.oozie.service.Services) WorkflowActionGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) WorkflowInstance(org.apache.oozie.workflow.WorkflowInstance) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 48 with WorkflowActionGetJPAExecutor

use of org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor in project oozie by apache.

the class TestWorkflowKillXCommand method testWfKillFailed.

/**
 * Test : kill job but failed to kill an already successful action.
 *
 * @throws Exception
 */
public void testWfKillFailed() throws Exception {
    WorkflowJobBean job = this.addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    WorkflowActionBean action = this.addRecordToWfActionTable(job.getId(), "1", WorkflowAction.Status.OK);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    WorkflowJobGetJPAExecutor wfJobGetCmd = new WorkflowJobGetJPAExecutor(job.getId());
    WorkflowActionGetJPAExecutor wfActionGetCmd = new WorkflowActionGetJPAExecutor(action.getId());
    job = jpaService.execute(wfJobGetCmd);
    action = jpaService.execute(wfActionGetCmd);
    assertEquals(job.getStatus(), WorkflowJob.Status.RUNNING);
    assertEquals(action.getStatus(), WorkflowAction.Status.OK);
    WorkflowInstance wfInstance = job.getWorkflowInstance();
    assertEquals(wfInstance.getStatus(), WorkflowInstance.Status.RUNNING);
    new KillXCommand(job.getId()).call();
    job = jpaService.execute(wfJobGetCmd);
    action = jpaService.execute(wfActionGetCmd);
    assertEquals(job.getStatus(), WorkflowJob.Status.KILLED);
    assertEquals(action.getStatus(), WorkflowAction.Status.OK);
    wfInstance = job.getWorkflowInstance();
    assertEquals(wfInstance.getStatus(), WorkflowInstance.Status.KILLED);
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) WorkflowActionGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) WorkflowInstance(org.apache.oozie.workflow.WorkflowInstance) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 49 with WorkflowActionGetJPAExecutor

use of org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor in project oozie by apache.

the class TestEventGeneration method testWorkflowActionEvent.

@Test
public void testWorkflowActionEvent() throws Exception {
    assertEquals(queue.size(), 0);
    // avoid noise from other apptype events by setting it to only
    // workflow action
    ehs.setAppTypes(new HashSet<String>(Arrays.asList("workflow_action")));
    WorkflowJobBean job = this.addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    WorkflowActionBean action = this.addRecordToWfActionTable(job.getId(), "1", WorkflowAction.Status.PREP, true);
    // adding record sets externalChildID to dummy workflow-id so resetting it
    action.setExternalChildIDs(null);
    WorkflowActionQueryExecutor.getInstance().executeUpdate(WorkflowActionQuery.UPDATE_ACTION_START, action);
    // Starting job
    new ActionStartXCommand(action.getId(), "map-reduce").call();
    WorkflowActionGetJPAExecutor wfActionGetCmd = new WorkflowActionGetJPAExecutor(action.getId());
    action = jpaService.execute(wfActionGetCmd);
    assertEquals(WorkflowAction.Status.RUNNING, action.getStatus());
    assertEquals(1, queue.size());
    WorkflowActionEvent event = (WorkflowActionEvent) queue.poll();
    assertNotNull(event);
    assertEquals(EventStatus.STARTED, event.getEventStatus());
    assertEquals(AppType.WORKFLOW_ACTION, event.getAppType());
    assertEquals(action.getId(), event.getId());
    assertEquals(job.getUser(), event.getUser());
    assertEquals(action.getName(), event.getAppName());
    assertEquals(action.getStartTime(), event.getStartTime());
    assertEquals(0, queue.size());
    // Suspending job
    ActionExecutor.Context context = new ActionXCommand.ActionExecutorContext(job, action, false, false);
    ActionExecutor executor = Services.get().get(ActionService.class).getExecutor(action.getType());
    ActionCheckXCommandForTest dac = new ActionCheckXCommandForTest(context, executor, action.getId());
    dac.execute();
    action = dac.getAction();
    assertEquals(WorkflowAction.Status.START_MANUAL, action.getStatus());
    assertEquals(1, queue.size());
    event = (WorkflowActionEvent) queue.poll();
    assertNotNull(event);
    assertEquals(EventStatus.SUSPEND, event.getEventStatus());
    assertEquals(AppType.WORKFLOW_ACTION, event.getAppType());
    assertEquals(action.getId(), event.getId());
    assertEquals(job.getUser(), event.getUser());
    assertEquals(action.getName(), event.getAppName());
    assertEquals(0, queue.size());
    // Killing job
    action.setStatus(WorkflowAction.Status.KILLED);
    action.setPendingOnly();
    // its already set by XTestCase add action record method above
    action.setEndTime(null);
    WorkflowActionQueryExecutor.getInstance().executeUpdate(WorkflowActionQuery.UPDATE_ACTION_END, action);
    new ActionKillXCommand(action.getId()).call();
    action = jpaService.execute(wfActionGetCmd);
    assertEquals(WorkflowAction.Status.KILLED, action.getStatus());
    assertEquals(1, queue.size());
    event = (WorkflowActionEvent) queue.poll();
    assertNotNull(event);
    assertEquals(EventStatus.FAILURE, event.getEventStatus());
    assertEquals(AppType.WORKFLOW_ACTION, event.getAppType());
    assertEquals(action.getId(), event.getId());
    assertEquals(job.getUser(), event.getUser());
    assertEquals(action.getName(), event.getAppName());
    assertEquals(action.getStartTime(), event.getStartTime());
    assertNotNull(action.getEndTime());
    assertNotNull(event.getEndTime());
    assertEquals(action.getEndTime(), event.getEndTime());
    assertEquals(0, queue.size());
}
Also used : ControlNodeActionExecutor(org.apache.oozie.action.control.ControlNodeActionExecutor) ActionExecutor(org.apache.oozie.action.ActionExecutor) ActionKillXCommand(org.apache.oozie.command.wf.ActionKillXCommand) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) ActionStartXCommand(org.apache.oozie.command.wf.ActionStartXCommand) WorkflowActionGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor) ActionService(org.apache.oozie.service.ActionService) Test(org.junit.Test)

Example 50 with WorkflowActionGetJPAExecutor

use of org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor in project oozie by apache.

the class TestWorkflowActionGetJPAExecutor method _testGetActionWithExecPath.

private void _testGetActionWithExecPath(String actionId, String execPath) throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    WorkflowActionGetJPAExecutor actionGetCmd = new WorkflowActionGetJPAExecutor(actionId);
    WorkflowActionBean ret = jpaService.execute(actionGetCmd);
    assertNotNull(ret);
    assertEquals(ret.getId(), actionId);
    assertEquals(ret.getExecutionPath(), execPath);
}
Also used : WorkflowActionGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Aggregations

WorkflowActionBean (org.apache.oozie.WorkflowActionBean)51 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)51 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)47 JPAService (org.apache.oozie.service.JPAService)47 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)38 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)35 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)22 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)21 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)21 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)20 BundleActionBean (org.apache.oozie.BundleActionBean)9 BundleJobBean (org.apache.oozie.BundleJobBean)9 BundleActionGetJPAExecutor (org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor)9 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)9 WorkflowInstance (org.apache.oozie.workflow.WorkflowInstance)9 Configuration (org.apache.hadoop.conf.Configuration)6 MapReduceActionExecutor (org.apache.oozie.action.hadoop.MapReduceActionExecutor)6 ActionExecutorContext (org.apache.oozie.command.wf.ActionXCommand.ActionExecutorContext)6 LiteWorkflowInstance (org.apache.oozie.workflow.lite.LiteWorkflowInstance)5 Date (java.util.Date)3