Search in sources :

Example 1 with ActionCheckRunnable

use of org.apache.oozie.service.ActionCheckerService.ActionCheckRunnable in project oozie by apache.

the class TestActionCheckerService method testActionCheckerServiceCoord.

/**
 * Tests functionality of the Action Checker Service Runnable for
 * coordinator actions. </p> Inserts Coord Job, Coord Action, and Workflow
 * Job, and verifies the action status updated to SUCCEEDED. </p> Runs the
 * ActionCheck runnable, and checks for the action job.
 *
 * @throws Exception
 */
public void testActionCheckerServiceCoord() throws Exception {
    final int actionNum = 1;
    final CoordinatorEngine ce = new CoordinatorEngine(getTestUser());
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    final CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, false, false, 0);
    final WorkflowJobBean wfJob = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    final CoordinatorActionBean action = addRecordToCoordActionTable(job.getId(), actionNum, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", wfJob.getId(), "RUNNING", 0);
    sleep(3000);
    Runnable actionCheckRunnable = new ActionCheckRunnable(1);
    actionCheckRunnable.run();
    sleep(3000);
    waitFor(200000, new Predicate() {

        public boolean evaluate() throws Exception {
            return (ce.getCoordAction(action.getId()).getStatus() == CoordinatorAction.Status.SUCCEEDED);
        }
    });
    JPAService jpaService = Services.get().get(JPAService.class);
    CoordinatorActionBean recoveredAction = jpaService.execute(new CoordActionGetJPAExecutor(action.getId()));
    assertEquals(CoordinatorAction.Status.SUCCEEDED, recoveredAction.getStatus());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) ActionCheckRunnable(org.apache.oozie.service.ActionCheckerService.ActionCheckRunnable) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) CoordinatorEngine(org.apache.oozie.CoordinatorEngine) ActionCheckRunnable(org.apache.oozie.service.ActionCheckerService.ActionCheckRunnable)

Example 2 with ActionCheckRunnable

use of org.apache.oozie.service.ActionCheckerService.ActionCheckRunnable in project oozie by apache.

the class TestActionCheckerService method testActionCheckerServiceDelay.

/**
 * Tests the delayed check functionality of the Action Check Service
 * Runnable. </p> Starts an action which behaves like an Async Action
 * (Action and Job state set to Running). Verifies the action status to be
 * RUNNING. </p> Updates the last check time to now, and attempts to run the
 * ActionCheckRunnable with the delay configured to 20 seconds.
 *
 * @throws Exception
 */
public void testActionCheckerServiceDelay() throws Exception {
    Reader reader = IOUtils.getResourceAsReader("wf-ext-schema-valid.xml", -1);
    Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
    IOUtils.copyCharStream(reader, writer);
    final DagEngine engine = new DagEngine("u");
    Configuration conf = new XConfiguration();
    conf.set(OozieClient.APP_PATH, getTestCaseFileUri("workflow.xml"));
    conf.setStrings(WorkflowAppService.HADOOP_USER, getTestUser());
    conf.setStrings(OozieClient.GROUP_NAME, getTestGroup());
    conf.set(OozieClient.LOG_TOKEN, "t");
    conf.set("external-status", "ok");
    conf.set("signal-value", "based_on_action_status");
    conf.set("running-mode", "async");
    final String jobId = engine.submitJob(conf, true);
    sleep(200);
    waitFor(5000, new Predicate() {

        public boolean evaluate() throws Exception {
            return (engine.getJob(jobId).getStatus() == WorkflowJob.Status.RUNNING);
        }
    });
    sleep(100);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    WorkflowActionsGetForJobJPAExecutor actionsGetExecutor = new WorkflowActionsGetForJobJPAExecutor(jobId);
    List<WorkflowActionBean> actions = jpaService.execute(actionsGetExecutor);
    WorkflowActionBean action = null;
    for (WorkflowActionBean bean : actions) {
        if (bean.getType().equals("test")) {
            action = bean;
            break;
        }
    }
    assertNotNull(action);
    assertEquals(WorkflowActionBean.Status.RUNNING, action.getStatus());
    action.setLastCheckTime(new Date());
    WorkflowActionQueryExecutor.getInstance().executeUpdate(WorkflowActionQuery.UPDATE_ACTION_FOR_LAST_CHECKED_TIME, action);
    int actionCheckDelay = 20;
    Runnable actionCheckRunnable = new ActionCheckRunnable(actionCheckDelay);
    actionCheckRunnable.run();
    sleep(3000);
    List<WorkflowActionBean> actions2 = jpaService.execute(actionsGetExecutor);
    WorkflowActionBean action2 = null;
    for (WorkflowActionBean bean : actions2) {
        if (bean.getType().equals("test")) {
            action2 = bean;
            break;
        }
    }
    assertNotNull(action);
    assertEquals(WorkflowActionBean.Status.RUNNING, action2.getStatus());
    assertEquals(WorkflowJob.Status.RUNNING, engine.getJob(jobId).getStatus());
}
Also used : WorkflowActionsGetForJobJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) FileWriter(java.io.FileWriter) Reader(java.io.Reader) ActionCheckRunnable(org.apache.oozie.service.ActionCheckerService.ActionCheckRunnable) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) Date(java.util.Date) XConfiguration(org.apache.oozie.util.XConfiguration) DagEngine(org.apache.oozie.DagEngine) ActionCheckRunnable(org.apache.oozie.service.ActionCheckerService.ActionCheckRunnable) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 3 with ActionCheckRunnable

