Search in sources :

Example 51 with JPAService

use of org.apache.oozie.service.JPAService 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 52 with JPAService

use of org.apache.oozie.service.JPAService 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 53 with JPAService

use of org.apache.oozie.service.JPAService 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 54 with JPAService

use of org.apache.oozie.service.JPAService 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 55 with JPAService

use of org.apache.oozie.service.JPAService in project oozie by apache.

the class TestCoordMaterializeTransitionXCommand method testActionMaterWithCronFrequency3.

public void testActionMaterWithCronFrequency3() 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, null, "0/15 2 * 5-7 4,5");
    new CoordMaterializeTransitionXCommand(job.getId(), hoursToSeconds(1)).call();
    final int expectedNominalTimeCount = 0;
    checkCoordActionsNominalTime(job.getId(), expectedNominalTimeCount, new Date[] {});
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        job = jpaService.execute(new CoordJobGetJPAExecutor(job.getId()));
        assertTrue(job.isDoneMaterialization());
        assertEquals(job.getLastActionNumber(), expectedNominalTimeCount);
        assertEquals(job.getNextMaterializedTime(), DateUtils.parseDateOozieTZ("2013-07-18T02:00Z"));
    } catch (JPAExecutorException se) {
        se.printStackTrace();
        fail("Job ID " + job.getId() + " was not stored properly in db");
    }
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date)

Aggregations

JPAService (org.apache.oozie.service.JPAService)449 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)156 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)152 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)113 Date (java.util.Date)95 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)94 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)84 BundleJobBean (org.apache.oozie.BundleJobBean)78 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)78 ArrayList (java.util.ArrayList)76 CommandException (org.apache.oozie.command.CommandException)66 List (java.util.List)59 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)54 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)54 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)49 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)47 HashMap (java.util.HashMap)41 BundleActionBean (org.apache.oozie.BundleActionBean)35 Configuration (org.apache.hadoop.conf.Configuration)32 EntityManager (javax.persistence.EntityManager)31