in taverna-external-tool-activity/src/main/java/org/apache/taverna/activities/externaltool/ssh/SshToolInvocation.java [256:369]
public HashMap<String, Object> submit_wait_fetch_results(
ReferenceService referenceService) throws InvocationException {
while (!running.isClosed()) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new InvocationException("Invocation interrupted:"
+ e.getMessage());
}
}
int exitcode = running.getExitStatus();
if (!usecase.getValidReturnCodes().contains(exitcode)) {
try {
throw new InvocationException("Invalid exit code " + exitcode
+ ":" + stderr_buf.toString("US-ASCII"));
} catch (UnsupportedEncodingException e) {
throw new InvocationException("Invalid exit code " + exitcode
+ ":" + stderr_buf.toString());
}
}
HashMap<String, Object> results = new HashMap<String, Object>();
results.put("STDOUT", stdout_buf.toByteArray());
results.put("STDERR", stderr_buf.toByteArray());
try {
stdout_buf.close();
stderr_buf.close();
} catch (IOException e2) {
throw new InvocationException(e2);
}
try {
ChannelSftp sftp = SshPool.getSftpPutChannel(workerNode,
askUserForPw);
synchronized (getNodeLock(workerNode)) {
for (Map.Entry<String, ScriptOutput> cur : usecase.getOutputs()
.entrySet()) {
ScriptOutput scriptOutput = cur.getValue();
String fullPath = workerNode.getDirectory() + tmpname + "/"
+ scriptOutput.getPath();
try {
if (sftp.stat(fullPath) != null) {
SshUrl url = new SshUrl(workerNode);
url.setSubDirectory(tmpname);
url.setFileName(scriptOutput.getPath());
if (scriptOutput.isBinary()) {
url.setDataNature(ReferencedDataNature.BINARY);
} else {
url.setDataNature(ReferencedDataNature.TEXT);
url.setCharset("UTF-8");
}
if (isRetrieveData()) {
SshReference urlRef = new SshReference(url);
InputStream is = urlRef.openStream(null);
AbstractExternalReference ref;
if (scriptOutput.isBinary()) {
ref = inlineByteArrayReferenceBuilder
.createReference(is, null);
} else {
ref = inlineStringReferenceBuilder
.createReference(is, null);
}
try {
is.close();
} catch (IOException e) {
throw new InvocationException(e);
}
results.put(cur.getKey(), ref);
} else {
results.put(cur.getKey(), url);
}
} else {
ErrorDocument ed = referenceService
.getErrorDocumentService().registerError(
"No result for " + cur.getKey(), 0,
getContext());
results.put(cur.getKey(), ed);
}
} catch (SftpException e) {
ErrorDocument ed = referenceService
.getErrorDocumentService().registerError(
"No result for " + cur.getKey(), 0,
getContext());
results.put(cur.getKey(), ed);
}
}
}
} catch (JSchException e1) {
throw new InvocationException(e1);
} catch (ErrorDocumentServiceException e) {
throw new InvocationException(e);
}
if (running != null) {
running.disconnect();
}
if (stdInputStream != null) {
try {
stdInputStream.close();
} catch (IOException e) {
throw new InvocationException(e);
}
}
if (isRetrieveData()) {
forgetRun();
deleteDirectory(location, credentialManager);
}
return results;
}