Search in sources :

Example 1 with ResourceBroker

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

the class GATJob method submit.

@Override
public void submit() throws Exception {
    // Prepare the job
    logger.info("Submit GATJob with ID " + jobId);
    JobDescription jobDescr = null;
    jobDescr = prepareJob();
    // Get a broker for the host
    ResourceBroker broker = null;
    String dest = (String) jobDescr.getResourceDescription().getResourceAttribute(RES_ATTR);
    if ((broker = brokers.get(dest)) == null) {
        broker = GAT.createResourceBroker(context, new URI(dest));
        brokers.put(dest, broker);
    }
    // Submit the job, registering for notifications of job state
    // transitions (associatedJM is the metric listener)
    Job job = null;
    try {
        job = broker.submitJob(jobDescr, this, JOB_STATUS);
        RUNNING_JOBS.add(this);
    } catch (Exception e) {
        if (Tracer.isActivated()) {
            Tracer.freeSlot(((GATWorkerNode) worker.getNode()).getHost(), (Integer) jobDescr.getSoftwareDescription().getAttributes().get("slot"));
        }
        throw e;
    }
    // Update mapping
    GATjob = job;
}
Also used : JobDescription(org.gridlab.gat.resources.JobDescription) ResourceBroker(org.gridlab.gat.resources.ResourceBroker) Job(org.gridlab.gat.resources.Job) URI(org.gridlab.gat.URI) GATInvocationException(org.gridlab.gat.GATInvocationException)

Example 2 with ResourceBroker

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

the class ResourceBrokerAdaptorTest method submitJobStateConsistency.

private AdaptorTestResultEntry submitJobStateConsistency(GATContext gatContext, Preferences preferences, String host) {
    SoftwareDescription sd = new SoftwareDescription();
    sd.setExecutable("/bin/sleep");
    sd.setArguments("2");
    JobDescription jd = new JobDescription(sd);
    ResourceBroker broker;
    try {
        broker = GAT.createResourceBroker(gatContext, preferences, new URI(host));
    } catch (GATObjectCreationException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    } catch (URISyntaxException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    }
    JobStateMetricListener listener = new JobStateMetricListener(this);
    long start = System.currentTimeMillis();
    try {
        broker.submitJob(jd, listener, "job.status");
    } catch (GATInvocationException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    }
    waitForJob();
    long stop = System.currentTimeMillis();
    return new AdaptorTestResultEntry(listener.getException() == null, (stop - start), listener.getException());
}
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) URI(org.gridlab.gat.URI) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription)

Example 3 with ResourceBroker

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

the class ResourceBrokerAdaptorTest method submitJobEnvironment.

private AdaptorTestResultEntry submitJobEnvironment(GATContext gatContext, Preferences preferences, String host) {
    SoftwareDescription sd = new SoftwareDescription();
    Map<String, Object> env = new HashMap<String, Object>();
    env.put("JAVAGAT_TEST_KEY", "javagat-test-value");
    sd.setEnvironment(env);
    sd.setExecutable("/usr/bin/env");
    try {
        sd.setStdout(GAT.createFile(gatContext, preferences, "stdout"));
    } catch (GATObjectCreationException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    }
    JobDescription jd = new JobDescription(sd);
    ResourceBroker broker;
    try {
        broker = GAT.createResourceBroker(gatContext, preferences, new URI(host));
    } catch (GATObjectCreationException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    } catch (URISyntaxException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    }
    long start = System.currentTimeMillis();
    Job job;
    try {
        job = broker.submitJob(jd, this, "job.status");
    } catch (GATInvocationException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    }
    waitForJob();
    try {
        Map<String, Object> info = job.getInfo();
        Throwable ex = (Throwable) info.get("poststage.exception");
        if (ex != null) {
            return new AdaptorTestResultEntry(false, 0L, ex);
        }
    } catch (GATInvocationException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    }
    long stop = System.currentTimeMillis();
    boolean success = false;
    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(new java.io.FileInputStream("stdout")));
        while (true) {
            String result = reader.readLine();
            if (result == null) {
                break;
            }
            if (result.contains("JAVAGAT_TEST_KEY") && result.contains("javagat-test-value")) {
                success = true;
            }
        }
        reader.close();
    } catch (Exception e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    }
    return new AdaptorTestResultEntry(success, (stop - start), null);
}
Also used : GATObjectCreationException(org.gridlab.gat.GATObjectCreationException) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) ResourceBroker(org.gridlab.gat.resources.ResourceBroker) URISyntaxException(java.net.URISyntaxException) URI(org.gridlab.gat.URI) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription) URISyntaxException(java.net.URISyntaxException) GATInvocationException(org.gridlab.gat.GATInvocationException) IOException(java.io.IOException) GATObjectCreationException(org.gridlab.gat.GATObjectCreationException) JobDescription(org.gridlab.gat.resources.JobDescription) GATInvocationException(org.gridlab.gat.GATInvocationException) BufferedReader(java.io.BufferedReader) Job(org.gridlab.gat.resources.Job)

Example 4 with ResourceBroker

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

the class ResourceBrokerAdaptorTest method submitJobGetInfo.

