}
return error;
}
public Map<String, ?> processOutput(InvocationContext invocationContext) throws ProviderException {
GlobusHostType host = (GlobusHostType) invocationContext.getExecutionDescription().getHost().getType();
ApplicationDeploymentDescriptionType app = invocationContext.getExecutionDescription().getApp().getType();
GridFtp ftp = new GridFtp();
File localStdErrFile = null;
try {
GSSCredential gssCred = gssContext.getGssCredentails();
String[] hostgridFTP = host.getGridFTPEndPointArray();
if (hostgridFTP == null || hostgridFTP.length == 0) {
hostgridFTP = new String[] { host.getHostAddress() };
}
ProviderException pe = null;
for (String endpoint : host.getGridFTPEndPointArray()) {
try {
/*
* Read Stdout and Stderror
*/
URI stdoutURI = GfacUtils.createGsiftpURI(endpoint, app.getStandardOutput());
URI stderrURI = GfacUtils.createGsiftpURI(endpoint, app.getStandardError());
log.info("STDOUT:" + stdoutURI.toString());
log.info("STDERR:" + stderrURI.toString());
File logDir = new File("./service_logs");
if (!logDir.exists()) {
logDir.mkdir();
}
String timeStampedServiceName = GfacUtils.createUniqueNameForService(invocationContext
.getServiceName());
File localStdOutFile = File.createTempFile(timeStampedServiceName, "stdout");
localStdErrFile = File.createTempFile(timeStampedServiceName, "stderr");
String stdout = ftp.readRemoteFile(stdoutURI, gssCred, localStdOutFile);
String stderr = ftp.readRemoteFile(stderrURI, gssCred, localStdErrFile);
Map<String,ActualParameter> stringMap = null;
MessageContext<Object> output = invocationContext.getOutput();
for (Iterator<String> iterator = output.getNames(); iterator.hasNext(); ) {
String paramName = iterator.next();
ActualParameter actualParameter = (ActualParameter) output.getValue(paramName);
if ("URIArray".equals(actualParameter.getType().getType().toString())) {
URI outputURI = GfacUtils.createGsiftpURI(endpoint,app.getOutputDataDirectory());
List<String> outputList = ftp.listDir(outputURI,gssCred);
String[] valueList = outputList.toArray(new String[outputList.size()]);
((URIArrayType) actualParameter.getType()).setValueArray(valueList);
stringMap = new HashMap<String, ActualParameter>();
stringMap.put(paramName, actualParameter);
invocationContext.getExecutionContext().getNotifier().output(invocationContext, actualParameter.toString());
}
if ("StringArray".equals(actualParameter.getType().getType().toString())) {
String[] valueList = OutputUtils.parseStdoutArray(stdout, paramName);
((StringArrayType) actualParameter.getType()).setValueArray(valueList);
stringMap = new HashMap<String, ActualParameter>();
stringMap.put(paramName, actualParameter);
invocationContext.getExecutionContext().getNotifier().output(invocationContext, actualParameter.toString());
}
else{
// This is to handle exception during the output parsing.
stringMap = OutputUtils.fillOutputFromStdout(invocationContext.<ActualParameter>getOutput(), stdout,stderr);
String paramValue = output.getStringValue(paramName);
if(paramValue == null || paramValue.isEmpty()){
int errCode = listener.getError();
String errorMsg = "Job " + job.getID() + " on host " + host.getHostAddress();
JobSubmissionFault error = new JobSubmissionFault(this, new Exception(errorMsg), "GFAC HOST",
gateKeeper, job.getRSL(), invocationContext);
errorReason(errCode, error);
invocationContext.getExecutionContext().getNotifier().executionFail(invocationContext,error,
readLastLinesofStdOut(localStdErrFile.getPath(), 20));