String[] hostgridFTP = host.getGridFTPEndPointArray();
if (hostgridFTP == null || hostgridFTP.length == 0) {
hostgridFTP = new String[] { host.getHostAddress() };
}
boolean success = false;
ProviderException pe = new ProviderException("");
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;
stringMap = OutputUtils.fillOutputFromStdout(invocationContext.<ActualParameter>getOutput(), stdout);
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());
// }
// else{
// This is to handle exception during the output parsing.
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());
errorReason(errCode, error);
invocationContext.getExecutionContext().getNotifier().executionFail(invocationContext,error,readLastLinesofStdOut(localStdErrFile.getPath(), 20));
throw error;
}
}
// }
// if(stringMap == null || stringMap.isEmpty()){
// ProviderException exception = new ProviderException("Error creating job output");
// invocationContext.getExecutionContext().getNotifier().executionFail(invocationContext,exception,exception.getLocalizedMessage());
// throw exception;
// }
// If users has given an output DAta poth we download the output files in to that directory, this will be apath in the machine where GFac is installed
if(WorkflowContextHeaderBuilder.getCurrentContextHeader()
.getWorkflowOutputDataHandling() != null){
WorkflowOutputDataHandlingDocument.WorkflowOutputDataHandling workflowOutputDataHandling =
WorkflowContextHeaderBuilder.getCurrentContextHeader().getWorkflowOutputDataHandling();
if(workflowOutputDataHandling.getApplicationOutputDataHandlingArray().length != 0){
String outputDataDirectory = workflowOutputDataHandling.getApplicationOutputDataHandlingArray()[0].getOutputDataDirectory();
if(outputDataDirectory != null && !"".equals(outputDataDirectory)){
stageOutputFiles(invocationContext,outputDataDirectory);
}
}
}
return stringMap;
} catch (URISyntaxException e) {
invocationContext.getExecutionContext().getNotifier().executionFail(invocationContext,e,readLastLinesofStdOut(localStdErrFile.getPath(), 20));
throw new ProviderException("URI is malformatted:" + e.getMessage(), e);
}
catch (NullPointerException e) {
invocationContext.getExecutionContext().getNotifier().executionFail(invocationContext,e,readLastLinesofStdOut(localStdErrFile.getPath(), 20));
throw new ProviderException("Empty output generated:" + e.getMessage(), e);
} catch (Exception e) {
invocationContext.getExecutionContext().getNotifier().executionFail(invocationContext, e, readLastLinesofStdOut(localStdErrFile.getPath(), 20));
throw new ProviderException(e.getMessage(), e);
}
}
/*
* If the execution reach here, all GridFTP Endpoint is failed.
*/
throw pe;
} catch (Exception e) {
invocationContext.getExecutionContext().getNotifier().executionFail(invocationContext,e,readLastLinesofStdOut(localStdErrFile.getPath(), 20));
throw new ProviderException(e.getMessage(), e);
}
}