Search in sources :

Example 51 with ActionExecutorException

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

the class FsActionExecutor method delete.

/**
 * Delete path
 *
 * @param context
 * @param fsConf
 * @param nameNodePath
 * @param path
 * @param skipTrash flag to skip the trash.
 * @throws ActionExecutorException
 */
public void delete(Context context, XConfiguration fsConf, Path nameNodePath, Path path, boolean skipTrash) throws ActionExecutorException {
    LOG.info("Deleting [{0}]. Skipping trash: [{1}]", path, skipTrash);
    URI uri = path.toUri();
    URIHandler handler;
    org.apache.oozie.dependency.URIHandler.Context hcatContext = null;
    try {
        handler = Services.get().get(URIHandlerService.class).getURIHandler(uri);
        if (handler instanceof FSURIHandler) {
            // Use legacy code to handle hdfs partition deletion
            path = resolveToFullPath(nameNodePath, path, true);
            final FileSystem fs = getFileSystemFor(path, context, fsConf);
            Path[] pathArr = FileUtil.stat2Paths(fs.globStatus(path));
            if (pathArr != null && pathArr.length > 0) {
                checkGlobMax(pathArr);
                for (final Path p : pathArr) {
                    if (fs.exists(p)) {
                        if (!skipTrash) {
                            // Moving directory/file to trash of user.
                            UserGroupInformationService ugiService = Services.get().get(UserGroupInformationService.class);
                            UserGroupInformation ugi = ugiService.getProxyUser(fs.getConf().get(OozieClient.USER_NAME));
                            ugi.doAs(new PrivilegedExceptionAction<FileSystem>() {

                                @Override
                                public FileSystem run() throws Exception {
                                    Trash trash = new Trash(fs.getConf());
                                    if (!trash.moveToTrash(p)) {
                                        throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "FS005", "Could not move path [{0}] to trash on delete", p);
                                    }
                                    return null;
                                }
                            });
                        } else if (!fs.delete(p, true)) {
                            throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "FS005", "delete, path [{0}] could not delete path", p);
                        }
                    }
                }
            }
        } else {
            hcatContext = handler.getContext(uri, fsConf, context.getWorkflow().getUser(), false);
            handler.delete(uri, hcatContext);
        }
    } catch (Exception ex) {
        throw convertException(ex);
    } finally {
        if (hcatContext != null) {
            hcatContext.destroy();
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) FSURIHandler(org.apache.oozie.dependency.FSURIHandler) URI(java.net.URI) Trash(org.apache.hadoop.fs.Trash) 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) UserGroupInformationService(org.apache.oozie.service.UserGroupInformationService) FileSystem(org.apache.hadoop.fs.FileSystem) URIHandler(org.apache.oozie.dependency.URIHandler) FSURIHandler(org.apache.oozie.dependency.FSURIHandler) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 52 with ActionExecutorException

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

the class FsActionExecutor method move.

/**
 * Move source to target
 *
 * @param context
 * @param fsConf
 * @param nameNodePath
 * @param source
 * @param target
 * @param recovery
 * @throws ActionExecutorException
 */
public void move(Context context, XConfiguration fsConf, Path nameNodePath, Path source, Path target, boolean recovery) throws ActionExecutorException {
    LOG.info("Moving [{0}] to [{1}]", source, target);
    try {
        source = resolveToFullPath(nameNodePath, source, true);
        validateSameNN(source, target);
        FileSystem fs = getFileSystemFor(source, context, fsConf);
        Path[] pathArr = FileUtil.stat2Paths(fs.globStatus(source));
        if ((pathArr == null || pathArr.length == 0)) {
            if (!recovery) {
                throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "FS006", "move, source path [{0}] does not exist", source);
            } else {
                return;
            }
        }
        if (pathArr.length > 1 && (!fs.exists(target) || fs.isFile(target))) {
            if (!recovery) {
                throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "FS012", "move, could not rename multiple sources to the same target name");
            } else {
                return;
            }
        }
        checkGlobMax(pathArr);
        for (Path p : pathArr) {
            if (!fs.rename(p, target) && !recovery) {
                throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "FS008", "move, could not move [{0}] to [{1}]", p, target);
            }
        }
    } catch (Exception ex) {
        throw convertException(ex);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) 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 53 with ActionExecutorException

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

the class FsActionExecutor method delete.

/**
 * Delete path
 *
 * @param user
 * @param group
 * @param path
 * @throws ActionExecutorException
 */
