Search in sources :

Example 1 with CertificateSecurityContext

use of org.gridlab.gat.security.CertificateSecurityContext 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 2 with CertificateSecurityContext

use of org.gridlab.gat.security.CertificateSecurityContext 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)

Example 3 with CertificateSecurityContext

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

the class LfnFileCopy method main.

/**
 * @param args
 */
public static void main(String[] args) throws Exception {
    String lfnroot = "lfn:/grid/pvier/ceriel/";
    // Create a new CertificateSecurityContext containing the globus certificates
    // and the user password.
    CertificateSecurityContext securityContext = new CertificateSecurityContext(new URI(System.getProperty("user.home") + "/.globus/userkey.pem"), new URI(System.getProperty("user.home") + "/.globus/usercert.pem"), getPassphrase());
    // Store this SecurityContext in a GATContext
    GATContext context = new GATContext();
    context.addSecurityContext(securityContext);
    context.addPreference("VirtualOrganisation", "pvier");
    context.addPreference("vomsServerUrl", "voms.grid.sara.nl");
    context.addPreference("vomsServerPort", "30000");
    context.addPreference("vomsHostDN", "/O=dutchgrid/O=hosts/OU=sara.nl/CN=voms.grid.sara.nl");
    context.addPreference("LfcServer", "lfc.grid.sara.nl");
    context.addPreference("bdiiURI", "ldap://bdii.grid.sara.nl:2170");
    // context.addPreference("ftp.connection.passive", "false");
    // context.addPreference("ftp.server.noauthentication", "true");
    // context.addPreference("gridftp.authenticate.retry", "5");
    // context.addPreference("preferredSEID", "srm.grid.sara.nl");
    GAT.setDefaultGATContext(context);
    File exampleFile = GAT.createFile(lfnroot + "text.txt");
    exampleFile.copy(new URI("localtext.txt"));
    File exampleFile2 = GAT.createFile("localtext.txt");
    exampleFile2.copy(new URI(lfnroot + "data"));
    GAT.end();
}
Also used : GATContext(org.gridlab.gat.GATContext) CertificateSecurityContext(org.gridlab.gat.security.CertificateSecurityContext) URI(org.gridlab.gat.URI) File(org.gridlab.gat.io.File)

Example 4 with CertificateSecurityContext

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

the class SubmitRemoteJob method main.

public static void main(String[] args) throws Exception {
    SoftwareDescription sd = new SoftwareDescription();
    sd.setExecutable("/bin/hostname");
    File stdout = GAT.createFile("hostname.txt");
    sd.setStdout(stdout);
    JobDescription jd = new JobDescription(sd);
    Preferences prefs = new Preferences();
    /*
        prefs.put("VirtualOrganisation", "pvier");
        prefs.put("vomsServerURL", "voms.grid.sara.nl");
        prefs.put("vomsServerPort", "30000");
        prefs.put("vomsHostDN", "/O=dutchgrid/O=hosts/OU=sara.nl/CN=voms.grid.sara.nl");
        */
    CertificateSecurityContext ctxt = new CertificateSecurityContext(new URI(System.getProperty("user.home") + "/.globus/userkey.pem"), new URI(System.getProperty("user.home") + "/.globus/usercert.pem"), getPassphrase());
    GATContext context = new GATContext();
    context.addPreferences(prefs);
    context.addSecurityContext(ctxt);
    ResourceBroker broker = GAT.createResourceBroker(context, new URI(args[0]));
    Job job = broker.submitJob(jd);
    while ((job.getState() != JobState.STOPPED) && (job.getState() != JobState.SUBMISSION_ERROR)) {
        System.out.println("State: " + job.getState());
        Thread.sleep(1000);
    }
}
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) Job(org.gridlab.gat.resources.Job) File(org.gridlab.gat.io.File) URI(org.gridlab.gat.URI) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription)

Aggregations

GATContext (org.gridlab.gat.GATContext)4 URI (org.gridlab.gat.URI)4 File (org.gridlab.gat.io.File)4 CertificateSecurityContext (org.gridlab.gat.security.CertificateSecurityContext)4 Preferences (org.gridlab.gat.Preferences)2 JobDescription (org.gridlab.gat.resources.JobDescription)2 ResourceBroker (org.gridlab.gat.resources.ResourceBroker)2 SoftwareDescription (org.gridlab.gat.resources.SoftwareDescription)2 URISyntaxException (java.net.URISyntaxException)1 Job (org.gridlab.gat.resources.Job)1 PasswordSecurityContext (org.gridlab.gat.security.PasswordSecurityContext)1