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());
}
}
}
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());
}
}
}
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;
}
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;
}
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());
}
Aggregations