use of org.gridlab.gat.io.File in project compss by bsc-wdc.
the class GATJob method processMetricEvent.
// MetricListener interface implementation
@Override
public void processMetricEvent(MetricEvent value) {
Job job = (Job) value.getSource();
JobState newJobState = (JobState) value.getValue();
JobDescription jd = (JobDescription) job.getJobDescription();
SoftwareDescription sd = jd.getSoftwareDescription();
Integer jobId = (Integer) sd.getAttributes().get("jobId");
logger.debug("Processing job ID = " + jobId);
/*
* Check if either the job has finished or there has been a submission error. We don't care about other state
* transitions
*/
if (newJobState == JobState.STOPPED) {
if (Tracer.isActivated()) {
Integer slot = (Integer) sd.getAttributes().get("slot");
String host = getResourceNode().getHost();
Tracer.freeSlot(host, slot);
}
/*
* We must check whether the chosen adaptor is globus In that case, since globus doesn't provide the exit
* status of a job, we must examine the standard error file
*/
try {
if (usingGlobus) {
File errFile = sd.getStderr();
// Error file should always be in the same host as the IT
File localFile = GAT.createFile(context, errFile.toGATURI());
if (localFile.length() > 0) {
GATjob = null;
RUNNING_JOBS.remove(this);
ErrorManager.warn("Error when creating file.");
listener.jobFailed(this, JobEndStatus.EXECUTION_FAILED);
} else {
if (!debug) {
localFile.delete();
}
RUNNING_JOBS.remove(this);
listener.jobCompleted(this);
}
} else {
if (job.getExitStatus() == 0) {
RUNNING_JOBS.remove(this);
listener.jobCompleted(this);
} else {
GATjob = null;
RUNNING_JOBS.remove(this);
listener.jobFailed(this, JobEndStatus.EXECUTION_FAILED);
}
}
} catch (Exception e) {
ErrorManager.fatal(CALLBACK_PROCESSING_ERR + ": " + this, e);
}
} else if (newJobState == JobState.SUBMISSION_ERROR) {
if (Tracer.isActivated()) {
Integer slot = (Integer) sd.getAttributes().get("slot");
String host = getResourceNode().getHost();
Tracer.freeSlot(host, slot);
}
try {
if (usingGlobus && job.getInfo().get("resManError").equals("NO_ERROR")) {
RUNNING_JOBS.remove(this);
listener.jobCompleted(this);
} else {
GATjob = null;
RUNNING_JOBS.remove(this);
listener.jobFailed(this, JobEndStatus.SUBMISSION_FAILED);
}
} catch (GATInvocationException e) {
ErrorManager.fatal(CALLBACK_PROCESSING_ERR + ": " + this, e);
}
}
}
use of org.gridlab.gat.io.File in project compss by bsc-wdc.
the class GATJob method processParameters.
private void processParameters(String sandboxPath, ArrayList<String> symlinks, ArrayList<String> lArgs) {
logger.debug("Processing parameters for GAT job " + this.jobId);
lArgs.add(Boolean.toString(taskParams.hasTargetObject()));
// Add return type
if (taskParams.hasReturnValue()) {
Parameter returnParam = taskParams.getParameters()[taskParams.getParameters().length - 1];
lArgs.add(Integer.toString(returnParam.getType().ordinal()));
} else {
lArgs.add("null");
}
// Add parameters
int numParams = taskParams.getParameters().length;
if (taskParams.hasReturnValue()) {
numParams--;
}
lArgs.add(Integer.toString(numParams));
for (Parameter param : taskParams.getParameters()) {
DataType type = param.getType();
lArgs.add(Integer.toString(type.ordinal()));
lArgs.add(Integer.toString(param.getStream().ordinal()));
String prefix = param.getPrefix();
if (prefix == null || prefix.isEmpty()) {
prefix = Constants.PREFIX_EMTPY;
}
lArgs.add(param.getPrefix());
switch(type) {
case FILE_T:
DependencyParameter dFilePar = (DependencyParameter) param;
java.io.File f = new java.io.File(dFilePar.getDataTarget());
if (!f.getName().equals(dFilePar.getOriginalName())) {
// Add file to manage symlinks and renames
String originalName = sandboxPath + File.separator + dFilePar.getOriginalName();
symlinks.add(dFilePar.getDataTarget());
symlinks.add(dFilePar.getOriginalName());
lArgs.add(originalName);
} else {
// Original and target is the same nothing to do
lArgs.add(dFilePar.getDataTarget());
}
break;
case PSCO_T:
case EXTERNAL_OBJECT_T:
logger.error("GAT Adaptor does not support PSCO Types");
listener.jobFailed(this, JobEndStatus.SUBMISSION_FAILED);
break;
case OBJECT_T:
DependencyParameter dPar = (DependencyParameter) param;
DataAccessId dAccId = dPar.getDataAccessId();
lArgs.add(dPar.getDataTarget());
if (dAccId instanceof RAccessId) {
lArgs.add("R");
} else {
// for the worker to know it must write the object to disk
lArgs.add("W");
}
break;
case STRING_T:
BasicTypeParameter btParS = (BasicTypeParameter) param;
// Check spaces
String value = btParS.getValue().toString();
int numSubStrings = value.split(" ").length;
lArgs.add(Integer.toString(numSubStrings));
lArgs.add(value);
break;
default:
// Basic Types
BasicTypeParameter btParB = (BasicTypeParameter) param;
lArgs.add(btParB.getValue().toString());
break;
}
}
}
use of org.gridlab.gat.io.File in project compss by bsc-wdc.
the class LoadLevelerJob method waitForTrigger.
// Wait for the creation of a special file (by the application).
void waitForTrigger(JobState state) throws GATInvocationException {
if (triggerDirectory == null) {
return;
}
if (jobName == null) {
return;
}
if (waiter == null) {
try {
waiter = FileWaiter.createFileWaiter(GAT.createFile(gatContext, triggerDirectory));
} catch (GATObjectCreationException e) {
throw new GATInvocationException("Could not create", e);
}
}
String filename = jobName + "." + state.toString().substring(0, 3);
File file;
try {
file = GAT.createFile(gatContext, triggerDirectory + "/" + filename);
} catch (GATObjectCreationException e) {
throw new GATInvocationException("Could not create");
}
if (logger.isDebugEnabled()) {
logger.debug("Waiting for " + filename + " in directory " + triggerDirectory);
}
waiter.waitFor(filename);
if (logger.isDebugEnabled()) {
logger.debug("Finished waiting for " + filename + " in directory " + triggerDirectory);
}
synchronized (this.getClass()) {
if (!file.delete()) {
if (logger.isDebugEnabled()) {
logger.debug("Could not remove " + file.toGATURI());
}
}
}
}
use of org.gridlab.gat.io.File in project compss by bsc-wdc.
the class LsfJob method waitForTrigger.
// Wait for the creation of a special file (by the application).
void waitForTrigger(JobState state) throws GATInvocationException {
if (triggerDirectory == null) {
return;
}
if (jobName == null) {
return;
}
if (waiter == null) {
try {
waiter = FileWaiter.createFileWaiter(GAT.createFile(gatContext, triggerDirectory));
} catch (GATObjectCreationException e) {
throw new GATInvocationException("Could not create", e);
}
}
String filename = jobName + "." + state.toString().substring(0, 3);
File file;
try {
file = GAT.createFile(gatContext, triggerDirectory + "/" + filename);
} catch (GATObjectCreationException e) {
throw new GATInvocationException("Could not create");
}
if (logger.isDebugEnabled()) {
logger.debug("Waiting for " + filename + " in directory " + triggerDirectory);
}
waiter.waitFor(filename);
if (logger.isDebugEnabled()) {
logger.debug("Finished waiting for " + filename + " in directory " + triggerDirectory);
}
synchronized (this.getClass()) {
if (!file.delete()) {
if (logger.isDebugEnabled()) {
logger.debug("Could not remove " + file.toGATURI());
}
}
}
}
use of org.gridlab.gat.io.File in project compss by bsc-wdc.
the class FileExample method start.
public void start(URI uri1, URI uri2, URI uri3) {
File file1 = null;
try {
file1 = GAT.createFile(uri1);
} catch (GATObjectCreationException e) {
System.err.println("failed to create file1 at location '" + uri1 + "': " + e);
return;
}
try {
file1.copy(uri2);
System.out.println("file1 at location '" + uri1 + "' copied to file2 at location '" + uri2 + "'");
} catch (GATInvocationException e) {
System.err.println("failed to copy file1 at location '" + uri1 + "' to file2 at location '" + uri2 + "': " + e);
return;
}
file1.delete();
System.out.println("file1 at location '" + uri1 + "' deleted");
File file2 = null;
try {
file2 = GAT.createFile(uri2);
} catch (GATObjectCreationException e) {
System.err.println("failed to create file2 at location '" + uri2 + "': " + e);
return;
}
try {
file2.move(uri3);
System.out.println("file2 at location '" + uri2 + "' moved to file3 at location '" + uri3 + "'");
} catch (GATInvocationException e) {
System.err.println("failed to move file2 at location '" + uri2 + "' to file3 at location '" + uri3 + "': " + e);
return;
}
}
Aggregations