Search in sources :

Example 46 with OozieClient

use of org.apache.oozie.client.OozieClient in project oozie by apache.

the class TestReRunXCommand method testRerunVariableSub.

/*
     * Test to ensure parameterized configuration variables get resolved in workflow rerun
     */
public void testRerunVariableSub() throws IOException, OozieClientException {
    Reader reader = IOUtils.getResourceAsReader("rerun-varsub-wf.xml", -1);
    Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
    IOUtils.copyCharStream(reader, writer);
    Path path = getFsTestCaseDir();
    final OozieClient wfClient = LocalOozie.getClient();
    Properties conf = wfClient.createConfiguration();
    conf.setProperty(OozieClient.APP_PATH, getTestCaseFileUri("workflow.xml"));
    conf.setProperty(OozieClient.USER_NAME, getTestUser());
    conf.setProperty("nnbase", path.toString());
    conf.setProperty("base", conf.getProperty("nnbase"));
    // setting the variables "srcDir" and "dstDir", used as a file paths in the workflow,
    // to parameterized expressions to test resolution.
    conf.setProperty("srcDir", "${base}/p1");
    conf.setProperty("dstDir", "${base}/p2");
    final String jobId1 = wfClient.submit(conf);
    wfClient.start(jobId1);
    wfClient.kill(jobId1);
    assertEquals(WorkflowJob.Status.KILLED, wfClient.getJobInfo(jobId1).getStatus());
    // Skip executed nodes
    getFileSystem().delete(new Path(path, "p2"), true);
    conf.setProperty(OozieClient.RERUN_FAIL_NODES, "false");
    wfClient.reRun(jobId1, conf);
    waitFor(15 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(jobId1).getStatus() == WorkflowJob.Status.SUCCEEDED;
        }
    });
    // workflow success reflects that rerun configuration contained correctly resolved variable values.
    assertEquals(WorkflowJob.Status.SUCCEEDED, wfClient.getJobInfo(jobId1).getStatus());
}
Also used : Path(org.apache.hadoop.fs.Path) OozieClient(org.apache.oozie.client.OozieClient) FileWriter(java.io.FileWriter) Reader(java.io.Reader) Properties(java.util.Properties) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer) OozieClientException(org.apache.oozie.client.OozieClientException) IOException(java.io.IOException)

Example 47 with OozieClient

use of org.apache.oozie.client.OozieClient in project oozie by apache.

the class TestReRunXCommand method testRerunWithExistingCoodConf.

// rerun should use existing coord conf
public void testRerunWithExistingCoodConf() throws Exception {
    final OozieClient wfClient = LocalOozie.getClient();
    Date start = DateUtils.parseDateOozieTZ("2009-12-15T01:00Z");
    Date end = DateUtils.parseDateOozieTZ("2009-12-16T01:00Z");
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, false, false, 1);
    CoordinatorActionBean action = addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.SUBMITTED, "coord-action-start-escape-strings.xml", 0);
    String actionId = action.getId();
    new CoordActionStartXCommand(actionId, getTestUser(), "myapp", "myjob").call();
    final JPAService jpaService = Services.get().get(JPAService.class);
    action = jpaService.execute(new CoordActionGetJPAExecutor(actionId));
    if (action.getStatus() == CoordinatorAction.Status.SUBMITTED) {
        fail("CoordActionStartCommand didn't work because the status for action id" + actionId + " is :" + action.getStatus() + " expected to be NOT SUBMITTED (i.e. RUNNING)");
    }
    final String wfId = action.getExternalId();
    wfClient.kill(wfId);
    waitFor(15 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(wfId).getStatus() == WorkflowJob.Status.KILLED;
        }
    });
    Properties newConf = wfClient.createConfiguration();
    newConf.setProperty(OozieClient.RERUN_FAIL_NODES, "true");
    wfClient.reRun(wfId, newConf);
    waitFor(15 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(wfId).getStatus() == WorkflowJob.Status.SUCCEEDED;
        }
    });
    assertEquals(WorkflowJob.Status.SUCCEEDED, wfClient.getJobInfo(wfId).getStatus());
}
Also used : OozieClient(org.apache.oozie.client.OozieClient) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordActionStartXCommand(org.apache.oozie.command.coord.CoordActionStartXCommand) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) Properties(java.util.Properties) Date(java.util.Date) OozieClientException(org.apache.oozie.client.OozieClientException) IOException(java.io.IOException)

