Search in sources :

Example 21 with Job

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

the class SshLsfResourceBrokerAdaptor method submitJob.

public Job submitJob(AbstractJobDescription abstractDescription, MetricListener listener, String metricDefinitionName) throws GATInvocationException {
    if (!(abstractDescription instanceof JobDescription)) {
        throw new GATInvocationException("can only handle JobDescriptions: " + abstractDescription.getClass());
    }
    JobDescription description = (JobDescription) ((JobDescription) abstractDescription).clone();
    SoftwareDescription sd = description.getSoftwareDescription();
    int nproc = description.getProcessCount();
    if (sd.streamingStderrEnabled() || sd.streamingStdinEnabled() || sd.streamingStdoutEnabled()) {
        throw new GATInvocationException("Streaming I/O not supported by SshLSF adaptor");
    }
    String authority = getAuthority();
    if (authority == null) {
        authority = "localhost";
    }
    // Create filename for return value.
    String returnValueFile = ".rc." + Math.random();
    /*java.io.File jobScriptFile = createJobScript(description);
    	java.io.File jobStarterFile = null;
    	if (nproc > 1) {
    	    jobStarterFile = createJobStarter(description, nproc, jobScriptFile);
    	}*/
    java.io.File bsubFile = createBsubScript(description, returnValueFile, nproc);
    if (logger.isDebugEnabled()) {
        logger.debug("**** Adding pre and post staging:\n  " + sd);
    }
    try {
        // Careful, you may be running on windows, so add a scheme.
        sd.addPostStagedFile(GAT.createFile(gatContext, new URI(returnValueFile)));
    } catch (Throwable e) {
        throw new GATInvocationException("Error in file staging", e);
    }
    ResourceBroker subBroker;
    try {
        subBroker = subResourceBroker(getSubContext(gatContext), brokerURI);
    } catch (Throwable e) {
        throw new GATInvocationException("Could not create subbroker to submit LSF jobs through ssh", e);
    }
    Sandbox sandbox = new Sandbox(gatContext, description, authority, null, true, true, true, true);
    SshLSFJob sshLSFJob = new SshLSFJob(gatContext, brokerURI, description, sandbox, subBroker, returnValueFile);
    Job job = null;
    if (description instanceof WrapperJobDescription) {
        WrapperJobCpi tmp = new WrapperJobCpi(gatContext, sshLSFJob, listener, metricDefinitionName);
        listener = tmp;
        job = tmp;
    } else {
        job = sshLSFJob;
    }
    if (listener != null && metricDefinitionName != null) {
        Metric metric = sshLSFJob.getMetricDefinitionByName(metricDefinitionName).createMetric(null);
        sshLSFJob.addMetricListener(listener, metric);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("*******We are going to perform the ssh submission: ");
    }
    String jobid = sshLsfSubmission(sshLSFJob, description, bsubFile, subBroker, sandbox);
    if (jobid != null) {
        sshLSFJob.setState(Job.JobState.SCHEDULED);
        sshLSFJob.setSoft(description.getSoftwareDescription());
        sshLSFJob.setJobID(jobid);
        sshLSFJob.startListener();
    } else {
        // sandbox.removeSandboxDir();
        throw new GATInvocationException("Could not submit sshLSF job");
    }
    bsubFile.delete();
    return job;
}
Also used : ResourceBroker(org.gridlab.gat.resources.ResourceBroker) URI(org.gridlab.gat.URI) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription) File(java.io.File) Sandbox(org.gridlab.gat.resources.cpi.Sandbox) JobDescription(org.gridlab.gat.resources.JobDescription) WrapperJobDescription(org.gridlab.gat.resources.WrapperJobDescription) AbstractJobDescription(org.gridlab.gat.resources.AbstractJobDescription) GATInvocationException(org.gridlab.gat.GATInvocationException) WrapperJobCpi(org.gridlab.gat.resources.cpi.WrapperJobCpi) Metric(org.gridlab.gat.monitoring.Metric) Job(org.gridlab.gat.resources.Job) WrapperJobDescription(org.gridlab.gat.resources.WrapperJobDescription)

Example 22 with Job

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

the class ConnectToAdvertJob method main.

public static void main(String[] args) throws Exception {
    GATContext c = new GATContext();
    Preferences prefs = new Preferences();
    prefs.put("File.adaptor.name", "local");
    AdvertService a = GAT.createAdvertService(c, prefs);
    a.importDataBase(new URI("file:///mydb"));
    c = new GATContext();
    prefs = new Preferences();
    // prefs.put("Resourcebroker.adaptor.name", "sshsge");
    prefs.put("File.adaptor.name", "local, commandlinessh");
    c.addPreferences(prefs);
    Job other = (Job) a.getAdvertisable(c, "/rob/testJob");
    System.err.println("got job back: " + other);
    while ((other.getState() != Job.JobState.STOPPED) && (other.getState() != Job.JobState.SUBMISSION_ERROR)) {
        System.err.println("job state = " + other.getInfo());
        Thread.sleep(1000);
    }
    System.err.println("job DONE, state = " + other.getInfo());
    GAT.end();
}
Also used : GATContext(org.gridlab.gat.GATContext) AdvertService(org.gridlab.gat.advert.AdvertService) Preferences(org.gridlab.gat.Preferences) Job(org.gridlab.gat.resources.Job) URI(org.gridlab.gat.URI)

