Search in sources :

Example 6 with CoordinatorJobBean

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

the class TestRecoveryService method testCoordActionRecoveryServiceForSuspended.

/**
 * Tests functionality of the Recovery Service Runnable command. </p> Insert a coordinator job with SUSPENDED and
 * action with SUSPENDED and workflow with RUNNING. Then, runs the recovery runnable and ensures the workflow status
 *  changes to SUSPENDED.
 *
 * @throws Exception
 */
public void testCoordActionRecoveryServiceForSuspended() throws Exception {
    Date start = DateUtils.parseDateOozieTZ("2009-02-01T01:00Z");
    Date end = DateUtils.parseDateOozieTZ("2009-02-02T23:59Z");
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.SUSPENDED, start, end, false, false, 1);
    WorkflowJobBean wfJob = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    final String wfJobId = wfJob.getId();
    addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.SUSPENDED, "coord-action-get.xml", wfJobId, "RUNNING", 2);
    sleep(3000);
    Runnable recoveryRunnable = new RecoveryRunnable(0, 1, 1);
    recoveryRunnable.run();
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    waitFor(10000, new Predicate() {

        public boolean evaluate() throws Exception {
            WorkflowJobGetJPAExecutor wfGetCmd = new WorkflowJobGetJPAExecutor(wfJobId);
            WorkflowJobBean ret = jpaService.execute(wfGetCmd);
            return (ret.getStatus() == WorkflowJob.Status.SUSPENDED);
        }
    });
    WorkflowJobGetJPAExecutor wfGetCmd = new WorkflowJobGetJPAExecutor(wfJobId);
    WorkflowJobBean ret = jpaService.execute(wfGetCmd);
    assertEquals(WorkflowJob.Status.SUSPENDED, ret.getStatus());
}
Also used : RecoveryRunnable(org.apache.oozie.service.RecoveryService.RecoveryRunnable) WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) RecoveryRunnable(org.apache.oozie.service.RecoveryService.RecoveryRunnable) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException)

Example 7 with CoordinatorJobBean

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

the class TestRecoveryService method addRecordToJobTable.

