String serviceMapStr = registryService.getServiceMap(context.getServiceName());
System.out.println(serviceMapStr);
if (serviceMapStr != null) {
try {
ServiceMapType serviceMap = ServiceMapDocument.Factory.parse(serviceMapStr).getServiceMap();
QName appName = GfacUtils.findApplcationName(serviceMap);
// host name
String hostName = findHostFromServiceMap(registryService, appName);
// app
String appDesc = registryService.getAppDesc(appName.toString(), hostName);
ApplicationDescriptionType appDescType = ApplicationDescriptionDocument.Factory.parse(appDesc).getApplicationDescription();
// host desc
String hostDesc = registryService.getHostDesc(hostName);
HostDescriptionType hostDescType = HostDescriptionDocument.Factory.parse(hostDesc).getHostDescription();
// application deployment
DeploymentDescriptionType deploymentDesc = appDescType.getDeploymentDescription();
String tmpDir = deploymentDesc.getTmpDir();
if (tmpDir == null && hostDescType != null) {
tmpDir = hostDescType.getHostConfiguration().getTmpDir();
}
if (tmpDir == null) {
tmpDir = "/tmp";
}
String date = new Date().toString();
date = date.replaceAll(" ", "_");
date = date.replaceAll(":", "_");
tmpDir = tmpDir + File.separator + appDescType.getApplicationName().getStringValue() + "_" + date + "_" + UUID.randomUUID();
String workingDir = deploymentDesc.getWorkDir();
if (workingDir == null || workingDir.trim().length() == 0) {
workingDir = tmpDir;
}
String stdOut = tmpDir + File.separator + appDescType.getApplicationName().getStringValue() + ".stdout";
String stderr = tmpDir + File.separator + appDescType.getApplicationName().getStringValue() + ".stderr";
String executable = deploymentDesc.getExecutable();
String host = deploymentDesc.getHostName();
NameValuePairType[] env = deploymentDesc.getApplicationEnvArray();
Map<String, String> envMap = new HashMap<String, String>();
if (env != null) {
for (int i = 0; i < env.length; i++) {
envMap.put(env[i].getName(), env[i].getValue());
}
}
String inputDataDir = tmpDir + File.separator + "inputData";
String outputDataDir = tmpDir + File.separator + "outputData";
GlobusGatekeeperType[] gatekeepers = hostDescType.getHostConfiguration().getGlobusGatekeeperArray();
ExecutionModel model = new ExecutionModel();
model.setHost(host);
model.setExecutable(executable);
model.setTmpDir(tmpDir);
model.setWorkingDir(workingDir);
model.setStdOut(stdOut);
model.setStderr(stderr);
model.setInputDataDir(inputDataDir);
model.setOutputDataDir(outputDataDir);
model.setEnv(envMap);
model.setAplicationDesc(appDescType);
model.setHostDesc(hostDescType);
model.setGatekeeper(gatekeepers[0]);
// input parameter
ArrayList<String> tmp = new ArrayList<String>();
for (Iterator<String> iterator = context.getMessageContext(INPUT_MESSAGE_CONTEXT).getParameterNames(); iterator.hasNext();) {
String key = iterator.next();
tmp.add(context.getMessageContext(INPUT_MESSAGE_CONTEXT).getStringParameterValue(key));
}
model.setInputParameters(tmp);
context.getExecutionContext().setExectionModel(model);
// output parameter
//TODO type mapping
if (serviceMap.getPortTypeArray(0).getMethodArray(0).getOutputParameterArray() != null) {
ParameterContextImpl outtmp = new ParameterContextImpl();
for (OutputParameterType output : serviceMap.getPortTypeArray(0).getMethodArray(0).getOutputParameterArray()) {
outtmp.addParameter(output.getParameterName(), output.getParameterType().toString(), new StringParameter());
}
context.addMessageContext(OUTPUT_MESSAGE_CONTEXT, outtmp);
}