public void invoke(JobExecutionContext jobExecutionContext) throws GFacHandlerException {
super.invoke(jobExecutionContext);
int index = 0;
int oldIndex = 0;
List<String> oldFiles = new ArrayList<String>();
MessageContext inputNew = new MessageContext();
StringBuffer data = new StringBuffer("|");
try {
String pluginData = GFacUtils.getPluginData(jobExecutionContext, this.getClass().getName());
if (pluginData != null) {
try {
oldIndex = Integer.parseInt(pluginData.split("\\|")[0].trim());
oldFiles = Arrays.asList(pluginData.split("\\|")[1].split(","));
if (oldIndex == oldFiles.size()) {
log.info("Old data looks good !!!!");
} else {
oldIndex = 0;
oldFiles.clear();
}
} catch (NumberFormatException e) {
log.error("Previously stored data " + pluginData + " is wrong so we continue the operations");
}
}
if (jobExecutionContext.getSecurityContext(SSHSecurityContext.SSH_SECURITY_CONTEXT) == null) {
try {
GFACSSHUtils.addSecurityContext(jobExecutionContext);
} catch (ApplicationSettingsException e) {
log.error(e.getMessage());
throw new GFacHandlerException("Error while creating SSHSecurityContext", e, e.getLocalizedMessage());
}
}
ApplicationDeploymentDescriptionType app = jobExecutionContext.getApplicationContext()
.getApplicationDeploymentDescription().getType();
AuthenticationInfo authenticationInfo = null;
if (password != null) {
authenticationInfo = new DefaultPasswordAuthenticationInfo(this.password);
} else {
authenticationInfo = new DefaultPublicKeyFileAuthentication(this.publicKeyPath, this.privateKeyPath,
this.passPhrase);
}
// Server info
ServerInfo serverInfo = new ServerInfo(this.userName, this.hostName);
Cluster pbsCluster = null;
// here doesn't matter what the job manager is because we are only doing some file handling
// not really dealing with monitoring or job submission, so we pa
pbsCluster = new PBSCluster(serverInfo, authenticationInfo, CommonUtils.getPBSJobManager("/opt/torque/torque-4.2.3.1/bin/"));
String parentPath = inputPath + File.separator + jobExecutionContext.getExperimentID() + File.separator + jobExecutionContext.getTaskData().getTaskID();
if (index < oldIndex) {
parentPath = oldFiles.get(index);
data.append(oldFiles.get(index++)).append(","); // we get already transfered file and increment the index
} else {
(new File(parentPath)).mkdirs();
StringBuffer temp = new StringBuffer(data.append(parentPath).append(",").toString());
GFacUtils.savePluginData(jobExecutionContext, temp.insert(0, ++index), this.getClass().getName());
}
MessageContext input = jobExecutionContext.getInMessageContext();
Set<String> parameters = input.getParameters().keySet();
for (String paramName : parameters) {
ActualParameter actualParameter = (ActualParameter) input.getParameters().get(paramName);
String paramValue = MappingFactory.toString(actualParameter);
//TODO: Review this with type
if ("URI".equals(actualParameter.getType().getType().toString())) {
if (index < oldIndex) {
log.info("Input File: " + paramValue + " is already transfered, so we skip this operation !!!");