Search in sources :

Example 26 with URI

use of org.gridlab.gat.URI 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 27 with URI

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

the class TestSubmitGlobus method test.

public void test(final String host) throws Exception {
    final SoftwareDescription sd = new SoftwareDescription();
    sd.setExecutable("/bin/sleep");
    sd.setArguments("10");
    final JobDescription jd = new JobDescription(sd);
    Preferences prefs = new Preferences();
    prefs.put("resourcebroker.adaptor.name", "wsgt4new");
    prefs.put("file.adaptor.name", "local,gridftp");
    CertificateSecurityContext ctxt = new CertificateSecurityContext(new URI(System.getProperty("user.home") + "/.globus/userkey.pem"), new URI(System.getProperty("user.home") + "/.globus/usercert.pem"), getPassphrase());
    final GATContext context = new GATContext();
    context.addPreferences(prefs);
    context.addSecurityContext(ctxt);
    File[] files = new File[NFILES];
    for (int i = 0; i < files.length; i++) {
        files[i] = GAT.createFile(context, "file" + i);
        files[i].createNewFile();
    }
    for (File f : files) {
        sd.addPreStagedFile(f);
        sd.addPostStagedFile(f);
    }
    final ResourceBroker broker = GAT.createResourceBroker(context, new URI(host));
    for (int j = 0; j < NBATCHES; j++) {
        logger.info("Starting a batch of " + NJOBS + " jobs");
        for (int i = 0; i < NJOBS; i++) {
            Thread t = new Thread() {

                public void run() {
                    try {
                        broker.submitJob(jd, TestSubmitGlobus.this, "job.status");
                    } catch (Throwable e) {
                        System.out.println("Submit failed");
                        e.printStackTrace();
                        synchronized (TestSubmitGlobus.this) {
                            finished++;
                            TestSubmitGlobus.this.notifyAll();
                        }
                    }
                }
            };
            t.start();
        }
        synchronized (this) {
            while (finished < NJOBS * (j - BACK)) {
                logger.info("Waiting until at least " + (NJOBS * (j - BACK)) + " jobs are finished");
                try {
                    wait();
                } catch (Throwable e) {
                // ignore
                }
            }
        }
    }
    synchronized (this) {
        while (finished != NJOBS * NBATCHES) {
            try {
                wait();
            } catch (Throwable e) {
            // ignore
            }
        }
    }
}
Also used : JobDescription(org.gridlab.gat.resources.JobDescription) GATContext(org.gridlab.gat.GATContext) CertificateSecurityContext(org.gridlab.gat.security.CertificateSecurityContext) ResourceBroker(org.gridlab.gat.resources.ResourceBroker) Preferences(org.gridlab.gat.Preferences) URI(org.gridlab.gat.URI) File(org.gridlab.gat.io.File) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription)

Example 28 with URI

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

the class RemoteCat method main.

public static void main(String[] args) throws Exception {
    FileInputStream in = GAT.createFileInputStream(new URI(args[0]));
    java.io.InputStreamReader reader = new java.io.InputStreamReader(in);
    java.io.BufferedReader buf = new java.io.BufferedReader(reader);
    while (true) {
        String result = buf.readLine();
        if (result == null) {
            break;
        }
        System.out.println(result);
    }
    in.close();
    GAT.end();
}
Also used : URI(org.gridlab.gat.URI) FileInputStream(org.gridlab.gat.io.FileInputStream)

Example 29 with URI

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

the class SubmitJobCallback method start.

public void start(String brokerURI) throws GATObjectCreationException, URISyntaxException, GATInvocationException {
    SoftwareDescription sd = new SoftwareDescription();
    sd.setExecutable("/bin/hostname");
    File stdout = GAT.createFile("hostname.txt");
    sd.setStdout(stdout);
    JobDescription jd = new JobDescription(sd);
    ResourceBroker broker = GAT.createResourceBroker(new URI(brokerURI));
    broker.submitJob(jd, this, "job.status");
    synchronized (this) {
        try {
            wait();
        } catch (InterruptedException e) {
        // ignore
        }
    }
}
Also used : JobDescription(org.gridlab.gat.resources.JobDescription) ResourceBroker(org.gridlab.gat.resources.ResourceBroker) File(org.gridlab.gat.io.File) URI(org.gridlab.gat.URI) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription)

