Search in sources :

Example 1 with RecoveryRunnable

use of org.apache.oozie.service.RecoveryService.RecoveryRunnable in project oozie by apache.

the class TestRecoveryService method testWorkflowActionRecoveryService.

/**
 * Tests functionality of the Recovery Service Runnable command. </p> Starts an action which behaves like an Async
 * Action (Action and Job state set to Running). Changes the action configuration to run in sync mode and updates
 * the store. Runs the recovery runnable, and ensures the state of the action and job have not changed. </p> Changes
 * the state of the action from RUNNING to PREP and updates the store. Again, runs the recovery runnable and ensures
 * the state changes to OK and the job completes successfully.
 *
 * @throws Exception
 */
public void testWorkflowActionRecoveryService() throws Exception {
    Reader reader = IOUtils.getResourceAsReader("wf-ext-schema-valid.xml", -1);
    Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
    createTestCaseSubDir("lib");
    IOUtils.copyCharStream(reader, writer);
    final DagEngine engine = new DagEngine(getTestUser());
    Configuration conf = new XConfiguration();
    conf.set(OozieClient.APP_PATH, getTestCaseFileUri("workflow.xml"));
    conf.set(OozieClient.USER_NAME, 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");
    // TODO CHECK, without this we get JPA concurrency exceptions, ODD
    sleep(1000);
    final String jobId = engine.submitJob(conf, true);
    // TODO CHECK, without this we get JPA concurrency exceptions, ODD
    sleep(1000);
    waitFor(5000, new Predicate() {

        public boolean evaluate() throws Exception {
            return (engine.getJob(jobId).getStatus() == WorkflowJob.Status.RUNNING);
        }
    });
    sleep(1000);
    final WorkflowStore store = Services.get().get(WorkflowStoreService.class).create();
    store.beginTrx();
    List<WorkflowActionBean> actions = store.getActionsForWorkflow(jobId, false);
    WorkflowActionBean action = null;
    for (WorkflowActionBean bean : actions) {
        if (bean.getType().equals("test")) {
            action = bean;
            break;
        }
    }
    assertNotNull(action);
    final String actionId = action.getId();
    assertEquals(WorkflowActionBean.Status.RUNNING, action.getStatus());
    String actionConf = action.getConf();
    String fixedActionConf = actionConf.replaceAll("async", "sync");
    action.setConf(fixedActionConf);
    action.setPending();
    store.updateAction(action);
    store.commitTrx();
    store.closeTrx();
    Runnable recoveryRunnable = new RecoveryRunnable(0, 60, 60);
    recoveryRunnable.run();
    sleep(3000);
    final WorkflowStore store2 = Services.get().get(WorkflowStoreService.class).create();
    assertEquals(WorkflowJob.Status.RUNNING, engine.getJob(jobId).getStatus());
    store2.beginTrx();
    WorkflowActionBean action2 = store2.getAction(actionId, false);
    assertEquals(WorkflowActionBean.Status.RUNNING, action2.getStatus());
    action2.setStatus(WorkflowActionBean.Status.PREP);
    action2.setPending();
    store2.updateAction(action2);
    store2.commitTrx();
    store2.closeTrx();
    sleep(1000);
    recoveryRunnable.run();
    sleep(3000);
    waitFor(10000, new Predicate() {

        public boolean evaluate() throws Exception {
            return (engine.getWorkflowAction(actionId).getStatus() == WorkflowActionBean.Status.OK);
        }
    });
    // getPendingActions works correctly only with MYSQL - following assertsfail with hsql - to be investigated
    // assertEquals(WorkflowJob.Status.SUCCEEDED, engine.getJob(jobId).getStatus());
    final WorkflowStore store3 = Services.get().get(WorkflowStoreService.class).create();
    store3.beginTrx();
    WorkflowActionBean action3 = store3.getAction(actionId, false);
    assertEquals(WorkflowActionBean.Status.OK, action3.getStatus());
    store3.commitTrx();
    store3.closeTrx();
}
Also used : RecoveryRunnable(org.apache.oozie.service.RecoveryService.RecoveryRunnable) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) WorkflowStore(org.apache.oozie.store.WorkflowStore) FileWriter(java.io.FileWriter) Reader(java.io.Reader) StringReader(java.io.StringReader) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) XConfiguration(org.apache.oozie.util.XConfiguration) DagEngine(org.apache.oozie.DagEngine) RecoveryRunnable(org.apache.oozie.service.RecoveryService.RecoveryRunnable) File(java.io.File) PrintWriter(java.io.PrintWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) FileWriter(java.io.FileWriter)

