Search in sources :

Example 11 with Job

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

the class ResourceBrokerJavaJobExample 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;
    }
    JavaSoftwareDescription sd = new JavaSoftwareDescription();
    sd.setExecutable("/usr/bin/java");
    sd.setJavaMain("my.package.HelloWorld");
    sd.setJavaArguments("hello", "world");
    sd.setJavaClassPath("myJar1:myDir");
    sd.setJavaOptions("-version");
    sd.addJavaSystemProperty("key", "value");
    try {
        sd.setStdout(GAT.createFile("javajob.txt"));
    } catch (GATObjectCreationException e) {
        System.err.println("Failed to create the stdout file 'javajob.txt': " + e);
        return;
    }
    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;
    }
    while (job.getState() != JobState.STOPPED) {
        System.out.println("job is in state: " + job.getState());
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
        // ignore
        }
    }
}
Also used : JavaSoftwareDescription(org.gridlab.gat.resources.JavaSoftwareDescription) 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) Job(org.gridlab.gat.resources.Job) URI(org.gridlab.gat.URI)

Example 12 with Job

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

the class SubmitJobWithMultipleInputs method main.

public static void main(String[] args) throws Exception {
    ResourceBroker broker = GAT.createResourceBroker(new URI(args[0]));
    SoftwareDescription sd = new SoftwareDescription();
    sd.setExecutable(args[1]);
    sd.setStdout(GAT.createFile("stdout.txt"));
    sd.setStderr(GAT.createFile("stderr.txt"));
    String[] arguments = new String[args.length - 2];
    for (int i = 2; i < args.length; i++) {
        File tmp = GAT.createFile(args[i]);
        sd.addPreStagedFile(tmp);
        arguments[i - 2] = tmp.getName();
    }
    sd.setArguments(arguments);
    Job job = broker.submitJob(new JobDescription(sd));
    while ((job.getState() != JobState.STOPPED) && (job.getState() != JobState.SUBMISSION_ERROR)) {
        Thread.sleep(1000);
    }
    GAT.end();
}
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) File(org.gridlab.gat.io.File) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription)

Example 13 with Job

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

the class GATTracer method startTracing.

public static Job startTracing(GATWorkerNode worker) {
    if (DEBUG) {
        LOGGER.debug("Starting trace for woker " + worker.getHost());
    }
    tracingLevel = 1;
    int numTasks = worker.getTotalComputingUnits();
    if (numTasks <= 0) {
        if (DEBUG) {
            LOGGER.debug("Resource " + worker.getName() + " has 0 slots, it won't appear in the trace");
        }
        return null;
    }
    int hostId = Tracer.registerHost(worker.getName(), numTasks);
    String user;
    if (worker.getUser() == null || worker.getUser().isEmpty()) {
        user = "";
    } else {
        user = worker.getUser() + "@";
    }
    SoftwareDescription sd = new SoftwareDescription();
    String uriString = Protocol.ANY_URI.getSchema() + user + worker.getHost();
    sd.addAttribute("uri", uriString);
    sd.setExecutable(worker.getInstallDir() + Tracer.TRACE_SCRIPT_PATH);
    sd.setArguments(new String[] { "init", worker.getWorkingDir(), String.valueOf(hostId), String.valueOf(numTasks) });
    if (DEBUG) {
        try {
            org.gridlab.gat.io.File outFile = GAT.createFile(worker.getContext(), Protocol.ANY_URI.getSchema() + File.separator + System.getProperty(COMPSsConstants.APP_LOG_DIR) + traceOutRelativePath);
            sd.setStdout(outFile);
            org.gridlab.gat.io.File errFile = GAT.createFile(worker.getContext(), Protocol.ANY_URI.getSchema() + File.separator + System.getProperty(COMPSsConstants.APP_LOG_DIR) + traceErrRelativePath);
            sd.setStderr(errFile);
        } catch (Exception e) {
            ErrorManager.warn("Error initializing tracing system in node " + worker.getHost(), e);
            return null;
        }
    }
    sd.addAttribute(SoftwareDescription.SANDBOX_ROOT, File.separator + "tmp" + File.separator);
    sd.addAttribute(SoftwareDescription.SANDBOX_USEROOT, "true");
    sd.addAttribute(SoftwareDescription.SANDBOX_DELETE, "false");
    Job job = null;
    try {
        URI brokerURI = new URI(uriString);
        ResourceBroker broker = GAT.createResourceBroker(worker.getContext(), brokerURI);
        LOGGER.debug("Starting tracer init job for worker " + uriString + " submited.");
        job = broker.submitJob(new JobDescription(sd));
    } catch (Exception e) {
        ErrorManager.warn("Error initializing tracing system in node " + worker.getHost(), e);
        return null;
    }
    return 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) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription) URISyntaxException(java.net.URISyntaxException)

