Search in sources :

Example 6 with ActionExecutorException

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

the class EmailActionExecutor method validateAndMail.

@SuppressWarnings("unchecked")
protected void validateAndMail(Context context, Element element) throws ActionExecutorException {
    // The XSD does the min/max occurrence validation for us.
    Namespace ns = element.getNamespace();
    String[] tos = new String[0];
    String[] ccs = new String[0];
    String[] bccs;
    String subject = "";
    String body = "";
    String[] attachments = new String[0];
    String contentType;
    Element child = null;
    // <to> - One ought to exist.
    String text = element.getChildTextTrim(TO, ns);
    if (text.isEmpty()) {
        throw new ActionExecutorException(ErrorType.ERROR, "EM001", "No recipients were specified in the to-address field.");
    }
    tos = text.split(COMMA);
    // <cc> - Optional, but only one ought to exist.
    try {
        ccs = element.getChildTextTrim(CC, ns).split(COMMA);
    } catch (Exception e) {
        // It is alright for cc to be given empty or not be present.
        ccs = new String[0];
    }
    // <bcc> - Optional, but only one ought to exist.
    try {
        bccs = element.getChildTextTrim(BCC, ns).split(COMMA);
    } catch (Exception e) {
        // It is alright for bcc to be given empty or not be present.
        bccs = new String[0];
    }
    // <subject> - One ought to exist.
    subject = element.getChildTextTrim(SUB, ns);
    // <body> - One ought to exist.
    body = element.getChildTextTrim(BOD, ns);
    // <attachment> - Optional
    String attachment = element.getChildTextTrim(ATTACHMENT, ns);
    if (attachment != null) {
        attachments = attachment.split(COMMA);
    }
    contentType = element.getChildTextTrim(CONTENT_TYPE, ns);
    if (contentType == null || contentType.isEmpty()) {
        contentType = DEFAULT_CONTENT_TYPE;
    }
    // All good - lets try to mail!
    email(tos, ccs, bccs, subject, body, attachments, contentType, context.getWorkflow().getUser());
}
Also used : Element(org.jdom.Element) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) Namespace(org.jdom.Namespace) URISyntaxException(java.net.URISyntaxException) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) IOException(java.io.IOException) NoSuchProviderException(javax.mail.NoSuchProviderException)

Example 7 with ActionExecutorException

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

the class EmailActionExecutor method start.

@Override
public void start(Context context, WorkflowAction action) throws ActionExecutorException {
    LOG.info("Starting action");
    try {
        context.setStartData("-", "-", "-");
        Element actionXml = XmlUtils.parseXml(action.getConf());
        validateAndMail(context, actionXml);
        context.setExecutionData("OK", null);
    } catch (Exception ex) {
        throw convertException(ex);
    }
}
Also used : Element(org.jdom.Element) URISyntaxException(java.net.URISyntaxException) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) IOException(java.io.IOException) NoSuchProviderException(javax.mail.NoSuchProviderException)

Example 8 with ActionExecutorException

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

the class FsActionExecutor method chmod.

void chmod(Context context, XConfiguration fsConf, Path nameNodePath, Path path, String permissions, boolean dirFiles, boolean recursive) throws ActionExecutorException {
    LOG.info("Setting permissions [{0}] on [{1}]. Recursive mode: [{2}]", permissions, path, recursive);
    HashMap<String, String> argsMap = new HashMap<String, String>();
    argsMap.put("permissions", permissions);
    try {
        FileSystem fs = getFileSystemFor(path, context, fsConf);
        path = resolveToFullPath(nameNodePath, path, true);
        Path[] pathArr = FileUtil.stat2Paths(fs.globStatus(path));
        if (pathArr == null || pathArr.length == 0) {
            throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "FS009", "chmod" + ", path(s) that matches [{0}] does not exist", path);
        }
        checkGlobMax(pathArr);
        for (Path p : pathArr) {
            recursiveFsOperation("chmod", fs, nameNodePath, p, argsMap, dirFiles, recursive, true);
        }
    } catch (Exception ex) {
        throw convertException(ex);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) HashMap(java.util.HashMap) FileSystem(org.apache.hadoop.fs.FileSystem) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) URISyntaxException(java.net.URISyntaxException) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) IOException(java.io.IOException) AccessControlException(org.apache.hadoop.security.AccessControlException)

Example 9 with ActionExecutorException

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

the class FsActionExecutor method resolveToFullPath.

Path resolveToFullPath(Path nameNode, Path path, boolean withScheme) throws ActionExecutorException {
    Path fullPath;
    // If no nameNode is given, validate the path as-is and return it as-is
    if (nameNode == null) {
        validatePath(path, withScheme);
        fullPath = path;
    } else {
        // If the path doesn't have a scheme or authority, use the nameNode which should have already been verified earlier
        String pathScheme = path.toUri().getScheme();
        String pathAuthority = path.toUri().getAuthority();
        if (pathScheme == null || pathAuthority == null) {
            if (path.isAbsolute()) {
                String nameNodeSchemeAuthority = nameNode.toUri().getScheme() + "://" + nameNode.toUri().getAuthority();
                fullPath = new Path(nameNodeSchemeAuthority + path.toString());
            } else {
                throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "FS011", "Path [{0}] cannot be relative", path);
            }
        } else {
            // If it is the nameNode, then it should have already been verified earlier so return it as-is
            if (!nameNode.toUri().getScheme().equals(pathScheme) || !nameNode.toUri().getAuthority().equals(pathAuthority)) {
                validatePath(path, withScheme);
            }
            fullPath = path;
        }
    }
    return fullPath;
}
Also used : Path(org.apache.hadoop.fs.Path) ActionExecutorException(org.apache.oozie.action.ActionExecutorException)

Example 10 with ActionExecutorException

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

the class FsActionExecutor method start.

@Override
public void start(Context context, WorkflowAction action) throws ActionExecutorException {
    LOG.info("Starting action");
    try {
        context.setStartData("-", "-", "-");
        Element actionXml = XmlUtils.parseXml(action.getConf());
        doOperations(context, actionXml);
        context.setExecutionData("OK", null);
    } catch (Exception ex) {
        throw convertException(ex);
    }
}
Also used : Element(org.jdom.Element) URISyntaxException(java.net.URISyntaxException) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) IOException(java.io.IOException) AccessControlException(org.apache.hadoop.security.AccessControlException)

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