Example 2 with RecoveryRunnable

use of org.apache.oozie.service.RecoveryService.RecoveryRunnable in project oozie by apache.

the class TestRecoveryService method testCoordActionRecoveryServiceForSuspended.

/**
 * Tests functionality of the Recovery Service Runnable command. </p> Insert a coordinator job with SUSPENDED and
 * action with SUSPENDED and workflow with RUNNING. Then, runs the recovery runnable and ensures the workflow status
 *  changes to SUSPENDED.
 *
 * @throws Exception
 */
public void testCoordActionRecoveryServiceForSuspended() throws Exception {
    Date start = DateUtils.parseDateOozieTZ("2009-02-01T01:00Z");
    Date end = DateUtils.parseDateOozieTZ("2009-02-02T23:59Z");
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.SUSPENDED, start, end, false, false, 1);
    WorkflowJobBean wfJob = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    final String wfJobId = wfJob.getId();
    addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.SUSPENDED, "coord-action-get.xml", wfJobId, "RUNNING", 2);
    sleep(3000);
    Runnable recoveryRunnable = new RecoveryRunnable(0, 1, 1);
    recoveryRunnable.run();
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    waitFor(10000, new Predicate() {

        public boolean evaluate() throws Exception {
            WorkflowJobGetJPAExecutor wfGetCmd = new WorkflowJobGetJPAExecutor(wfJobId);
            WorkflowJobBean ret = jpaService.execute(wfGetCmd);
            return (ret.getStatus() == WorkflowJob.Status.SUSPENDED);
        }
    });
    WorkflowJobGetJPAExecutor wfGetCmd = new WorkflowJobGetJPAExecutor(wfJobId);
    WorkflowJobBean ret = jpaService.execute(wfGetCmd);
    assertEquals(WorkflowJob.Status.SUSPENDED, ret.getStatus());
}
Also used : RecoveryRunnable(org.apache.oozie.service.RecoveryService.RecoveryRunnable) WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) RecoveryRunnable(org.apache.oozie.service.RecoveryService.RecoveryRunnable) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException)

Example 3 with RecoveryRunnable

use of org.apache.oozie.service.RecoveryService.RecoveryRunnable in project oozie by apache.

the class TestRecoveryService method testCoordActionRecoveryServiceForWaitingRegisterPartition.

public void testCoordActionRecoveryServiceForWaitingRegisterPartition() throws Exception {
    services.destroy();
    services = super.setupServicesForHCatalog();
    services.getConf().set(URIHandlerService.URI_HANDLERS, FSURIHandler.class.getName() + "," + HCatURIHandler.class.getName());
    services.getConf().setLong(RecoveryService.CONF_PUSH_DEPENDENCY_INTERVAL, 1);
    services.init();
    String db = "default";
    String table = "tablename";
    // dep1 is not available and dep2 is available
    String newHCatDependency1 = "hcat://" + server + "/" + db + "/" + table + "/dt=20120430;country=brazil";
    String newHCatDependency2 = "hcat://" + server + "/" + db + "/" + table + "/dt=20120430;country=usa";
    String newHCatDependency = newHCatDependency1 + CoordELFunctions.INSTANCE_SEPARATOR + newHCatDependency2;
    HCatAccessorService hcatService = services.get(HCatAccessorService.class);
    JMSAccessorService jmsService = services.get(JMSAccessorService.class);
    PartitionDependencyManagerService pdms = services.get(PartitionDependencyManagerService.class);
    assertFalse(jmsService.isListeningToTopic(hcatService.getJMSConnectionInfo(new URI(newHCatDependency1)), db + "." + table));
    populateTable(db, table);
    String actionId = addInitRecords(newHCatDependency);
    CoordinatorAction ca = checkCoordActionDependencies(actionId, newHCatDependency);
    assertEquals(CoordinatorAction.Status.WAITING, ca.getStatus());
    // Register the missing dependencies to PDMS assuming CoordPushDependencyCheckCommand did this.
    pdms.addMissingDependency(new HCatURI(newHCatDependency1), actionId);
    pdms.addMissingDependency(new HCatURI(newHCatDependency2), actionId);
    sleep(2000);
    Runnable recoveryRunnable = new RecoveryRunnable(0, 1, 1);
    recoveryRunnable.run();
    sleep(2000);
    // Recovery service should have discovered newHCatDependency2 and JMS Connection should exist
    // and newHCatDependency1 should be in PDMS waiting list
    assertTrue(jmsService.isListeningToTopic(hcatService.getJMSConnectionInfo(new URI(newHCatDependency2)), "hcat." + db + "." + table));
    checkCoordActionDependencies(actionId, newHCatDependency1);
    assertNull(pdms.getWaitingActions(new HCatURI(newHCatDependency2)));
    Collection<String> waitingActions = pdms.getWaitingActions(new HCatURI(newHCatDependency1));
    assertEquals(1, waitingActions.size());
    assertTrue(waitingActions.contains(actionId));
}
Also used : RecoveryRunnable(org.apache.oozie.service.RecoveryService.RecoveryRunnable) RecoveryRunnable(org.apache.oozie.service.RecoveryService.RecoveryRunnable) CoordinatorAction(org.apache.oozie.client.CoordinatorAction) FSURIHandler(org.apache.oozie.dependency.FSURIHandler) HCatURI(org.apache.oozie.util.HCatURI) URI(java.net.URI) HCatURI(org.apache.oozie.util.HCatURI)

