Search in sources :

Example 6 with WorkflowStore

use of org.apache.oozie.store.WorkflowStore in project oozie by apache.

the class TestActionFailover method testFsFailover.

public void testFsFailover() throws Exception {
    Path wf = new Path(getFsTestCaseDir(), "workflow.xml");
    Reader reader = IOUtils.getResourceAsReader("failover-fs-wf.xml", -1);
    Writer writer = new OutputStreamWriter(getFileSystem().create(wf));
    IOUtils.copyCharStream(reader, writer);
    final OozieClient wfClient = LocalOozie.getClient();
    Properties conf = wfClient.createConfiguration();
    conf.setProperty(OozieClient.APP_PATH, wf.toString());
    conf.setProperty(OozieClient.USER_NAME, getTestUser());
    conf.setProperty(OozieClient.GROUP_NAME, getTestGroup());
    final Path source = new Path(getFsTestCaseDir(), "fsfailover-source");
    getFileSystem().mkdirs(source);
    final Path target = new Path(getFsTestCaseDir().toString(), "fsfailover-target");
    conf.setProperty("source", source.toString());
    conf.setProperty("target", target.toUri().getPath());
    final String jobId1 = wfClient.submit(conf);
    setSystemProperty(FaultInjection.FAULT_INJECTION, "true");
    setSystemProperty(SkipCommitFaultInjection.ACTION_FAILOVER_FAULT_INJECTION, "true");
    try {
        wfClient.start(jobId1);
        fail("Should have skipped commit for failover testing");
    } catch (OozieClientException oce) {
        assertTrue(oce.getMessage().contains("Skipping Commit for Failover Testing"));
    }
    waitFor(10 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return getFileSystem().exists(target);
        }
    });
    assertFalse(getFileSystem().exists(target));
    waitFor(10 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return FaultInjection.isActive("org.apache.oozie.command.SkipCommitFaultInjection");
        }
    });
    assertFalse(FaultInjection.isActive("org.apache.oozie.command.SkipCommitFaultInjection"));
    assertEquals(WorkflowJob.Status.RUNNING, wfClient.getJobInfo(jobId1).getStatus());
    WorkflowStore store = Services.get().get(WorkflowStoreService.class).create();
    List<WorkflowActionBean> actions = store.getActionsForWorkflow(jobId1, false);
    assertEquals(1, actions.size());
    WorkflowActionBean action = actions.get(0);
    assertEquals(WorkflowAction.Status.PREP, action.getStatus());
    assertEquals(StartActionExecutor.TYPE, action.getType());
    setSystemProperty(FaultInjection.FAULT_INJECTION, "false");
    setSystemProperty(SkipCommitFaultInjection.ACTION_FAILOVER_FAULT_INJECTION, "false");
    ActionStartXCommand actionStartCommand = new ActionStartXCommand(action.getId(), action.getType());
    actionStartCommand.call();
    sleep(500);
    store = Services.get().get(WorkflowStoreService.class).create();
    actions = store.getActionsForWorkflow(jobId1, false);
    action = actions.get(0);
    assertEquals(WorkflowAction.Status.OK, action.getStatus());
    waitFor(5 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(jobId1).getStatus() == WorkflowJob.Status.SUCCEEDED;
        }
    });
    assertEquals(WorkflowJob.Status.SUCCEEDED, wfClient.getJobInfo(jobId1).getStatus());
    final String jobId2 = wfClient.submit(conf);
    wfClient.start(jobId2);
    waitFor(10 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(jobId2).getStatus() == WorkflowJob.Status.KILLED;
        }
    });
    assertEquals(WorkflowJob.Status.KILLED, wfClient.getJobInfo(jobId2).getStatus());
}
Also used : Path(org.apache.hadoop.fs.Path) OozieClientException(org.apache.oozie.client.OozieClientException) WorkflowStore(org.apache.oozie.store.WorkflowStore) WorkflowStoreService(org.apache.oozie.service.WorkflowStoreService) Reader(java.io.Reader) Properties(java.util.Properties) OozieClientException(org.apache.oozie.client.OozieClientException) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) OozieClient(org.apache.oozie.client.OozieClient) ActionStartXCommand(org.apache.oozie.command.wf.ActionStartXCommand) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 7 with WorkflowStore

