Search in sources :

Example 6 with GATContext

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

the class LogicalFileAdaptorTest method test.

public AdaptorTestResult test(String adaptor, String[] hosts) throws URISyntaxException {
    if (hosts.length != 4) {
        System.out.println("please provide 4 hosts (comma separated, no spaces)");
        System.exit(1);
    }
    AdaptorTestResult adaptorTestResult = new AdaptorTestResult(adaptor, hosts[0]);
    GATContext gatContext = new GATContext();
    Preferences preferences = new Preferences();
    preferences.put("logicalfile.adaptor.name", adaptor);
    LogicalFile logicalFile = null;
    try {
        logicalFile = GAT.createLogicalFile(gatContext, preferences, "test-logical-file", LogicalFile.CREATE);
    } catch (GATObjectCreationException e) {
        e.printStackTrace();
        GAT.end();
        System.exit(1);
    }
    adaptorTestResult.put("replicate [0]", replicateTest(gatContext, preferences, logicalFile, new URI("any://" + hosts[0] + "/JavaGAT-test-logical-file"), false));
    adaptorTestResult.put("add       [0]", addTest(gatContext, preferences, logicalFile, new URI("any://" + hosts[0] + "/JavaGAT-test-logical-file"), true));
    adaptorTestResult.put("add false [1]", addTest(gatContext, preferences, logicalFile, new URI("any://" + hosts[1] + "/JavaGAT-test-logical-file"), false));
    adaptorTestResult.put("replicate [1]", replicateTest(gatContext, preferences, logicalFile, new URI("any://" + hosts[1] + "/JavaGAT-test-logical-file"), true));
    adaptorTestResult.put("remove    [1]", removeTest(gatContext, preferences, logicalFile, new URI("any://" + hosts[1] + "/JavaGAT-test-logical-file"), true));
    adaptorTestResult.put("add true  [1]", addTest(gatContext, preferences, logicalFile, new URI("any://" + hosts[1] + "/JavaGAT-test-logical-file"), true));
    adaptorTestResult.put("replicate2[1]", replicateTest(gatContext, preferences, logicalFile, new URI("any://" + hosts[1] + "/JavaGAT-test-logical-file"), false));
    adaptorTestResult.put("replicate [2]", replicateTest(gatContext, preferences, logicalFile, new URI("any://" + hosts[2] + "/JavaGAT-test-logical-file"), true));
    adaptorTestResult.put("closest   [3]", closestTest(gatContext, preferences, logicalFile, new URI("any://" + hosts[3] + "/JavaGAT-test-logical-file"), true));
    return adaptorTestResult;
}
Also used : GATContext(org.gridlab.gat.GATContext) GATObjectCreationException(org.gridlab.gat.GATObjectCreationException) LogicalFile(org.gridlab.gat.io.LogicalFile) Preferences(org.gridlab.gat.Preferences) URI(org.gridlab.gat.URI)

Example 7 with GATContext

use of org.gridlab.gat.GATContext 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 8 with GATContext

use of org.gridlab.gat.GATContext 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 9 with GATContext

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

the class GATAdaptor method init.

public void init() {
    // Create request queues
    copyQueue = new RequestQueue<DataOperation>();
    safeQueue = new RequestQueue<DataOperation>();
    String adaptor = System.getProperty(COMPSsConstants.GAT_FILE_ADAPTOR);
    if (debug) {
        logger.debug("Initializing GAT");
    }
    pool = new ThreadPool(GAT_POOL_SIZE, POOL_NAME, new Dispatcher(copyQueue));
    try {
        pool.startThreads();
    } catch (Exception e) {
        ErrorManager.error(THREAD_POOL_ERR, e);
    }
    safePool = new ThreadPool(SAFE_POOL_SIZE, SAFE_POOL_NAME, new Dispatcher(safeQueue));
    try {
        safePool.startThreads();
    } catch (Exception e) {
        ErrorManager.error(THREAD_POOL_ERR, e);
    }
    // GAT adaptor path
    if (debug) {
        logger.debug("Initializing GAT Tranfer Context");
    }
    transferContext = new GATContext();
    /*
         * We need to try the local adaptor when both source and target hosts are local, because ssh file adaptor cannot
         * perform local operations
         */
    transferContext.addPreference("File.adaptor.name", adaptor + ", srcToLocalToDestCopy, local");
}
Also used : DataOperation(es.bsc.compss.types.data.operation.DataOperation) GATContext(org.gridlab.gat.GATContext) ThreadPool(es.bsc.compss.util.ThreadPool) Dispatcher(es.bsc.compss.comm.Dispatcher) URISyntaxException(java.net.URISyntaxException) ConstructConfigurationException(es.bsc.compss.exceptions.ConstructConfigurationException)

