Search in sources :

Example 21 with OozieClientException

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

the class LocalOozieClientCoord method getCoordJobsInfo.

/**
 * Return the info of the coordinator jobs that match the filter.
 *
 * @param filter job filter. Refer to the {@link OozieClient} for the filter
 *        syntax.
 * @param start jobs offset, base 1.
 * @param len number of jobs to return.
 * @return a list with the coordinator jobs info
 * @throws OozieClientException thrown if the jobs info could not be
 *         retrieved.
 */
@Override
public List<CoordinatorJob> getCoordJobsInfo(String filter, int start, int len) throws OozieClientException {
    try {
        CoordinatorJobInfo info = coordEngine.getCoordJobs(filter, start, len);
        List<CoordinatorJob> jobs = new ArrayList<CoordinatorJob>();
        List<CoordinatorJobBean> jobBeans = info.getCoordJobs();
        for (CoordinatorJobBean jobBean : jobBeans) {
            jobs.add(jobBean);
        }
        return jobs;
    } catch (CoordinatorEngineException ex) {
        throw new OozieClientException(ex.getErrorCode().toString(), ex);
    }
}
Also used : CoordinatorJob(org.apache.oozie.client.CoordinatorJob) OozieClientException(org.apache.oozie.client.OozieClientException) ArrayList(java.util.ArrayList)

Example 22 with OozieClientException

use of org.apache.oozie.client.OozieClientException 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 23 with OozieClientException

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

the class TestReRunXCommand method testRedeploy.

public void testRedeploy() throws IOException, OozieClientException, InterruptedException {
    Reader reader = IOUtils.getResourceAsReader("rerun-elerr-wf.xml", -1);
    Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
    IOUtils.copyCharStream(reader, writer);
    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("inPath", getFsTestCaseDir().toString());
    conf.setProperty("checkDir", getFsTestCaseDir().toString() + "/check");
    final String jobId1 = wfClient.submit(conf);
    wfClient.start(jobId1);
    waitFor(15 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(jobId1).getStatus() == WorkflowJob.Status.FAILED;
        }
    });
    assertEquals(WorkflowJob.Status.FAILED, wfClient.getJobInfo(jobId1).getStatus());
    reader = IOUtils.getResourceAsReader("rerun-el-wf.xml", -1);
    writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
    IOUtils.copyCharStream(reader, writer);
    sleep(5000);
    conf.setProperty(OozieClient.RERUN_SKIP_NODES, "hdfs11");
    conf.setProperty("WF_NAME", "wf_test");
    conf.setProperty("FEED_NAME", "feed_test");
    wfClient.reRun(jobId1, conf);
    waitFor(15 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(jobId1).getStatus() == WorkflowJob.Status.SUCCEEDED;
        }
    });
    assertEquals(WorkflowJob.Status.SUCCEEDED, wfClient.getJobInfo(jobId1).getStatus());
    assertEquals("wf_test-feed_test", wfClient.getJobInfo(jobId1).getAppName());
}
Also used : 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 24 with OozieClientException

use of org.apache.oozie.client.OozieClientException 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 25 with OozieClientException

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

the class AppInfoCollector method storeWorkflowJobDetails.

private void storeWorkflowJobDetails(final File outputDir, final String jobId, int maxChildActions) {
    if (jobId == null || !isWorkflow(jobId)) {
        return;
    }
    try {
        System.out.print("Getting Details for " + jobId + "...");
        final File workflowOutputDir = new File(outputDir, jobId);
        if (!createOutputDirectory(workflowOutputDir)) {
            return;
        }
        final File resolvedActionsDir = new File(workflowOutputDir, "resolved-actions");
        if (!createOutputDirectory(resolvedActionsDir)) {
            System.out.println("Workflow details already stored.");
            return;
        }
        final WorkflowJob job = client.getJobInfo(jobId);
        try (DiagBundleEntryWriter diagBundleEntryWriter = new DiagBundleEntryWriter(workflowOutputDir, "info.txt")) {
            persistWorkflowJobInfo(maxChildActions, resolvedActionsDir, job, diagBundleEntryWriter);
        }
        storeCommonDetails(workflowOutputDir, jobId, "workflow", job.getConf());
        System.out.println("Done");
    } catch (IOException | OozieClientException e) {
        System.err.printf("Exception occurred during the retrieval of workflow information: %s%n", e.getMessage());
    }
}
Also used : OozieClientException(org.apache.oozie.client.OozieClientException) IOException(java.io.IOException) WorkflowJob(org.apache.oozie.client.WorkflowJob) File(java.io.File)

Aggregations

OozieClientException (org.apache.oozie.client.OozieClientException)26 IOException (java.io.IOException)13 Properties (java.util.Properties)12 OozieClient (org.apache.oozie.client.OozieClient)11 File (java.io.File)10 XOozieClient (org.apache.oozie.client.XOozieClient)8 Reader (java.io.Reader)7 Writer (java.io.Writer)7 ArrayList (java.util.ArrayList)6 Path (org.apache.hadoop.fs.Path)6 FileWriter (java.io.FileWriter)5 Option (org.apache.commons.cli.Option)3 CoordinatorJob (org.apache.oozie.client.CoordinatorJob)3 FileOutputStream (java.io.FileOutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Map (java.util.Map)2 CoordinatorAction (org.apache.oozie.client.CoordinatorAction)2 WorkflowJob (org.apache.oozie.client.WorkflowJob)2 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1