Search in sources :

Example 31 with DagEngine

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

the class TestActionErrors method _testNonTransientWithCoordActionUpdate.

/**
 * Provides functionality to test non transient failures and coordinator action update
 *
 * @param errorType the error type. (start.non-transient, end.non-transient)
 * @param expStatus1 expected status. (START_MANUAL, END_MANUAL)
 * @param expErrorMsg expected error message.
 * @throws Exception
 */
private void _testNonTransientWithCoordActionUpdate(String errorType, WorkflowActionBean.Status expStatus1, String expErrorMsg) throws Exception {
    String workflowPath = getTestCaseFileUri("workflow.xml");
    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, workflowPath);
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set(OozieClient.LOG_TOKEN, "t");
    conf.set("signal-value", "OK");
    conf.set("external-status", "ok");
    conf.set("error", errorType);
    final String jobId = engine.submitJob(conf, false);
    final JPAService jpaService = Services.get().get(JPAService.class);
    final CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
    CoordinatorActionBean coordAction = addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", jobId, "RUNNING", 0);
    engine.start(jobId);
    waitFor(5000, new Predicate() {

        public boolean evaluate() throws Exception {
            return (engine.getJob(jobId).getStatus() == WorkflowJob.Status.SUSPENDED);
        }
    });
    assertNotNull(jpaService);
    WorkflowJobGetJPAExecutor wfGetCmd = new WorkflowJobGetJPAExecutor(jobId);
    WorkflowJobBean job = jpaService.execute(wfGetCmd);
    WorkflowActionsGetForJobJPAExecutor actionsGetExe = new WorkflowActionsGetForJobJPAExecutor(jobId);
    List<WorkflowActionBean> actionsList = jpaService.execute(actionsGetExe);
    int n = actionsList.size();
    WorkflowActionBean action = actionsList.get(n - 1);
    assertEquals("TEST_ERROR", action.getErrorCode());
    assertEquals(expErrorMsg, action.getErrorMessage());
    assertEquals(expStatus1, action.getStatus());
    assertFalse(action.isPending());
    assertEquals(WorkflowJob.Status.SUSPENDED, job.getStatus());
    waitFor(5000, new Predicate() {

        public boolean evaluate() throws Exception {
            CoordinatorActionBean coordAction2 = jpaService.execute(new CoordActionGetForExternalIdJPAExecutor(jobId));
            return coordAction2.getStatus().equals(CoordinatorAction.Status.SUSPENDED);
        }
    });
    coordAction = jpaService.execute(new CoordActionGetForExternalIdJPAExecutor(jobId));
    assertEquals(CoordinatorAction.Status.SUSPENDED, coordAction.getStatus());
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) WorkflowActionsGetForJobJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) FileWriter(java.io.FileWriter) Reader(java.io.Reader) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) XConfiguration(org.apache.oozie.util.XConfiguration) DagEngine(org.apache.oozie.DagEngine) JPAService(org.apache.oozie.service.JPAService) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer) CoordActionGetForExternalIdJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetForExternalIdJPAExecutor)

Example 32 with DagEngine

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

the class TestEventGeneration method testForNoDuplicatesWorkflowEvents.

@Test
public void testForNoDuplicatesWorkflowEvents() throws Exception {
    // test workflow job events
    Reader reader = IOUtils.getResourceAsReader("wf-no-op.xml", -1);
    Writer writer = new FileWriter(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(OozieClient.USER_NAME, getTestUser());
    final String jobId1 = engine.submitJob(conf, true);
    final WorkflowJobGetJPAExecutor readCmd = new WorkflowJobGetJPAExecutor(jobId1);
    waitFor(1 * 100, new Predicate() {

        @Override
        public boolean evaluate() throws Exception {
            return jpaService.execute(readCmd).getStatus() == WorkflowJob.Status.SUCCEEDED;
        }
    });
    assertEquals(2, queue.size());
    assertEquals(EventStatus.STARTED, ((JobEvent) queue.poll()).getEventStatus());
    assertEquals(EventStatus.SUCCESS, ((JobEvent) queue.poll()).getEventStatus());
    queue.clear();
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) XConfiguration(org.apache.oozie.util.XConfiguration) DagEngine(org.apache.oozie.DagEngine) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) FileWriter(java.io.FileWriter) Reader(java.io.Reader) Writer(java.io.Writer) FileWriter(java.io.FileWriter) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CommandException(org.apache.oozie.command.CommandException) Test(org.junit.Test)

Example 33 with DagEngine

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

the class TestSignalXCommand method _testJoinFail.