public void delete(String user, String group, Path path) throws ActionExecutorException {
    try {
        validatePath(path, true);
        FileSystem fs = getFileSystemFor(path, user);
        if (fs.exists(path)) {
            if (!fs.delete(path, true)) {
                throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "FS005", "delete, path [{0}] could not delete path", 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 54 with ActionExecutorException

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

the class MapReduceActionExecutor method check.

@Override
public void check(Context context, WorkflowAction action) throws ActionExecutorException {
    Map<String, String> actionData = Collections.emptyMap();
    Configuration jobConf = null;
    try {
        FileSystem actionFs = context.getAppFileSystem();
        Element actionXml = XmlUtils.parseXml(action.getConf());
        jobConf = createBaseHadoopConf(context, actionXml);
        Path actionDir = context.getActionDir();
        actionData = LauncherHelper.getActionData(actionFs, actionDir, jobConf);
    } catch (Exception e) {
        LOG.warn("Exception in check(). Message[{0}]", e.getMessage(), e);
        throw convertException(e);
    }
    final String newId = actionData.get(LauncherAMUtils.ACTION_DATA_NEW_ID);
    // check the Hadoop job if newID is defined (which should be the case here) - otherwise perform the normal check()
    if (newId != null) {
        boolean jobCompleted;
        JobClient jobClient = null;
        boolean exception = false;
        try {
            jobClient = createJobClient(context, new JobConf(jobConf));
            RunningJob runningJob = jobClient.getJob(JobID.forName(newId));
            if (runningJob == null) {
                context.setExternalStatus(FAILED);
                throw new ActionExecutorException(ActionExecutorException.ErrorType.FAILED, "JA017", "Unknown hadoop job [{0}] associated with action [{1}].  Failing this action!", newId, action.getId());
            }
            jobCompleted = runningJob.isComplete();
        } catch (Exception e) {
            LOG.warn("Unable to check the state of a running MapReduce job -" + " please check the health of the Job History Server!", e);
            exception = true;
            throw convertException(e);
        } finally {
            if (jobClient != null) {
                try {
                    jobClient.close();
                } catch (Exception e) {
                    if (exception) {
                        LOG.error("JobClient error (not re-throwing due to a previous error): ", e);
                    } else {
                        throw convertException(e);
                    }
                }
            }
        }
        // run original check() if the MR action is completed or there are errors - otherwise mark it as RUNNING
        if (jobCompleted || actionData.containsKey(LauncherAMUtils.ACTION_DATA_ERROR_PROPS)) {
            super.check(context, action);
        } else {
            context.setExternalStatus(RUNNING);
            String externalAppId = TypeConverter.toYarn(JobID.forName(newId)).getAppId().toString();
            context.setExternalChildIDs(externalAppId);
        }
    } else {
        super.check(context, action);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) FileSystem(org.apache.hadoop.fs.FileSystem) Element(org.jdom.Element) RunningJob(org.apache.hadoop.mapred.RunningJob) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) JobClient(org.apache.hadoop.mapred.JobClient) JobConf(org.apache.hadoop.mapred.JobConf) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) IOException(java.io.IOException)

Example 55 with ActionExecutorException

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

the class MapReduceActionExecutor method end.

@Override
public void end(Context context, WorkflowAction action) throws ActionExecutorException {
    super.end(context, action);
    JobClient jobClient = null;
    boolean exception = false;
    try {
        if (action.getStatus() == WorkflowAction.Status.OK) {
            Element actionXml = XmlUtils.parseXml(action.getConf());
            Configuration jobConf = createBaseHadoopConf(context, actionXml);
            jobClient = createJobClient(context, jobConf);
            RunningJob runningJob = jobClient.getJob(JobID.forName(action.getExternalChildIDs()));
            if (runningJob == null) {
                throw new ActionExecutorException(ActionExecutorException.ErrorType.FAILED, "MR002", "Unknown hadoop job [{0}] associated with action [{1}].  Failing this action!", action.getExternalChildIDs(), action.getId());
            }
            Counters counters = runningJob.getCounters();
            if (counters != null) {
                ActionStats stats = new MRStats(counters);
                String statsJsonString = stats.toJSON();
                context.setVar(HADOOP_COUNTERS, statsJsonString);
                // do not store the action stats
                if (Boolean.parseBoolean(evaluateConfigurationProperty(actionXml, OOZIE_ACTION_EXTERNAL_STATS_WRITE, "false")) && (statsJsonString.getBytes().length <= getMaxExternalStatsSize())) {
                    context.setExecutionStats(statsJsonString);
                    log.debug("Printing stats for Map-Reduce action as a JSON string : [{0}]", statsJsonString);
                }
            } else {
                context.setVar(HADOOP_COUNTERS, "");
                XLog.getLog(getClass()).warn("Could not find Hadoop Counters for: [{0}]", action.getExternalChildIDs());
            }
        }
    } catch (Exception ex) {
        exception = true;
        throw convertException(ex);
    } finally {
        if (jobClient != null) {
            try {
                jobClient.close();
            } catch (Exception e) {
                if (exception) {
                    log.error("JobClient error: ", e);
                } else {
                    throw convertException(e);
                }
            }
        }
    }
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) Element(org.jdom.Element) RunningJob(org.apache.hadoop.mapred.RunningJob) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) Counters(org.apache.hadoop.mapred.Counters) JobClient(org.apache.hadoop.mapred.JobClient) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) IOException(java.io.IOException)

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