Search in sources :

Example 36 with CoordinatorActionBean

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

Example 37 with CoordinatorActionBean

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

the class TestCoordKillXCommand method testCoordKillSuccess1.

/**
 * Test : kill job and action (READY) successfully
 *
 * @throws Exception
 */
public void testCoordKillSuccess1() 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, false, false, 0);
    CoordinatorActionBean action = addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.READY, "coord-action-get.xml", 0);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    CoordJobGetJPAExecutor coordJobGetCmd = new CoordJobGetJPAExecutor(job.getId());
    CoordActionGetJPAExecutor coordActionGetCmd = new CoordActionGetJPAExecutor(action.getId());
    job = jpaService.execute(coordJobGetCmd);
    action = jpaService.execute(coordActionGetCmd);
    assertEquals(job.getStatus(), CoordinatorJob.Status.RUNNING);
    assertEquals(action.getStatus(), CoordinatorAction.Status.READY);
    assertFalse(job.isDoneMaterialization());
    new CoordKillXCommand(job.getId()).call();
    job = jpaService.execute(coordJobGetCmd);
    action = jpaService.execute(coordActionGetCmd);
    assertEquals(job.getStatus(), CoordinatorJob.Status.KILLED);
    assertTrue(job.isDoneMaterialization());
    assertNotNull(job.getLastModifiedTime());
    assertEquals(action.getStatus(), CoordinatorAction.Status.KILLED);
    // Change job status to RUNNINGWITHERROR to simulate StatusTransitService changing it to
    // RUNNINGWITHERROR if it had loaded status and had it as RUNNING in memory when CoordKill
    // executes and updates status to KILLED in database.
    job.setStatus(CoordinatorJob.Status.RUNNINGWITHERROR);
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB_STATUS, job);
    job = jpaService.execute(coordJobGetCmd);
    assertEquals(job.getStatus(), CoordinatorJob.Status.RUNNINGWITHERROR);
    final CoordMaterializeTransitionXCommand transitionCmd = new CoordMaterializeTransitionXCommand(job.getId(), 3600);
    try {
        transitionCmd.loadState();
        transitionCmd.verifyPrecondition();
        fail();
    } catch (PreconditionException e) {
    // Materialization should not happen as done materialization is set to true by coord kill
    }
    StatusTransitService.StatusTransitRunnable statusTransit = new StatusTransitService.StatusTransitRunnable();
    statusTransit.run();
    // StatusTransitService should change the job back to KILLED
    job = jpaService.execute(coordJobGetCmd);
    assertEquals(job.getStatus(), CoordinatorJob.Status.KILLED);
    assertTrue(job.isDoneMaterialization());
    assertNotNull(job.getLastModifiedTime());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) Date(java.util.Date) PreconditionException(org.apache.oozie.command.PreconditionException) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) StatusTransitService(org.apache.oozie.service.StatusTransitService) JPAService(org.apache.oozie.service.JPAService)

Example 38 with CoordinatorActionBean

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

the class TestCoordKillXCommand method testCoordKillSuccess2.

/**
 * Test : kill job and action (RUNNING) successfully
 *
 * @throws Exception
 */
public void testCoordKillSuccess2() 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, false, true, 0);
    CoordinatorActionBean action = addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    CoordJobGetJPAExecutor coordJobGetCmd = new CoordJobGetJPAExecutor(job.getId());
    CoordActionGetJPAExecutor coordActionGetCmd = new CoordActionGetJPAExecutor(action.getId());
    job = jpaService.execute(coordJobGetCmd);
    action = jpaService.execute(coordActionGetCmd);
    assertEquals(job.getStatus(), CoordinatorJob.Status.RUNNING);
    assertEquals(action.getStatus(), CoordinatorAction.Status.RUNNING);
    new CoordKillXCommand(job.getId()).call();
    job = jpaService.execute(coordJobGetCmd);
    action = jpaService.execute(coordActionGetCmd);
    assertEquals(job.getStatus(), CoordinatorJob.Status.KILLED);
    assertNotNull(job.getLastModifiedTime());
    assertEquals(action.getStatus(), CoordinatorAction.Status.KILLED);
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date)

Example 39 with CoordinatorActionBean

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

the class TestCoordKillXCommand method testCoordKillRemovePushMissingDeps.

public void testCoordKillRemovePushMissingDeps() throws Exception {
    try {
        services.destroy();
        services = super.setupServicesForHCatalog();
        services.init();
        String db = "default";
        String table = "tablename";
        String server = "hcatserver";
        String newHCatDependency1 = "hcat://" + server + "/" + db + "/" + table + "/dt=20120430;country=brazil";
        String newHCatDependency2 = "hcat://" + server + "/" + db + "/" + table + "/dt=20120430;country=usa";
        String pushMissingDeps = newHCatDependency1 + CoordELFunctions.INSTANCE_SEPARATOR + newHCatDependency2;
        PartitionDependencyManagerService pdms = Services.get().get(PartitionDependencyManagerService.class);
        CoordinatorJobBean job = addRecordToCoordJobTableForWaiting("coord-job-for-action-input-check.xml", CoordinatorJob.Status.RUNNING, false, true);
        CoordinatorActionBean action1 = addRecordToCoordActionTableForWaiting(job.getId(), 1, CoordinatorAction.Status.WAITING, "coord-action-for-action-input-check.xml", null, pushMissingDeps, "Z");
        String newHCatDependency3 = "hcat://" + server + "/" + db + "/" + table + "/dt=20120430;country=russia";
        CoordinatorActionBean action2 = addRecordToCoordActionTableForWaiting(job.getId(), 2, CoordinatorAction.Status.WAITING, "coord-action-for-action-input-check.xml", null, newHCatDependency3, "Z");
        HCatURI hcatURI1, hcatURI2, hcatURI3;
        hcatURI1 = new HCatURI(newHCatDependency1);
        hcatURI2 = new HCatURI(newHCatDependency2);
        hcatURI3 = new HCatURI(newHCatDependency3);
        pdms.addMissingDependency(hcatURI1, action1.getId());
        pdms.addMissingDependency(hcatURI2, action1.getId());
        pdms.addMissingDependency(hcatURI3, action2.getId());
        assertTrue(pdms.getWaitingActions(new HCatURI(newHCatDependency1)).contains(action1.getId()));
        assertTrue(pdms.getWaitingActions(new HCatURI(newHCatDependency2)).contains(action1.getId()));
        assertTrue(pdms.getWaitingActions(new HCatURI(newHCatDependency3)).contains(action2.getId()));
        new CoordKillXCommand(job.getId()).call();
        assertNull(pdms.getWaitingActions(new HCatURI(newHCatDependency1)));
        assertNull(pdms.getWaitingActions(new HCatURI(newHCatDependency2)));
        assertNull(pdms.getWaitingActions(new HCatURI(newHCatDependency3)));
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) HCatURI(org.apache.oozie.util.HCatURI) PartitionDependencyManagerService(org.apache.oozie.service.PartitionDependencyManagerService) CommandException(org.apache.oozie.command.CommandException) PreconditionException(org.apache.oozie.command.PreconditionException)

Example 40 with CoordinatorActionBean

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

the class TestCoordMaterializeTransitionXCommand method getCoordAction.

private CoordinatorActionBean getCoordAction(String actionId) throws JPAExecutorException {
    JPAService jpaService = Services.get().get(JPAService.class);
    CoordinatorActionBean actionBean;
    actionBean = jpaService.execute(new CoordActionGetJPAExecutor(actionId));
    return actionBean;
}
Also used : CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService)

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