public void dispose(JobExecutionContext jobExecutionContext) throws GFacProviderException {
}
private File createShellScript(JobExecutionContext context) throws IOException {
ApplicationDeploymentDescriptionType app = context.getApplicationContext()
.getApplicationDeploymentDescription().getType();
String uniqueDir = app.getApplicationName().getStringValue() + System.currentTimeMillis()
+ new Random().nextLong();
File shellScript = File.createTempFile(uniqueDir, "sh");
OutputStream out = new FileOutputStream(shellScript);
out.write("#!/bin/bash\n".getBytes());
out.write(("cd " + app.getStaticWorkingDirectory() + "\n").getBytes());
out.write(("export " + Constants.INPUT_DATA_DIR_VAR_NAME + "=" + app.getInputDataDirectory() + "\n").getBytes());
out.write(("export " + Constants.OUTPUT_DATA_DIR_VAR_NAME + "=" + app.getOutputDataDirectory() + "\n")
.getBytes());
// 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);
}
}
for (Entry<String, String> entry : nv.entrySet()) {
log.debug("Env[" + entry.getKey() + "] = " + entry.getValue());
out.write(("export " + entry.getKey() + "=" + entry.getValue() + "\n").getBytes());
}
// prepare the command
final String SPACE = " ";
StringBuffer cmd = new StringBuffer();
cmd.append(app.getExecutableLocation());
cmd.append(SPACE);
MessageContext input = context.getInMessageContext();
;
Map<String, Object> inputs = input.getParameters();
Set<String> keys = inputs.keySet();
for (String paramName : keys) {
ActualParameter actualParameter = (ActualParameter) inputs.get(paramName);
if ("URIArray".equals(actualParameter.getType().getType().toString())) {
String[] values = ((URIArrayType) actualParameter.getType()).getValueArray();
for (String value : values) {
cmd.append(value);
cmd.append(SPACE);
}
} else {
String paramValue = MappingFactory.toString(actualParameter);
cmd.append(paramValue);
cmd.append(SPACE);
}
}
// We redirect the error and stdout to remote files, they will be read
// in later
cmd.append(SPACE);
cmd.append("1>");
cmd.append(SPACE);
cmd.append(app.getStandardOutput());
cmd.append(SPACE);
cmd.append("2>");
cmd.append(SPACE);
cmd.append(app.getStandardError());
String cmdStr = cmd.toString();
log.info("Command = " + cmdStr);
out.write((cmdStr + "\n").getBytes());
String message = "\"execuationSuceeded\"";