}
public void executeApplication(InvocationContext context) throws ProviderException {
ApplicationDeploymentDescriptionType app = context.getExecutionDescription().getApp().getType();
Session session = null;
try {
session = getSession(context);
/*
* Going to working Directory
*/
session.exec("cd " + app.getStaticWorkingDirectory());
// get the env of the host and the application
NameValuePairType[] env = app.getApplicationEnvironmentArray();
Map<String, String> nv = new HashMap<String, String>();
if (env != null) {
for (int i = 0; i < env.length; i++) {
String key = env[i].getName();
String value = env[i].getValue();
nv.put(key, value);
}
}
// extra env's
nv.put(GFacConstants.INPUT_DATA_DIR_VAR_NAME, app.getInputDataDirectory());
nv.put(GFacConstants.OUTPUT_DATA_DIR_VAR_NAME, app.getOutputDataDirectory());
/*
* Set environment
*/
log.info("Command = " + command);
for (Entry<String, String> entry : nv.entrySet()) {
log.info("Env[" + entry.getKey() + "] = " + entry.getValue());
session.setEnvVar(entry.getKey(), entry.getValue());
}
/*
* Execute
*/
Command cmd = session.exec(command);
log.info("stdout=" + GfacUtils.readFromStream(session.getInputStream()));
cmd.join(COMMAND_EXECUTION_TIMEOUT, TimeUnit.SECONDS);
/*
* check return value. usually not very helpful to draw conclusions based on return values so don't bother.
* just provide warning in the log messages