use of org.jdom.Namespace in project oozie by apache.
the class SqoopActionExecutor method setupActionConf.
@Override
Configuration setupActionConf(Configuration actionConf, Context context, Element actionXml, Path appPath) throws ActionExecutorException {
super.setupActionConf(actionConf, context, actionXml, appPath);
Namespace ns = actionXml.getNamespace();
try {
Element e = actionXml.getChild("configuration", ns);
if (e != null) {
String strConf = XmlUtils.prettyPrint(e).toString();
XConfiguration inlineConf = new XConfiguration(new StringReader(strConf));
XConfiguration.copy(inlineConf, actionConf);
checkForDisallowedProps(inlineConf, "inline configuration");
}
} catch (IOException ex) {
throw convertException(ex);
}
final List<String> argList = new ArrayList<>();
// Build a list of arguments from either a tokenized <command> string or a list of <arg>
if (actionXml.getChild("command", ns) != null) {
String command = actionXml.getChild("command", ns).getTextTrim();
StringTokenizer st = new StringTokenizer(command, " ");
while (st.hasMoreTokens()) {
argList.add(st.nextToken());
}
} else {
@SuppressWarnings("unchecked") List<Element> eArgs = (List<Element>) actionXml.getChildren("arg", ns);
for (Element elem : eArgs) {
argList.add(elem.getTextTrim());
}
}
// "sqoop --option", as that's entirely invalid.
if (argList.size() > 1 && argList.get(0).equalsIgnoreCase(SQOOP) && !argList.get(1).startsWith("-")) {
XLog.getLog(getClass()).info("Found a redundant 'sqoop' prefixing the command. Removing it.");
argList.remove(0);
}
setSqoopCommand(actionConf, argList.toArray(new String[argList.size()]));
return actionConf;
}
use of org.jdom.Namespace in project oozie by apache.
the class SqoopActionExecutor method evaluateConfigurationProperty.
// Return the value of the specified configuration property
private String evaluateConfigurationProperty(Element actionConf, String key, String defaultValue) throws ActionExecutorException {
try {
if (actionConf != null) {
Namespace ns = actionConf.getNamespace();
Element e = actionConf.getChild("configuration", ns);
if (e != null) {
String strConf = XmlUtils.prettyPrint(e).toString();
XConfiguration inlineConf = new XConfiguration(new StringReader(strConf));
return inlineConf.get(key, defaultValue);
}
}
return defaultValue;
} catch (IOException ex) {
throw convertException(ex);
}
}
use of org.jdom.Namespace in project oozie by apache.
the class SshActionExecutor method check.
/**
* Check ssh action status.
*
* @param context action execution context.
* @param action action object.
* @throws org.apache.oozie.action.ActionExecutorException
*/
@Override
public void check(Context context, WorkflowAction action) throws ActionExecutorException {
LOG.trace("check() start for action={0}", action.getId());
Status status = getActionStatus(context, action);
boolean captureOutput = false;
try {
Element eConf = XmlUtils.parseXml(action.getConf());
Namespace ns = eConf.getNamespace();
captureOutput = eConf.getChild("capture-output", ns) != null;
} catch (JDOMException ex) {
throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "ERR_XML_PARSE_FAILED", "unknown error", ex);
}
LOG.debug("Capture Output: {0}", captureOutput);
if (status == Status.OK) {
if (captureOutput) {
String outFile = getRemoteFileName(context, action, "stdout", false, true);
String dataCommand = SSH_COMMAND_BASE + action.getTrackerUri() + " cat " + outFile;
LOG.debug("Ssh command [{0}]", dataCommand);
try {
final Process process = Runtime.getRuntime().exec(dataCommand.split("\\s"));
final StringBuffer outBuffer = new StringBuffer();
final StringBuffer errBuffer = new StringBuffer();
boolean overflow = false;
drainBuffers(process, outBuffer, errBuffer, maxLen);
LOG.trace("outBuffer={0}", outBuffer);
LOG.trace("errBuffer={0}", errBuffer);
if (outBuffer.length() > maxLen) {
overflow = true;
}
if (overflow) {
throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "ERR_OUTPUT_EXCEED_MAX_LEN", "unknown error");
}
context.setExecutionData(status.toString(), PropertiesUtils.stringToProperties(outBuffer.toString()));
LOG.trace("Execution data set. status={0}, properties={1}", status, PropertiesUtils.stringToProperties(outBuffer.toString()));
} catch (Exception ex) {
throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "ERR_UNKNOWN_ERROR", "unknown error", ex);
}
} else {
LOG.trace("Execution data set to null. status={0}", status);
context.setExecutionData(status.toString(), null);
}
} else {
if (status == Status.ERROR) {
LOG.warn("Execution data set to null in ERROR");
context.setExecutionData(status.toString(), null);
} else {
LOG.warn("Execution data not set");
context.setExternalStatus(status.toString());
}
}
LOG.trace("check() end for action={0}", action);
}
use of org.jdom.Namespace in project oozie by apache.
the class SshActionExecutor method start.
/**
* Start the ssh action execution.
*
* @param context action execution context.
* @param action action object.
* @throws org.apache.oozie.action.ActionExecutorException
*/
@SuppressWarnings("unchecked")
@Override
public void start(final Context context, final WorkflowAction action) throws ActionExecutorException {
LOG.info("Starting action");
String confStr = action.getConf();
Element conf;
try {
conf = XmlUtils.parseXml(confStr);
} catch (Exception ex) {
throw convertException(ex);
}
Namespace nameSpace = conf.getNamespace();
Element hostElement = conf.getChild("host", nameSpace);
String hostString = hostElement.getValue().trim();
hostString = prepareUserHost(hostString, context);
final String host = hostString;
final String dirLocation = execute(new Callable<String>() {
public String call() throws Exception {
return setupRemote(host, context, action);
}
});
String runningPid = execute(new Callable<String>() {
public String call() throws Exception {
return checkIfRunning(host, context, action);
}
});
String pid = "";
LOG.trace("runningPid={0}", runningPid);
if (runningPid == null) {
final Element commandElement = conf.getChild("command", nameSpace);
final boolean ignoreOutput = conf.getChild("capture-output", nameSpace) == null;
boolean preserve = false;
if (commandElement != null) {
String[] args = null;
// Will either have <args>, <arg>, or neither (but not both)
List<Element> argsList = conf.getChildren("args", nameSpace);
// Arguments in an <args> are "flattened" (spaces are delimiters)
if (argsList != null && argsList.size() > 0) {
StringBuilder argsString = new StringBuilder("");
for (Element argsElement : argsList) {
argsString = argsString.append(argsElement.getValue()).append(" ");
}
args = new String[] { argsString.toString() };
} else {
// Arguments in an <arg> are preserved, even with spaces
argsList = conf.getChildren("arg", nameSpace);
if (argsList != null && argsList.size() > 0) {
preserve = true;
args = new String[argsList.size()];
for (int i = 0; i < argsList.size(); i++) {
Element argsElement = argsList.get(i);
args[i] = argsElement.getValue();
// them or escape their space (because the scripts will split them up otherwise)
if (args[i].contains(" ") && !(args[i].startsWith("\"") && args[i].endsWith("\"") || args[i].startsWith("'") && args[i].endsWith("'"))) {
args[i] = StringUtils.escapeString(args[i], '\\', ' ');
}
}
}
}
final String[] argsF = args;
final String recoveryId = context.getRecoveryId();
final boolean preserveF = preserve;
pid = execute(new Callable<String>() {
@Override
public String call() throws Exception {
return doExecute(host, dirLocation, commandElement.getValue(), argsF, ignoreOutput, action, recoveryId, preserveF);
}
});
}
context.setStartData(pid, host, host);
} else {
pid = runningPid;
context.setStartData(pid, host, host);
check(context, action);
}
}
use of org.jdom.Namespace in project oozie by apache.
the class InputLogicParser method processChildNode.
/**
* Process child node.
*
* @param root the root
* @param opt the opt
* @param min the min
* @param wait the wait
* @return the string
*/
@SuppressWarnings("unchecked")
private String processChildNode(final Element root, final String opt, final String min, final String wait) {
StringBuffer parsedString = new StringBuffer();
Namespace ns = root.getNamespace();
List<Element> childrens = root.getChildren(COORD_INPUT_EVENTS_DATA_IN, ns);
for (int i = 0; i < childrens.size(); i++) {
parsedString.append(parseDataInNode(childrens.get(i), min, wait));
if (i < childrens.size() - 1) {
parsedString.append(" " + opt + " ");
}
}
return parsedString.toString();
}
Aggregations