use of org.gridlab.gat.GATInvocationException in project compss by bsc-wdc.
the class LoadLevelerFileAdaptor method copyDir.
protected void copyDir(File sourceFile, File destFile) throws GATInvocationException {
String sourcePath = sourceFile.getPath();
String destPath = destFile.getPath();
if (logger.isDebugEnabled()) {
logger.debug("copyDir '" + sourcePath + "' to '" + destPath + "'");
}
boolean existingDir = false;
if (destFile.exists()) {
// check whether the target is an existing file
if (!destFile.isDirectory()) {
throw new GATInvocationException("cannot overwrite non-directory '" + destPath + "' with directory '" + sourcePath + "'!");
} else {
existingDir = true;
}
}
if (!existingDir) {
// copy dir a to b will result in a new directory b with contents
// that is a copy of the contents of a.
} else if (gatContext.getPreferences().containsKey("file.directory.copy") && ((String) gatContext.getPreferences().get("file.directory.copy")).equalsIgnoreCase("contents")) {
// don't modify the dest dir, so copy dir a to dir b ends up as
// copying a/* to b/*, note that a/dir/* also ends up in b/*
} else {
// dest.
if (sourcePath.length() > 0) {
int start = sourcePath.lastIndexOf(File.separator) + 1;
String separator = "";
if (!destPath.endsWith(File.separator)) {
separator = File.separator;
}
destPath = destPath + separator + sourcePath.substring(start);
destFile = new File(destPath);
}
}
if (logger.isDebugEnabled()) {
logger.debug("destPath = " + destPath);
}
if (gatContext.getPreferences().containsKey("file.create") && ((String) gatContext.getPreferences().get("file.create")).equalsIgnoreCase("true")) {
destFile.mkdirs();
} else {
// if source is a dir 'dir1' and dest is a dir 'dir2' then the
// result of dir1.copy(dir2) will be dir2/dir1/.. so even if the
// 'file.create' flag isn't set, create the dir1 in dir2 before
// copying the files.
boolean mkdir = destFile.mkdir();
if (logger.isDebugEnabled()) {
logger.debug("mkdir: " + mkdir);
}
}
// list all the files and copy recursively.
File[] files = sourceFile.listFiles();
if (files == null) {
if (logger.isDebugEnabled()) {
logger.debug("copyDirectory: no files in src directory: " + sourcePath);
}
return;
}
for (File file : files) {
if (logger.isDebugEnabled()) {
logger.debug("copyDirectory: file to copy = " + file);
}
String newDestString = destPath;
newDestString += File.separator + file.getName();
if (logger.isDebugEnabled()) {
logger.debug("new dest: " + newDestString);
logger.debug("src is file: " + file.isFile());
logger.debug("src is dir: " + file.isDirectory());
}
File newDest = new File(newDestString);
if (file.isFile()) {
if (logger.isDebugEnabled()) {
logger.debug("copyDir: copying " + file);
}
copy(file, newDest);
} else if (file.isDirectory()) {
copyDir(file, newDest);
} else {
throw new GATInvocationException("don't know how to handle file: " + file.getPath() + " (links are not supported).");
}
}
}
use of org.gridlab.gat.GATInvocationException in project compss by bsc-wdc.
the class LoadLevelerResourceBrokerAdaptor method submitJob.
/*
* (non-Javadoc)
*
* @see org.gridlab.gat.resources.ResourceBroker#submitJob(org.gridlab.gat.resources.JobDescription)
*/
public Job submitJob(AbstractJobDescription abstractDescription, MetricListener listener, String metricDefinitionName) throws GATInvocationException {
if (!(abstractDescription instanceof JobDescription)) {
throw new GATInvocationException("can only handle JobDescriptions: " + abstractDescription.getClass());
}
JobDescription description = (JobDescription) abstractDescription;
SoftwareDescription sd = description.getSoftwareDescription();
if (sd == null) {
throw new GATInvocationException("The job description does not contain a software description");
}
if (description.getProcessCount() < 1) {
throw new GATInvocationException("Adaptor cannot handle: process count < 1: " + description.getProcessCount());
}
if (description.getResourceCount() != 1) {
throw new GATInvocationException("Adaptor cannot handle: resource count > 1: " + description.getResourceCount());
}
String home = System.getProperty("user.home");
if (home == null) {
throw new GATInvocationException("loadleveler broker could not get user home dir");
}
Sandbox sandbox = new Sandbox(gatContext, description, "localhost", home, true, true, false, false);
LoadLevelerJob loadlevelerJob = new LoadLevelerJob(gatContext, description, sandbox);
Job job = null;
if (description instanceof WrapperJobDescription) {
WrapperJobCpi tmp = new WrapperJobCpi(gatContext, loadlevelerJob, listener, metricDefinitionName);
listener = tmp;
job = tmp;
} else {
job = loadlevelerJob;
}
if (listener != null && metricDefinitionName != null) {
Metric metric = loadlevelerJob.getMetricDefinitionByName(metricDefinitionName).createMetric(null);
loadlevelerJob.addMetricListener(listener, metric);
}
loadlevelerJob.setState(Job.JobState.PRE_STAGING);
loadlevelerJob.waitForTrigger(Job.JobState.PRE_STAGING);
sandbox.prestage();
String exe;
if (sandbox.getResolvedExecutable() != null) {
exe = sandbox.getResolvedExecutable().getPath();
// try to set the executable bit, it might be lost
/* CDIAZ: The command "exe" can be also in a remote host
* The command must have the right permissions in the remote host
try {
new CommandRunner("chmod", "+x", exe);
} catch (Throwable t) {
// ignore
}
*/
} else {
exe = getExecutable(description);
}
String[] args = getArgumentsArray(description);
// Directory where the loadleveler command will be executed
java.io.File f = new java.io.File(sandbox.getSandboxPath());
if (!f.exists()) {
throw new GATInvocationException("Unable to find directory " + f.getAbsolutePath());
}
// Check and set the environment for a blaunch command
Map<String, Object> env = sd.getEnvironment();
this.prepareBLaunchEnv(env);
// Encapsulate the original command into a blaunch command
String host = brokerURI.getHost();
String newExe = this.getLoadLevelerCommand();
String[] newArgs = this.getLoadLevelerArgs(host, exe, args);
System.out.println("[AFTER] exe: " + newExe);
System.out.println("[AFTER] llspawan.stdio args:");
for (int i = 0; i < newArgs.length; i++) System.out.print(" " + newArgs[i]);
System.out.println();
ProcessBundle bundle = new ProcessBundle(description.getProcessCount(), newExe, newArgs, f, env);
loadlevelerJob.setSubmissionTime();
loadlevelerJob.setState(Job.JobState.SCHEDULED);
try {
loadlevelerJob.setState(Job.JobState.RUNNING);
loadlevelerJob.waitForTrigger(Job.JobState.RUNNING);
loadlevelerJob.setStartTime();
bundle.startBundle();
loadlevelerJob.setProcess(bundle);
if (logger.isDebugEnabled()) {
logger.debug("Job with PID: " + LOADL_PID + " is executed on host " + host);
}
} catch (IOException e) {
throw new CommandNotFoundException("LoadLevelerResourceBrokerAdaptor", e);
}
if (!sd.streamingStderrEnabled()) {
try {
if (sd.getStderr() != null) {
OutputStream err = GAT.createFileOutputStream(gatContext, sd.getStderr());
// to file
StreamForwarder forwarder = new StreamForwarder(bundle.getStderr(), err, sd.getExecutable() + " [stderr]");
loadlevelerJob.setErrorStream(forwarder);
if (logger.isDebugEnabled()) {
logger.debug("Created stderr forwarder to file " + sd.getStderr());
}
} else {
// or throw it away
new StreamForwarder(bundle.getStderr(), null, sd.getExecutable() + " [stderr]");
}
} catch (GATObjectCreationException e) {
throw new GATInvocationException("Unable to create file output stream for stderr!", e);
}
}
if (!sd.streamingStdoutEnabled()) {
// read away the stdout
try {
if (sd.getStdout() != null) {
// to file
OutputStream out = GAT.createFileOutputStream(gatContext, sd.getStdout());
StreamForwarder forwarder = new StreamForwarder(bundle.getStdout(), out, sd.getExecutable() + " [stdout]");
loadlevelerJob.setOutputStream(forwarder);
if (logger.isDebugEnabled()) {
logger.debug("Created stdout forwarder to file " + sd.getStdout());
}
} else {
// or throw it away
new StreamForwarder(bundle.getStdout(), null, sd.getExecutable() + " [stdout]");
}
} catch (GATObjectCreationException e) {
throw new GATInvocationException("Unable to create file output stream for stdout!", e);
}
}
if (!sd.streamingStdinEnabled() && sd.getStdin() != null) {
// forward the stdin from file
try {
InputStream in = GAT.createFileInputStream(gatContext, sd.getStdin());
bundle.setStdin(sd.getExecutable(), in);
} catch (GATObjectCreationException e) {
throw new GATInvocationException("Unable to create file input stream for stdin!", e);
}
}
loadlevelerJob.monitorState();
return job;
}
use of org.gridlab.gat.GATInvocationException in project compss by bsc-wdc.
the class LsfFileAdaptor method listFiles.
/*
* (non-Javadoc)
*
* @see org.gridlab.gat.io.File#listFiles(java.io.FilenameFilter)
*/
public org.gridlab.gat.io.File[] listFiles(FilenameFilter arg0) throws GATInvocationException {
File[] r = f.listFiles(arg0);
ArrayList<File> l = new ArrayList<File>();
for (int i = 0; i < r.length; i++) {
if (!(ignoreHiddenFiles && r[i].isHidden())) {
l.add(r[i]);
}
}
org.gridlab.gat.io.File[] res = new org.gridlab.gat.io.File[r.length];
for (int i = 0; i < res.length; i++) {
try {
res[i] = GAT.createFile(gatContext, localToURI(l.get(i).getPath()));
} catch (Exception e) {
throw new GATInvocationException("LsfFile", e);
}
}
return res;
}
use of org.gridlab.gat.GATInvocationException in project compss by bsc-wdc.
the class LsfFileAdaptor method copyDir.
protected void copyDir(File sourceFile, File destFile) throws GATInvocationException {
String sourcePath = sourceFile.getPath();
String destPath = destFile.getPath();
if (logger.isDebugEnabled()) {
logger.debug("copyDir '" + sourcePath + "' to '" + destPath + "'");
}
boolean existingDir = false;
if (destFile.exists()) {
// check whether the target is an existing file
if (!destFile.isDirectory()) {
throw new GATInvocationException("cannot overwrite non-directory '" + destPath + "' with directory '" + sourcePath + "'!");
} else {
existingDir = true;
}
}
if (!existingDir) {
// copy dir a to b will result in a new directory b with contents
// that is a copy of the contents of a.
} else if (gatContext.getPreferences().containsKey("file.directory.copy") && ((String) gatContext.getPreferences().get("file.directory.copy")).equalsIgnoreCase("contents")) {
// don't modify the dest dir, so copy dir a to dir b ends up as
// copying a/* to b/*, note that a/dir/* also ends up in b/*
} else {
// dest.
if (sourcePath.length() > 0) {
int start = sourcePath.lastIndexOf(File.separator) + 1;
String separator = "";
if (!destPath.endsWith(File.separator)) {
separator = File.separator;
}
destPath = destPath + separator + sourcePath.substring(start);
destFile = new File(destPath);
}
}
if (logger.isDebugEnabled()) {
logger.debug("destPath = " + destPath);
}
if (gatContext.getPreferences().containsKey("file.create") && ((String) gatContext.getPreferences().get("file.create")).equalsIgnoreCase("true")) {
destFile.mkdirs();
} else {
// if source is a dir 'dir1' and dest is a dir 'dir2' then the
// result of dir1.copy(dir2) will be dir2/dir1/.. so even if the
// 'file.create' flag isn't set, create the dir1 in dir2 before
// copying the files.
boolean mkdir = destFile.mkdir();
if (logger.isDebugEnabled()) {
logger.debug("mkdir: " + mkdir);
}
}
// list all the files and copy recursively.
File[] files = sourceFile.listFiles();
if (files == null) {
if (logger.isDebugEnabled()) {
logger.debug("copyDirectory: no files in src directory: " + sourcePath);
}
return;
}
for (File file : files) {
if (logger.isDebugEnabled()) {
logger.debug("copyDirectory: file to copy = " + file);
}
String newDestString = destPath;
newDestString += File.separator + file.getName();
if (logger.isDebugEnabled()) {
logger.debug("new dest: " + newDestString);
logger.debug("src is file: " + file.isFile());
logger.debug("src is dir: " + file.isDirectory());
}
File newDest = new File(newDestString);
if (file.isFile()) {
if (logger.isDebugEnabled()) {
logger.debug("copyDir: copying " + file);
}
copy(file, newDest);
} else if (file.isDirectory()) {
copyDir(file, newDest);
} else {
throw new GATInvocationException("don't know how to handle file: " + file.getPath() + " (links are not supported).");
}
}
}
use of org.gridlab.gat.GATInvocationException in project compss by bsc-wdc.
the class LsfFileAdaptor method listFiles.
/*
* (non-Javadoc)
*
* @see org.gridlab.gat.io.File#listFiles(java.io.FileFilter)
*/
public org.gridlab.gat.io.File[] listFiles(FileFilter arg0) throws GATInvocationException {
File[] r = f.listFiles(arg0);
ArrayList<File> l = new ArrayList<File>();
for (int i = 0; i < r.length; i++) {
if (!(ignoreHiddenFiles && r[i].isHidden())) {
l.add(r[i]);
}
}
org.gridlab.gat.io.File[] res = new org.gridlab.gat.io.File[r.length];
for (int i = 0; i < res.length; i++) {
try {
res[i] = GAT.createFile(gatContext, localToURI(l.get(i).getPath()));
} catch (Exception e) {
throw new GATInvocationException("LsfFile", e);
}
}
return res;
}
Aggregations