private AdaptorTestResultEntry submitJobGetInfo(GATContext gatContext, Preferences preferences, String host) {
    SoftwareDescription sd = new SoftwareDescription();
    sd.setExecutable("/bin/sleep");
    sd.setArguments("2");
    JobDescription jd = new JobDescription(sd);
    ResourceBroker broker;
    try {
        broker = GAT.createResourceBroker(gatContext, preferences, new URI(host));
    } catch (GATObjectCreationException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    } catch (URISyntaxException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    }
    Job job = null;
    Exception exception = null;
    long start = System.currentTimeMillis();
    try {
        job = broker.submitJob(jd);
    } catch (GATInvocationException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    }
    while (job.getState() != Job.JobState.STOPPED) {
        Map<String, Object> info = null;
        try {
            info = job.getInfo();
        } catch (GATInvocationException e) {
            exception = e;
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e1) {
            // ignored
            }
            continue;
        }
        if (info == null) {
            exception = new Exception("getInfo returns null");
        } else {
            if (!info.containsKey("state")) {
                exception = new Exception("getInfo doesn't contain a key 'state'");
            }
            if (!info.containsKey("hostname")) {
                exception = new Exception("getInfo doesn't contain a key 'hostname'");
            } else {
                if (info.get("state").equals(Job.JobState.RUNNING) && info.get("hostname") == null) {
                    exception = new Exception("inconsistent getInfo: state=RUNNING, hostname=null");
                }
            }
            if (!info.containsKey("submissiontime")) {
                exception = new Exception("getInfo doesn't contain a key 'submissiontime'");
            }
            if (!info.containsKey("starttime")) {
                exception = new Exception("getInfo doesn't contain a key 'starttime'");
            }
            if (!info.containsKey("stoptime")) {
                exception = new Exception("getInfo doesn't contain a key 'stoptime'");
            }
            if (!info.containsKey("poststage.exception")) {
                exception = new Exception("getInfo doesn't contain a key 'poststage.exception'");
            }
        }
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            exception = e;
        }
    }
    long stop = System.currentTimeMillis();
    return new AdaptorTestResultEntry(exception == null, (stop - start), exception);
}
Also used : GATObjectCreationException(org.gridlab.gat.GATObjectCreationException) ResourceBroker(org.gridlab.gat.resources.ResourceBroker) URISyntaxException(java.net.URISyntaxException) URI(org.gridlab.gat.URI) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription) URISyntaxException(java.net.URISyntaxException) GATInvocationException(org.gridlab.gat.GATInvocationException) IOException(java.io.IOException) GATObjectCreationException(org.gridlab.gat.GATObjectCreationException) JobDescription(org.gridlab.gat.resources.JobDescription) GATInvocationException(org.gridlab.gat.GATInvocationException) Job(org.gridlab.gat.resources.Job)

Example 5 with ResourceBroker

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

the class ResourceBrokerAdaptorTest method submitJobParallel.

private AdaptorTestResultEntry submitJobParallel(GATContext gatContext, Preferences preferences, String host) {
    SoftwareDescription sd = new SoftwareDescription();
    sd.setExecutable("/bin/echo");
    sd.setArguments("test", "1", "2", "3");
    try {
        sd.setStdout(GAT.createFile(gatContext, preferences, "parallel-stdout"));
    } catch (GATObjectCreationException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    }
    JobDescription jd = new JobDescription(sd);
    jd.setProcessCount(2);
    jd.setResourceCount(1);
    ResourceBroker broker;
    try {
        broker = GAT.createResourceBroker(gatContext, preferences, new URI(host));
    } catch (GATObjectCreationException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    } catch (URISyntaxException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    }
    long start = System.currentTimeMillis();
    try {
        broker.submitJob(jd, this, "job.status");
    } catch (GATInvocationException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    }
    waitForJob();
    long stop = System.currentTimeMillis();
    return new AdaptorTestResultEntry(true, (stop - start), null);
}
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) URI(org.gridlab.gat.URI) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription)

Aggregations

URI (org.gridlab.gat.URI)26 JobDescription (org.gridlab.gat.resources.JobDescription)26 ResourceBroker (org.gridlab.gat.resources.ResourceBroker)26 SoftwareDescription (org.gridlab.gat.resources.SoftwareDescription)24 Job (org.gridlab.gat.resources.Job)19 GATInvocationException (org.gridlab.gat.GATInvocationException)18 URISyntaxException (java.net.URISyntaxException)17 GATObjectCreationException (org.gridlab.gat.GATObjectCreationException)16 Preferences (org.gridlab.gat.Preferences)8 IOException (java.io.IOException)6 File (org.gridlab.gat.io.File)6 BufferedReader (java.io.BufferedReader)4 InputStreamReader (java.io.InputStreamReader)4 GATContext (org.gridlab.gat.GATContext)3 HashMap (java.util.HashMap)2 WrapperJobDescription (org.gridlab.gat.resources.WrapperJobDescription)2 CertificateSecurityContext (org.gridlab.gat.security.CertificateSecurityContext)2 File (java.io.File)1 InputStream (java.io.InputStream)1 AdvertService (org.gridlab.gat.advert.AdvertService)1