Example 48 with OozieClient

use of org.apache.oozie.client.OozieClient in project oozie by apache.

the class TestSignalXCommand method _testSuspendPoints.

public void _testSuspendPoints() throws Exception {
    services.destroy();
    LocalOozie.start();
    FileSystem fs = getFileSystem();
    Path appPath = new Path(getFsTestCaseDir(), "app");
    fs.mkdirs(appPath);
    Reader reader = IOUtils.getResourceAsReader("wf-suspendpoints.xml", -1);
    Writer writer = new OutputStreamWriter(fs.create(new Path(appPath, "workflow.xml")));
    IOUtils.copyCharStream(reader, writer);
    writer.close();
    reader.close();
    final OozieClient oc = LocalOozie.getClient();
    Properties conf = oc.createConfiguration();
    conf.setProperty(OozieClient.APP_PATH, new Path(appPath, "workflow.xml").toString());
    conf.setProperty(OozieClient.USER_NAME, getTestUser());
    conf.setProperty("oozie.suspend.on.nodes", "action1,nonexistant_action_name,decision1, action3,join1 ,fork1,action4b");
    final String jobId = oc.submit(conf);
    assertNotNull(jobId);
    WorkflowJob wf = oc.getJobInfo(jobId);
    assertEquals(WorkflowJob.Status.PREP, wf.getStatus());
    long beforeStart = System.currentTimeMillis();
    oc.start(jobId);
    checkSuspendActions(wf, oc, jobId, WorkflowJob.Status.SUSPENDED, new String[] { "action1" }, new String[] { ":start:" });
    // Check for creation time
    long afterStart = System.currentTimeMillis();
    WorkflowJob wf1 = oc.getJobInfo(jobId);
    for (WorkflowAction action : wf1.getActions()) {
        WorkflowActionBean bean = (WorkflowActionBean) action;
        assertNotNull(bean.getCreatedTime());
        assertTrue((bean.getCreatedTime().getTime() > beforeStart) && (bean.getCreatedTime().getTime() < afterStart));
    }
    oc.resume(jobId);
    checkSuspendActions(wf, oc, jobId, WorkflowJob.Status.SUSPENDED, new String[] { "decision1" }, new String[] { ":start:", "action1", "action2" });
    oc.resume(jobId);
    checkSuspendActions(wf, oc, jobId, WorkflowJob.Status.SUSPENDED, new String[] { "action3" }, new String[] { ":start:", "action1", "action2", "decision1" });
    oc.resume(jobId);
    checkSuspendActions(wf, oc, jobId, WorkflowJob.Status.SUSPENDED, new String[] { "fork1" }, new String[] { ":start:", "action1", "action2", "decision1", "action3" });
    oc.resume(jobId);
    checkSuspendActions(wf, oc, jobId, WorkflowJob.Status.SUSPENDED, new String[] { "action4a", "action4b", "action4c" }, new String[] { ":start:", "action1", "action2", "decision1", "action3", "fork1" });
    oc.resume(jobId);
    checkSuspendActions(wf, oc, jobId, WorkflowJob.Status.SUSPENDED, new String[] { "join1" }, new String[] { ":start:", "action1", "action2", "decision1", "action3", "fork1", "action4a", "action4b", "action4c" });
    oc.resume(jobId);
    checkSuspendActions(wf, oc, jobId, WorkflowJob.Status.SUCCEEDED, new String[] {}, new String[] { ":start:", "action1", "action2", "decision1", "action3", "fork1", "action4a", "action4b", "action4c", "join1", "end" });
    LocalOozie.stop();
}
Also used : Path(org.apache.hadoop.fs.Path) OozieClient(org.apache.oozie.client.OozieClient) WorkflowAction(org.apache.oozie.client.WorkflowAction) FileSystem(org.apache.hadoop.fs.FileSystem) Reader(java.io.Reader) OutputStreamWriter(java.io.OutputStreamWriter) Properties(java.util.Properties) WorkflowJob(org.apache.oozie.client.WorkflowJob) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 49 with OozieClient

