Search in sources :

Example 1 with CoordinatorEngine

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

the class LocalOozie method getClientCoord.

/**
 * Return a {@link org.apache.oozie.client.OozieClient} for LocalOozie
 * configured for a given user.
 * <p>
 * The following methods of the client are NOP in the returned instance:
 * {@link org.apache.oozie.client.OozieClient#validateWSVersion},
 * {@link org.apache.oozie.client.OozieClient#setHeader},
 * {@link org.apache.oozie.client.OozieClient#getHeader},
 * {@link org.apache.oozie.client.OozieClient#removeHeader},
 * {@link org.apache.oozie.client.OozieClient#getHeaderNames},
 * {@link org.apache.oozie.client.OozieClient#setSystemMode(OozieClient.SYSTEM_MODE)},
 * {@link org.apache.oozie.client.OozieClient#getHeaders},
 * {@link org.apache.oozie.client.OozieClient#getClientBuildVersion}.
 *
 * @param user user name to use in LocalOozie for running coordinator.
 * @return a {@link org.apache.oozie.client.OozieClient} for LocalOozie
 *         configured for the given user.
 */
public static OozieClient getClientCoord(String user) {
    if (!localOozieActive) {
        throw new IllegalStateException("LocalOozie is not initialized");
    }
    ParamChecker.notEmpty(user, "user");
    CoordinatorEngine coordEngine = Services.get().get(CoordinatorEngineService.class).getCoordinatorEngine(user);
    return new LocalOozieClientCoord(coordEngine);
}
Also used : CoordinatorEngine(org.apache.oozie.CoordinatorEngine) LocalOozieClientCoord(org.apache.oozie.LocalOozieClientCoord) CoordinatorEngineService(org.apache.oozie.service.CoordinatorEngineService)

Example 2 with CoordinatorEngine

use of org.apache.oozie.CoordinatorEngine 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 3 with CoordinatorEngine

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

the class TestRecoveryService method testCoordActionRecoveryServiceForSubmitted.

/**
 * Tests functionality of the Recovery Service Runnable command. </p> Insert a coordinator job with RUNNING and
 * action with SUBMITTED. Then, runs the recovery runnable and ensures the action status changes to RUNNING.
 *
 * @throws Exception
 */
public void testCoordActionRecoveryServiceForSubmitted() throws Exception {
    final String jobId = "0000000-" + new Date().getTime() + "-testCoordRecoveryService-C";
    final int actionNum = 1;
    final String actionId = jobId + "@" + actionNum;
    final CoordinatorEngine ce = new CoordinatorEngine(getTestUser());
    createTestCaseSubDir("one-op");
    createTestCaseSubDir("one-op", "lib");
    createTestCaseSubDir("workflows");
    createTestCaseSubDir("in");
    addRecordToJobTable(jobId, getTestCaseDir());
    addRecordToActionTable(jobId, actionNum, actionId, getTestCaseDir());
    sleep(3000);
    Runnable recoveryRunnable = new RecoveryRunnable(0, 1, 1);
    recoveryRunnable.run();
    waitFor(10000, new Predicate() {

        public boolean evaluate() throws Exception {
            CoordinatorActionBean bean = ce.getCoordAction(actionId);
            return (bean.getStatus() == CoordinatorAction.Status.RUNNING || bean.getStatus() == CoordinatorAction.Status.SUCCEEDED);
        }
    });
    CoordinatorActionBean action = getCoordinatorAction(actionId);
    if (action.getStatus() == CoordinatorAction.Status.RUNNING || action.getStatus() == CoordinatorAction.Status.SUCCEEDED) {
    } else {
        fail();
    }
}
Also used : RecoveryRunnable(org.apache.oozie.service.RecoveryService.RecoveryRunnable) CoordinatorEngine(org.apache.oozie.CoordinatorEngine) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) RecoveryRunnable(org.apache.oozie.service.RecoveryService.RecoveryRunnable) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException)

Example 4 with CoordinatorEngine

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

the class TestFutureActionsTimeOut method _testSubmitJob.