use of org.apache.oozie.store.WorkflowStore in project oozie by apache.

the class TestActionErrors method _testDataNotSet.

/**
 * Provides functionality to test for set*Data calls not being made by the Action Handler.
 *
 * @param avoidParam set*Data function call to avoid.
 * @param expActionErrorCode the expected action error code.
 * @throws Exception
 */
private void _testDataNotSet(String avoidParam, String expActionErrorCode) 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("external-status", "ok");
    conf.set("signal-value", "based_on_action_status");
    conf.set(avoidParam, "true");
    final String jobId = engine.submitJob(conf, true);
    final WorkflowStore store = Services.get().get(WorkflowStoreService.class).create();
    store.beginTrx();
    Thread.sleep(2000);
    waitFor(5000, new Predicate() {

        public boolean evaluate() throws Exception {
            WorkflowJobBean bean = store.getWorkflow(jobId, false);
            return (bean.getWorkflowInstance().getStatus() == WorkflowInstance.Status.FAILED);
        }
    });
    store.commitTrx();
    store.closeTrx();
    final WorkflowStore store2 = Services.get().get(WorkflowStoreService.class).create();
    store2.beginTrx();
    assertEquals(WorkflowInstance.Status.FAILED, store2.getWorkflow(jobId, false).getWorkflowInstance().getStatus());
    assertEquals(WorkflowJob.Status.FAILED, engine.getJob(jobId).getStatus());
    List<WorkflowActionBean> actions = store2.getActionsForWorkflow(jobId, false);
    WorkflowActionBean action = null;
    for (WorkflowActionBean bean : actions) {
        if (bean.getType().equals("test")) {
            action = bean;
            break;
        }
    }
    assertNotNull(action);
    assertEquals(expActionErrorCode, action.getErrorCode());
    store2.commitTrx();
    store2.closeTrx();
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) WorkflowStore(org.apache.oozie.store.WorkflowStore) WorkflowStoreService(org.apache.oozie.service.WorkflowStoreService) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) 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) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 8 with WorkflowStore

use of org.apache.oozie.store.WorkflowStore in project oozie by apache.

the class TestSubmitXCommand method testSubmitAppName.

public void testSubmitAppName() throws Exception {
    Configuration conf = new XConfiguration();
    String workflowUri = getTestCaseFileUri("workflow.xml");
    String appXml = "<workflow-app xmlns='uri:oozie:workflow:0.1' name='${appName}-foo'> " + "<start to='end' /> " + "<end name='end' /> " + "</workflow-app>";
    writeToFile(appXml, workflowUri);
    conf.set(OozieClient.APP_PATH, workflowUri);
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("appName", "var-app-name");
    SubmitXCommand sc = new SubmitXCommand(conf);
    String jobId = sc.call();
    WorkflowStoreService wss = Services.get().get(WorkflowStoreService.class);
    WorkflowStore ws = wss.create();
    WorkflowJobBean wfb = ws.getWorkflow(jobId, false);
    assertEquals("var-app-name-foo", wfb.getAppName());
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) WorkflowStoreService(org.apache.oozie.service.WorkflowStoreService) WorkflowStore(org.apache.oozie.store.WorkflowStore) WorkflowJobBean(org.apache.oozie.WorkflowJobBean)

Aggregations

WorkflowStore (org.apache.oozie.store.WorkflowStore)8 Reader (java.io.Reader)6 Writer (java.io.Writer)6 Configuration (org.apache.hadoop.conf.Configuration)6 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)6 WorkflowStoreService (org.apache.oozie.service.WorkflowStoreService)6 XConfiguration (org.apache.oozie.util.XConfiguration)6 File (java.io.File)5 FileWriter (java.io.FileWriter)5 DagEngine (org.apache.oozie.DagEngine)5 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)4 LiteWorkflowStoreService (org.apache.oozie.service.LiteWorkflowStoreService)4 OutputStreamWriter (java.io.OutputStreamWriter)2 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringReader (java.io.StringReader)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Path (org.apache.hadoop.fs.Path)1 OozieClient (org.apache.oozie.client.OozieClient)1