Search in sources :

Example 11 with URI

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

the class FileExample method main.

/**
 * This example shows the use of Files in JavaGAT.
 *
 * This example requires three valid URIs as arguments. At the first URI
 * there should exist a file. This file will be copied to the second URI,
 * then deleted at it's origin, and afterwards moved from the second to the
 * third URI. It's just an example of the File object, there are much more
 * possibilities using the File object.
 *
 * @param args
 *                a String array of size 3 with each element containing a
 *                String representation of a valid URI.
 */
public static void main(String[] args) {
    if (args.length != 3) {
        System.out.println("\tUsage: bin/run_gat_app examples20.FileExample <location1> <location2> <location3> (where location is a valid JavaGAT URI)\n\n" + "\tprogram does:\n" + "\t\tcp <location1> <location2>\n" + "\t\trm <location1>\n" + "\t\tmv <location2> <location3>\n");
        System.exit(1);
    }
    try {
        new FileExample().start(new URI(args[0]), new URI(args[1]), new URI(args[2]));
    } catch (URISyntaxException e) {
        System.out.println(e);
        System.out.println("\tUsage: bin/run_gat_app examples20.FileExample <location1> <location2> <location3> (where location is a valid JavaGAT URI)\n\n" + "\tprogram does:\n" + "\t\tcp <location1> <location2>\n" + "\t\trm <location1>\n" + "\t\tmv <location2> <location3>\n");
        System.exit(1);
    }
    GAT.end();
}
Also used : URISyntaxException(java.net.URISyntaxException) URI(org.gridlab.gat.URI)

Example 12 with URI

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

the class SshLsfResourceBrokerAdaptor method sshLsfSubmission.

/*private java.io.File createJobScript(JobDescription description)
			throws GATInvocationException {

		java.io.File temp;

		SoftwareDescription sd = description.getSoftwareDescription();

		try {
			temp = java.io.File.createTempFile("lsf-sub", null);
		} catch (IOException e) {
			throw new GATInvocationException("Cannot create file", e);
		}
		PrintWriter job = null;
		try {
			job = new PrintWriter(new BufferedWriter(new FileWriter(temp)));

			job.print("#!/bin/sh\n");
			job.print("# job script\n");

			// Support DIRECTORY
			String dir = sd.getStringAttribute(SoftwareDescription.DIRECTORY, null);
			if (dir != null) {
				job.print("cd " + dir + "\n");
			}

			// Support environment.
			Map<String, Object> env = sd.getEnvironment();
			if (env != null) {
				Set<String> s = env.keySet();
				Object[] keys = s.toArray();

				for (int i = 0; i < keys.length; i++) {
					String val = (String) env.get(keys[i]);
					job.print(keys[i] + "=" + val + " && export " + keys[i] + "\n");
				}
			}

			// Construct command.
			StringBuffer cmd = new StringBuffer();

			cmd.append(sd.getExecutable().toString());
			if (sd.getArguments() != null) {
				String[] args = sd.getArguments();
				for (int i = 0; i < args.length; ++i) {
					cmd.append(" ");
					cmd.append(args[i]);
				}
			}
			job.print(cmd.toString() + "\n");
			//job.print("exit $?\n");
		} catch (Throwable e) {
			throw new GATInvocationException(
					"Cannot create temporary job script file "
							+ temp.getAbsolutePath(), e);
		} finally {
			if (job != null)
				job.close();
		}
		return temp;
	}*/
