Search in sources :

Example 1 with CoordActionGetJPAExecutor

use of org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor in project oozie by apache.

the class TestPurgeService method testPurgeServiceForCoordinator.

/**
 * Tests the {@link org.apache.oozie.service.PurgeService}.
 * </p>
 * Creates a new coordinator job. Attempts to purge jobs older than a day.
 * Verifies the presence of the job in the system.
 * </p>
 * Sets the end date for the same job to make it qualify for the purge criteria.
 * Calls the purge service, and ensure the job does not exist in the system.
 */
public void testPurgeServiceForCoordinator() throws Exception {
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, start, end, false, false, 0);
    final String jobId = job.getId();
    CoordinatorActionBean action = addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    CoordJobGetJPAExecutor coordJobGetExecutor = new CoordJobGetJPAExecutor(job.getId());
    CoordActionGetJPAExecutor coordActionGetExecutor = new CoordActionGetJPAExecutor(action.getId());
    job = jpaService.execute(coordJobGetExecutor);
    action = jpaService.execute(coordActionGetExecutor);
    assertEquals(job.getStatus(), CoordinatorJob.Status.SUCCEEDED);
    assertEquals(action.getStatus(), CoordinatorAction.Status.SUCCEEDED);
    Runnable purgeRunnable = new PurgeRunnable(1, 1, 1, 100);
    purgeRunnable.run();
    final CoordinatorEngine engine = new CoordinatorEngine("u");
    waitFor(10000, new Predicate() {

        public boolean evaluate() throws Exception {
            try {
                engine.getCoordJob(jobId).getStatus();
            } catch (Exception ex) {
                return true;
            }
            return false;
        }
    });
    try {
        job = jpaService.execute(coordJobGetExecutor);
        fail("Job should be purged. Should fail.");
    } catch (JPAExecutorException je) {
    // Job doesn't exist. Exception is expected.
    }
    try {
        jpaService.execute(coordActionGetExecutor);
        fail("Action should be purged. Should fail.");
    } catch (JPAExecutorException je) {
    // Job doesn't exist. Exception is expected.
    }
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) DagEngineException(org.apache.oozie.DagEngineException) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) CoordinatorEngine(org.apache.oozie.CoordinatorEngine) PurgeRunnable(org.apache.oozie.service.PurgeService.PurgeRunnable) PurgeRunnable(org.apache.oozie.service.PurgeService.PurgeRunnable)

Example 2 with CoordActionGetJPAExecutor

use of org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor in project oozie by apache.

the class TestRecoveryService method checkCoordActionDependencies.

private CoordinatorActionBean checkCoordActionDependencies(String actionId, String expDeps) throws Exception {
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        CoordinatorActionBean action = jpaService.execute(new CoordActionGetJPAExecutor(actionId));
        assertEquals(expDeps, action.getPushMissingDependencies());
        return action;
    } catch (JPAExecutorException se) {
        throw new Exception("Action ID " + actionId + " was not stored properly in db");
    }
}
Also used : JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException)

Example 3 with CoordActionGetJPAExecutor

use of org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor in project oozie by apache.

the class TestCoordActionStartXCommand method checkCoordAction.

private void checkCoordAction(String actionId) {
    try {
        final JPAService jpaService = Services.get().get(JPAService.class);
        CoordinatorActionBean action = jpaService.execute(new CoordActionGetJPAExecutor(actionId));
        if (action.getStatus() == CoordinatorAction.Status.SUBMITTED) {
            fail("CoordActionStartCommand didn't work because the status for action id" + actionId + " is :" + action.getStatus() + " expected to be NOT SUBMITTED (i.e. RUNNING)");
        }
        if (action.getExternalId() != null) {
            WorkflowJobBean wfJob = jpaService.execute(new WorkflowJobGetJPAExecutor(action.getExternalId()));
            assertEquals(wfJob.getParentId(), action.getId());
        }
    } catch (JPAExecutorException je) {
        fail("Action ID " + actionId + " was not stored properly in db");
    }
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean)

