Search in sources :

Example 6 with OozieClientException

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

the class LocalOozieClientCoord method getCoordinatorActions.

private List<CoordinatorAction> getCoordinatorActions(String jobId, String rerunType, String scope, boolean refresh, boolean noCleanup, boolean failed, Properties prop) throws OozieClientException {
    try {
        XConfiguration conf = null;
        if (prop != null) {
            conf = new XConfiguration(prop);
        }
        if (!(rerunType.equals(RestConstants.JOB_COORD_SCOPE_DATE) || rerunType.equals(RestConstants.JOB_COORD_SCOPE_ACTION))) {
            throw new CommandException(ErrorCode.E1018, "date or action expected.");
        }
        CoordinatorActionInfo coordInfo = coordEngine.reRun(jobId, rerunType, scope, Boolean.valueOf(refresh), Boolean.valueOf(noCleanup), Boolean.valueOf(failed), conf);
        List<CoordinatorActionBean> actionBeans;
        if (coordInfo != null) {
            actionBeans = coordInfo.getCoordActions();
        } else {
            actionBeans = CoordUtils.getCoordActions(rerunType, jobId, scope, false);
        }
        List<CoordinatorAction> actions = new ArrayList<CoordinatorAction>();
        for (CoordinatorActionBean actionBean : actionBeans) {
            actions.add(actionBean);
        }
        return actions;
    } catch (CommandException ce) {
        throw new OozieClientException(ce.getErrorCode().toString(), ce);
    } catch (BaseEngineException ex) {
        throw new OozieClientException(ex.getErrorCode().toString(), ex);
    }
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) OozieClientException(org.apache.oozie.client.OozieClientException) CoordinatorAction(org.apache.oozie.client.CoordinatorAction) ArrayList(java.util.ArrayList) CommandException(org.apache.oozie.command.CommandException)

Example 7 with OozieClientException

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

the class TestReRunXCommand method testRerunWithExistingConf.

// rerun should use existing wf conf
public void testRerunWithExistingConf() throws IOException, OozieClientException {
    Reader reader = IOUtils.getResourceAsReader("rerun-wf.xml", -1);
    Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
    IOUtils.copyCharStream(reader, writer);
    Path path = getFsTestCaseDir();
    getFileSystem().create(new Path(path, "p2"));
    final OozieClient wfClient = LocalOozie.getClient();
    final 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", path.toUri().getPath());
    Properties newConf = wfClient.createConfiguration();
    newConf.setProperty("base", path.toUri().getPath());
    final String jobId = wfClient.submit(conf);
    wfClient.start(jobId);
    waitFor(15 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(jobId).getStatus() == WorkflowJob.Status.KILLED;
        }
    });
    assertEquals(WorkflowJob.Status.KILLED, wfClient.getJobInfo(jobId).getStatus());
    try {
        wfClient.reRun(jobId, newConf);
    } catch (OozieClientException e) {
        assertTrue(e.getCause().getMessage().contains(ErrorCode.E0401.toString()));
    }
    newConf = wfClient.createConfiguration();
    // Skip a non-executed node
    getFileSystem().delete(new Path(path, "p2"), true);
    newConf.setProperty(OozieClient.RERUN_SKIP_NODES, "fs1");
    wfClient.reRun(jobId, newConf);
    waitFor(15 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(jobId).getStatus() == WorkflowJob.Status.SUCCEEDED;
        }
    });
    assertEquals(WorkflowJob.Status.SUCCEEDED, wfClient.getJobInfo(jobId).getStatus());
}
Also used : Path(org.apache.hadoop.fs.Path) OozieClient(org.apache.oozie.client.OozieClient) OozieClientException(org.apache.oozie.client.OozieClientException) 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 8 with OozieClientException

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

the class TestReRunXCommand method testRerun.

public void testRerun() throws IOException, OozieClientException {
    Reader reader = IOUtils.getResourceAsReader("rerun-wf.xml", -1);
    Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
    IOUtils.copyCharStream(reader, writer);
    Path path = getFsTestCaseDir();
    getFileSystem().create(new Path(path, "p2"));
    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", path.toUri().getPath());
    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.KILLED;
        }
    });
    assertEquals(WorkflowJob.Status.KILLED, wfClient.getJobInfo(jobId1).getStatus());
    // Skip a non-executed node
    conf.setProperty(OozieClient.RERUN_SKIP_NODES, "fs1,fs2,dec3");
    boolean failed = false;
    try {
        wfClient.reRun(jobId1, conf);
    } catch (OozieClientException e) {
        failed = true;
        assertTrue(e.getCause().getMessage().contains(ErrorCode.E0807.toString()));
    }
    assertEquals(true, failed);
    // Skip executed nodes
    getFileSystem().delete(new Path(path, "p2"), true);
    conf.setProperty(OozieClient.RERUN_SKIP_NODES, "fs1");
    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());
}
Also used : Path(org.apache.hadoop.fs.Path) OozieClient(org.apache.oozie.client.OozieClient) OozieClientException(org.apache.oozie.client.OozieClientException) 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 9 with OozieClientException

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

the class TestReRunXCommand method testRerunFromFailNodes.

public void testRerunFromFailNodes() throws IOException, OozieClientException {
    Reader reader = IOUtils.getResourceAsReader("rerun-wf.xml", -1);
    Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
    IOUtils.copyCharStream(reader, writer);
    Path path = getFsTestCaseDir();
    getFileSystem().create(new Path(path, "p2"));
    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", path.toUri().getPath());
    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.KILLED;
        }
    });
    assertEquals(WorkflowJob.Status.KILLED, wfClient.getJobInfo(jobId1).getStatus());
    // Skip succeeded nodes
    getFileSystem().delete(new Path(path, "p2"), true);
    conf.setProperty(OozieClient.RERUN_FAIL_NODES, "true");
    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());
}
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 10 with OozieClientException

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

the class TestReRunXCommand method testRerunDisableForChild.

/**
 * Rerun workflow should run by parent only if configuration has been set to
 * true for oozie.wf.child.disable.rerun , Default it is disabled.
 * @throws Exception
 */
public void testRerunDisableForChild() 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");
    Services.get().getConf().setBoolean(ReRunXCommand.DISABLE_CHILD_RERUN, true);
    try {
        wfClient.reRun(wfId, newConf);
        fail("OozieClientException should have been thrown (" + ErrorCode.E0755 + " Rerun is not allowed through child workflow, please re-run through the parent)");
    } catch (OozieClientException ex) {
        assertEquals(ErrorCode.E0755.toString(), ex.getErrorCode());
    }
    Services.get().getConf().setBoolean(ReRunXCommand.DISABLE_CHILD_RERUN, false);
    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) OozieClientException(org.apache.oozie.client.OozieClientException) 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)

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