Search in sources :

Example 51 with CoordinatorJobBean

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

the class TestCoordChangeXCommand method addRecordToCoordJobTableForPauseTimeTest.

protected CoordinatorJobBean addRecordToCoordJobTableForPauseTimeTest(CoordinatorJob.Status status, Date start, Date end, Date lastActionTime, boolean pending, boolean doneMatd, int lastActionNum) throws Exception {
    CoordinatorJobBean coordJob = createCoordJob(status, start, end, pending, doneMatd, lastActionNum);
    coordJob.setFrequency("1");
    coordJob.setTimeUnit(Timeunit.HOUR);
    coordJob.setLastActionNumber(lastActionNum);
    coordJob.setLastActionTime(lastActionTime);
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        assertNotNull(jpaService);
        CoordJobInsertJPAExecutor coordInsertCmd = new CoordJobInsertJPAExecutor(coordJob);
        jpaService.execute(coordInsertCmd);
    } catch (JPAExecutorException je) {
        je.printStackTrace();
        fail("Unable to insert the test coord job record to table");
        throw je;
    }
    return coordJob;
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordJobInsertJPAExecutor(org.apache.oozie.executor.jpa.CoordJobInsertJPAExecutor) JPAService(org.apache.oozie.service.JPAService)

Example 52 with CoordinatorJobBean

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

the class TestCoordChangeXCommand method testCoordChangeEndTime1.

/**
 * Testcase when changing end-time == nextMaterializedTime
 * reflects correct job status via StatusTransit
 *
 * @throws Exception
 */
public void testCoordChangeEndTime1() throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    Date startTime = new Date();
    Date endTime = new Date(startTime.getTime() + (50 * 60 * 1000));
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, true, true, 1);
    coordJob.setNextMaterializedTime(new Date(startTime.getTime() + (30 * 60 * 1000)));
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, coordJob);
    addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    Runnable runnable = new StatusTransitService.StatusTransitRunnable();
    // dummy run so we get to the interval check following coord job change
    runnable.run();
    sleep(1000);
    // checking before change
    assertEquals(endTime.getTime(), coordJob.getEndTime().getTime());
    String newEndTime = convertDateToString(startTime.getTime() + 30 * 60 * 1000);
    new CoordChangeXCommand(coordJob.getId(), "endtime=" + newEndTime).call();
    try {
        checkCoordJobs(coordJob.getId(), DateUtils.parseDateOozieTZ(newEndTime), null, null, false);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail("Invalid date" + ex);
    }
    CoordJobGetJPAExecutor coordGetCmd = new CoordJobGetJPAExecutor(coordJob.getId());
    coordJob = jpaService.execute(coordGetCmd);
    assertEquals(Job.Status.RUNNING, coordJob.getStatus());
    // checking after change
    assertEquals(newEndTime, convertDateToString(coordJob.getEndTime().getTime()));
    assertTrue(coordJob.isPending());
    assertTrue(coordJob.isDoneMaterialization());
    runnable.run();
    sleep(1000);
    coordJob = jpaService.execute(coordGetCmd);
    assertEquals(Job.Status.SUCCEEDED, coordJob.getStatus());
    assertFalse(coordJob.isPending());
    assertTrue(coordJob.isDoneMaterialization());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) StoreException(org.apache.oozie.store.StoreException) CommandException(org.apache.oozie.command.CommandException)

Example 53 with CoordinatorJobBean

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

the class TestCoordChangeXCommand method testCoordChangeEndTime2.

/**
 * Testcase when changing end-time > nextMaterializedTime, but < original end
 * reflects correct job state and values
 *
 * @throws Exception
 */