private void addRecordToJobTable(String jobId, String baseDir) throws Exception {
    CoordinatorJobBean coordJob = new CoordinatorJobBean();
    coordJob.setId(jobId);
    coordJob.setAppName("testApp");
    coordJob.setAppPath("testAppPath");
    coordJob.setStatus(CoordinatorJob.Status.RUNNING);
    coordJob.setCreatedTime(new Date());
    coordJob.setLastModifiedTime(new Date());
    coordJob.setUser(getTestUser());
    coordJob.setGroup(getTestGroup());
    coordJob.setTimeZone("UTC");
    String confStr = "<configuration></configuration>";
    coordJob.setConf(confStr);
    String appXml = "<coordinator-app xmlns='uri:oozie:coordinator:0.2' name='NAME' frequency=\"1\" start='2009-02-01T01:00Z'" + " end='2009-02-03T23:59Z'";
    appXml += " timezone='UTC' freq_timeunit='DAY' end_of_duration='NONE'>";
    appXml += "<controls>";
    appXml += "<timeout>10</timeout>";
    appXml += "<concurrency>2</concurrency>";
    appXml += "<execution>LIFO</execution>";
    appXml += "</controls>";
    appXml += "<input-events>";
    appXml += "<data-in name='A' dataset='a'>";
    appXml += "<dataset name='a' frequency='7' initial-instance='2009-02-01T01:00Z' timezone='UTC'" + " freq_timeunit='DAY' end_of_duration='NONE'>";
    appXml += "<uri-template>" + getTestCaseFileUri("workflows/${YEAR}/${DAY}") + "</uri-template>";
    appXml += "</dataset>";
    appXml += "<instance>${coord:latest(0)}</instance>";
    appXml += "</data-in>";
    appXml += "</input-events>";
    appXml += "<output-events>";
    appXml += "<data-out name='LOCAL_A' dataset='local_a'>";
    appXml += "<dataset name='local_a' frequency='7' initial-instance='2009-02-01T01:00Z' timezone='UTC'" + " freq_timeunit='DAY' end_of_duration='NONE'>";
    appXml += "<uri-template>" + getTestCaseFileUri("workflows/${YEAR}/${DAY}") + "</uri-template>";
    appXml += "</dataset>";
    appXml += "<instance>${coord:current(-1)}</instance>";
    appXml += "</data-out>";
    appXml += "</output-events>";
    appXml += "<action>";
    appXml += "<workflow>";
    appXml += "<app-path>" + getTestCaseFileUri("workflows") + "</app-path>";
    appXml += "<configuration>";
    appXml += "<property>";
    appXml += "<name>inputA</name>";
    appXml += "<value>${coord:dataIn('A')}</value>";
    appXml += "</property>";
    appXml += "<property>";
    appXml += "<name>inputB</name>";
    appXml += "<value>${coord:dataOut('LOCAL_A')}</value>";
    appXml += "</property>";
    appXml += "</configuration>";
    appXml += "</workflow>";
    appXml += "</action>";
    appXml += "</coordinator-app>";
    coordJob.setJobXml(appXml);
    coordJob.setLastActionNumber(0);
    coordJob.setFrequency("1");
    coordJob.setExecutionOrder(Execution.FIFO);
    coordJob.setConcurrency(1);
    try {
        coordJob.setEndTime(DateUtils.parseDateOozieTZ("2009-02-03T23:59Z"));
        coordJob.setStartTime(DateUtils.parseDateOozieTZ("2009-02-01T23:59Z"));
    } catch (Exception e) {
        e.printStackTrace();
        fail("Could not set Date/time");
    }
    try {
        addRecordToCoordJobTable(coordJob);
    } catch (Exception se) {
        se.printStackTrace();
        fail("Unable to insert the test job record to table");
        throw se;
    }
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException)

Example 8 with CoordinatorJobBean

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

the class MockCoordinatorEngineService method createDummyCoordinatorJob.

private static CoordinatorJob createDummyCoordinatorJob(int idx) {
    CoordinatorJobBean coordJob = new CoordinatorJobBean();
    coordJob.setId(JOB_ID + idx);
    coordJob.setAppName("testApp");
    coordJob.setAppPath("testAppPath");
    coordJob.setStatus(CoordinatorJob.Status.RUNNING);
    coordJob.setCreatedTime(new Date());
    coordJob.setLastModifiedTime(new Date());
    coordJob.setUser(USER);
    coordJob.setGroup(GROUP);
    coordJob.setConf(CONFIGURATION);
    coordJob.setLastActionNumber(0);
    coordJob.setFrequency("1");
    coordJob.setExecutionOrder(Execution.FIFO);
    coordJob.setConcurrency(1);
    try {
        coordJob.setEndTime(DateUtils.parseDateOozieTZ("2009-02-03T23:59Z"));
        coordJob.setStartTime(DateUtils.parseDateOozieTZ("2009-02-01T23:59Z"));
    } catch (Exception e) {
        e.printStackTrace();
    }
    List<CoordinatorActionBean> actions = new ArrayList<CoordinatorActionBean>();
    for (int i = 0; i < idx; i++) {
        actions.add(createDummyAction(i, JOB_ID + idx));
    }
    coordJob.setActions(actions);
    return coordJob;
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) ArrayList(java.util.ArrayList) Date(java.util.Date) BaseEngineException(org.apache.oozie.BaseEngineException) IOException(java.io.IOException) XException(org.apache.oozie.XException) CoordinatorEngineException(org.apache.oozie.CoordinatorEngineException) CommandException(org.apache.oozie.command.CommandException)

Example 9 with CoordinatorJobBean

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

the class TestStatusTransitService method testCoordStatusTransitServiceDoneWithError.

