Search in sources :

Example 96 with CoordinatorActionBean

use of org.apache.oozie.CoordinatorActionBean in project oozie by apache.

the class TestCoordinatorInputLogic method testNestedCondition1.

public void testNestedCondition1() throws Exception {
    Configuration conf = getConf();
    // @formatter:off
    String inputLogic = "<and name=\"test\">" + "<or>" + "<and>" + "<data-in dataset=\"A\"/>" + "<data-in dataset=\"B\"/>" + "</and>" + "<and>" + "<data-in dataset=\"C\"/>" + "<data-in dataset=\"D\"/>" + "</and>" + "</or>" + "<and>" + "<data-in dataset=\"E\"/>" + "<data-in dataset=\"F\"/>" + "</and>" + "</and>";
    // @formatter:on
    conf.set("partitionName", "test");
    conf.set("A_done_flag", "done");
    final String jobId = _testCoordSubmit("coord-inputlogic.xml", conf, inputLogic);
    String input1 = createTestCaseSubDir("input-data/a/2014/10/08/00/done".split("/"));
    String input2 = createTestCaseSubDir("input-data/b/2014/10/08/00/_SUCCESS".split("/"));
    String input3 = createTestCaseSubDir("input-data/e/2014/10/08/00/_SUCCESS".split("/"));
    String input4 = createTestCaseSubDir("input-data/f/2014/10/08/00/_SUCCESS".split("/"));
    startCoordAction(jobId);
    CoordinatorActionBean actionBean = CoordActionQueryExecutor.getInstance().get(CoordActionQuery.GET_COORD_ACTION, jobId + "@1");
    XConfiguration runConf = new XConfiguration(new StringReader(actionBean.getRunConf()));
    String dataSets = runConf.get("inputLogicData");
    assertEquals(dataSets.split(",").length, 4);
    checkDataSets(dataSets, input1.replace("/done", ""), input2, input3, input4);
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) StringReader(java.io.StringReader)

Example 97 with CoordinatorActionBean

use of org.apache.oozie.CoordinatorActionBean 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 98 with CoordinatorActionBean

use of org.apache.oozie.CoordinatorActionBean in project oozie by apache.

the class TestEventGeneration method testCoordinatorActionEvent.

