Search in sources :

Example 36 with GATInvocationException

use of org.gridlab.gat.GATInvocationException in project compss by bsc-wdc.

the class ResourceBrokerCallBackExample method start.

public void start(String brokerURI) {
    ResourceBroker broker = null;
    Preferences prefs = new Preferences();
    try {
        broker = GAT.createResourceBroker(prefs, new URI(brokerURI));
    } catch (GATObjectCreationException e) {
        System.err.println("Failed to create resource broker at location '" + brokerURI + "': " + e);
        return;
    } catch (URISyntaxException e) {
        System.err.println("Wrong uri '" + brokerURI + "': " + e);
        return;
    }
    SoftwareDescription sd = new SoftwareDescription();
    sd.setExecutable("/bin/hostname");
    try {
        sd.setStdout(GAT.createFile("hostname.txt"));
    } catch (GATObjectCreationException e) {
        System.err.println("Failed to create the stdout file 'hostname.txt': " + e);
        return;
    }
    JobDescription jd = new JobDescription(sd);
    try {
        broker.submitJob(jd, this, "job.status");
    } catch (GATInvocationException e) {
        System.err.println("Failed to submit the job: " + e);
        return;
    }
    synchronized (this) {
        try {
            wait();
        } catch (InterruptedException e) {
        // ignore
        }
    }
}
Also used : JobDescription(org.gridlab.gat.resources.JobDescription) GATObjectCreationException(org.gridlab.gat.GATObjectCreationException) GATInvocationException(org.gridlab.gat.GATInvocationException) ResourceBroker(org.gridlab.gat.resources.ResourceBroker) URISyntaxException(java.net.URISyntaxException) Preferences(org.gridlab.gat.Preferences) URI(org.gridlab.gat.URI) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription)

Example 37 with GATInvocationException

use of org.gridlab.gat.GATInvocationException in project compss by bsc-wdc.

the class ResourceBrokerPollingExample method start.

public void start(String brokerURI) {
    ResourceBroker broker = null;
    try {
        broker = GAT.createResourceBroker(new URI(brokerURI));
    } catch (GATObjectCreationException e) {
        System.err.println("Failed to create resource broker at location '" + brokerURI + "': " + e);
        return;
    } catch (URISyntaxException e) {
        System.err.println("Wrong uri '" + brokerURI + "': " + e);
        return;
    }
    SoftwareDescription sd = new SoftwareDescription();
    sd.setExecutable("/bin/hostname");
    try {
        sd.setStdout(GAT.createFile("hostname.txt"));
    } catch (GATObjectCreationException e) {
        System.err.println("Failed to create the stdout file 'hostname.txt': " + e);
        return;
    }
    JobDescription jd = new JobDescription(sd);
    Job job = null;
    try {
        job = broker.submitJob(jd);
    } catch (GATInvocationException e) {
        System.err.println("Failed to submit the job: " + e);
        return;
    }
    while (job.getState() != JobState.STOPPED) {
        System.out.println("job is in state: " + job.getState());
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
        // ignore
        }
    }
}
Also used : JobDescription(org.gridlab.gat.resources.JobDescription) GATObjectCreationException(org.gridlab.gat.GATObjectCreationException) GATInvocationException(org.gridlab.gat.GATInvocationException) ResourceBroker(org.gridlab.gat.resources.ResourceBroker) URISyntaxException(java.net.URISyntaxException) Job(org.gridlab.gat.resources.Job) URI(org.gridlab.gat.URI) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription)

Example 38 with GATInvocationException

use of org.gridlab.gat.GATInvocationException in project compss by bsc-wdc.

the class ResourceBrokerJavaJobExample method start.

public void start(String brokerURI) {
    ResourceBroker broker = null;
    try {
        broker = GAT.createResourceBroker(new URI(brokerURI));
    } catch (GATObjectCreationException e) {
        System.err.println("Failed to create resource broker at location '" + brokerURI + "': " + e);
        return;
    } catch (URISyntaxException e) {
        System.err.println("Wrong uri '" + brokerURI + "': " + e);
        return;
    }
    JavaSoftwareDescription sd = new JavaSoftwareDescription();
    sd.setExecutable("/usr/bin/java");
    sd.setJavaMain("my.package.HelloWorld");
    sd.setJavaArguments("hello", "world");
    sd.setJavaClassPath("myJar1:myDir");
    sd.setJavaOptions("-version");
    sd.addJavaSystemProperty("key", "value");
    try {
        sd.setStdout(GAT.createFile("javajob.txt"));
    } catch (GATObjectCreationException e) {
        System.err.println("Failed to create the stdout file 'javajob.txt': " + e);
        return;
    }
    JobDescription jd = new JobDescription(sd);
    Job job = null;
    try {
        job = broker.submitJob(jd);
    } catch (GATInvocationException e) {
        System.err.println("Failed to submit the job: " + e);
        return;
    }
    while (job.getState() != JobState.STOPPED) {
        System.out.println("job is in state: " + job.getState());
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
        // ignore
        }
    }
}
Also used : JavaSoftwareDescription(org.gridlab.gat.resources.JavaSoftwareDescription) JobDescription(org.gridlab.gat.resources.JobDescription) GATObjectCreationException(org.gridlab.gat.GATObjectCreationException) GATInvocationException(org.gridlab.gat.GATInvocationException) ResourceBroker(org.gridlab.gat.resources.ResourceBroker) URISyntaxException(java.net.URISyntaxException) Job(org.gridlab.gat.resources.Job) URI(org.gridlab.gat.URI)