public void testCoordChangeEndTime2() throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    Date startTime = new Date();
    Date endTime = new Date(startTime.getTime() + (50 * 60 * 1000));
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, true, true, 1);
    coordJob.setNextMaterializedTime(new Date(startTime.getTime() + (30 * 60 * 1000)));
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, coordJob);
    addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    // checking initial condition before change
    assertTrue(coordJob.isDoneMaterialization());
    Runnable runnable = new StatusTransitService.StatusTransitRunnable();
    // dummy run so we get to the interval check following coord job change
    runnable.run();
    sleep(1000);
    String newEndTime = convertDateToString(startTime.getTime() + 40 * 60 * 1000);
    new CoordChangeXCommand(coordJob.getId(), "endtime=" + newEndTime).call();
    try {
        checkCoordJobs(coordJob.getId(), DateUtils.parseDateOozieTZ(newEndTime), null, null, false);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail("Invalid date" + ex);
    }
    CoordJobGetJPAExecutor coordGetCmd = new CoordJobGetJPAExecutor(coordJob.getId());
    coordJob = jpaService.execute(coordGetCmd);
    assertEquals(Job.Status.RUNNING, coordJob.getStatus());
    assertTrue(coordJob.isPending());
    // <-- changed
    assertFalse(coordJob.isDoneMaterialization());
    assertEquals(newEndTime, convertDateToString(coordJob.getEndTime().getTime()));
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) StoreException(org.apache.oozie.store.StoreException) CommandException(org.apache.oozie.command.CommandException)

Example 54 with CoordinatorJobBean

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

the class TestCoordCommandUtils method testGetNextValidActionTime.

public void testGetNextValidActionTime() throws Exception {
    Date startTime = DateUtils.parseDateOozieTZ("2013-07-18T00:00Z");
    Date endTime = DateUtils.parseDateOozieTZ("2013-07-18T01:00Z");
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, "10,20 * * * *");
    Date actionTime = DateUtils.parseDateOozieTZ("2013-07-18T00:15Z");
    Date expectedDate = DateUtils.parseDateOozieTZ("2013-07-18T00:20Z");
    Date retDate = CoordCommandUtils.getNextValidActionTimeForCronFrequency(actionTime, job);
    assertEquals(expectedDate, retDate);
    job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, "10/20 * * 5-7 4,5");
    actionTime = DateUtils.parseDateOozieTZ("2013-07-18T00:15Z");
    expectedDate = DateUtils.parseDateOozieTZ("2013-07-18T00:30Z");
    retDate = CoordCommandUtils.getNextValidActionTimeForCronFrequency(actionTime, job);
    assertEquals(expectedDate, retDate);
    job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, "20-30 * 20 5-7 4,5");
    actionTime = DateUtils.parseDateOozieTZ("2013-07-18T00:20Z");
    expectedDate = DateUtils.parseDateOozieTZ("2013-07-18T00:21Z");
    retDate = CoordCommandUtils.getNextValidActionTimeForCronFrequency(actionTime, job);
    assertEquals(expectedDate, retDate);
    job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, "30 * 20 5-7 ?");
    actionTime = DateUtils.parseDateOozieTZ("2013-07-18T00:20Z");
    expectedDate = DateUtils.parseDateOozieTZ("2013-07-20T00:30Z");
    retDate = CoordCommandUtils.getNextValidActionTimeForCronFrequency(actionTime, job);
    assertEquals(expectedDate, retDate);
    job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, "0 9-16 * * 2-6");
    actionTime = DateUtils.parseDateOozieTZ("2013-07-20T00:20Z");
    expectedDate = DateUtils.parseDateOozieTZ("2013-07-22T09:00Z");
    retDate = CoordCommandUtils.getNextValidActionTimeForCronFrequency(actionTime, job);
    assertEquals(expectedDate, retDate);
    retDate = CoordCommandUtils.getNextValidActionTimeForCronFrequency(retDate, job);
    expectedDate = DateUtils.parseDateOozieTZ("2013-07-22T10:00Z");
    assertEquals(expectedDate, retDate);
    job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, "20-30 * * 1 *");
    actionTime = DateUtils.parseDateOozieTZ("2013-07-18T00:20Z");
    expectedDate = DateUtils.parseDateOozieTZ("2014-01-01T00:20Z");
    retDate = CoordCommandUtils.getNextValidActionTimeForCronFrequency(actionTime, job);
    assertEquals(expectedDate, retDate);
    job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, "20-30 10 * * MON,WED");
    actionTime = DateUtils.parseDateOozieTZ("2013-07-18T00:20Z");
    expectedDate = DateUtils.parseDateOozieTZ("2013-07-22T10:20Z");
    retDate = CoordCommandUtils.getNextValidActionTimeForCronFrequency(actionTime, job);
    assertEquals(expectedDate, retDate);
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) Date(java.util.Date)