public void _testJoinFail() throws Exception {
    Logger logger = Logger.getLogger(SignalXCommand.class);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Layout layout = new SimpleLayout();
    Appender appender = new WriterAppender(layout, out);
    logger.addAppender(appender);
    FileSystem fs = getFileSystem();
    Path appPath = new Path(getFsTestCaseDir(), "app");
    fs.mkdirs(appPath);
    Reader reader = IOUtils.getResourceAsReader("wf-fork.xml", -1);
    Writer writer = new OutputStreamWriter(fs.create(new Path(appPath, "workflow.xml")));
    IOUtils.copyCharStream(reader, writer);
    writer.close();
    reader.close();
    final DagEngine engine = new DagEngine("u");
    XConfiguration conf = new XConfiguration();
    conf.set(OozieClient.APP_PATH, new Path(appPath, "workflow.xml").toString());
    conf.set(OozieClient.USER_NAME, getTestUser());
    final String jobId = engine.submitJob(conf, false);
    assertNotNull(jobId);
    engine.start(jobId);
    Thread.sleep(2000);
    assertFalse(out.toString().contains("EntityExistsException"));
}
Also used : Appender(org.apache.log4j.Appender) WriterAppender(org.apache.log4j.WriterAppender) Path(org.apache.hadoop.fs.Path) Reader(java.io.Reader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) WriterAppender(org.apache.log4j.WriterAppender) Logger(org.apache.log4j.Logger) XConfiguration(org.apache.oozie.util.XConfiguration) DagEngine(org.apache.oozie.DagEngine) SimpleLayout(org.apache.log4j.SimpleLayout) SimpleLayout(org.apache.log4j.SimpleLayout) Layout(org.apache.log4j.Layout) FileSystem(org.apache.hadoop.fs.FileSystem) OutputStreamWriter(java.io.OutputStreamWriter) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer)

Example 34 with DagEngine

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

the class TestPurgeService method testPurgeServiceForWorkflow.

/**
 * Tests the {@link org.apache.oozie.service.PurgeService}.
 * </p>
 * Creates and runs a new workflow job to completion.
 * 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 testPurgeServiceForWorkflow() 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(OozieClient.USER_NAME, 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");
    final String jobId = engine.submitJob(conf, true);
    waitFor(5000, new Predicate() {

        public boolean evaluate() throws Exception {
            return (engine.getJob(jobId).getStatus() == WorkflowJob.Status.SUCCEEDED);
        }
    });
    assertEquals(WorkflowJob.Status.SUCCEEDED, engine.getJob(jobId).getStatus());
    new PurgeXCommand(1, 1, 1, 10000).call();
    sleep(1000);
    JPAService jpaService = Services.get().get(JPAService.class);
    WorkflowJobGetJPAExecutor wfJobGetCmd = new WorkflowJobGetJPAExecutor(jobId);
    WorkflowJobBean wfBean = jpaService.execute(wfJobGetCmd);
    Date endDate = new Date(System.currentTimeMillis() - 2 * 24 * 60 * 60 * 1000);
    wfBean.setEndTime(endDate);
    wfBean.setLastModifiedTime(new Date());
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_END, wfBean);
    Runnable purgeRunnable = new PurgeRunnable(1, 1, 1, 100);
    purgeRunnable.run();
    waitFor(10000, new Predicate() {

        public boolean evaluate() throws Exception {
            try {
                engine.getJob(jobId).getStatus();
            } catch (Exception ex) {
                return true;
            }
            return false;
        }
    });
    try {
        engine.getJob(jobId).getStatus();
        fail("Job should be purged. Should fail.");
    } catch (Exception ex) {
        assertEquals(ex.getClass(), DagEngineException.class);
        DagEngineException dex = (DagEngineException) ex;
        assertEquals(ErrorCode.E0604, dex.getErrorCode());
    }
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) FileWriter(java.io.FileWriter) Reader(java.io.Reader) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) DagEngineException(org.apache.oozie.DagEngineException) Date(java.util.Date) XConfiguration(org.apache.oozie.util.XConfiguration) DagEngineException(org.apache.oozie.DagEngineException) DagEngine(org.apache.oozie.DagEngine) PurgeXCommand(org.apache.oozie.command.PurgeXCommand) PurgeRunnable(org.apache.oozie.service.PurgeService.PurgeRunnable) PurgeRunnable(org.apache.oozie.service.PurgeService.PurgeRunnable) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 35 with DagEngine

use of org.apache.oozie.DagEngine 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)

Aggregations

DagEngine (org.apache.oozie.DagEngine)36 DagEngineService (org.apache.oozie.service.DagEngineService)22 DagEngineException (org.apache.oozie.DagEngineException)19 XConfiguration (org.apache.oozie.util.XConfiguration)15 Reader (java.io.Reader)14 Writer (java.io.Writer)14 Configuration (org.apache.hadoop.conf.Configuration)14 FileWriter (java.io.FileWriter)13 File (java.io.File)12 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)9 JSONObject (org.json.simple.JSONObject)8 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)7 WorkflowActionsGetForJobJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor)5 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)5 IOException (java.io.IOException)4 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)4 JPAService (org.apache.oozie.service.JPAService)4 WorkflowStore (org.apache.oozie.store.WorkflowStore)4 Date (java.util.Date)3 WorkflowsInfo (org.apache.oozie.WorkflowsInfo)3