Search in sources :

Example 56 with CoordinatorJobBean

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

the class TestCoordCommandUtils method addRecordToCoordJobTable.

protected CoordinatorJobBean addRecordToCoordJobTable(CoordinatorJob.Status status, Date startTime, Date endTime, String freq) throws Exception {
    CoordinatorJobBean coordJob = createCoordJob(status, startTime, endTime, false, false, 0);
    coordJob.setStartTime(startTime);
    coordJob.setEndTime(endTime);
    coordJob.setFrequency(freq);
    coordJob.setTimeUnit(CoordinatorJob.Timeunit.MINUTE);
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        assertNotNull(jpaService);
        CoordJobInsertJPAExecutor coordInsertCmd = new CoordJobInsertJPAExecutor(coordJob);
        jpaService.execute(coordInsertCmd);
    } catch (JPAExecutorException ex) {
        ex.printStackTrace();
        fail("Unable to insert the test coord job record to table");
        throw ex;
    }
    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 57 with CoordinatorJobBean

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

the class TestCoordELExtensions method testCoordELActionMater.

public void testCoordELActionMater() throws Exception {
    Date startTime = DateUtils.parseDateUTC("2009-03-06T010:00Z");
    Date endTime = DateUtils.parseDateUTC("2009-03-07T12:00Z");
    CoordinatorJobBean job = createCoordJob("coord-job-for-elext.xml", CoordinatorJob.Status.RUNNING, startTime, endTime, false, false, 0);
    addRecordToCoordJobTable(job);
    new CoordMaterializeTransitionXCommand(job.getId(), 3600).call();
    checkCoordAction(job.getId() + "@1");
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) Date(java.util.Date)

Example 58 with CoordinatorJobBean

use of org.apache.oozie.CoordinatorJobBean 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 59 with CoordinatorJobBean

use of org.apache.oozie.CoordinatorJobBean 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 60 with CoordinatorJobBean

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

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