Example 14 with Job

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

the class LoadLevelerResourceBrokerAdaptor method submitJob.

/*
     * (non-Javadoc)
     * 
     * @see org.gridlab.gat.resources.ResourceBroker#submitJob(org.gridlab.gat.resources.JobDescription)
     */
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) abstractDescription;
    SoftwareDescription sd = description.getSoftwareDescription();
    if (sd == null) {
        throw new GATInvocationException("The job description does not contain a software description");
    }
    if (description.getProcessCount() < 1) {
        throw new GATInvocationException("Adaptor cannot handle: process count < 1: " + description.getProcessCount());
    }
    if (description.getResourceCount() != 1) {
        throw new GATInvocationException("Adaptor cannot handle: resource count > 1: " + description.getResourceCount());
    }
    String home = System.getProperty("user.home");
    if (home == null) {
        throw new GATInvocationException("loadleveler broker could not get user home dir");
    }
    Sandbox sandbox = new Sandbox(gatContext, description, "localhost", home, true, true, false, false);
    LoadLevelerJob loadlevelerJob = new LoadLevelerJob(gatContext, description, sandbox);
    Job job = null;
    if (description instanceof WrapperJobDescription) {
        WrapperJobCpi tmp = new WrapperJobCpi(gatContext, loadlevelerJob, listener, metricDefinitionName);
        listener = tmp;
        job = tmp;
    } else {
        job = loadlevelerJob;
    }
    if (listener != null && metricDefinitionName != null) {
        Metric metric = loadlevelerJob.getMetricDefinitionByName(metricDefinitionName).createMetric(null);
        loadlevelerJob.addMetricListener(listener, metric);
    }
    loadlevelerJob.setState(Job.JobState.PRE_STAGING);
    loadlevelerJob.waitForTrigger(Job.JobState.PRE_STAGING);
    sandbox.prestage();
    String exe;
    if (sandbox.getResolvedExecutable() != null) {
        exe = sandbox.getResolvedExecutable().getPath();
    // try to set the executable bit, it might be lost
    /* CDIAZ: The command "exe" can be also in a remote host
             * 		  The command must have the right permissions in the remote host
            try {
                new CommandRunner("chmod", "+x", exe);
            } catch (Throwable t) {
                // ignore
            }
            */
    } else {
        exe = getExecutable(description);
    }
    String[] args = getArgumentsArray(description);
    // Directory where the loadleveler command will be executed
    java.io.File f = new java.io.File(sandbox.getSandboxPath());
    if (!f.exists()) {
        throw new GATInvocationException("Unable to find directory " + f.getAbsolutePath());
    }
    // Check and set the environment for a blaunch command
    Map<String, Object> env = sd.getEnvironment();
    this.prepareBLaunchEnv(env);
    // Encapsulate the original command into a blaunch command
    String host = brokerURI.getHost();
    String newExe = this.getLoadLevelerCommand();
    String[] newArgs = this.getLoadLevelerArgs(host, exe, args);
    System.out.println("[AFTER] exe: " + newExe);
    System.out.println("[AFTER] llspawan.stdio args:");
    for (int i = 0; i < newArgs.length; i++) System.out.print(" " + newArgs[i]);
    System.out.println();
    ProcessBundle bundle = new ProcessBundle(description.getProcessCount(), newExe, newArgs, f, env);
    loadlevelerJob.setSubmissionTime();
    loadlevelerJob.setState(Job.JobState.SCHEDULED);
    try {
        loadlevelerJob.setState(Job.JobState.RUNNING);
        loadlevelerJob.waitForTrigger(Job.JobState.RUNNING);
        loadlevelerJob.setStartTime();
        bundle.startBundle();
        loadlevelerJob.setProcess(bundle);
        if (logger.isDebugEnabled()) {
            logger.debug("Job with PID: " + LOADL_PID + " is executed on host " + host);
        }
    } catch (IOException e) {
        throw new CommandNotFoundException("LoadLevelerResourceBrokerAdaptor", e);
    }
    if (!sd.streamingStderrEnabled()) {
        try {
            if (sd.getStderr() != null) {
                OutputStream err = GAT.createFileOutputStream(gatContext, sd.getStderr());
                // to file
                StreamForwarder forwarder = new StreamForwarder(bundle.getStderr(), err, sd.getExecutable() + " [stderr]");
                loadlevelerJob.setErrorStream(forwarder);
                if (logger.isDebugEnabled()) {
                    logger.debug("Created stderr forwarder to file " + sd.getStderr());
                }
            } else {
                // or throw it away
                new StreamForwarder(bundle.getStderr(), null, sd.getExecutable() + " [stderr]");
            }
        } catch (GATObjectCreationException e) {
            throw new GATInvocationException("Unable to create file output stream for stderr!", e);
        }
    }
    if (!sd.streamingStdoutEnabled()) {
        // read away the stdout
        try {
            if (sd.getStdout() != null) {
                // to file
                OutputStream out = GAT.createFileOutputStream(gatContext, sd.getStdout());
                StreamForwarder forwarder = new StreamForwarder(bundle.getStdout(), out, sd.getExecutable() + " [stdout]");
                loadlevelerJob.setOutputStream(forwarder);
                if (logger.isDebugEnabled()) {
                    logger.debug("Created stdout forwarder to file " + sd.getStdout());
                }
            } else {
                // or throw it away
                new StreamForwarder(bundle.getStdout(), null, sd.getExecutable() + " [stdout]");
            }
        } catch (GATObjectCreationException e) {
            throw new GATInvocationException("Unable to create file output stream for stdout!", e);
        }
    }
    if (!sd.streamingStdinEnabled() && sd.getStdin() != null) {
        // forward the stdin from file
        try {
            InputStream in = GAT.createFileInputStream(gatContext, sd.getStdin());
            bundle.setStdin(sd.getExecutable(), in);
        } catch (GATObjectCreationException e) {
            throw new GATInvocationException("Unable to create file input stream for stdin!", e);
        }
    }
    loadlevelerJob.monitorState();
    return job;
}
Also used : ProcessBundle(org.gridlab.gat.engine.util.ProcessBundle) OutputStream(java.io.OutputStream) StreamForwarder(org.gridlab.gat.engine.util.StreamForwarder) Sandbox(org.gridlab.gat.resources.cpi.Sandbox) WrapperJobDescription(org.gridlab.gat.resources.WrapperJobDescription) JobDescription(org.gridlab.gat.resources.JobDescription) AbstractJobDescription(org.gridlab.gat.resources.AbstractJobDescription) Job(org.gridlab.gat.resources.Job) WrapperJobDescription(org.gridlab.gat.resources.WrapperJobDescription) GATObjectCreationException(org.gridlab.gat.GATObjectCreationException) InputStream(java.io.InputStream) IOException(java.io.IOException) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription) GATInvocationException(org.gridlab.gat.GATInvocationException) WrapperJobCpi(org.gridlab.gat.resources.cpi.WrapperJobCpi) Metric(org.gridlab.gat.monitoring.Metric) CommandNotFoundException(org.gridlab.gat.CommandNotFoundException)

Example 15 with Job

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

the class SshLSFJob method kill.

protected void kill(String jobID) {
    try {
        // Create qdel job
        SoftwareDescription sd = new SoftwareDescription();
        sd.setExecutable("bkill");
        sd.setArguments(jobID);
        sd.addAttribute(SoftwareDescription.SANDBOX_USEROOT, "true");
        sd.addAttribute(SoftwareDescription.SANDBOX_ROOT, sandbox.getSandboxPath());
        sd.addAttribute(SoftwareDescription.STOP_ON_EXIT, "false");
        JobDescription jd = new JobDescription(sd);
        Job job = jobHelper.submitJob(jd, this, "job.status");
        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) {
            throw new GATInvocationException("Could not submit scancel job");
        }
    } catch (Throwable e) {
        logger.info("Failed to stop sshSlurm job: " + jobID, e);
    }
}
Also used : JobDescription(org.gridlab.gat.resources.JobDescription) GATInvocationException(org.gridlab.gat.GATInvocationException) SshLSFJob(org.gridlab.gat.resources.cpi.sshlsf.SshLSFJob) Job(org.gridlab.gat.resources.Job) 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