Search in sources :

Example 1 with ShareLibService

use of org.apache.oozie.service.ShareLibService in project oozie by apache.

the class JavaActionExecutor method addShareLib.

protected void addShareLib(Configuration conf, String[] actionShareLibNames) throws ActionExecutorException {
    Set<String> confSet = new HashSet<String>(Arrays.asList(getShareLibFilesForActionConf() == null ? new String[0] : getShareLibFilesForActionConf()));
    Set<Path> sharelibList = new HashSet<Path>();
    if (actionShareLibNames != null) {
        try {
            ShareLibService shareLibService = Services.get().get(ShareLibService.class);
            FileSystem fs = shareLibService.getFileSystem();
            if (fs != null) {
                for (String actionShareLibName : actionShareLibNames) {
                    List<Path> listOfPaths = shareLibService.getShareLibJars(actionShareLibName);
                    if (listOfPaths != null && !listOfPaths.isEmpty()) {
                        for (Path actionLibPath : listOfPaths) {
                            String fragmentName = new URI(actionLibPath.toString()).getFragment();
                            String fileName = fragmentName == null ? actionLibPath.getName() : fragmentName;
                            if (confSet.contains(fileName)) {
                                Configuration jobXmlConf = shareLibService.getShareLibConf(actionShareLibName, actionLibPath);
                                if (jobXmlConf != null) {
                                    checkForDisallowedProps(jobXmlConf, actionLibPath.getName());
                                    XConfiguration.injectDefaults(jobXmlConf, conf);
                                    LOG.trace("Adding properties of " + actionLibPath + " to job conf");
                                }
                            } else {
                                // Filtering out duplicate jars or files
                                sharelibList.add(new Path(actionLibPath.toUri()) {

                                    @Override
                                    public int hashCode() {
                                        return getName().hashCode();
                                    }

                                    @Override
                                    public String getName() {
                                        try {
                                            return (new URI(toString())).getFragment() == null ? new Path(toUri()).getName() : (new URI(toString())).getFragment();
                                        } catch (URISyntaxException e) {
                                            throw new RuntimeException(e);
                                        }
                                    }

                                    @Override
                                    public boolean equals(Object input) {
                                        if (input == null) {
                                            return false;
                                        }
                                        if (input == this) {
                                            return true;
                                        }
                                        if (!(input instanceof Path)) {
                                            return false;
                                        }
                                        return getName().equals(((Path) input).getName());
                                    }
                                });
                            }
                        }
                    }
                }
            }
            addLibPathsToCache(conf, sharelibList);
        } catch (URISyntaxException ex) {
            throw new ActionExecutorException(ActionExecutorException.ErrorType.FAILED, "Error configuring sharelib", ex.getMessage());
        } catch (IOException ex) {
            throw new ActionExecutorException(ActionExecutorException.ErrorType.FAILED, "It should never happen", ex.getMessage());
        }
    }
}
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) ShareLibService(org.apache.oozie.service.ShareLibService) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) FileSystem(org.apache.hadoop.fs.FileSystem) HashSet(java.util.HashSet)

Example 2 with ShareLibService

use of org.apache.oozie.service.ShareLibService in project oozie by apache.

the class JavaActionExecutor method addSystemShareLibForAction.