private String _testSubmitJob(String appPath) throws Exception {
    Configuration conf = new XConfiguration();
    GregorianCalendar start = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    start.add(Calendar.MINUTE, -15);
    GregorianCalendar end = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    end.add(Calendar.MINUTE, 45);
    String appXml = "<coordinator-app name=\"NAME\" frequency=\"5\" " + "start=\"" + start.get(Calendar.YEAR) + "-" + (start.get(Calendar.MONTH) + 1) + "-" + start.get(Calendar.DAY_OF_MONTH) + "T" + start.get(Calendar.HOUR_OF_DAY) + ":" + start.get(Calendar.MINUTE) + "Z\" " + "end=\"" + end.get(Calendar.YEAR) + "-" + (end.get(Calendar.MONTH) + 1) + "-" + end.get(Calendar.DAY_OF_MONTH) + "T" + end.get(Calendar.HOUR_OF_DAY) + ":" + end.get(Calendar.MINUTE) + "Z\" timezone=\"UTC\" " + "xmlns=\"uri:oozie:coordinator:0.1\"> <controls> <timeout>10</timeout> <concurrency>2</concurrency> " + "<execution>LIFO</execution> </controls> <datasets> " + "<dataset name=\"a\" frequency=\"${coord:days(7)}\" initial-instance=\"9999-02-01T01:00Z\" " + "timezone=\"UTC\"> <uri-template>" + getTestCaseFileUri("${YEAR}/${DAY}") + "</uri-template> </dataset> " + "<dataset name=\"local_a\" frequency=\"${coord:days(7)}\" initial-instance=\"9999-02-01T01:00Z\" " + "timezone=\"UTC\"> <uri-template>" + getTestCaseFileUri("${YEAR}/${DAY}") + "</uri-template> </dataset> " + "</datasets> <input-events> " + "<data-in name=\"A\" dataset=\"a\"> <instance>${coord:latest(0)}</instance> </data-in>  " + "</input-events> " + "<output-events> <data-out name=\"LOCAL_A\" dataset=\"local_a\"> " + "<instance>${coord:current(-1)}</instance> </data-out> </output-events> <action> <workflow> <app-path>hdfs:" + "///tmp/workflows/</app-path> " + "<configuration> <property> <name>inputA</name> <value>${coord:dataIn('A')}</value> </property> " + "<property> <name>inputB</name> <value>${coord:dataOut('LOCAL_A')}</value> " + "</property></configuration> </workflow> </action> </coordinator-app>";
    System.out.println(appXml);
    writeToFile(appXml, appPath);
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPath);
    conf.set(OozieClient.USER_NAME, getTestUser());
    CoordinatorEngine ce = new CoordinatorEngine(getTestUser());
    String jobId = ce.submitJob(conf, true);
    assertEquals(jobId.substring(jobId.length() - 2), "-C");
    checkCoordJob(jobId);
    return jobId;
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) CoordinatorEngine(org.apache.oozie.CoordinatorEngine) GregorianCalendar(java.util.GregorianCalendar)

Example 5 with CoordinatorEngine

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

the class TestFutureActionsTimeOut method _testTimeout.

/**
 * The catch-up mode time up has been setup in {@link CoordActionMaterializeXCommand}
 * @param jobId job id
 * @param createDate create date
 * @throws Exception thrown if failed
 */
private void _testTimeout(final String jobId, Date createDate) throws Exception {
    final CoordinatorEngine ce = new CoordinatorEngine(getTestUser());
    waitFor(12000, new Predicate() {

        public boolean evaluate() throws Exception {
            CoordinatorJob job = ce.getCoordJob(jobId);
            return !(job.getStatus().equals(CoordinatorJob.Status.PREP));
        }
    });
    CoordinatorJob job = ce.getCoordJob(jobId);
    assertTrue(!(job.getStatus().equals(CoordinatorJob.Status.PREP)));
    waitFor(12000, new Predicate() {

        public boolean evaluate() throws Exception {
            CoordinatorJob job = ce.getCoordJob(jobId);
            List<CoordinatorAction> actions = job.getActions();
            return actions.size() > 0;
        }
    });
    job = ce.getCoordJob(jobId);
    List<CoordinatorAction> actions = job.getActions();
    assertTrue(actions.size() > 0);
    for (CoordinatorAction action : actions) {
        CoordinatorActionBean jsonAction = (CoordinatorActionBean) action;
        if (jsonAction.getNominalTime().before(createDate)) {
            assertEquals(10, jsonAction.getTimeOut());
        } else {
            assertEquals(10, jsonAction.getTimeOut());
        }
    }
}
Also used : CoordinatorJob(org.apache.oozie.client.CoordinatorJob) CoordinatorEngine(org.apache.oozie.CoordinatorEngine) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordinatorAction(org.apache.oozie.client.CoordinatorAction) List(java.util.List) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException) StoreException(org.apache.oozie.store.StoreException)

Aggregations

CoordinatorEngine (org.apache.oozie.CoordinatorEngine)17 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)7 CoordinatorEngineException (org.apache.oozie.CoordinatorEngineException)6 CoordinatorEngineService (org.apache.oozie.service.CoordinatorEngineService)6 JSONObject (org.json.simple.JSONObject)6 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)4 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)4 IOException (java.io.IOException)3 Date (java.util.Date)3 XConfiguration (org.apache.oozie.util.XConfiguration)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Configuration (org.apache.hadoop.conf.Configuration)2 CoordinatorJobInfo (org.apache.oozie.CoordinatorJobInfo)2 DagEngineException (org.apache.oozie.DagEngineException)2 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)2 CoordinatorAction (org.apache.oozie.client.CoordinatorAction)2 CoordinatorJob (org.apache.oozie.client.CoordinatorJob)2 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)2 StoreException (org.apache.oozie.store.StoreException)2