Example 55 with CoordinatorJobBean

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

the class TestCoordCommandUtils method testCoordOffset.

@Test
public void testCoordOffset() throws Exception {
    CoordinatorJobBean job = addRecordToCoordJobTableForWaiting("coord-dataset-offset.xml", CoordinatorJob.Status.RUNNING, false, true);
    Path appPath = new Path(getFsTestCaseDir(), "coord");
    String actionXml = getCoordActionXml(appPath, "coord-dataset-offset.xml");
    actionXml = actionXml.replace("-unit-", "DAY");
    actionXml = actionXml.replace("-frequency-", "1");
    CoordinatorActionBean actionBean = createCoordinatorActionBean(job);
    Configuration jobConf = new XConfiguration(new StringReader(job.getConf()));
    Element eAction = createActionElement(actionXml);
    jobConf.set("startInstance", "coord:offset(-4,DAY)");
    jobConf.set("endInstance", "coord:offset(0,DAY)");
    String output = CoordCommandUtils.materializeOneInstance("jobId", true, eAction, DateUtils.parseDateOozieTZ("2009-08-20T10:00Z"), DateUtils.parseDateOozieTZ("2009-08-20T10:00Z"), 1, jobConf, actionBean);
    eAction = XmlUtils.parseXml(output);
    Element e = (Element) ((Element) eAction.getChildren("input-events", eAction.getNamespace()).get(0)).getChildren().get(0);
    assertEquals(e.getChild("uris", e.getNamespace()).getTextTrim(), "hdfs:///tmp/workflows/2009/08/20/01;region=us#hdfs:///tmp/workflows/2009/08/19/01;region=us#" + "hdfs:///tmp/workflows/2009/08/18/01;region=us#hdfs:///tmp/workflows/2009/08/17/01;" + "region=us#hdfs:///tmp/workflows/2009/08/16/01;region=us");
    jobConf.set("startInstance", "coord:offset(-4,HOUR)");
    jobConf.set("endInstance", "coord:offset(0,HOUR)");
    actionXml = getCoordActionXml(appPath, "coord-dataset-offset.xml");
    actionXml = actionXml.replace("-unit-", "MINUTE");
    actionXml = actionXml.replace("-frequency-", "60");
    eAction = createActionElement(actionXml);
    output = CoordCommandUtils.materializeOneInstance("jobId", true, eAction, DateUtils.parseDateOozieTZ("2009-08-20T01:00Z"), DateUtils.parseDateOozieTZ("2009-08-20T01:00Z"), 1, jobConf, actionBean);
    eAction = XmlUtils.parseXml(output);
    e = (Element) ((Element) eAction.getChildren("input-events", eAction.getNamespace()).get(0)).getChildren().get(0);
    assertEquals(e.getChild("uris", e.getNamespace()).getTextTrim(), "hdfs:///tmp/workflows/2009/08/20/01;region=us#hdfs:///tmp/workflows/2009/08/20/00;region=us#" + "hdfs:///tmp/workflows/2009/08/19/23;region=us#hdfs:///tmp/workflows/2009/08/19/22;region=us#" + "hdfs:///tmp/workflows/2009/08/19/21;region=us");
}
Also used : Path(org.apache.hadoop.fs.Path) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) Element(org.jdom.Element) StringReader(java.io.StringReader) Test(org.junit.Test)

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