Example 4 with RecoveryRunnable

use of org.apache.oozie.service.RecoveryService.RecoveryRunnable in project oozie by apache.

the class TestRecoveryService method testBundleRecoveryCoordCreate.

/**
 * If the bundle action is in PREP state and coord is not yet created, recovery should submit new coord
 * @throws Exception
 */
public void testBundleRecoveryCoordCreate() throws Exception {
    final BundleJobBean bundle = addRecordToBundleJobTable(Job.Status.RUNNING, false);
    addRecordToBundleActionTable(bundle.getId(), "coord1", 1, Job.Status.PREP);
    final JPAService jpaService = Services.get().get(JPAService.class);
    sleep(3000);
    Runnable recoveryRunnable = new RecoveryRunnable(0, 1, 1);
    recoveryRunnable.run();
    waitFor(10000, new Predicate() {

        public boolean evaluate() throws Exception {
            BundleActionBean mybundleAction = jpaService.execute(new BundleActionGetJPAExecutor(bundle.getId(), "coord1"));
            try {
                if (mybundleAction.getCoordId() != null) {
                    jpaService.execute(new CoordJobGetJPAExecutor(mybundleAction.getCoordId()));
                    return true;
                }
            } catch (Exception e) {
            }
            return false;
        }
    });
    BundleActionBean mybundleAction = jpaService.execute(new BundleActionGetJPAExecutor(bundle.getId(), "coord1"));
    assertNotNull(mybundleAction.getCoordId());
    try {
        jpaService.execute(new CoordJobGetJPAExecutor(mybundleAction.getCoordId()));
    } catch (Exception e) {
        e.printStackTrace();
        fail("Expected coord " + mybundleAction.getCoordId() + " to be created");
    }
}
Also used : RecoveryRunnable(org.apache.oozie.service.RecoveryService.RecoveryRunnable) BundleJobBean(org.apache.oozie.BundleJobBean) BundleActionGetJPAExecutor(org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) RecoveryRunnable(org.apache.oozie.service.RecoveryService.RecoveryRunnable) BundleActionBean(org.apache.oozie.BundleActionBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException)

Example 5 with RecoveryRunnable

use of org.apache.oozie.service.RecoveryService.RecoveryRunnable 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)

Aggregations

RecoveryRunnable (org.apache.oozie.service.RecoveryService.RecoveryRunnable)12 IOException (java.io.IOException)10 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)10 Date (java.util.Date)5 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)5 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)4 BundleActionBean (org.apache.oozie.BundleActionBean)3 BundleJobBean (org.apache.oozie.BundleJobBean)3 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)3 File (java.io.File)2 Configuration (org.apache.hadoop.conf.Configuration)2 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)2 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)2 BundleActionGetJPAExecutor (org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor)2 HCatURI (org.apache.oozie.util.HCatURI)2 XConfiguration (org.apache.oozie.util.XConfiguration)2 FileWriter (java.io.FileWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 Reader (java.io.Reader)1