Search in sources :

Example 1 with ActionStartXCommand

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

the class TestEventGeneration method testInvalidXMLCoordinatorFailsForNoDuplicates.

@Test
public void testInvalidXMLCoordinatorFailsForNoDuplicates() throws Exception {
    Date startTime = DateUtils.parseDateOozieTZ("2009-02-01T23:59Z");
    Date endTime = DateUtils.parseDateOozieTZ("2009-02-02T23:59Z");
    // test coordinator action events (failure from ActionStartX)
    ehs.getAppTypes().add("workflow_action");
    CoordinatorJobBean coord = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, false, false, 0);
    CoordinatorActionBean action = addRecordToCoordActionTable(coord.getId(), 1, CoordinatorAction.Status.RUNNING, "coord-action-sla1.xml", 0);
    WorkflowJobBean wf = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING, action.getId());
    action.setExternalId(wf.getId());
    CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION, action);
    String waId = _createWorkflowAction(wf.getId(), "wf-action");
    new ActionStartXCommand(waId, action.getType()).call();
    final CoordJobGetJPAExecutor readCmd2 = new CoordJobGetJPAExecutor(coord.getId());
    waitFor(1 * 100, new Predicate() {

        @Override
        public boolean evaluate() throws Exception {
            return jpaService.execute(readCmd2).getStatus() == CoordinatorJob.Status.KILLED;
        }
    });
    assertEquals(3, queue.size());
    HashMap<AppType, JobEvent> eventsMap = new HashMap<AppType, JobEvent>();
    while (queue.size() > 0) {
        JobEvent event = (JobEvent) queue.poll();
        eventsMap.put(event.getAppType(), event);
    }
    assertEquals(3, eventsMap.size());
    // Check the WF action
    {
        JobEvent wfActionEvent = eventsMap.get(AppType.WORKFLOW_ACTION);
        assertNotNull("There should be a WF action", wfActionEvent);
        assertEquals(EventStatus.FAILURE, wfActionEvent.getEventStatus());
        assertEquals(waId, wfActionEvent.getId());
        assertEquals(AppType.WORKFLOW_ACTION, wfActionEvent.getAppType());
    }
    // Check the WF job
    {
        JobEvent wfJobEvent = eventsMap.get(AppType.WORKFLOW_JOB);
        assertNotNull("There should be a WF job", wfJobEvent);
        assertEquals(EventStatus.FAILURE, wfJobEvent.getEventStatus());
        assertEquals(wf.getId(), wfJobEvent.getId());
        assertEquals(AppType.WORKFLOW_JOB, wfJobEvent.getAppType());
    }
    // Check the Coordinator action
    {
        JobEvent coordActionEvent = eventsMap.get(AppType.COORDINATOR_ACTION);
        assertNotNull("There should be a Coordinator action", coordActionEvent);
        assertEquals(EventStatus.FAILURE, coordActionEvent.getEventStatus());
        assertEquals(action.getId(), coordActionEvent.getId());
        assertEquals(AppType.COORDINATOR_ACTION, coordActionEvent.getAppType());
    }
    queue.clear();
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) HashMap(java.util.HashMap) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CommandException(org.apache.oozie.command.CommandException) JobEvent(org.apache.oozie.client.event.JobEvent) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) ActionStartXCommand(org.apache.oozie.command.wf.ActionStartXCommand) AppType(org.apache.oozie.AppType) Test(org.junit.Test)

Example 2 with ActionStartXCommand

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

the class TestActionFailover method testFsFailover.