Example 10 with GATContext

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

the class AdvertJob method main.

public static void main(String[] args) throws Exception {
    try {
        GATContext c = new GATContext();
        Preferences prefs = new Preferences();
        prefs.put("File.adaptor.name", "local,commandlinessh");
        prefs.put("job.stop.on.exit", "false");
        c.addPreferences(prefs);
        SoftwareDescription sd = new SoftwareDescription();
        sd.setExecutable("/bin/sleep");
        sd.setArguments("100");
        // stdout & stderr
        File stdout = GAT.createFile(c, "std.out");
        File stderr = GAT.createFile(c, "std.err");
        sd.setStderr(stderr);
        sd.setStdout(stdout);
        ResourceDescription rd = new HardwareResourceDescription();
        JobDescription jd = new JobDescription(sd, rd);
        ResourceBroker broker = GAT.createResourceBroker(c, new URI("sshsge://fs0.das3.cs.vu.nl"));
        Job job = broker.submitJob(jd);
        AdvertService a = GAT.createAdvertService(c);
        MetaData m = new MetaData();
        m.put("name", "testJob");
        a.add(job, m, "/rob/testJob");
        a.exportDataBase(new URI("file:///mydb"));
        GAT.end();
        System.exit(0);
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
Also used : GATContext(org.gridlab.gat.GATContext) ResourceBroker(org.gridlab.gat.resources.ResourceBroker) HardwareResourceDescription(org.gridlab.gat.resources.HardwareResourceDescription) AdvertService(org.gridlab.gat.advert.AdvertService) URI(org.gridlab.gat.URI) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription) JobDescription(org.gridlab.gat.resources.JobDescription) ResourceDescription(org.gridlab.gat.resources.ResourceDescription) HardwareResourceDescription(org.gridlab.gat.resources.HardwareResourceDescription) MetaData(org.gridlab.gat.advert.MetaData) Preferences(org.gridlab.gat.Preferences) Job(org.gridlab.gat.resources.Job) File(org.gridlab.gat.io.File)

Aggregations

GATContext (org.gridlab.gat.GATContext)15 Preferences (org.gridlab.gat.Preferences)11 URI (org.gridlab.gat.URI)8 File (org.gridlab.gat.io.File)5 GATObjectCreationException (org.gridlab.gat.GATObjectCreationException)4 CertificateSecurityContext (org.gridlab.gat.security.CertificateSecurityContext)4 PasswordSecurityContext (org.gridlab.gat.security.PasswordSecurityContext)4 URISyntaxException (java.net.URISyntaxException)3 Job (org.gridlab.gat.resources.Job)3 JobDescription (org.gridlab.gat.resources.JobDescription)3 ResourceBroker (org.gridlab.gat.resources.ResourceBroker)3 SoftwareDescription (org.gridlab.gat.resources.SoftwareDescription)3 AdvertService (org.gridlab.gat.advert.AdvertService)2 Dispatcher (es.bsc.compss.comm.Dispatcher)1 ConstructConfigurationException (es.bsc.compss.exceptions.ConstructConfigurationException)1 DataOperation (es.bsc.compss.types.data.operation.DataOperation)1 ThreadPool (es.bsc.compss.util.ThreadPool)1 MetaData (org.gridlab.gat.advert.MetaData)1 FileInputStream (org.gridlab.gat.io.FileInputStream)1 FileOutputStream (org.gridlab.gat.io.FileOutputStream)1