Example 39 with GATInvocationException

use of org.gridlab.gat.GATInvocationException in project compss by bsc-wdc.

the class LoadLevelerFileAdaptor method copy.

/**
 * This method copies the physical file represented by this File instance to
 * a physical file identified by the passed URI.
 *
 * @param destination
 *                The new location
 */
public void copy(URI destination) throws GATInvocationException {
    destination = newcorrectURI(destination);
    String path = getPath();
    String destPath = destination.getPath();
    if (logger.isInfoEnabled()) {
        logger.info("copy of " + path + " to " + destPath);
    }
    if (destPath.equals(path)) {
        if (logger.isInfoEnabled()) {
            logger.info("copy, source is the same file as dest.");
        }
        return;
    }
    File destFile = getFile(destination);
    if (!exists()) {
        throw new GATInvocationException("the source file does not exist, path = " + path);
    }
    if (isDirectory()) {
        if (logger.isDebugEnabled()) {
            logger.debug("copy, it is a dir");
        }
        copyDir(f, destFile);
        return;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("copy, it is a file");
    }
    if (gatContext.getPreferences().containsKey("file.create")) {
        if (((String) gatContext.getPreferences().get("file.create")).equalsIgnoreCase("true")) {
            File destinationParentFile = destFile.getParentFile();
            if (destinationParentFile != null) {
                boolean result = destinationParentFile.mkdirs();
                if (logger.isDebugEnabled()) {
                    logger.debug("new dirs created: " + result);
                }
            }
        }
    }
    // if the destination URI is a dir, append the file name.
    if (destFile.isDirectory()) {
        destPath = destPath + File.separator + getName();
        destFile = new File(destPath);
    }
    try {
        destFile.createNewFile();
    } catch (IOException e) {
        throw new GATInvocationException("Creating file failed", e);
    }
    copy(f, destFile);
}
Also used : GATInvocationException(org.gridlab.gat.GATInvocationException) IOException(java.io.IOException) File(java.io.File)

Example 40 with GATInvocationException

use of org.gridlab.gat.GATInvocationException in project compss by bsc-wdc.

the class LoadLevelerFileAdaptor method listFiles.

/*
     * (non-Javadoc)
     * 
     * @see org.gridlab.gat.io.File#listFiles()
     */
public org.gridlab.gat.io.File[] listFiles() throws GATInvocationException {
    if (!isDirectory()) {
        throw new GATInvocationException("this is not a directory: " + location);
    }
    File[] r = f.listFiles();
    if (r == null) {
        throw new GATInvocationException("IO error in LSF file adaptor");
    }
    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[l.size()];
    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("LoadLevelerFile", e);
        }
    }
    return res;
}
Also used : GATInvocationException(org.gridlab.gat.GATInvocationException) ArrayList(java.util.ArrayList) File(java.io.File) URISyntaxException(java.net.URISyntaxException) GATInvocationException(org.gridlab.gat.GATInvocationException) IOException(java.io.IOException) GATObjectCreationException(org.gridlab.gat.GATObjectCreationException)

Aggregations

GATInvocationException (org.gridlab.gat.GATInvocationException)64 GATObjectCreationException (org.gridlab.gat.GATObjectCreationException)46 URISyntaxException (java.net.URISyntaxException)25 SoftwareDescription (org.gridlab.gat.resources.SoftwareDescription)24 URI (org.gridlab.gat.URI)23 JobDescription (org.gridlab.gat.resources.JobDescription)23 File (java.io.File)22 IOException (java.io.IOException)21 Job (org.gridlab.gat.resources.Job)19 ResourceBroker (org.gridlab.gat.resources.ResourceBroker)17 FileInterface (org.gridlab.gat.io.FileInterface)14 BufferedReader (java.io.BufferedReader)7 FileOutputStream (java.io.FileOutputStream)6 ArrayList (java.util.ArrayList)6 PrintWriter (java.io.PrintWriter)5 InputStreamReader (java.io.InputStreamReader)4 StringWriter (java.io.StringWriter)4 AdaptorNotApplicableException (org.gridlab.gat.AdaptorNotApplicableException)4 Preferences (org.gridlab.gat.Preferences)4 File (org.gridlab.gat.io.File)4