public void testFsFailover() throws Exception {
    Path wf = new Path(getFsTestCaseDir(), "workflow.xml");
    Reader reader = IOUtils.getResourceAsReader("failover-fs-wf.xml", -1);
    Writer writer = new OutputStreamWriter(getFileSystem().create(wf));
    IOUtils.copyCharStream(reader, writer);
    final OozieClient wfClient = LocalOozie.getClient();
    Properties conf = wfClient.createConfiguration();
    conf.setProperty(OozieClient.APP_PATH, wf.toString());
    conf.setProperty(OozieClient.USER_NAME, getTestUser());
    conf.setProperty(OozieClient.GROUP_NAME, getTestGroup());
    final Path source = new Path(getFsTestCaseDir(), "fsfailover-source");
    getFileSystem().mkdirs(source);
    final Path target = new Path(getFsTestCaseDir().toString(), "fsfailover-target");
    conf.setProperty("source", source.toString());
    conf.setProperty("target", target.toUri().getPath());
    final String jobId1 = wfClient.submit(conf);
    setSystemProperty(FaultInjection.FAULT_INJECTION, "true");
    setSystemProperty(SkipCommitFaultInjection.ACTION_FAILOVER_FAULT_INJECTION, "true");
    try {
        wfClient.start(jobId1);
        fail("Should have skipped commit for failover testing");
    } catch (OozieClientException oce) {
        assertTrue(oce.getMessage().contains("Skipping Commit for Failover Testing"));
    }
    waitFor(10 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return getFileSystem().exists(target);
        }
    });
    assertFalse(getFileSystem().exists(target));
    waitFor(10 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return FaultInjection.isActive("org.apache.oozie.command.SkipCommitFaultInjection");
        }
    });
    assertFalse(FaultInjection.isActive("org.apache.oozie.command.SkipCommitFaultInjection"));
    assertEquals(WorkflowJob.Status.RUNNING, wfClient.getJobInfo(jobId1).getStatus());
    WorkflowStore store = Services.get().get(WorkflowStoreService.class).create();
    List<WorkflowActionBean> actions = store.getActionsForWorkflow(jobId1, false);
    assertEquals(1, actions.size());
    WorkflowActionBean action = actions.get(0);
    assertEquals(WorkflowAction.Status.PREP, action.getStatus());
    assertEquals(StartActionExecutor.TYPE, action.getType());
    setSystemProperty(FaultInjection.FAULT_INJECTION, "false");
    setSystemProperty(SkipCommitFaultInjection.ACTION_FAILOVER_FAULT_INJECTION, "false");
    ActionStartXCommand actionStartCommand = new ActionStartXCommand(action.getId(), action.getType());
    actionStartCommand.call();
    sleep(500);
    store = Services.get().get(WorkflowStoreService.class).create();
    actions = store.getActionsForWorkflow(jobId1, false);
    action = actions.get(0);
    assertEquals(WorkflowAction.Status.OK, action.getStatus());
    waitFor(5 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(jobId1).getStatus() == WorkflowJob.Status.SUCCEEDED;
        }
    });
    assertEquals(WorkflowJob.Status.SUCCEEDED, wfClient.getJobInfo(jobId1).getStatus());
    final String jobId2 = wfClient.submit(conf);
    wfClient.start(jobId2);
    waitFor(10 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(jobId2).getStatus() == WorkflowJob.Status.KILLED;
        }
    });
    assertEquals(WorkflowJob.Status.KILLED, wfClient.getJobInfo(jobId2).getStatus());
}
Also used : Path(org.apache.hadoop.fs.Path) OozieClientException(org.apache.oozie.client.OozieClientException) WorkflowStore(org.apache.oozie.store.WorkflowStore) WorkflowStoreService(org.apache.oozie.service.WorkflowStoreService) Reader(java.io.Reader) Properties(java.util.Properties) OozieClientException(org.apache.oozie.client.OozieClientException) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) OozieClient(org.apache.oozie.client.OozieClient) ActionStartXCommand(org.apache.oozie.command.wf.ActionStartXCommand) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 3 with ActionStartXCommand

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

Aggregations

ActionStartXCommand (org.apache.oozie.command.wf.ActionStartXCommand)3 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)2 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)2 Test (org.junit.Test)2 OutputStreamWriter (java.io.OutputStreamWriter)1 Reader (java.io.Reader)1 Writer (java.io.Writer)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 Path (org.apache.hadoop.fs.Path)1 AppType (org.apache.oozie.AppType)1 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)1 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)1 ActionExecutor (org.apache.oozie.action.ActionExecutor)1 ControlNodeActionExecutor (org.apache.oozie.action.control.ControlNodeActionExecutor)1 OozieClient (org.apache.oozie.client.OozieClient)1 OozieClientException (org.apache.oozie.client.OozieClientException)1 JobEvent (org.apache.oozie.client.event.JobEvent)1 CommandException (org.apache.oozie.command.CommandException)1