/**
 * Tests functionality of the StatusTransitService Runnable command. </p> Insert a coordinator job with RUNNING and
 * pending true and coordinator actions with pending false, but one of action is KILLED.
 * Then, runs the StatusTransitService runnable and ensures the job status changes to DONEWITHERROR.
 *
 * @throws Exception
 */
public void testCoordStatusTransitServiceDoneWithError() throws Exception {
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, true, true, 3);
    addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.KILLED, "coord-action-get.xml", 0);
    addRecordToCoordActionTable(job.getId(), 2, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    addRecordToCoordActionTable(job.getId(), 3, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    Runnable runnable = new StatusTransitRunnable();
    runnable.run();
    sleep(1000);
    JPAService jpaService = Services.get().get(JPAService.class);
    CoordJobGetJPAExecutor coordGetCmd = new CoordJobGetJPAExecutor(job.getId());
    CoordinatorJobBean coordJob = jpaService.execute(coordGetCmd);
    assertEquals(CoordinatorJob.Status.DONEWITHERROR, coordJob.getStatus());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) Date(java.util.Date)

Example 10 with CoordinatorJobBean

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

the class TestStatusTransitService method testBundleStatusTransitServiceForTerminalStates.

/**
 * Insert a coordinator job in KILLED state with one coordinator action as
 * SUCCEEDED. Make sure the status of the job changes to DONEWITHERROR.
 * Also, the status of bundle action and bundle job should change to
 * DONEWITHERROR
 *
 * @throws Exception
 */
public void testBundleStatusTransitServiceForTerminalStates() throws Exception {
    BundleJobBean job = this.addRecordToBundleJobTable(Job.Status.RUNNING, false);
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    final String bundleId = job.getId();
    CoordinatorJobBean coord1 = addRecordToCoordJobTable(CoordinatorJob.Status.KILLED, false, false);
    addRecordToBundleActionTable(bundleId, coord1.getId(), "action1", 0, Job.Status.KILLED);
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    addRecordToCoordJobTableWithBundle(bundleId, "action1", CoordinatorJob.Status.KILLED, start, end, true, true, 2);
    addRecordToCoordActionTable("action1", 1, CoordinatorAction.Status.KILLED, "coord-action-get.xml", 0);
    addRecordToCoordActionTable("action1", 2, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    Runnable runnable = new StatusTransitRunnable();
    runnable.run();
    waitFor(15 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            CoordinatorJobBean coordJob = jpaService.execute(new CoordJobGetJPAExecutor("action1"));
            return coordJob.getStatus().equals(Job.Status.DONEWITHERROR);
        }
    });
    CoordinatorJobBean coordJob = jpaService.execute(new CoordJobGetJPAExecutor("action1"));
    assertEquals(Job.Status.KILLED, coordJob.getStatus());
    BundleActionBean bab = jpaService.execute(new BundleActionGetJPAExecutor(bundleId, "action1"));
    assertEquals(Job.Status.KILLED, bab.getStatus());
    job = jpaService.execute(new BundleJobGetJPAExecutor(bundleId));
    assertEquals(Job.Status.KILLED, job.getStatus());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) BundleActionGetJPAExecutor(org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) BundleJobBean(org.apache.oozie.BundleJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) BundleActionBean(org.apache.oozie.BundleActionBean)

Aggregations

CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)373 Date (java.util.Date)177 JPAService (org.apache.oozie.service.JPAService)153 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)149 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)121 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)114 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)53 CommandException (org.apache.oozie.command.CommandException)49 BundleJobBean (org.apache.oozie.BundleJobBean)46 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)43 IOException (java.io.IOException)39 XConfiguration (org.apache.oozie.util.XConfiguration)38 ArrayList (java.util.ArrayList)36 BundleActionBean (org.apache.oozie.BundleActionBean)36 StatusTransitRunnable (org.apache.oozie.service.StatusTransitService.StatusTransitRunnable)34 Configuration (org.apache.hadoop.conf.Configuration)33 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)32 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)30 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)30 Path (org.apache.hadoop.fs.Path)24