@Test
public void testCoordinatorActionEvent() throws Exception {
    // avoid noise from other apptype events by setting it to only
    // coord action
    ehs.setAppTypes(new HashSet<String>(Arrays.asList("coordinator_action")));
    assertEquals(queue.size(), 0);
    Date startTime = DateUtils.parseDateOozieTZ("2013-01-01T10:00Z");
    Date endTime = DateUtils.parseDateOozieTZ("2013-01-01T10:01Z");
    CoordinatorJobBean coord = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, false, false, 0);
    modifyCoordForRunning(coord);
    // Action WAITING on materialization
    new CoordMaterializeTransitionXCommand(coord.getId(), 3600).call();
    final CoordActionGetJPAExecutor coordGetCmd = new CoordActionGetJPAExecutor(coord.getId() + "@1");
    CoordinatorActionBean action = jpaService.execute(coordGetCmd);
    assertEquals(CoordinatorAction.Status.WAITING, action.getStatus());
    assertEquals(1, queue.size());
    JobEvent event = (JobEvent) queue.poll();
    assertNotNull(event);
    assertEquals(EventStatus.WAITING, event.getEventStatus());
    assertEquals(AppType.COORDINATOR_ACTION, event.getAppType());
    assertEquals(action.getId(), event.getId());
    assertEquals(action.getJobId(), event.getParentId());
    assertEquals(action.getNominalTime(), ((CoordinatorActionEvent) event).getNominalTime());
    assertNull(event.getStartTime());
    assertEquals(coord.getUser(), event.getUser());
    assertEquals(coord.getAppName(), event.getAppName());
    assertEquals(0, queue.size());
    // Make Action ready
    // In this case it will proceed to Running since n(ready_actions) < concurrency
    new CoordActionInputCheckXCommand(action.getId(), coord.getId()).call();
    action = jpaService.execute(coordGetCmd);
    assertEquals(CoordinatorAction.Status.RUNNING, action.getStatus());
    event = (JobEvent) queue.poll();
    assertEquals(EventStatus.STARTED, event.getEventStatus());
    assertEquals(AppType.COORDINATOR_ACTION, event.getAppType());
    assertEquals(action.getId(), event.getId());
    assertEquals(action.getJobId(), event.getParentId());
    assertEquals(action.getNominalTime(), ((CoordinatorActionEvent) event).getNominalTime());
    WorkflowJobBean wfJob = jpaService.execute(new WorkflowJobGetJPAExecutor(action.getExternalId()));
    assertEquals(wfJob.getStartTime(), event.getStartTime());
    assertEquals(coord.getUser(), event.getUser());
    assertEquals(coord.getAppName(), event.getAppName());
    sleep(2000);
    // Action Success
    wfJob.setStatus(WorkflowJob.Status.SUCCEEDED);
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_MODTIME, wfJob);
    action.setStatus(CoordinatorAction.Status.RUNNING);
    CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, action);
    new CoordActionCheckXCommand(action.getId(), 0).call();
    action = jpaService.execute(coordGetCmd);
    assertEquals(CoordinatorAction.Status.SUCCEEDED, action.getStatus());
    List<Event> list = queue.pollBatch();
    event = (JobEvent) list.get(list.size() - 1);
    assertEquals(EventStatus.SUCCESS, event.getEventStatus());
    assertEquals(AppType.COORDINATOR_ACTION, event.getAppType());
    assertEquals(action.getId(), event.getId());
    assertEquals(action.getJobId(), event.getParentId());
    assertEquals(action.getNominalTime(), ((CoordinatorActionEvent) event).getNominalTime());
    assertEquals(wfJob.getStartTime(), event.getStartTime());
    assertEquals(coord.getUser(), event.getUser());
    assertEquals(coord.getAppName(), event.getAppName());
    // Action Failure
    wfJob.setStatus(WorkflowJob.Status.FAILED);
    action.setStatus(CoordinatorAction.Status.RUNNING);
    CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, action);
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_MODTIME, wfJob);
    new CoordActionCheckXCommand(action.getId(), 0).call();
    action = jpaService.execute(coordGetCmd);
    assertEquals(CoordinatorAction.Status.FAILED, action.getStatus());
    event = (JobEvent) queue.poll();
    assertEquals(EventStatus.FAILURE, event.getEventStatus());
    assertEquals(AppType.COORDINATOR_ACTION, event.getAppType());
    assertEquals(action.getId(), event.getId());
    assertEquals(action.getJobId(), event.getParentId());
    assertEquals(action.getNominalTime(), ((CoordinatorActionEvent) event).getNominalTime());
    assertEquals(wfJob.getStartTime(), event.getStartTime());
    assertEquals(coord.getUser(), event.getUser());
    assertEquals(coord.getAppName(), event.getAppName());
    // Action Suspended
    wfJob.setStatus(WorkflowJob.Status.SUSPENDED);
    action.setStatus(CoordinatorAction.Status.RUNNING);
    CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, action);
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_MODTIME, wfJob);
    new CoordActionCheckXCommand(action.getId(), 0).call();
    action = jpaService.execute(coordGetCmd);
    assertEquals(CoordinatorAction.Status.SUSPENDED, action.getStatus());
    event = (JobEvent) queue.poll();
    assertEquals(EventStatus.SUSPEND, event.getEventStatus());
    assertEquals(AppType.COORDINATOR_ACTION, event.getAppType());
    assertEquals(action.getId(), event.getId());
    assertEquals(action.getJobId(), event.getParentId());
    assertEquals(action.getNominalTime(), ((CoordinatorActionEvent) event).getNominalTime());
    assertEquals(wfJob.getStartTime(), event.getStartTime());
    assertEquals(coord.getUser(), event.getUser());
    assertEquals(coord.getAppName(), event.getAppName());
    // Action start on Coord Resume
    coord.setStatus(CoordinatorJobBean.Status.SUSPENDED);
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB_STATUS, coord);
    action.setStatus(CoordinatorAction.Status.SUSPENDED);
    CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, action);
    wfJob.setStatus(WorkflowJob.Status.SUSPENDED);
    WorkflowInstance wfInstance = wfJob.getWorkflowInstance();
    ((LiteWorkflowInstance) wfInstance).setStatus(WorkflowInstance.Status.SUSPENDED);
    wfJob.setWorkflowInstance(wfInstance);
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MODIFIED, wfJob);
    queue.clear();
    new CoordResumeXCommand(coord.getId()).call();
    waitForEventGeneration(1000);
    CoordinatorActionEvent cevent = (CoordinatorActionEvent) queue.poll();
    assertEquals(EventStatus.STARTED, cevent.getEventStatus());
    assertEquals(AppType.COORDINATOR_ACTION, cevent.getAppType());
    assertEquals(action.getId(), cevent.getId());
    assertEquals(action.getJobId(), cevent.getParentId());
    assertEquals(action.getNominalTime(), cevent.getNominalTime());
    coord = CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB, coord.getId());
    assertEquals(coord.getLastModifiedTime(), cevent.getStartTime());
    // Action going to WAITING on Coord Rerun
    action.setStatus(CoordinatorAction.Status.KILLED);
    CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, action);
    queue.clear();
    new CoordRerunXCommand(coord.getId(), RestConstants.JOB_COORD_SCOPE_ACTION, "1", false, true, false, null).call();
    waitFor(3 * 100, new Predicate() {

        @Override
        public boolean evaluate() throws Exception {
            return jpaService.execute(coordGetCmd).getStatus() == CoordinatorAction.Status.WAITING;
        }
    });
    cevent = (CoordinatorActionEvent) queue.poll();
    assertEquals(EventStatus.WAITING, cevent.getEventStatus());
    assertEquals(AppType.COORDINATOR_ACTION, cevent.getAppType());
    assertEquals(action.getId(), cevent.getId());
    assertEquals(action.getJobId(), cevent.getParentId());
    assertEquals(action.getNominalTime(), cevent.getNominalTime());
    assertEquals(wfJob.getStartTime(), event.getStartTime());
    assertNotNull(cevent.getMissingDeps());
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordRerunXCommand(org.apache.oozie.command.coord.CoordRerunXCommand) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) CoordMaterializeTransitionXCommand(org.apache.oozie.command.coord.CoordMaterializeTransitionXCommand) CoordActionCheckXCommand(org.apache.oozie.command.coord.CoordActionCheckXCommand) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) WorkflowInstance(org.apache.oozie.workflow.WorkflowInstance) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CommandException(org.apache.oozie.command.CommandException) CoordResumeXCommand(org.apache.oozie.command.coord.CoordResumeXCommand) JobEvent(org.apache.oozie.client.event.JobEvent) JobEvent(org.apache.oozie.client.event.JobEvent) Event(org.apache.oozie.client.event.Event) CoordActionInputCheckXCommand(org.apache.oozie.command.coord.CoordActionInputCheckXCommand) Test(org.junit.Test)

