Search in sources :

Example 11 with ActionExecutorException

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

the class FsActionExecutor method touchz.

void touchz(Context context, XConfiguration fsConf, Path nameNodePath, Path path) throws ActionExecutorException {
    LOG.info("Performing touch on [{0}]", path);
    try {
        path = resolveToFullPath(nameNodePath, path, true);
        FileSystem fs = getFileSystemFor(path, context, fsConf);
        FileStatus st;
        if (fs.exists(path)) {
            st = fs.getFileStatus(path);
            if (st.isDirectory()) {
                throw new Exception(path.toString() + " is a directory");
            } else if (st.getLen() != 0) {
                throw new Exception(path.toString() + " must be a zero-length file");
            }
        }
        FSDataOutputStream out = fs.create(path);
        out.close();
    } catch (Exception ex) {
        throw convertException(ex);
    }
}
Also used : FileStatus(org.apache.hadoop.fs.FileStatus) FileSystem(org.apache.hadoop.fs.FileSystem) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) 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 12 with ActionExecutorException

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

the class FsActionExecutor method mkdir.

void mkdir(Context context, XConfiguration fsConf, Path nameNodePath, Path path) throws ActionExecutorException {
    LOG.info("Creating directory [{0}]", path);
    try {
        path = resolveToFullPath(nameNodePath, path, true);
        FileSystem fs = getFileSystemFor(path, context, fsConf);
        if (!fs.exists(path)) {
            if (!fs.mkdirs(path)) {
                throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "FS004", "mkdir, path [{0}] could not create directory", path);
            }
        } else {
            LOG.info("[{0}] already exist, no need for creation", path);
        }
    } catch (Exception ex) {
        throw convertException(ex);
    }
}
Also used : 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 13 with ActionExecutorException

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

the class FsActionExecutor method end.

@Override
public void end(Context context, WorkflowAction action) throws ActionExecutorException {
    String externalStatus = action.getExternalStatus();
    WorkflowAction.Status status = externalStatus.equals("OK") ? WorkflowAction.Status.OK : WorkflowAction.Status.ERROR;
    context.setEndData(status, getActionSignal(status));
    if (!context.getProtoActionConf().getBoolean(WorkflowXCommand.KEEP_WF_ACTION_DIR, false)) {
        try {
            FileSystem fs = context.getAppFileSystem();
            fs.delete(context.getActionDir(), true);
        } catch (Exception ex) {
            throw convertException(ex);
        }
    }
    LOG.info("Action ended with external status [{0}]", action.getExternalStatus());
}
Also used : WorkflowAction(org.apache.oozie.client.WorkflowAction) FileSystem(org.apache.hadoop.fs.FileSystem) 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 14 with ActionExecutorException

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

the class FsActionExecutor method recursiveFsOperation.

