Search in sources :

Example 16 with ActionExecutorException

use of org.apache.oozie.action.ActionExecutorException in project oozie by apache.

the class SubWorkflowActionExecutor method start.

public void start(Context context, WorkflowAction action) throws ActionExecutorException {
    LOG.info("Starting action");
    try {
        Element eConf = XmlUtils.parseXml(action.getConf());
        Namespace ns = eConf.getNamespace();
        Element e = eConf.getChild("oozie", ns);
        String oozieUri = (e == null) ? LOCAL : e.getTextTrim();
        OozieClient oozieClient = getWorkflowClient(context, oozieUri);
        String subWorkflowId = null;
        String extId = context.getRecoveryId();
        String runningJobId = null;
        if (extId != null) {
            runningJobId = checkIfRunning(oozieClient, extId);
        }
        if (runningJobId == null) {
            String appPath = eConf.getChild("app-path", ns).getTextTrim();
            XConfiguration subWorkflowConf = new XConfiguration();
            Configuration parentConf = new XConfiguration(new StringReader(context.getWorkflow().getConf()));
            if (eConf.getChild(("propagate-configuration"), ns) != null) {
                XConfiguration.copy(parentConf, subWorkflowConf);
            }
            // Propagate coordinator and bundle info to subworkflow
            if (OozieJobInfo.isJobInfoEnabled()) {
                if (parentConf.get(OozieJobInfo.COORD_ID) != null) {
                    subWorkflowConf.set(OozieJobInfo.COORD_ID, parentConf.get(OozieJobInfo.COORD_ID));
                    subWorkflowConf.set(OozieJobInfo.COORD_NAME, parentConf.get(OozieJobInfo.COORD_NAME));
                    subWorkflowConf.set(OozieJobInfo.COORD_NOMINAL_TIME, parentConf.get(OozieJobInfo.COORD_NOMINAL_TIME));
                }
                if (parentConf.get(OozieJobInfo.BUNDLE_ID) != null) {
                    subWorkflowConf.set(OozieJobInfo.BUNDLE_ID, parentConf.get(OozieJobInfo.BUNDLE_ID));
                    subWorkflowConf.set(OozieJobInfo.BUNDLE_NAME, parentConf.get(OozieJobInfo.BUNDLE_NAME));
                }
            }
            // the proto has the necessary credentials
            Configuration protoActionConf = context.getProtoActionConf();
            XConfiguration.copy(protoActionConf, subWorkflowConf);
            subWorkflowConf.set(OozieClient.APP_PATH, appPath);
            String group = ConfigUtils.getWithDeprecatedCheck(parentConf, OozieClient.JOB_ACL, OozieClient.GROUP_NAME, null);
            if (group != null) {
                subWorkflowConf.set(OozieClient.GROUP_NAME, group);
            }
            injectInline(eConf.getChild("configuration", ns), subWorkflowConf);
            injectCallback(context, subWorkflowConf);
            injectRecovery(extId, subWorkflowConf);
            injectParent(context.getWorkflow().getId(), subWorkflowConf);
            injectSuperParent(context.getWorkflow(), parentConf, subWorkflowConf);
            verifyAndInjectSubworkflowDepth(parentConf, subWorkflowConf);
            // TODO: this has to be refactored later to be done in a single place for REST calls and this
            JobUtils.normalizeAppPath(context.getWorkflow().getUser(), context.getWorkflow().getGroup(), subWorkflowConf);
            subWorkflowConf.set(OOZIE_ACTION_YARN_TAG, getActionYarnTag(parentConf, context.getWorkflow(), action));
            // rerun again.
            if (action.getExternalId() != null && parentConf.getBoolean(OozieClient.RERUN_FAIL_NODES, false)) {
                subWorkflowConf.setBoolean(SUBWORKFLOW_RERUN, true);
                oozieClient.reRun(action.getExternalId(), subWorkflowConf.toProperties());
                subWorkflowId = action.getExternalId();
            } else {
                subWorkflowId = oozieClient.run(subWorkflowConf.toProperties());
            }
        } else {
            subWorkflowId = runningJobId;
        }
        LOG.info("Sub workflow id: [{0}]", subWorkflowId);
        WorkflowJob workflow = oozieClient.getJobInfo(subWorkflowId);
        String consoleUrl = workflow.getConsoleUrl();
        context.setStartData(subWorkflowId, oozieUri, consoleUrl);
        if (runningJobId != null) {
            check(context, action);
        }
    } catch (Exception ex) {
        LOG.error(ex);
        throw convertException(ex);
    }
}
Also used : OozieClient(org.apache.oozie.client.OozieClient) LocalOozieClient(org.apache.oozie.LocalOozieClient) XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) Element(org.jdom.Element) StringReader(java.io.StringReader) WorkflowJob(org.apache.oozie.client.WorkflowJob) Namespace(org.jdom.Namespace) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) OozieClientException(org.apache.oozie.client.OozieClientException) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException)

