Search in sources :

Example 6 with BundleEngine

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

the class TestPurgeService method testPurgeServiceForBundle.

/**
 * Tests the {@link org.apache.oozie.service.PurgeService}.
 * </p>
 * Creates a new Bundle 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 testPurgeServiceForBundle() throws Exception {
    BundleJobBean job = this.addRecordToBundleJobTable(Job.Status.SUCCEEDED, DateUtils.parseDateOozieTZ("2011-01-01T01:00Z"));
    final String jobId = job.getId();
    this.addRecordToBundleActionTable(job.getId(), "action1", 0, Job.Status.SUCCEEDED);
    this.addRecordToBundleActionTable(job.getId(), "action2", 0, Job.Status.SUCCEEDED);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    BundleJobGetJPAExecutor bundleJobGetExecutor = new BundleJobGetJPAExecutor(job.getId());
    job = jpaService.execute(bundleJobGetExecutor);
    assertEquals(Job.Status.SUCCEEDED, job.getStatus());
    BundleActionGetJPAExecutor bundleActionGetExecutor1 = new BundleActionGetJPAExecutor(job.getId(), "action1");
    BundleActionBean action1 = jpaService.execute(bundleActionGetExecutor1);
    assertEquals(Job.Status.SUCCEEDED, action1.getStatus());
    BundleActionGetJPAExecutor bundleActionGetExecutor2 = new BundleActionGetJPAExecutor(job.getId(), "action2");
    BundleActionBean action2 = jpaService.execute(bundleActionGetExecutor2);
    assertEquals(Job.Status.SUCCEEDED, action2.getStatus());
    Runnable purgeRunnable = new PurgeRunnable(1, 1, 1, 100);
    purgeRunnable.run();
    final BundleEngine engine = new BundleEngine("u");
    waitFor(10000, new Predicate() {

        public boolean evaluate() throws Exception {
            try {
                engine.getBundleJob(jobId).getStatus();
            } catch (Exception ex) {
                return true;
            }
            return false;
        }
    });
    try {
        job = jpaService.execute(bundleJobGetExecutor);
        fail("Job should be purged. Should fail.");
    } catch (JPAExecutorException je) {
    // Job doesn't exist. Exception is expected.
    }
    try {
        jpaService.execute(bundleActionGetExecutor1);
        fail("Action should be purged. Should fail.");
    } catch (JPAExecutorException je) {
    // Job doesn't exist. Exception is expected.
    }
    try {
        jpaService.execute(bundleActionGetExecutor2);
        fail("Action should be purged. Should fail.");
    } catch (JPAExecutorException je) {
    // Job doesn't exist. Exception is expected.
    }
}
Also used : BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) BundleJobBean(org.apache.oozie.BundleJobBean) BundleActionGetJPAExecutor(org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor) PurgeRunnable(org.apache.oozie.service.PurgeService.PurgeRunnable) PurgeRunnable(org.apache.oozie.service.PurgeService.PurgeRunnable) BundleEngine(org.apache.oozie.BundleEngine) BundleActionBean(org.apache.oozie.BundleActionBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) DagEngineException(org.apache.oozie.DagEngineException)

Aggregations

BundleEngine (org.apache.oozie.BundleEngine)6 BundleEngineService (org.apache.oozie.service.BundleEngineService)4 JSONObject (org.json.simple.JSONObject)4 BundleEngineException (org.apache.oozie.BundleEngineException)3 BundleJobInfo (org.apache.oozie.BundleJobInfo)2 DagEngineException (org.apache.oozie.DagEngineException)2 ArrayList (java.util.ArrayList)1 BaseEngineException (org.apache.oozie.BaseEngineException)1 BulkResponseInfo (org.apache.oozie.BulkResponseInfo)1 BundleActionBean (org.apache.oozie.BundleActionBean)1 BundleJobBean (org.apache.oozie.BundleJobBean)1 CoordinatorEngine (org.apache.oozie.CoordinatorEngine)1 CoordinatorEngineException (org.apache.oozie.CoordinatorEngineException)1 CoordinatorJobInfo (org.apache.oozie.CoordinatorJobInfo)1 DagEngine (org.apache.oozie.DagEngine)1 LocalOozieClientBundle (org.apache.oozie.LocalOozieClientBundle)1 WorkflowsInfo (org.apache.oozie.WorkflowsInfo)1 BulkResponseImpl (org.apache.oozie.client.rest.BulkResponseImpl)1 BundleActionGetJPAExecutor (org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor)1 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)1