Example 99 with CoordinatorActionBean

use of org.apache.oozie.CoordinatorActionBean in project oozie by apache.

the class TestReRunXCommand method testRerunDisableForChild.

/**
 * Rerun workflow should run by parent only if configuration has been set to
 * true for oozie.wf.child.disable.rerun , Default it is disabled.
 * @throws Exception
 */
public void testRerunDisableForChild() throws Exception {
    final OozieClient wfClient = LocalOozie.getClient();
    Date start = DateUtils.parseDateOozieTZ("2009-12-15T01:00Z");
    Date end = DateUtils.parseDateOozieTZ("2009-12-16T01:00Z");
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, false, false, 1);
    CoordinatorActionBean action = addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.SUBMITTED, "coord-action-start-escape-strings.xml", 0);
    String actionId = action.getId();
    new CoordActionStartXCommand(actionId, getTestUser(), "myapp", "myjob").call();
    final JPAService jpaService = Services.get().get(JPAService.class);
    action = jpaService.execute(new CoordActionGetJPAExecutor(actionId));
    if (action.getStatus() == CoordinatorAction.Status.SUBMITTED) {
        fail("CoordActionStartCommand didn't work because the status for action id" + actionId + " is :" + action.getStatus() + " expected to be NOT SUBMITTED (i.e. RUNNING)");
    }
    final String wfId = action.getExternalId();
    wfClient.kill(wfId);
    waitFor(15 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(wfId).getStatus() == WorkflowJob.Status.KILLED;
        }
    });
    Properties newConf = wfClient.createConfiguration();
    newConf.setProperty(OozieClient.RERUN_FAIL_NODES, "true");
    Services.get().getConf().setBoolean(ReRunXCommand.DISABLE_CHILD_RERUN, true);
    try {
        wfClient.reRun(wfId, newConf);
        fail("OozieClientException should have been thrown (" + ErrorCode.E0755 + " Rerun is not allowed through child workflow, please re-run through the parent)");
    } catch (OozieClientException ex) {
        assertEquals(ErrorCode.E0755.toString(), ex.getErrorCode());
    }
    Services.get().getConf().setBoolean(ReRunXCommand.DISABLE_CHILD_RERUN, false);
    wfClient.reRun(wfId, newConf);
    waitFor(15 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(wfId).getStatus() == WorkflowJob.Status.SUCCEEDED;
        }
    });
    assertEquals(WorkflowJob.Status.SUCCEEDED, wfClient.getJobInfo(wfId).getStatus());
}
Also used : OozieClient(org.apache.oozie.client.OozieClient) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) OozieClientException(org.apache.oozie.client.OozieClientException) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordActionStartXCommand(org.apache.oozie.command.coord.CoordActionStartXCommand) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) Properties(java.util.Properties) Date(java.util.Date) OozieClientException(org.apache.oozie.client.OozieClientException) IOException(java.io.IOException)