protected void addSystemShareLibForAction(Configuration conf) throws ActionExecutorException {
    ShareLibService shareLibService = Services.get().get(ShareLibService.class);
    // ShareLibService is null for test cases
    if (shareLibService != null) {
        try {
            List<Path> listOfPaths = shareLibService.getSystemLibJars(JavaActionExecutor.OOZIE_COMMON_LIBDIR);
            if (listOfPaths.isEmpty()) {
                throw new ActionExecutorException(ActionExecutorException.ErrorType.FAILED, "EJ001", "Could not locate Oozie sharelib");
            }
            addLibPathsToClassPath(conf, listOfPaths);
            addLibPathsToClassPath(conf, shareLibService.getSystemLibJars(getType()));
        } catch (IOException ex) {
            throw new ActionExecutorException(ActionExecutorException.ErrorType.FAILED, "It should never happen", ex.getMessage());
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) ShareLibService(org.apache.oozie.service.ShareLibService) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) IOException(java.io.IOException)

Example 3 with ShareLibService

use of org.apache.oozie.service.ShareLibService in project oozie by apache.

the class BaseAdminServlet method getShareLib.

/**
 * Gets the list of share lib.
 *
 * @param sharelibKey the sharelib key
 * @return the list of supported share lib
 * @throws IOException in case of any servlet error
 */
@SuppressWarnings("unchecked")
private JSONObject getShareLib(String sharelibKey) throws IOException {
    JSONObject json = new JSONObject();
    ShareLibService shareLibService = Services.get().get(ShareLibService.class);
    // for testcases.
    if (shareLibService == null) {
        return json;
    }
    JSONArray shareLibList = new JSONArray();
    Map<String, List<Path>> shareLibLauncherMap = shareLibService.getShareLib();
    if (sharelibKey != null && !sharelibKey.isEmpty()) {
        Pattern pattern = Pattern.compile(sharelibKey);
        for (String key : shareLibLauncherMap.keySet()) {
            if (pattern.matcher(key).matches() == true) {
                JSONObject object = new JSONObject();
                JSONArray fileList = new JSONArray();
                List<Path> pathList = shareLibLauncherMap.get(key);
                for (Path file : pathList) {
                    fileList.add(file.toString());
                }
                object.put(JsonTags.SHARELIB_LIB_NAME, key);
                object.put(JsonTags.SHARELIB_LIB_FILES, fileList);
                shareLibList.add(object);
            }
        }
    } else {
        for (String key : shareLibLauncherMap.keySet()) {
            JSONObject object = new JSONObject();
            object.put(JsonTags.SHARELIB_LIB_NAME, key);
            shareLibList.add(object);
        }
    }
    json.put(JsonTags.SHARELIB_LIB, shareLibList);
    return json;
}
Also used : Path(org.apache.hadoop.fs.Path) Pattern(java.util.regex.Pattern) JSONObject(org.json.simple.JSONObject) ShareLibService(org.apache.oozie.service.ShareLibService) JSONArray(org.json.simple.JSONArray) List(java.util.List)

Example 4 with ShareLibService

use of org.apache.oozie.service.ShareLibService in project oozie by apache.

the class BaseAdminServlet method updateLocalShareLib.

@SuppressWarnings("unchecked")
private JSONObject updateLocalShareLib(HttpServletRequest request) {
    ShareLibService shareLibService = Services.get().get(ShareLibService.class);
    JSONObject json = new JSONObject();
    json.put(JsonTags.SHARELIB_UPDATE_HOST, ConfigUtils.getOozieEffectiveUrl());
    try {
        json.putAll(shareLibService.updateShareLib());
        json.put(JsonTags.SHARELIB_UPDATE_STATUS, "Successful");
    } catch (Exception e) {
        json.put(JsonTags.SHARELIB_UPDATE_STATUS, e.getClass().getName() + ": " + e.getMessage());
    }
    return json;
}
Also used : JSONObject(org.json.simple.JSONObject) ShareLibService(org.apache.oozie.service.ShareLibService) ServletException(javax.servlet.ServletException) AuthorizationException(org.apache.oozie.service.AuthorizationException) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException)

Example 5 with ShareLibService

use of org.apache.oozie.service.ShareLibService in project oozie by apache.

the class TestOozieSharelibCLI method testOozieSharelibCLICreate.

/**
 * test copy libraries
 */
public void testOozieSharelibCLICreate() throws Exception {
    File libDirectory = tmpFolder.newFolder("lib");
    writeFile(libDirectory, "file1", "test File");
    writeFile(libDirectory, "file2", "test File2");
    String[] argsCreate = { "create", "-fs", outPath, "-locallib", libDirectory.getParentFile().getAbsolutePath() };
    assertEquals(0, execOozieSharelibCLICommands(argsCreate));
    FileSystem fs = getTargetFileSysyem();
    ShareLibService sharelibService = getServices().get(ShareLibService.class);
    // test files in new folder
    assertEquals(9, fs.getFileStatus(new Path(sharelibService.getLatestLibPath(getDistPath(), ShareLibService.SHARE_LIB_PREFIX), "file1")).getLen());
    assertEquals(10, fs.getFileStatus(new Path(sharelibService.getLatestLibPath(getDistPath(), ShareLibService.SHARE_LIB_PREFIX), "file2")).getLen());
}
Also used : Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) ShareLibService(org.apache.oozie.service.ShareLibService) File(java.io.File)

Aggregations

ShareLibService (org.apache.oozie.service.ShareLibService)6 Path (org.apache.hadoop.fs.Path)5 IOException (java.io.IOException)3 File (java.io.File)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)2 JSONObject (org.json.simple.JSONObject)2 InputStream (java.io.InputStream)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Pattern (java.util.regex.Pattern)1 ServletException (javax.servlet.ServletException)1 Configuration (org.apache.hadoop.conf.Configuration)1 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)1 CommandException (org.apache.oozie.command.CommandException)1 AuthorizationException (org.apache.oozie.service.AuthorizationException)1 XConfiguration (org.apache.oozie.util.XConfiguration)1 JSONArray (org.json.simple.JSONArray)1