use of org.apache.oozie.service.ActionCheckerService.ActionCheckRunnable in project oozie by apache.

the class TestActionCheckerService method testActionCheckerService.

/**
 * Tests functionality of the Action Checker Service Runnable. </p> Starts
 * an action which behaves like an Async Action (Action and Job state set to
 * Running). Verifies the action status to be RUNNING. </p> Runs the
 * ActionCheck runnable, and checks for thw job to complete.
 *
 * @throws Exception
 */
public void testActionCheckerService() throws Exception {
    Reader reader = IOUtils.getResourceAsReader("wf-ext-schema-valid.xml", -1);
    Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
    IOUtils.copyCharStream(reader, writer);
    final DagEngine engine = new DagEngine(getTestUser());
    Configuration conf = new XConfiguration();
    conf.set(OozieClient.APP_PATH, getTestCaseFileUri("workflow.xml"));
    conf.set(WorkflowAppService.HADOOP_USER, getTestUser());
    conf.set(OozieClient.LOG_TOKEN, "t");
    conf.set("external-status", "ok");
    conf.set("signal-value", "based_on_action_status");
    conf.set("running-mode", "async");
    final String jobId = engine.submitJob(conf, true);
    waitFor(5000, new Predicate() {

        public boolean evaluate() throws Exception {
            return (engine.getJob(jobId).getStatus() == WorkflowJob.Status.RUNNING);
        }
    });
    sleep(2000);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    WorkflowActionsGetForJobJPAExecutor actionsGetExecutor = new WorkflowActionsGetForJobJPAExecutor(jobId);
    List<WorkflowActionBean> actions = jpaService.execute(actionsGetExecutor);
    WorkflowActionBean action = null;
    for (WorkflowActionBean bean : actions) {
        if (bean.getType().equals("test")) {
            action = bean;
            break;
        }
    }
    assertNotNull(action);
    assertEquals(WorkflowActionBean.Status.RUNNING, action.getStatus());
    sleep(2000);
    Runnable actionCheckRunnable = new ActionCheckRunnable(0);
    actionCheckRunnable.run();
    waitFor(20000, new Predicate() {

        public boolean evaluate() throws Exception {
            return (engine.getJob(jobId).getStatus() == WorkflowJob.Status.SUCCEEDED);
        }
    });
    List<WorkflowActionBean> actions2 = jpaService.execute(actionsGetExecutor);
    WorkflowActionBean action2 = actions2.get(0);
    assertEquals(WorkflowActionBean.Status.OK, action2.getStatus());
}
Also used : WorkflowActionsGetForJobJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) FileWriter(java.io.FileWriter) Reader(java.io.Reader) ActionCheckRunnable(org.apache.oozie.service.ActionCheckerService.ActionCheckRunnable) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) XConfiguration(org.apache.oozie.util.XConfiguration) DagEngine(org.apache.oozie.DagEngine) ActionCheckRunnable(org.apache.oozie.service.ActionCheckerService.ActionCheckRunnable) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Aggregations

ActionCheckRunnable (org.apache.oozie.service.ActionCheckerService.ActionCheckRunnable)3 File (java.io.File)2 FileWriter (java.io.FileWriter)2 Reader (java.io.Reader)2 Writer (java.io.Writer)2 Date (java.util.Date)2 Configuration (org.apache.hadoop.conf.Configuration)2 DagEngine (org.apache.oozie.DagEngine)2 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)2 WorkflowActionsGetForJobJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor)2 XConfiguration (org.apache.oozie.util.XConfiguration)2 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)1 CoordinatorEngine (org.apache.oozie.CoordinatorEngine)1 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)1 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)1 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)1