Example 100 with CoordinatorActionBean

use of org.apache.oozie.CoordinatorActionBean in project oozie by apache.

the class TestCoordUtils method testGetCoordActionsFromIds.

// test retrieval of single action (action 1)
public void testGetCoordActionsFromIds() throws Exception {
    int actionNum = 1;
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
    String jobId = job.getId();
    CoordinatorActionBean action1 = addRecordToCoordActionTable(jobId, actionNum, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    List<CoordinatorActionBean> coordActions = CoordUtils.getCoordActionsFromIds(jobId, Integer.toString(actionNum));
    // check for the expected size of actions list
    assertEquals(1, coordActions.size());
    // check for the expected action
    assertEquals(action1, coordActions.get(0));
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean)

Aggregations

CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)307 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)148 Date (java.util.Date)117 JPAService (org.apache.oozie.service.JPAService)113 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)102 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)60 CommandException (org.apache.oozie.command.CommandException)55 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)53 IOException (java.io.IOException)49 XConfiguration (org.apache.oozie.util.XConfiguration)44 Configuration (org.apache.hadoop.conf.Configuration)43 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)42 ArrayList (java.util.ArrayList)40 JDOMException (org.jdom.JDOMException)33 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)32 StringReader (java.io.StringReader)30 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)29 StoreException (org.apache.oozie.store.StoreException)24 Test (org.junit.Test)24 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)22