Example 30 with URI

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

the class SecurityExample method main.

/**
 * This example shows the use of the SecurityContext objects in JavaGAT.
 *
 * This example will attach various security contexts to a GATContext. Then
 * it will try to create the same file with and without this GATContext.
 * Note that you've to replace the arguments of the methods with values that
 * are suitable for your environment. Please don't put passwords and
 * passphrases directly in the source code, but try to retrieve by having
 * the user to type it.
 *
 * @param args
 *                a String representation of a valid JavaGAT uri that points
 *                to a file
 */
public static void main(String[] args) {
    GATContext context = new GATContext();
    try {
        // create a certificate security context
        CertificateSecurityContext globusSecurityContext = new CertificateSecurityContext(new URI("userkey.pem"), new URI("usercert.pem"), "grid-proxy-init passphrase");
        // add a note to this security context; it's only to be used for the
        // globus and wsgt4new adaptors
        globusSecurityContext.addNote("adaptors", "globus,wsgt4new");
        context.addSecurityContext(globusSecurityContext);
    } catch (URISyntaxException e) {
    // ignore
    }
    // create a password security context
    PasswordSecurityContext ftpSecurityContext = new PasswordSecurityContext(System.getProperty("user.name"), "ftp password");
    // add a note to this security context; it's only to be used for ftp and
    // only for two hosts, host1 and host2:21
    ftpSecurityContext.addNote("adaptors", "ftp");
    ftpSecurityContext.addNote("hosts", "host1,host2:21");
    context.addSecurityContext(ftpSecurityContext);
    PasswordSecurityContext sshSecurityContext = new PasswordSecurityContext(System.getProperty("user.name"), "ssh password");
    // add a note to this security context; it's only to be used for
    // sshtrilead and commandlinessh and only for one host, host3
    sshSecurityContext.addNote("adaptors", "sshtrilead,commandlinessh");
    sshSecurityContext.addNote("hosts", "host3");
    context.addSecurityContext(sshSecurityContext);
    // contexts attached
    try {
        File file = GAT.createFile(context, new URI(args[0]));
        System.out.println(args[0] + " exists: " + file.exists());
    } catch (Exception e) {
        System.err.println("Failed to check whether '" + args[0] + "' exists: " + e);
    }
    // contexts.
    try {
        File file2 = GAT.createFile(new URI(args[0]));
        System.out.println(args[0] + " exists: " + file2.exists());
    } catch (Exception e) {
        System.err.println("Failed to check whether '" + args[0] + "' exists: " + e);
    }
}
Also used : GATContext(org.gridlab.gat.GATContext) PasswordSecurityContext(org.gridlab.gat.security.PasswordSecurityContext) CertificateSecurityContext(org.gridlab.gat.security.CertificateSecurityContext) URISyntaxException(java.net.URISyntaxException) URI(org.gridlab.gat.URI) File(org.gridlab.gat.io.File) URISyntaxException(java.net.URISyntaxException)

Aggregations

URI (org.gridlab.gat.URI)53 URISyntaxException (java.net.URISyntaxException)28 JobDescription (org.gridlab.gat.resources.JobDescription)28 SoftwareDescription (org.gridlab.gat.resources.SoftwareDescription)27 ResourceBroker (org.gridlab.gat.resources.ResourceBroker)26 GATInvocationException (org.gridlab.gat.GATInvocationException)24 Job (org.gridlab.gat.resources.Job)23 GATObjectCreationException (org.gridlab.gat.GATObjectCreationException)19 Preferences (org.gridlab.gat.Preferences)11 BufferedReader (java.io.BufferedReader)8 File (java.io.File)8 IOException (java.io.IOException)8 GATContext (org.gridlab.gat.GATContext)8 File (org.gridlab.gat.io.File)8 InputStreamReader (java.io.InputStreamReader)5 LinkedList (java.util.LinkedList)4 AdvertService (org.gridlab.gat.advert.AdvertService)4 CertificateSecurityContext (org.gridlab.gat.security.CertificateSecurityContext)4 GATScriptExecutor (es.bsc.compss.gat.master.utils.GATScriptExecutor)3 MultiURI (es.bsc.compss.types.uri.MultiURI)3