Example 17 with ActionExecutorException

use of org.apache.oozie.action.ActionExecutorException in project oozie by apache.

the class SubWorkflowActionExecutor method check.

public void check(Context context, WorkflowAction action) throws ActionExecutorException {
    try {
        String subWorkflowId = action.getExternalId();
        String oozieUri = action.getTrackerUri();
        OozieClient oozieClient = getWorkflowClient(context, oozieUri);
        WorkflowJob subWorkflow = oozieClient.getJobInfo(subWorkflowId);
        WorkflowJob.Status status = subWorkflow.getStatus();
        switch(status) {
            case FAILED:
            case KILLED:
            case SUCCEEDED:
                context.setExecutionData(status.toString(), null);
                break;
            default:
                context.setExternalStatus(status.toString());
                break;
        }
    } catch (Exception ex) {
        throw convertException(ex);
    }
}
Also used : OozieClient(org.apache.oozie.client.OozieClient) LocalOozieClient(org.apache.oozie.LocalOozieClient) WorkflowJob(org.apache.oozie.client.WorkflowJob) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) OozieClientException(org.apache.oozie.client.OozieClientException) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException)

Example 18 with ActionExecutorException

use of org.apache.oozie.action.ActionExecutorException in project oozie by apache.

the class TestSshActionExecutor method testSshCheckWithInvalidXml.

/**
 * test {@code SshActionExecutor.check()} method with invalid
 * xml configuration
 */
public void testSshCheckWithInvalidXml() throws Exception {
    String baseDir = getTestCaseDir();
    Path appPath = new Path(getNameNodeUri(), baseDir);
    XConfiguration protoConf = new XConfiguration();
    protoConf.setStrings(WorkflowAppService.HADOOP_USER, getTestUser());
    XConfiguration wfConf = new XConfiguration();
    wfConf.set(OozieClient.APP_PATH, appPath.toString());
    WorkflowJobBean workflow = new WorkflowJobBean();
    workflow.setConf(wfConf.toXmlString());
    workflow.setAppPath(wfConf.get(OozieClient.APP_PATH));
    workflow.setProtoActionConf(protoConf.toXmlString());
    workflow.setId(Services.get().get(UUIDService.class).generateId(ApplicationType.WORKFLOW));
    WorkflowActionBean action = new WorkflowActionBean();
    action.setId("actionId");
    action.setConf("<ssh xmlns='" + getActionXMLSchema() + "'> invalid body ");
    action.setName("ssh");
    final SshActionExecutor ssh = new SshActionExecutor();
    final Context context = new Context(workflow, action);
    try {
        ssh.check(context, action);
        fail("testSshCheckWithInvalidXml expected ex error");
    } catch (ActionExecutorException aex) {
        // ActionExecutorException should be thrown to pass the test
        assertEquals("ERR_XML_PARSE_FAILED", aex.getErrorCode());
        assertEquals(ActionExecutorException.ErrorType.ERROR, aex.getErrorType());
    }
}
Also used : Path(org.apache.hadoop.fs.Path) XConfiguration(org.apache.oozie.util.XConfiguration) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 19 with ActionExecutorException