private void recursiveFsOperation(String op, FileSystem fs, Path nameNodePath, Path path, Map<String, String> argsMap, boolean dirFiles, boolean recursive, boolean isRoot) throws ActionExecutorException {
    try {
        FileStatus pathStatus = fs.getFileStatus(path);
        List<Path> paths = new ArrayList<Path>();
        if (dirFiles && pathStatus.isDirectory()) {
            if (isRoot) {
                paths.add(path);
            }
            FileStatus[] filesStatus = fs.listStatus(path);
            for (int i = 0; i < filesStatus.length; i++) {
                Path p = filesStatus[i].getPath();
                paths.add(p);
                if (recursive && filesStatus[i].isDirectory()) {
                    recursiveFsOperation(op, fs, null, p, argsMap, dirFiles, recursive, false);
                }
            }
        } else {
            paths.add(path);
        }
        for (Path p : paths) {
            doFsOperation(op, fs, p, argsMap);
        }
    } catch (Exception ex) {
        throw convertException(ex);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) ArrayList(java.util.ArrayList) 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 15 with ActionExecutorException

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

the class MapReduceActionExecutor method setupActionConf.

@Override
@SuppressWarnings("unchecked")
Configuration setupActionConf(Configuration actionConf, Context context, Element actionXml, Path appPath) throws ActionExecutorException {
    boolean regularMR = false;
    injectConfigClass(actionConf, actionXml);
    Namespace ns = actionXml.getNamespace();
    if (actionXml.getChild("streaming", ns) != null) {
        Element streamingXml = actionXml.getChild("streaming", ns);
        String mapper = streamingXml.getChildTextTrim("mapper", ns);
        String reducer = streamingXml.getChildTextTrim("reducer", ns);
        String recordReader = streamingXml.getChildTextTrim("record-reader", ns);
        List<Element> list = (List<Element>) streamingXml.getChildren("record-reader-mapping", ns);
        String[] recordReaderMapping = new String[list.size()];
        for (int i = 0; i < list.size(); i++) {
            recordReaderMapping[i] = list.get(i).getTextTrim();
        }
        list = (List<Element>) streamingXml.getChildren("env", ns);
        String[] env = new String[list.size()];
        for (int i = 0; i < list.size(); i++) {
            env[i] = list.get(i).getTextTrim();
        }
        setStreaming(actionConf, mapper, reducer, recordReader, recordReaderMapping, env);
    } else {
        if (actionXml.getChild("pipes", ns) != null) {
            Element pipesXml = actionXml.getChild("pipes", ns);
            String map = pipesXml.getChildTextTrim("map", ns);
            String reduce = pipesXml.getChildTextTrim("reduce", ns);
            String inputFormat = pipesXml.getChildTextTrim("inputformat", ns);
            String partitioner = pipesXml.getChildTextTrim("partitioner", ns);
            String writer = pipesXml.getChildTextTrim("writer", ns);
            String program = pipesXml.getChildTextTrim("program", ns);
            PipesMain.setPipes(actionConf, map, reduce, inputFormat, partitioner, writer, program, appPath);
        } else {
            regularMR = true;
        }
    }
    actionConf = super.setupActionConf(actionConf, context, actionXml, appPath);
    setJobName(actionConf, context);
    // For "regular" (not streaming or pipes) MR jobs
    if (regularMR) {
        // Resolve uber jar path (has to be done after super because oozie.mapreduce.uber.jar is under <configuration>)
        String uberJar = actionConf.get(MapReduceMain.OOZIE_MAPREDUCE_UBER_JAR);
        if (uberJar != null) {
            if (!ConfigurationService.getBoolean(OOZIE_MAPREDUCE_UBER_JAR_ENABLE)) {
                throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "MR003", "{0} property is not allowed.  Set {1} to true in oozie-site to enable.", MapReduceMain.OOZIE_MAPREDUCE_UBER_JAR, OOZIE_MAPREDUCE_UBER_JAR_ENABLE);
            }
            String nameNode = actionXml.getChildTextTrim("name-node", ns);
            if (nameNode != null) {
                Path uberJarPath = new Path(uberJar);
                if (uberJarPath.toUri().getScheme() == null || uberJarPath.toUri().getAuthority() == null) {
                    if (uberJarPath.isAbsolute()) {
                        // absolute path without namenode --> prepend namenode
                        Path nameNodePath = new Path(nameNode);
                        String nameNodeSchemeAuthority = nameNodePath.toUri().getScheme() + "://" + nameNodePath.toUri().getAuthority();
                        actionConf.set(MapReduceMain.OOZIE_MAPREDUCE_UBER_JAR, new Path(nameNodeSchemeAuthority + uberJarPath).toString());
                    } else {
                        // relative path --> prepend app path
                        actionConf.set(MapReduceMain.OOZIE_MAPREDUCE_UBER_JAR, new Path(appPath, uberJarPath).toString());
                    }
                }
            }
        }
    } else {
        if (actionConf.get(MapReduceMain.OOZIE_MAPREDUCE_UBER_JAR) != null) {
            log.warn("The " + MapReduceMain.OOZIE_MAPREDUCE_UBER_JAR + " property is only applicable for MapReduce (not" + "streaming nor pipes) workflows, ignoring");
            actionConf.set(MapReduceMain.OOZIE_MAPREDUCE_UBER_JAR, "");
        }
    }
    // child job cancel delegation token for mapred action
    actionConf.setBoolean("mapreduce.job.complete.cancel.delegation.tokens", true);
    return actionConf;
}
Also used : Path(org.apache.hadoop.fs.Path) Element(org.jdom.Element) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) ArrayList(java.util.ArrayList) List(java.util.List) Namespace(org.jdom.Namespace)

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