private String sshLsfSubmission(SshLSFJob lsfJob, JobDescription description, java.io.File bsubFile, ResourceBroker subBroker, Sandbox sandbox) throws GATInvocationException {
    java.io.File slurmResultFile = null;
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("***** Doing sandbox prestage " + sandbox.getSandboxPath());
        }
        sandbox.prestage();
        if (logger.isDebugEnabled()) {
            logger.debug("***** Sandbox prestage done " + sandbox.getSandboxPath());
        }
        // Create sbatch job
        SoftwareDescription sd = new SoftwareDescription();
        sd.setExecutable("sh");
        sd.setArguments("-c", "bsub < " + bsubFile.getName() + " 2>submit.err");
        // + " && rm -rf " + bsubFile.getName() + " submit.err");
        sd.setAttributes(description.getSoftwareDescription().getAttributes());
        sd.addAttribute(SoftwareDescription.SANDBOX_USEROOT, "true");
        slurmResultFile = java.io.File.createTempFile("GAT", "tmp");
        try {
            sd.setStdout(GAT.createFile(gatContext, new URI(slurmResultFile.toURI())));
            sd.addPreStagedFile(GAT.createFile(gatContext, new URI(bsubFile.toURI())));
        } catch (Throwable e1) {
            try {
                sandbox.removeSandboxDir();
            } catch (Throwable e) {
            // ignore
            }
            throw new GATInvocationException("Could not create GAT object for temporary " + slurmResultFile.getAbsolutePath(), e1);
        }
        // sd.addAttribute(SoftwareDescription.DIRECTORY, sd.getStringAttribute(SoftwareDescription, defaultVal)));
        JobDescription jd = new JobDescription(sd);
        if (logger.isDebugEnabled()) {
            logger.debug("Submitting lsf job: " + sd);
        }
        Job job = subBroker.submitJob(jd, this, "job.status");
        if (logger.isDebugEnabled()) {
            logger.debug("Job submitted.");
        }
        synchronized (job) {
            while (job.getState() != Job.JobState.STOPPED && job.getState() != Job.JobState.SUBMISSION_ERROR) {
                try {
                    job.wait();
                } catch (InterruptedException e) {
                // ignore
                }
            }
        }
        if (job.getState() != Job.JobState.STOPPED || job.getExitStatus() != 0) {
            try {
                sandbox.removeSandboxDir();
            } catch (Throwable e) {
            // ignore
            }
            logger.debug("jobState = " + job.getState() + ", exit status = " + job.getExitStatus());
            throw new GATInvocationException("Could not submit LSF job");
        }
        // submit success.
        BufferedReader in = new BufferedReader(new FileReader(slurmResultFile.getAbsolutePath()));
        String result = in.readLine();
        if (logger.isDebugEnabled()) {
            logger.debug("bsub result line = " + result);
        }
        // Check for LSF bsub result ...
        // TODO Check if LSF return the same
        String job_prefix = "Job <";
        if (result.contains(job_prefix)) {
            int i = result.indexOf(job_prefix);
            result = result.substring(i + job_prefix.length(), result.indexOf(">", i));
        }
        return result;
    } catch (IOException e) {
        try {
            sandbox.removeSandboxDir();
        } catch (Throwable e1) {
        // ignore
        }
        throw new GATInvocationException("Got IOException", e);
    } finally {
        slurmResultFile.delete();
        bsubFile.delete();
    }
}
Also used : IOException(java.io.IOException) URI(org.gridlab.gat.URI) File(java.io.File) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription) JobDescription(org.gridlab.gat.resources.JobDescription) WrapperJobDescription(org.gridlab.gat.resources.WrapperJobDescription) AbstractJobDescription(org.gridlab.gat.resources.AbstractJobDescription) GATInvocationException(org.gridlab.gat.GATInvocationException) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Job(org.gridlab.gat.resources.Job)

Example 13 with URI

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

the class FileAdaptorTest method copyFileTest.

private AdaptorTestResultEntry copyFileTest(GATContext gatContext, Preferences preferences, String host, String filename, int tabs, boolean correctValue) {
    FileInterface file = null;
    try {
        file = GAT.createFile(gatContext, preferences, "any://" + host + "/" + filename).getFileInterface();
    } catch (GATObjectCreationException e) {
        return new AdaptorTestResultEntry(false, 0, e);
    }
    long start = System.currentTimeMillis();
    try {
        file.copy(new URI("any:///" + filename + ".copy"));
    } catch (GATInvocationException e) {
        return new AdaptorTestResultEntry(false, 0, e);
    } catch (URISyntaxException e) {
        return new AdaptorTestResultEntry(false, 0, e);
    }
    long stop = System.currentTimeMillis();
    boolean exists = new java.io.File(filename + ".copy").exists();
    if (exists) {
        new java.io.File(filename + ".copy").delete();
    }
    return new AdaptorTestResultEntry(exists == correctValue, (stop - start), null);
}
Also used : FileInterface(org.gridlab.gat.io.FileInterface) GATObjectCreationException(org.gridlab.gat.GATObjectCreationException) GATInvocationException(org.gridlab.gat.GATInvocationException) URISyntaxException(java.net.URISyntaxException) URI(org.gridlab.gat.URI)

Example 14 with URI

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

the class AdvertServiceAdaptorTest method importTest.

private AdaptorTestResultEntry importTest(AdvertService advert, String importLocation) {
    long start = System.currentTimeMillis();
    try {
        advert.importDataBase(new URI(importLocation));
    } catch (GATInvocationException e) {
        return new AdaptorTestResultEntry(false, 0, e);
    } catch (URISyntaxException e) {
        return new AdaptorTestResultEntry(false, 0, e);
    }
    long stop = System.currentTimeMillis();
    return new AdaptorTestResultEntry(true, (stop - start), null);
}
Also used : GATInvocationException(org.gridlab.gat.GATInvocationException) URISyntaxException(java.net.URISyntaxException) URI(org.gridlab.gat.URI)

Example 15 with URI

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

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