Example 4 with CoordActionGetJPAExecutor

use of org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor in project oozie by apache.

the class TestCoordActionStartXCommand method testActionStartWithEscapeStrings.

/**
 * Test : configuration contains url string which should be escaped before put into the evaluator.
 * If not escape, the error 'SAXParseException' will be thrown and workflow job will not be submitted.
 *
 * @throws Exception
 */
public void testActionStartWithEscapeStrings() throws Exception {
    Date start = DateUtils.parseDateOozieTZ("2009-12-15T01:00Z");
    Date end = DateUtils.parseDateOozieTZ("2009-12-16T01:00Z");
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, false, false, 1);
    CoordinatorActionBean action = addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.SUBMITTED, "coord-action-start-escape-strings.xml", 0);
    String actionId = action.getId();
    new CoordActionStartXCommand(actionId, getTestUser(), "myapp", "myjob").call();
    final JPAService jpaService = Services.get().get(JPAService.class);
    action = jpaService.execute(new CoordActionGetJPAExecutor(actionId));
    if (action.getStatus() == CoordinatorAction.Status.SUBMITTED) {
        fail("CoordActionStartCommand didn't work because the status for action id" + actionId + " is :" + action.getStatus() + " expected to be NOT SUBMITTED (i.e. RUNNING)");
    }
    final String wfId = action.getExternalId();
    waitFor(3000, new Predicate() {

        public boolean evaluate() throws Exception {
            List<WorkflowActionBean> wfActions = jpaService.execute(new WorkflowActionsGetForJobJPAExecutor(wfId));
            return wfActions.size() > 0;
        }
    });
    List<WorkflowActionBean> wfActions = jpaService.execute(new WorkflowActionsGetForJobJPAExecutor(wfId));
    assertTrue(wfActions.size() > 0);
    final String wfActionId = wfActions.get(0).getId();
    waitFor(20 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            WorkflowActionBean wfAction = jpaService.execute(new WorkflowActionGetJPAExecutor(wfActionId));
            return wfAction.getExternalId() != null;
        }
    });
    WorkflowActionBean wfAction = jpaService.execute(new WorkflowActionGetJPAExecutor(wfActionId));
    assertNotNull(wfAction.getExternalId());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) WorkflowActionsGetForJobJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) WorkflowActionGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor) List(java.util.List) JPAService(org.apache.oozie.service.JPAService)

Example 5 with CoordActionGetJPAExecutor

use of org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor in project oozie by apache.

the class TestCoordActionUpdatePushMissingDependency method checkCoordAction.

private CoordinatorActionBean checkCoordAction(String actionId, String expDeps, CoordinatorAction.Status stat) throws Exception {
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        CoordinatorActionBean action = jpaService.execute(new CoordActionGetJPAExecutor(actionId));
        String missDeps = action.getPushMissingDependencies();
        assertEquals(missDeps, expDeps);
        assertEquals(action.getStatus(), stat);
        return action;
    } catch (JPAExecutorException se) {
        throw new Exception("Action ID " + actionId + " was not stored properly in db");
    }
}
Also used : JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException)

Aggregations

CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)60 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)60 JPAService (org.apache.oozie.service.JPAService)54 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)43 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)41 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)32 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)25 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)23 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)21 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)21 Date (java.util.Date)19 BundleActionBean (org.apache.oozie.BundleActionBean)9 BundleJobBean (org.apache.oozie.BundleJobBean)9 BundleActionGetJPAExecutor (org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor)9 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)9 IOException (java.io.IOException)8 CommandException (org.apache.oozie.command.CommandException)7 CoordActionStartXCommand (org.apache.oozie.command.coord.CoordActionStartXCommand)3 Properties (java.util.Properties)2 CoordinatorEngine (org.apache.oozie.CoordinatorEngine)2