Search in sources :

Example 46 with ActionExecutorException

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

the class JavaActionExecutor method createLauncherConf.

@SuppressWarnings("unchecked")
Configuration createLauncherConf(FileSystem actionFs, Context context, WorkflowAction action, Element actionXml, Configuration actionConf) throws ActionExecutorException {
    try {
        // app path could be a file
        Path appPathRoot = new Path(context.getWorkflow().getAppPath());
        if (actionFs.isFile(appPathRoot)) {
            appPathRoot = appPathRoot.getParent();
        }
        // launcher job configuration
        Configuration launcherJobConf = createBaseHadoopConf(context, actionXml);
        // cancel delegation token on a launcher job which stays alive till child job(s) finishes
        // otherwise (in mapred action), doesn't cancel not to disturb running child job
        launcherJobConf.setBoolean("mapreduce.job.complete.cancel.delegation.tokens", true);
        setupLauncherConf(launcherJobConf, actionXml, appPathRoot, context);
        // Properties for when a launcher job's AM gets restarted
        if (ConfigurationService.getBoolean(HADOOP_YARN_KILL_CHILD_JOBS_ON_AMRESTART)) {
            // launcher time filter is required to prune the search of launcher tag.
            // Setting coordinator action nominal time as launcher time as it child job cannot launch before nominal
            // time. Workflow created time is good enough when workflow is running independently or workflow is
            // rerunning from failed node.
            long launcherTime = System.currentTimeMillis();
            String coordActionNominalTime = context.getProtoActionConf().get(CoordActionStartXCommand.OOZIE_COORD_ACTION_NOMINAL_TIME);
            if (coordActionNominalTime != null) {
                launcherTime = Long.parseLong(coordActionNominalTime);
            } else if (context.getWorkflow().getCreatedTime() != null) {
                launcherTime = context.getWorkflow().getCreatedTime().getTime();
            }
            String actionYarnTag = getActionYarnTag(getWorkflowConf(context), context.getWorkflow(), action);
            LauncherHelper.setupYarnRestartHandling(launcherJobConf, actionConf, actionYarnTag, launcherTime);
        } else {
            LOG.info(MessageFormat.format("{0} is set to false, not setting YARN restart properties", HADOOP_YARN_KILL_CHILD_JOBS_ON_AMRESTART));
        }
        String actionShareLibProperty = actionConf.get(ACTION_SHARELIB_FOR + getType());
        if (actionShareLibProperty != null) {
            launcherJobConf.set(ACTION_SHARELIB_FOR + getType(), actionShareLibProperty);
        }
        setLibFilesArchives(context, actionXml, appPathRoot, launcherJobConf);
        // Inject Oozie job information if enabled.
        injectJobInfo(launcherJobConf, actionConf, context, action);
        injectLauncherCallback(context, launcherJobConf);
        String jobId = context.getWorkflow().getId();
        String actionId = action.getId();
        Path actionDir = context.getActionDir();
        String recoveryId = context.getRecoveryId();
        // Getting the prepare XML from the action XML
        Namespace ns = actionXml.getNamespace();
        Element prepareElement = actionXml.getChild("prepare", ns);
        String prepareXML = "";
        if (prepareElement != null) {
            if (prepareElement.getChildren().size() > 0) {
                prepareXML = XmlUtils.prettyPrint(prepareElement).toString().trim();
            }
        }
        LauncherHelper.setupLauncherInfo(launcherJobConf, jobId, actionId, actionDir, recoveryId, actionConf, prepareXML);
        // Set the launcher Main Class
        LauncherHelper.setupMainClass(launcherJobConf, getLauncherMain(launcherJobConf, actionXml));
        LauncherHelper.setupLauncherURIHandlerConf(launcherJobConf);
        LauncherHelper.setupMaxOutputData(launcherJobConf, getMaxOutputData(actionConf));
        LauncherHelper.setupMaxExternalStatsSize(launcherJobConf, maxExternalStatsSize);
        LauncherHelper.setupMaxFSGlob(launcherJobConf, maxFSGlobMax);
        List<Element> list = actionXml.getChildren("arg", ns);
        String[] args = new String[list.size()];
        for (int i = 0; i < list.size(); i++) {
            args[i] = list.get(i).getTextTrim();
        }
        LauncherHelper.setupMainArguments(launcherJobConf, args);
        // backward compatibility flag - see OOZIE-2872
        boolean nullArgsAllowed = ConfigurationService.getBoolean(LauncherAMUtils.CONF_OOZIE_NULL_ARGS_ALLOWED);
        launcherJobConf.setBoolean(LauncherAMUtils.CONF_OOZIE_NULL_ARGS_ALLOWED, nullArgsAllowed);
        // Make mapred.child.java.opts and mapreduce.map.java.opts equal, but give values from the latter priority; also append
        // <java-opt> and <java-opts> and give those highest priority
        StringBuilder opts = new StringBuilder(launcherJobConf.get(HADOOP_CHILD_JAVA_OPTS, ""));
        if (launcherJobConf.get(HADOOP_MAP_JAVA_OPTS) != null) {
            opts.append(" ").append(launcherJobConf.get(HADOOP_MAP_JAVA_OPTS));
        }
        List<Element> javaopts = actionXml.getChildren("java-opt", ns);
        // Either one or more <java-opt> element or one <java-opts> can be present since oozie-workflow-0.4
        if (!javaopts.isEmpty()) {
            for (Element opt : javaopts) {
                opts.append(" ").append(opt.getTextTrim());
            }
        } else {
            Element opt = actionXml.getChild("java-opts", ns);
            if (opt != null) {
                opts.append(" ").append(opt.getTextTrim());
            }
        }
        launcherJobConf.set(HADOOP_CHILD_JAVA_OPTS, opts.toString().trim());
        launcherJobConf.set(HADOOP_MAP_JAVA_OPTS, opts.toString().trim());
        injectLauncherTimelineServiceEnabled(launcherJobConf, actionConf);
        // properties from action that are needed by the launcher (e.g. QUEUE NAME, ACLs)
        // maybe we should add queue to the WF schema, below job-tracker
        actionConfToLauncherConf(actionConf, launcherJobConf);
        return launcherJobConf;
    } catch (Exception ex) {
        throw convertException(ex);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Element(org.jdom.Element) Namespace(org.jdom.Namespace) URISyntaxException(java.net.URISyntaxException) JDOMException(org.jdom.JDOMException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) FileNotFoundException(java.io.FileNotFoundException) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) ConnectException(java.net.ConnectException) ELEvaluationException(org.apache.oozie.util.ELEvaluationException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) RemoteException(org.apache.hadoop.ipc.RemoteException) AccessControlException(org.apache.hadoop.security.AccessControlException)

Example 47 with ActionExecutorException

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

the class JavaActionExecutor method prepareActionDir.

public void prepareActionDir(FileSystem actionFs, Context context) throws ActionExecutorException {
    try {
        Path actionDir = context.getActionDir();
        Path tempActionDir = new Path(actionDir.getParent(), actionDir.getName() + ".tmp");
        if (!actionFs.exists(actionDir)) {
            try {
                actionFs.mkdirs(tempActionDir);
                actionFs.rename(tempActionDir, actionDir);
            } catch (IOException ex) {
                actionFs.delete(tempActionDir, true);
                actionFs.delete(actionDir, true);
                throw ex;
            }
        }
    } catch (Exception ex) {
        throw convertException(ex);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) JDOMException(org.jdom.JDOMException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) FileNotFoundException(java.io.FileNotFoundException) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) ConnectException(java.net.ConnectException) ELEvaluationException(org.apache.oozie.util.ELEvaluationException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) RemoteException(org.apache.hadoop.ipc.RemoteException) AccessControlException(org.apache.hadoop.security.AccessControlException)

Example 48 with ActionExecutorException

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

the class FsActionExecutor method validateSameNN.

void validateSameNN(Path source, Path dest) throws ActionExecutorException {
    Path destPath = new Path(source, dest);
    String t = destPath.toUri().getScheme() + destPath.toUri().getAuthority();
    String s = source.toUri().getScheme() + source.toUri().getAuthority();
    // checking whether NN prefix of source and target is same. can modify this to adjust for a set of multiple whitelisted NN
    if (!t.equals(s)) {
        throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "FS007", "move, target NN URI different from that of source", dest);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) ActionExecutorException(org.apache.oozie.action.ActionExecutorException)

Example 49 with ActionExecutorException

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

the class FsActionExecutor method chgrp.

void chgrp(Context context, XConfiguration fsConf, Path nameNodePath, Path path, String user, String group, boolean dirFiles, boolean recursive) throws ActionExecutorException {
    LOG.info("Setting ownership for [{0}] to group: [{1}], user: [{2}]. Recursive mode: [{3}]", path, group, user, recursive);
    HashMap<String, String> argsMap = new HashMap<String, String>();
    argsMap.put("user", user);
    argsMap.put("group", group);
    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", "chgrp" + ", path(s) that matches [{0}] does not exist", path);
        }
        checkGlobMax(pathArr);
        for (Path p : pathArr) {
            recursiveFsOperation("chgrp", 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 50 with ActionExecutorException

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

the class FsActionExecutor method doOperations.

@SuppressWarnings("unchecked")
void doOperations(Context context, Element element) throws ActionExecutorException {
    try {
        FileSystem fs = context.getAppFileSystem();
        boolean recovery = fs.exists(getRecoveryPath(context));
        if (!recovery) {
            fs.mkdirs(getRecoveryPath(context));
        }
        Path nameNodePath = null;
        Element nameNodeElement = element.getChild("name-node", element.getNamespace());
        if (nameNodeElement != null) {
            String nameNode = nameNodeElement.getTextTrim();
            if (nameNode != null) {
                nameNodePath = new Path(nameNode);
                // Verify the name node now
                validatePath(nameNodePath, true);
            }
        }
        XConfiguration fsConf = new XConfiguration();
        Path appPath = new Path(context.getWorkflow().getAppPath());
        // app path could be a file
        if (fs.isFile(appPath)) {
            appPath = appPath.getParent();
        }
        JavaActionExecutor.parseJobXmlAndConfiguration(context, element, appPath, fsConf);
        for (Element commandElement : (List<Element>) element.getChildren()) {
            String command = commandElement.getName();
            if (command.equals("mkdir")) {
                Path path = getPath(commandElement, "path");
                mkdir(context, fsConf, nameNodePath, path);
            } else {
                if (command.equals("delete")) {
                    Path path = getPath(commandElement, "path");
                    boolean skipTrash = true;
                    if (commandElement.getAttributeValue("skip-trash") != null && commandElement.getAttributeValue("skip-trash").equals("false")) {
                        skipTrash = false;
                    }
                    delete(context, fsConf, nameNodePath, path, skipTrash);
                } else {
                    if (command.equals("move")) {
                        Path source = getPath(commandElement, "source");
                        Path target = getPath(commandElement, "target");
                        move(context, fsConf, nameNodePath, source, target, recovery);
                    } else {
                        if (command.equals("chmod")) {
                            Path path = getPath(commandElement, "path");
                            boolean recursive = commandElement.getChild("recursive", commandElement.getNamespace()) != null;
                            String str = commandElement.getAttributeValue("dir-files");
                            boolean dirFiles = (str == null) || Boolean.parseBoolean(str);
                            String permissionsMask = commandElement.getAttributeValue("permissions").trim();
                            chmod(context, fsConf, nameNodePath, path, permissionsMask, dirFiles, recursive);
                        } else {
                            if (command.equals("touchz")) {
                                Path path = getPath(commandElement, "path");
                                touchz(context, fsConf, nameNodePath, path);
                            } else {
                                if (command.equals("chgrp")) {
                                    Path path = getPath(commandElement, "path");
                                    boolean recursive = commandElement.getChild("recursive", commandElement.getNamespace()) != null;
                                    String group = commandElement.getAttributeValue("group");
                                    String str = commandElement.getAttributeValue("dir-files");
                                    boolean dirFiles = (str == null) || Boolean.parseBoolean(str);
                                    chgrp(context, fsConf, nameNodePath, path, context.getWorkflow().getUser(), group, dirFiles, recursive);
                                } else {
                                    if (command.equals("setrep")) {
                                        Path path = getPath(commandElement, "path");
                                        String replicationFactor = commandElement.getAttributeValue("replication-factor");
                                        if (commandElement.getAttributeValue("replication-factor") != null) {
                                            setrep(context, path, Short.parseShort(replicationFactor));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } catch (Exception ex) {
        throw convertException(ex);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) XConfiguration(org.apache.oozie.util.XConfiguration) FileSystem(org.apache.hadoop.fs.FileSystem) Element(org.jdom.Element) ArrayList(java.util.ArrayList) List(java.util.List) 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