Example 23 with Job

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

the class FileAdaptorTest method run.

private void run(String host, String script) {
    Preferences preferences = new Preferences();
    preferences.put("resourcebroker.adaptor.name", "commandlinessh,sshtrilead,local");
    preferences.put("file.adaptor.name", "commandlinessh,sshtrilead,local");
    SoftwareDescription sd = new SoftwareDescription();
    sd.setExecutable("/bin/bash");
    sd.setArguments(script);
    try {
        sd.addPreStagedFile(GAT.createFile(preferences, "tests" + java.io.File.separator + "src" + java.io.File.separator + "benchmarks" + java.io.File.separator + script));
    } catch (GATObjectCreationException e) {
        e.printStackTrace();
        System.exit(1);
    }
    ResourceBroker broker = null;
    try {
        broker = GAT.createResourceBroker(preferences, new URI("any://" + host));
    } catch (GATObjectCreationException e) {
        e.printStackTrace();
        System.exit(1);
    } catch (URISyntaxException e) {
        e.printStackTrace();
        System.exit(1);
    }
    Job job = null;
    try {
        job = broker.submitJob(new JobDescription(sd));
    } catch (GATInvocationException e) {
        e.printStackTrace();
        System.exit(1);
    }
    while (job.getState() != Job.JobState.STOPPED && job.getState() != Job.JobState.SUBMISSION_ERROR) {
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
        // ignored
        }
    }
}
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) Job(org.gridlab.gat.resources.Job) URI(org.gridlab.gat.URI) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription)

Example 24 with Job

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

the class FileOutputStreamAdaptorTest method run.

private void run(String host, String script) {
    Preferences preferences = new Preferences();
    preferences.put("resourcebroker.adaptor.name", "commandlinessh,sshtrilead,local");
    preferences.put("file.adaptor.name", "commandlinessh,sshtrilead,local");
    SoftwareDescription sd = new SoftwareDescription();
    sd.setExecutable("/bin/bash");
    sd.setArguments(script);
    try {
        sd.addPreStagedFile(GAT.createFile(preferences, "tests" + java.io.File.separator + "src" + java.io.File.separator + "benchmarks" + java.io.File.separator + script));
    } catch (GATObjectCreationException e) {
        e.printStackTrace();
        System.exit(1);
    }
    ResourceBroker broker = null;
    try {
        broker = GAT.createResourceBroker(preferences, new URI("any://" + host));
    } catch (GATObjectCreationException e) {
        e.printStackTrace();
        System.exit(1);
    } catch (URISyntaxException e) {
        e.printStackTrace();
        System.exit(1);
    }
    Job job = null;
    try {
        job = broker.submitJob(new JobDescription(sd));
    } catch (GATInvocationException e) {
        e.printStackTrace();
        System.exit(1);
    }
    while (job.getState() != Job.JobState.STOPPED && job.getState() != Job.JobState.SUBMISSION_ERROR) {
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
        // ignored
        }
    }
}
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) Job(org.gridlab.gat.resources.Job) URI(org.gridlab.gat.URI) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription)

Example 25 with Job

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

the class ResourceBrokerStreamingOutExample 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("/usr/bin/env");
    sd.enableStreamingStdout(true);
    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;
    }
    InputStream in = null;
    try {
        in = job.getStdout();
    } catch (GATInvocationException e) {
        System.err.println("Failed to get the stdout stream: " + e);
        return;
    }
    while (true) {
        int i = 0;
        try {
            i = in.read();
        } catch (IOException e) {
            System.err.println("Failed to read: " + e);
            return;
        }
        if (i == -1) {
            break;
        } else {
            System.out.print((char) i);
        }
    }
}
Also used : JobDescription(org.gridlab.gat.resources.JobDescription) GATObjectCreationException(org.gridlab.gat.GATObjectCreationException) GATInvocationException(org.gridlab.gat.GATInvocationException) ResourceBroker(org.gridlab.gat.resources.ResourceBroker) InputStream(java.io.InputStream) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Job(org.gridlab.gat.resources.Job) URI(org.gridlab.gat.URI) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription)

Aggregations

Job (org.gridlab.gat.resources.Job)27 JobDescription (org.gridlab.gat.resources.JobDescription)25 SoftwareDescription (org.gridlab.gat.resources.SoftwareDescription)24 URI (org.gridlab.gat.URI)23 GATInvocationException (org.gridlab.gat.GATInvocationException)20 ResourceBroker (org.gridlab.gat.resources.ResourceBroker)19 GATObjectCreationException (org.gridlab.gat.GATObjectCreationException)14 URISyntaxException (java.net.URISyntaxException)13 IOException (java.io.IOException)10 BufferedReader (java.io.BufferedReader)7 Preferences (org.gridlab.gat.Preferences)6 File (org.gridlab.gat.io.File)5 File (java.io.File)4 InputStreamReader (java.io.InputStreamReader)4 AbstractJobDescription (org.gridlab.gat.resources.AbstractJobDescription)4 WrapperJobDescription (org.gridlab.gat.resources.WrapperJobDescription)4 FileReader (java.io.FileReader)3 InputStream (java.io.InputStream)3 GATContext (org.gridlab.gat.GATContext)3 Metric (org.gridlab.gat.monitoring.Metric)3