Search in sources :

Example 1 with FSURIHandler

use of org.apache.oozie.dependency.FSURIHandler in project oozie by apache.

the class URIHandlerService method init.

private void init(Configuration conf) throws ClassNotFoundException {
    cache = new HashMap<String, URIHandler>();
    String[] classes = ConfigurationService.getStrings(conf, URI_HANDLERS);
    for (String classname : classes) {
        Class<?> clazz = Class.forName(classname.trim());
        URIHandler uriHandler = (URIHandler) ReflectionUtils.newInstance(clazz, null);
        uriHandler.init(conf);
        for (String scheme : uriHandler.getSupportedSchemes()) {
            cache.put(scheme, uriHandler);
        }
    }
    Class<?> defaultClass = conf.getClass(URI_HANDLER_DEFAULT, null);
    defaultHandler = (defaultClass == null) ? new FSURIHandler() : (URIHandler) ReflectionUtils.newInstance(defaultClass, null);
    defaultHandler.init(conf);
    for (String scheme : defaultHandler.getSupportedSchemes()) {
        cache.put(scheme, defaultHandler);
    }
    initLauncherClassesToShip();
    initLauncherURIHandlerConf();
    LOG.info("Loaded urihandlers {0}", Arrays.toString(classes));
    LOG.info("Loaded default urihandler {0}", defaultHandler.getClass().getName());
}
Also used : LauncherURIHandler(org.apache.oozie.action.hadoop.LauncherURIHandler) URIHandler(org.apache.oozie.dependency.URIHandler) FSURIHandler(org.apache.oozie.dependency.FSURIHandler) FSURIHandler(org.apache.oozie.dependency.FSURIHandler)

Example 2 with FSURIHandler

use of org.apache.oozie.dependency.FSURIHandler 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)

Aggregations

FSURIHandler (org.apache.oozie.dependency.FSURIHandler)2 URIHandler (org.apache.oozie.dependency.URIHandler)2 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 Trash (org.apache.hadoop.fs.Trash)1 AccessControlException (org.apache.hadoop.security.AccessControlException)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)1 LauncherURIHandler (org.apache.oozie.action.hadoop.LauncherURIHandler)1 HadoopAccessorException (org.apache.oozie.service.HadoopAccessorException)1 UserGroupInformationService (org.apache.oozie.service.UserGroupInformationService)1