use of org.apache.oozie.action.ActionExecutorException in project oozie by apache.

the class TestSshActionExecutor method testJobStart.

public void testJobStart() throws ActionExecutorException {
    String baseDir = getTestCaseDir();
    Path appPath = new Path(getNameNodeUri(), baseDir);
    XConfiguration protoConf = new XConfiguration();
    protoConf.setStrings(WorkflowAppService.HADOOP_USER, getTestUser());
    XConfiguration wfConf = new XConfiguration();
    wfConf.set(OozieClient.APP_PATH, appPath.toString());
    WorkflowJobBean workflow = new WorkflowJobBean();
    workflow.setConf(wfConf.toXmlString());
    workflow.setAppPath(wfConf.get(OozieClient.APP_PATH));
    workflow.setProtoActionConf(protoConf.toXmlString());
    workflow.setId(Services.get().get(UUIDService.class).generateId(ApplicationType.WORKFLOW));
    final WorkflowActionBean action = new WorkflowActionBean();
    action.setId("actionId");
    action.setConf("<ssh xmlns='" + getActionXMLSchema() + "'>" + "<host>localhost</host>" + "<command>echo</command>" + "<capture-output/>" + "<args>\"prop1=something\"</args>" + "</ssh>");
    action.setName("ssh");
    final SshActionExecutor ssh = new SshActionExecutor();
    final Context context = new Context(workflow, action);
    ssh.start(context, action);
    waitFor(30 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            ssh.check(context, action);
            return Status.DONE == action.getStatus();
        }
    });
    ssh.end(context, action);
    assertEquals(Status.OK, action.getStatus());
    assertEquals("something", PropertiesUtils.stringToProperties(action.getData()).getProperty("prop1"));
}
Also used : Path(org.apache.hadoop.fs.Path) XConfiguration(org.apache.oozie.util.XConfiguration) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) URISyntaxException(java.net.URISyntaxException) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) IOException(java.io.IOException)

Example 20 with ActionExecutorException

use of org.apache.oozie.action.ActionExecutorException in project oozie by apache.

the class TestSshActionExecutor method testConnectionErrors.