use of org.apache.oozie.client.OozieClient in project oozie by apache.

the class LocalOozieExample method execute.

static int execute(String... args) {
    if (args.length != 2) {
        System.out.println();
        System.out.println("Expected parameters: <WF_APP_HDFS_URI> <WF_PROPERTIES>");
        return -1;
    }
    String appUri = args[0];
    String propertiesFile = args[1];
    if (propertiesFile != null) {
        File file = new File(propertiesFile);
        if (!file.exists()) {
            System.out.println();
            System.out.println("Specified Properties file does not exist: " + propertiesFile);
            return -1;
        }
        if (!file.isFile()) {
            System.out.println();
            System.out.println("Specified Properties file is not a file: " + propertiesFile);
            return -1;
        }
    }
    try {
        // start local Oozie
        LocalOozie.start();
        // get a OozieClient for local Oozie
        OozieClient wc = LocalOozie.getClient();
        // create a workflow job configuration and set the workflow application path
        Properties conf = wc.createConfiguration();
        conf.setProperty(OozieClient.APP_PATH, new Path(appUri, "workflow.xml").toString());
        // load additional workflow job parameters from properties file
        if (propertiesFile != null) {
            conf.load(new FileInputStream(propertiesFile));
        }
        // submit and start the workflow job
        String jobId = wc.run(conf);
        Thread.sleep(1000);
        System.out.println("Workflow job submitted");
        // wait until the workflow job finishes printing the status every 10 seconds
        while (wc.getJobInfo(jobId).getStatus() == WorkflowJob.Status.RUNNING) {
            System.out.println("Workflow job running ...");
            printWorkflowInfo(wc.getJobInfo(jobId));
            Thread.sleep(10 * 1000);
        }
        // print the final status o the workflow job
        System.out.println("Workflow job completed ...");
        printWorkflowInfo(wc.getJobInfo(jobId));
        return (wc.getJobInfo(jobId).getStatus() == WorkflowJob.Status.SUCCEEDED) ? 0 : -1;
    } catch (Exception ex) {
        System.out.println();
        System.out.println(ex.getMessage());
        return -1;
    } finally {
        // stop local Oozie
        LocalOozie.stop();
    }
}
Also used : Path(org.apache.hadoop.fs.Path) OozieClient(org.apache.oozie.client.OozieClient) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

OozieClient (org.apache.oozie.client.OozieClient)49 Properties (java.util.Properties)28 Path (org.apache.hadoop.fs.Path)25 IOException (java.io.IOException)19 WorkflowJob (org.apache.oozie.client.WorkflowJob)18 OozieClientException (org.apache.oozie.client.OozieClientException)16 FileSystem (org.apache.hadoop.fs.FileSystem)15 XConfiguration (org.apache.oozie.util.XConfiguration)15 Writer (java.io.Writer)14 Reader (java.io.Reader)12 Configuration (org.apache.hadoop.conf.Configuration)11 File (java.io.File)10 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)10 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)9 FileWriter (java.io.FileWriter)7 OutputStreamWriter (java.io.OutputStreamWriter)7 CommandException (org.apache.oozie.command.CommandException)6 Element (org.jdom.Element)6 StringReader (java.io.StringReader)5 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)5