use of org.apache.oozie.action.ActionExecutorException in project oozie by apache.
the class ScriptLanguageActionExecutor method addScriptToCache.
protected void addScriptToCache(Configuration conf, Element actionXml, Path appPath, Context context) throws ActionExecutorException {
Namespace ns = actionXml.getNamespace();
String script = actionXml.getChild("script", ns).getTextTrim();
String name = new Path(script).getName();
String scriptContent = context.getProtoActionConf().get(this.getScriptName());
Path scriptFile = null;
if (scriptContent != null) {
// Create script on filesystem if this is
// an http submission job;
FSDataOutputStream dos = null;
try {
Path actionPath = context.getActionDir();
scriptFile = new Path(actionPath, script);
FileSystem fs = context.getAppFileSystem();
dos = fs.create(scriptFile);
dos.write(scriptContent.getBytes(StandardCharsets.UTF_8));
addToCache(conf, actionPath, script + "#" + name, false);
} catch (Exception ex) {
throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "FAILED_OPERATION", XLog.format("Not able to write script file {0} on hdfs", scriptFile), ex);
} finally {
try {
if (dos != null) {
dos.close();
}
} catch (IOException ex) {
XLog.getLog(getClass()).error("Error: " + ex.getMessage());
}
}
} else {
addToCache(conf, appPath, script + "#" + name, false);
}
}
use of org.apache.oozie.action.ActionExecutorException in project oozie by apache.
the class SshActionExecutor method getReturnValue.
/**
* Get the return value of a processSettings.
*
* @param command command to be executed.
* @return zero if execution is successful and any non zero value for failure.
* @throws ActionExecutorException
*/
private int getReturnValue(String command) throws ActionExecutorException {
LOG.trace("Getting return value for command={0}", command);
int returnValue;
Process ps = null;
try {
ps = Runtime.getRuntime().exec(command.split("\\s"));
returnValue = drainBuffers(ps, null, null, 0);
} catch (IOException e) {
throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "FAILED_OPERATION", XLog.format("Not able to perform operation {0}", command), e);
} finally {
ps.destroy();
}
LOG.trace("returnValue={0}", returnValue);
return returnValue;
}
use of org.apache.oozie.action.ActionExecutorException in project oozie by apache.
the class TestJavaActionExecutor method testCredentialsModule.
public void testCredentialsModule() throws Exception {
String actionXml = "<workflow-app xmlns='uri:oozie:workflow:0.2.5' name='pig-wf'>" + "<credentials>" + "<credential name='abcname' type='abc'>" + "<property>" + "<name>property1</name>" + "<value>value1</value>" + "</property>" + "<property>" + "<name>property2</name>" + "<value>value2</value>" + "</property>" + "<property>" + "<name>${property3}</name>" + "<value>${value3}</value>" + "</property>" + "</credential>" + "</credentials>" + "<start to='pig1' />" + "<action name='pig1' cred='abcname'>" + "<pig>" + "</pig>" + "<ok to='end' />" + "<error to='fail' />" + "</action>" + "<kill name='fail'>" + "<message>Pig failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>" + "</kill>" + "<end name='end' />" + "</workflow-app>";
JavaActionExecutor ae = new JavaActionExecutor();
WorkflowJobBean wfBean = addRecordToWfJobTable("test1", actionXml);
WorkflowActionBean action = (WorkflowActionBean) wfBean.getActions().get(0);
action.setType(ae.getType());
action.setCred("abcname");
String actionxml = "<pig>" + "<job-tracker>${jobTracker}</job-tracker>" + "<name-node>${nameNode}</name-node>" + "<prepare>" + "<delete path='outputdir' />" + "</prepare>" + "<configuration>" + "<property>" + "<name>mapred.compress.map.output</name>" + "<value>true</value>" + "</property>" + "<property>" + "<name>mapred.job.queue.name</name>" + "<value>${queueName}</value>" + "</property>" + "</configuration>" + "<script>org/apache/oozie/examples/pig/id.pig</script>" + "<param>INPUT=${inputDir}</param>" + "<param>OUTPUT=${outputDir}/pig-output</param>" + "</pig>";
action.setConf(actionxml);
Context context = new Context(wfBean, action);
Element actionXmlconf = XmlUtils.parseXml(action.getConf());
// action job configuration
Configuration actionConf = ae.createBaseHadoopConf(context, actionXmlconf);
// Setting the credential properties in launcher conf
Map<String, CredentialsProperties> credProperties = ae.setCredentialPropertyToActionConf(context, action, actionConf);
assertNotNull(credProperties);
CredentialsProperties prop = credProperties.get("abcname");
assertEquals("value1", prop.getProperties().get("property1"));
assertEquals("value2", prop.getProperties().get("property2"));
assertEquals("val3", prop.getProperties().get("prop3"));
// Try to load the token without it being defined in oozie-site; should get an exception
CredentialsProviderFactory.destroy();
JobConf credentialsConf = new JobConf();
Credentials credentials = new Credentials();
Configuration launcherConf = ae.createBaseHadoopConf(context, actionXmlconf);
XConfiguration.copy(launcherConf, credentialsConf);
try {
ae.setCredentialTokens(credentials, credentialsConf, context, action, credProperties);
fail("Should have gotten an exception but did not");
} catch (ActionExecutorException aee) {
assertEquals("JA020", aee.getErrorCode());
assertTrue(aee.getMessage().contains("type [abc]"));
assertTrue(aee.getMessage().contains("name [abcname]"));
}
CredentialsProviderFactory.destroy();
// Define 'abc' token type in oozie-site
ConfigurationService.set("oozie.credentials.credentialclasses", "abc=org.apache.oozie.action.hadoop.InsertTestToken");
// Try to load the token after being defined in oozie-site; should work correctly
credentialsConf = new JobConf();
credentials = new Credentials();
launcherConf = ae.createBaseHadoopConf(context, actionXmlconf);
XConfiguration.copy(launcherConf, credentialsConf);
ae.setCredentialTokens(credentials, credentialsConf, context, action, credProperties);
Token<? extends TokenIdentifier> tk = credentials.getToken(new Text("ABC Token"));
assertNotNull(tk);
byte[] secKey = credentials.getSecretKey(new Text(InsertTestToken.DUMMY_SECRET_KEY));
assertNotNull(secKey);
assertEquals(InsertTestToken.DUMMY_SECRET_KEY, new String(secKey, "UTF-8"));
}
use of org.apache.oozie.action.ActionExecutorException in project oozie by apache.
the class TestJavaActionExecutor method testIdSwapSubmitOK.
public void testIdSwapSubmitOK() throws Exception {
String actionXml = "<java>" + "<job-tracker>" + getJobTrackerUri() + "</job-tracker>" + "<name-node>" + getNameNodeUri() + "</name-node>" + "<main-class>" + LauncherMainTester.class.getName() + "</main-class>" + "<arg>id</arg>" + "<capture-output/>" + "</java>";
Context context = createContext(actionXml, null);
final String runningJob = submitAction(context);
waitUntilYarnAppDoneAndAssertSuccess(runningJob);
ActionExecutor ae = new JavaActionExecutor();
try {
ae.check(context, context.getAction());
} catch (ActionExecutorException ex) {
if (!ex.getMessage().contains("IDSWAP")) {
fail();
}
}
}
use of org.apache.oozie.action.ActionExecutorException in project oozie by apache.
the class TestJavaActionExecutor method testSetupMethods.
public void testSetupMethods() throws Exception {
JavaActionExecutor ae = new JavaActionExecutor();
assertEquals(Arrays.asList(JavaMain.class), ae.getLauncherClasses());
Configuration conf = new XConfiguration();
conf.set("user.name", "a");
try {
JavaActionExecutor.checkForDisallowedProps(conf, "x");
fail();
} catch (ActionExecutorException ex) {
}
conf = new XConfiguration();
conf.set(YARN_RESOURCEMANAGER_ADDRESS, "a");
try {
JavaActionExecutor.checkForDisallowedProps(conf, "x");
fail();
} catch (ActionExecutorException ex) {
}
conf = new XConfiguration();
conf.set("fs.default.name", "a");
try {
JavaActionExecutor.checkForDisallowedProps(conf, "x");
fail();
} catch (ActionExecutorException ex) {
}
conf = new XConfiguration();
conf.set("a", "a");
try {
JavaActionExecutor.checkForDisallowedProps(conf, "x");
} catch (ActionExecutorException ex) {
fail();
}
Element actionXml = XmlUtils.parseXml("<java>" + "<job-tracker>" + getJobTrackerUri() + "</job-tracker>" + "<name-node>" + getNameNodeUri() + "</name-node>" + "<job-xml>job.xml</job-xml>" + "<job-xml>job2.xml</job-xml>" + "<configuration>" + "<property><name>oozie.launcher.a</name><value>LA</value></property>" + "<property><name>a</name><value>AA</value></property>" + "<property><name>b</name><value>BB</value></property>" + "</configuration>" + "<main-class>MAIN-CLASS</main-class>" + "<java-opts>JAVA-OPTS</java-opts>" + "<arg>A1</arg>" + "<arg>A2</arg>" + "<file>f.jar</file>" + "<archive>a.tar</archive>" + "</java>");
Path appPath = new Path(getFsTestCaseDir(), "wf");
Path appJarPath = new Path("lib/a.jar");
getFileSystem().create(new Path(appPath, appJarPath)).close();
Path appSoPath = new Path("lib/a.so");
getFileSystem().create(new Path(appPath, appSoPath)).close();
Path appSo1Path = new Path("lib/a.so.1");
String expectedSo1Path = "lib/a.so.1#a.so.1";
getFileSystem().create(new Path(appPath, appSo1Path)).close();
Path filePath = new Path("f.jar");
getFileSystem().create(new Path(appPath, filePath)).close();
Path archivePath = new Path("a.tar");
getFileSystem().create(new Path(appPath, archivePath)).close();
XConfiguration protoConf = new XConfiguration();
protoConf.set(WorkflowAppService.HADOOP_USER, getTestUser());
protoConf.setStrings(WorkflowAppService.APP_LIB_PATH_LIST, appJarPath.toString(), appSoPath.toString());
WorkflowJobBean wf = createBaseWorkflow(protoConf, "action");
WorkflowActionBean action = (WorkflowActionBean) wf.getActions().get(0);
action.setType(ae.getType());
Context context = new Context(wf, action);
conf = new XConfiguration();
conf.set("c", "C");
conf.set("oozie.launcher.d", "D");
OutputStream os = getFileSystem().create(new Path(getFsTestCaseDir(), "job.xml"));
conf.writeXml(os);
os.close();
os = getFileSystem().create(new Path(getFsTestCaseDir(), new Path("app", "job.xml")));
conf.writeXml(os);
os.close();
conf = new XConfiguration();
conf.set("e", "E");
conf.set("oozie.launcher.f", "F");
os = getFileSystem().create(new Path(getFsTestCaseDir(), "job2.xml"));
conf.writeXml(os);
os.close();
os = getFileSystem().create(new Path(getFsTestCaseDir(), new Path("app", "job2.xml")));
conf.writeXml(os);
os.close();
conf = ae.createBaseHadoopConf(context, actionXml);
assertEquals(protoConf.get(WorkflowAppService.HADOOP_USER), conf.get(WorkflowAppService.HADOOP_USER));
assertEquals(getJobTrackerUri(), conf.get(YARN_RESOURCEMANAGER_ADDRESS));
assertEquals(getNameNodeUri(), conf.get("fs.default.name"));
conf = ae.createBaseHadoopConf(context, actionXml);
ae.setupLauncherConf(conf, actionXml, getFsTestCaseDir(), context);
assertEquals("LA", conf.get("oozie.launcher.a"));
assertEquals("LA", conf.get("a"));
assertNull(conf.get("b"));
assertEquals("D", conf.get("oozie.launcher.d"));
assertEquals("D", conf.get("d"));
assertEquals("F", conf.get("oozie.launcher.f"));
assertEquals("F", conf.get("f"));
assertNull(conf.get("action.foo"));
assertEquals("action.barbar", conf.get("action.foofoo"));
conf = ae.createBaseHadoopConf(context, actionXml);
ae.setupActionConf(conf, context, actionXml, getFsTestCaseDir());
assertEquals("LA", conf.get("oozie.launcher.a"));
assertEquals("AA", conf.get("a"));
assertEquals("BB", conf.get("b"));
assertEquals("C", conf.get("c"));
assertEquals("D", conf.get("oozie.launcher.d"));
assertNull(conf.get("d"));
assertEquals("E", conf.get("e"));
assertEquals("F", conf.get("oozie.launcher.f"));
assertNull(conf.get("f"));
assertEquals("action.bar", conf.get("action.foo"));
conf = ae.createBaseHadoopConf(context, actionXml);
ae.setupLauncherConf(conf, actionXml, getFsTestCaseDir(), context);
ae.addToCache(conf, appPath, appJarPath.toString(), false);
assertTrue(conf.get("mapred.job.classpath.files").contains(appJarPath.toUri().getPath()));
ae.addToCache(conf, appPath, appSoPath.toString(), false);
assertTrue(conf.get("mapred.cache.files").contains(appSoPath.toUri().getPath()));
ae.addToCache(conf, appPath, appSo1Path.toString(), false);
assertTrue(conf.get("mapred.cache.files").contains(expectedSo1Path));
assertFalse(getFileSystem().exists(context.getActionDir()));
ae.prepareActionDir(getFileSystem(), context);
assertTrue(getFileSystem().exists(context.getActionDir()));
ae.cleanUpActionDir(getFileSystem(), context);
assertFalse(getFileSystem().exists(context.getActionDir()));
conf = ae.createBaseHadoopConf(context, actionXml);
ae.setupLauncherConf(conf, actionXml, getFsTestCaseDir(), context);
ae.setLibFilesArchives(context, actionXml, appPath, conf);
assertTrue(conf.get("mapred.cache.files").contains(filePath.toUri().getPath()));
assertTrue(conf.get("mapred.cache.archives").contains(archivePath.toUri().getPath()));
conf = ae.createBaseHadoopConf(context, actionXml);
ae.setupActionConf(conf, context, actionXml, getFsTestCaseDir());
ae.setLibFilesArchives(context, actionXml, appPath, conf);
assertTrue(conf.get("mapred.cache.files").contains(filePath.toUri().getPath()));
assertTrue(conf.get("mapred.cache.archives").contains(archivePath.toUri().getPath()));
Configuration actionConf = ae.createBaseHadoopConf(context, actionXml);
ae.setupActionConf(actionConf, context, actionXml, getFsTestCaseDir());
conf = ae.createLauncherConf(getFileSystem(), context, action, actionXml, actionConf);
ae.setupLauncherConf(conf, actionXml, getFsTestCaseDir(), context);
assertEquals("MAIN-CLASS", actionConf.get("oozie.action.java.main", "null"));
assertEquals("org.apache.oozie.action.hadoop.JavaMain", ae.getLauncherMain(conf, actionXml));
assertTrue(conf.get(MAPRED_CHILD_JAVA_OPTS).contains("JAVA-OPTS"));
assertTrue(conf.get(MAPREDUCE_MAP_JAVA_OPTS).contains("JAVA-OPTS"));
assertEquals(Arrays.asList("A1", "A2"), Arrays.asList(LauncherAMUtils.getMainArguments(conf)));
actionXml = XmlUtils.parseXml("<java>" + "<job-tracker>" + getJobTrackerUri() + "</job-tracker>" + "<name-node>" + getNameNodeUri() + "</name-node> <configuration>" + "<property><name>mapred.job.queue.name</name><value>AQ</value></property>" + "<property><name>oozie.action.sharelib.for.java</name><value>sharelib-java</value></property>" + "</configuration>" + "<main-class>MAIN-CLASS</main-class>" + "</java>");
actionConf = ae.createBaseHadoopConf(context, actionXml);
ae.setupActionConf(actionConf, context, actionXml, appPath);
conf = ae.createLauncherConf(getFileSystem(), context, action, actionXml, actionConf);
assertEquals("AQ", conf.get("mapred.job.queue.name"));
assertEquals("AQ", actionConf.get("mapred.job.queue.name"));
assertEquals("sharelib-java", actionConf.get("oozie.action.sharelib.for.java"));
actionXml = XmlUtils.parseXml("<java>" + "<job-tracker>" + getJobTrackerUri() + "</job-tracker>" + "<name-node>" + getNameNodeUri() + "</name-node> <configuration>" + "<property><name>oozie.launcher.mapred.job.queue.name</name><value>LQ</value></property>" + "</configuration>" + "<main-class>MAIN-CLASS</main-class>" + "</java>");
actionConf = ae.createBaseHadoopConf(context, actionXml);
ae.setupActionConf(actionConf, context, actionXml, appPath);
conf = ae.createLauncherConf(getFileSystem(), context, action, actionXml, actionConf);
assertEquals("LQ", conf.get("mapred.job.queue.name"));
actionXml = XmlUtils.parseXml("<java>" + "<job-tracker>" + getJobTrackerUri() + "</job-tracker>" + "<name-node>" + getNameNodeUri() + "</name-node> <configuration>" + "<property><name>oozie.launcher.mapred.job.queue.name</name><value>LQ</value></property>" + "<property><name>mapred.job.queue.name</name><value>AQ</value></property>" + "</configuration>" + "<main-class>MAIN-CLASS</main-class>" + "</java>");
actionConf = ae.createBaseHadoopConf(context, actionXml);
ae.setupActionConf(actionConf, context, actionXml, appPath);
conf = ae.createLauncherConf(getFileSystem(), context, action, actionXml, actionConf);
assertEquals("LQ", conf.get("mapred.job.queue.name"));
assertEquals("AQ", actionConf.get("mapred.job.queue.name"));
assertEquals(true, conf.getBoolean("mapreduce.job.complete.cancel.delegation.tokens", false));
assertEquals(false, actionConf.getBoolean("mapreduce.job.complete.cancel.delegation.tokens", true));
}
Aggregations