* @param action action object.
*/
@SuppressWarnings("unchecked")
@Override
public void start(final Context context, final WorkflowAction action) throws ActionExecutorException {
XLog log = XLog.getLog(getClass());
log.info("start() begins");
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 = "";
if (runningPid == null) {
final Element commandElement = conf.getChild("command", nameSpace);
final boolean ignoreOutput = conf.getChild("capture-output", nameSpace) == null;
if (commandElement != null) {
List<Element> argsList = conf.getChildren("args", nameSpace);
StringBuilder args = new StringBuilder("");
if ((argsList != null) && (argsList.size() > 0)) {
for (Element argsElement : argsList) {
args = args.append(argsElement.getValue()).append(" ");
}
args.setLength(args.length() - 1);
}
final String argsString = args.toString();
final String recoveryId = context.getRecoveryId();
pid = execute(new Callable<String>() {
@Override
public String call() throws Exception {
return doExecute(host, dirLocation, commandElement.getValue(), argsString, ignoreOutput,
action, recoveryId);
}
});
}
context.setStartData(pid, host, host);
}
else {
pid = runningPid;
context.setStartData(pid, host, host);
check(context, action);
}
log.info("start() ends");
}