// TODO Move this test case over to a new class. Conflict between this one
// and testConnectionErrors. The property to replace the ssh user cannot be
// reset in a good way during runtime.
// 
// public void testOozieUserMismatch() throws ActionExecutorException {
// String baseDir = getTestCaseDir();
// Path appPath = new Path(getNameNodeUri(), baseDir);
// 
// Services.get().getConf().setBoolean(SshActionExecutor.CONF_SSH_ALLOW_USER_AT_HOST, false);
// XConfiguration protoConf = new XConfiguration();
// protoConf.setStrings(WorkflowAppService.HADOOP_USER, getTestUser());
// protoConf.setStrings(WorkflowAppService.HADOOP_UGI, getTestUser() + "," + getTestGroup());
// 
// XConfiguration wfConf = new XConfiguration();
// wfConf.set(OozieClient.APP_PATH, appPath.toString());
// 
// WorkflowJobBean workflow = new WorkflowJobBean();
// workflow.setConf(wfConf.toXmlString());
// workflow.setAppPath(wfConf.get(OozieClient.APP_PATH));
// workflow.setProtoActionConf(protoConf.toXmlString());
// workflow.setId("wfId");
// 
// final WorkflowActionBean action = new WorkflowActionBean();
// action.setId("actionId_" + System.currentTimeMillis());
// action.setConf("<ssh xmlns='" + getActionXMLSchema() + "'>" +
// "<host>invalid@localhost</host>" +
// "<command>echo</command>" +
// "<capture-output/>" +
// "<args>\"prop1=something\"</args>" +
// "</ssh>");
// action.setName("ssh");
// 
// final SshActionExecutor ssh = new SshActionExecutor();
// 
// final Context context = new Context(workflow, action);
// try {
// ssh.start(context, action);
// assertTrue(false);
// } catch (ActionExecutorException ex) {
// System.err.println("Caught exception, Error Code: " + ex.getErrorCode());
// assertEquals(SshActionExecutor.ERR_USER_MISMATCH, ex.getErrorCode());
// }
// }
public void testConnectionErrors() throws ActionExecutorException {
    String baseDir = getTestCaseDir();
    Path appPath = new Path(getNameNodeUri(), baseDir);
    XConfiguration protoConf = new XConfiguration();
    protoConf.setStrings(WorkflowAppService.HADOOP_USER, getTestUser());
    XConfiguration wfConf = new XConfiguration();
    wfConf.set(OozieClient.APP_PATH, appPath.toString());
    WorkflowJobBean workflow = new WorkflowJobBean();
    workflow.setConf(wfConf.toXmlString());
    workflow.setAppPath(wfConf.get(OozieClient.APP_PATH));
    workflow.setProtoActionConf(protoConf.toXmlString());
    workflow.setId(Services.get().get(UUIDService.class).generateId(ApplicationType.WORKFLOW));
    final WorkflowActionBean action = new WorkflowActionBean();
    action.setId("actionId");
    action.setConf("<ssh xmlns='" + getActionXMLSchema() + "'>" + "<host>blabla</host>" + "<command>echo</command>" + "<args>\"prop1=something\"</args>" + "</ssh>");
    action.setName("ssh");
    final SshActionExecutor ssh = new SshActionExecutor();
    final Context context = new Context(workflow, action);
    try {
        ssh.start(context, action);
    } catch (ActionExecutorException ex) {
        System.out.println("Testing COULD_NOT_RESOLVE_HOST");
        assertEquals("COULD_NOT_RESOLVE_HOST", ex.getErrorCode());
        assertEquals(ActionExecutorException.ErrorType.TRANSIENT, ex.getErrorType());
    }
    action.setConf("<ssh xmlns='" + getActionXMLSchema() + "'>" + "<host>11.11.11.11</host>" + "<command>echo</command>" + "<args>\"prop1=something\"</args>" + "</ssh>");
    try {
        ssh.start(context, action);
    } catch (ActionExecutorException ex) {
        System.out.println("Testing COULD_NOT_CONNECT");
        assertEquals("COULD_NOT_CONNECT", ex.getErrorCode());
        assertEquals(ActionExecutorException.ErrorType.TRANSIENT, ex.getErrorType());
    }
    action.setConf("<ssh xmlns='" + getActionXMLSchema() + "'>" + "<host>y@localhost</host>" + "<command>echo</command>" + "<args>\"prop1=something\"</args>" + "</ssh>");
    try {
        ssh.start(context, action);
    } catch (ActionExecutorException ex) {
        System.out.println("Testing AUTH_FAILED");
        assertEquals("AUTH_FAILED", ex.getErrorCode());
        assertEquals(ActionExecutorException.ErrorType.NON_TRANSIENT, ex.getErrorType());
    }
}
Also used : Path(org.apache.hadoop.fs.Path) XConfiguration(org.apache.oozie.util.XConfiguration) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Aggregations

ActionExecutorException (org.apache.oozie.action.ActionExecutorException)75 Path (org.apache.hadoop.fs.Path)41 IOException (java.io.IOException)39 Element (org.jdom.Element)28 URISyntaxException (java.net.URISyntaxException)27 FileSystem (org.apache.hadoop.fs.FileSystem)25 HadoopAccessorException (org.apache.oozie.service.HadoopAccessorException)24 XConfiguration (org.apache.oozie.util.XConfiguration)23 Configuration (org.apache.hadoop.conf.Configuration)20 AccessControlException (org.apache.hadoop.security.AccessControlException)20 Namespace (org.jdom.Namespace)13 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)12 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)12 JDOMException (org.jdom.JDOMException)12 FileNotFoundException (java.io.FileNotFoundException)10 ELEvaluationException (org.apache.oozie.util.ELEvaluationException)10 ConnectException (java.net.ConnectException)9 UnknownHostException (java.net.UnknownHostException)9 RemoteException (org.apache.hadoop.ipc.RemoteException)9 ArrayList (java.util.ArrayList)8