Search in sources :

Example 51 with SimpleScript

use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.

the class SchedulerEfficiencyMetricsTest method createJob.

public static TaskFlowJob createJob(int taskNumber, int taskDuration) throws Exception {
    final TaskFlowJob job = new TaskFlowJob();
    job.setName(String.format("EP_%d_NO_MERGE_%dSEC", taskNumber, taskDuration));
    job.setOnTaskError(OnTaskError.CANCEL_JOB);
    job.getVariables().put(OPTIMAL_JOB_DURATION, new JobVariable(OPTIMAL_JOB_DURATION, String.valueOf(taskDuration)));
    for (int i = 0; i < taskNumber; i++) {
        ScriptTask task = new ScriptTask();
        task.setName("process_" + i);
        task.setScript(new TaskScript(new SimpleScript(String.format("Thread.sleep(%s)", taskDuration), "groovy")));
        job.addTask(task);
    }
    return job;
}
Also used : ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) TaskScript(org.ow2.proactive.scripting.TaskScript) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleScript(org.ow2.proactive.scripting.SimpleScript) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable)

Example 52 with SimpleScript

use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.

the class TestJobSchedulerHome method pahomeScriptTask.

public void pahomeScriptTask() throws Throwable {
    log("Test ProActive Home Script Task...");
    String tname = "pahomeScriptTask";
    TaskFlowJob job = new TaskFlowJob();
    job.setName(this.getClass().getSimpleName() + "_" + tname);
    ScriptTask task1 = new ScriptTask();
    task1.setName(tname);
    Script pahomeScript = new SimpleScript(TestJobSchedulerHome.class.getResource("/functionaltests/scripts/schedulerHome.js"), new String[] { schedulerHomePath });
    ;
    TaskScript ts = new TaskScript(pahomeScript);
    task1.setScript(ts);
    job.addTask(task1);
    submitAndCheckJob(job, tname, false);
}
Also used : SimpleScript(org.ow2.proactive.scripting.SimpleScript) TaskScript(org.ow2.proactive.scripting.TaskScript) Script(org.ow2.proactive.scripting.Script) TaskScript(org.ow2.proactive.scripting.TaskScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript)

Example 53 with SimpleScript

use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.

the class TestJobWalltime method walltimeScriptTask.

public JobId walltimeScriptTask() throws Throwable {
    log("Test WallTime Script Task...");
    String tname = "walltimeScriptTask";
    // pre script interruption
    TaskFlowJob job = new TaskFlowJob();
    job.setName(this.getClass().getSimpleName() + "_" + tname);
    ScriptTask task1 = new ScriptTask();
    task1.setName(tname);
    task1.setWallTime(5000);
    task1.setScript(new TaskScript(new SimpleScript("while(true){java.lang.Thread.sleep(500);}", "javascript")));
    job.addTask(task1);
    return submitJob(job);
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript)

Example 54 with SimpleScript

use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.

the class FlatJobFactory method createNativeTaskFromCommandString.

/**
 * Creates a native task from a string representing a native command to execute.
 * @param command a String representing a native command.
 * @param taskName an eventual name for the task.
 * @param selectionScriptPath path to an existing file containing a selection script code.
 * @return a NativeTask object that can be put in a Job Object.
 * @throws InvalidScriptException if an error occurs in definition of selection script
 * from file path specified.
 */
private NativeTask createNativeTaskFromCommandString(String command, String taskName, String selectionScriptPath) throws InvalidScriptException {
    NativeTask desc = new NativeTask();
    desc.setCommandLine(Tools.parseCommandLine(command));
    desc.setName(taskName);
    if (selectionScriptPath != null) {
        SelectionScript script = new SelectionScript(new SimpleScript(new File(selectionScriptPath), null), true);
        desc.addSelectionScript(script);
    }
    return desc;
}
Also used : SelectionScript(org.ow2.proactive.scripting.SelectionScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) File(java.io.File)

Example 55 with SimpleScript

use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.

the class StaxJobFactory method createScript.

/**
 * Get the script defined at the specified cursor.
 * Leave the method with cursor at the end of the corresponding script.
 *
 * @param cursorScript the streamReader with the cursor on the corresponding script tag (pre, post, cleaning, selection, generation).
 * @param type         nature of the script
 * @return the script  defined at the specified cursor.
 */
private Script<?> createScript(XMLStreamReader cursorScript, ScriptType type, Map<String, String> variables) throws JobCreationException {
    String attrtmp = null;
    String currentScriptTag = cursorScript.getLocalName();
    String current = null;
    try {
        boolean isDynamic = true;
        Script<?> toReturn = null;
        int eventType = -1;
        while (cursorScript.hasNext()) {
            if (type == ScriptType.SELECTION && eventType == -1) {
                eventType = cursorScript.getEventType();
            } else {
                eventType = cursorScript.next();
            }
            switch(eventType) {
                case XMLEvent.START_ELEMENT:
                    current = cursorScript.getLocalName();
                    if (XMLTags.SCRIPT_CODE.matches(current)) {
                        String language = null;
                        String content = "";
                        if (cursorScript.getAttributeCount() > 0) {
                            language = cursorScript.getAttributeValue(0);
                            attrtmp = cursorScript.getAttributeLocalName(0);
                        }
                        // goto script content
                        if (cursorScript.next() == XMLEvent.CHARACTERS) {
                            content = cursorScript.getText();
                        }
                        toReturn = new SimpleScript(content, language);
                        // fast forward to the end of tag
                        while (true) {
                            int ev = cursorScript.next();
                            if (XMLTags.SCRIPT_CODE.matches(current) && ev == XMLEvent.END_ELEMENT) {
                                break;
                            }
                        }
                    } else if (XMLTags.SCRIPT_FILE.matches(current)) {
                        String path = null;
                        String url = null;
                        String language = null;
                        for (int i = 0; i < cursorScript.getAttributeCount(); i++) {
                            attrtmp = cursorScript.getAttributeLocalName(i);
                            if (XMLAttributes.SCRIPT_URL.matches(attrtmp)) {
                                url = replace(cursorScript.getAttributeValue(i), variables);
                            } else if (XMLAttributes.LANGUAGE.matches(attrtmp)) {
                                language = replace(cursorScript.getAttributeValue(i), variables);
                            } else if (XMLAttributes.PATH.matches(attrtmp)) {
                                path = checkPath(cursorScript.getAttributeValue(i), variables);
                            } else {
                                throw new JobCreationException("Unrecognized attribute : " + attrtmp);
                            }
                        }
                        // go to the next 'arguments' start element or the 'file' end element
                        while (true) {
                            int ev = cursorScript.next();
                            if (((ev == XMLEvent.START_ELEMENT) && XMLTags.SCRIPT_ARGUMENTS.matches(cursorScript.getLocalName())) || (ev == XMLEvent.END_ELEMENT)) {
                                break;
                            }
                        }
                        if (url != null) {
                            if (language != null) {
                                toReturn = new SimpleScript(new URL(url), language, getArguments(cursorScript));
                            } else {
                                toReturn = new SimpleScript(new URL(url), getArguments(cursorScript));
                            }
                        } else if (path != null) {
                            // language is ignored if a File is provided, the script language will be determined based on the file extension
                            toReturn = new SimpleScript(new File(path), getArguments(cursorScript));
                        } else {
                            attrtmp = null;
                            throw new JobCreationException("Invalid script file definition, one of path/url attributes must be declared");
                        }
                    } else if (XMLTags.SCRIPT_ARGUMENTS.matches(current)) {
                        toReturn = new SimpleScript(toReturn.getScript(), toReturn.getEngineName(), getArguments(cursorScript));
                    } else if (XMLTags.SCRIPT_SCRIPT.matches(current)) {
                        if (cursorScript.getAttributeCount() > 0) {
                            isDynamic = !"static".equals(cursorScript.getAttributeValue(0));
                        }
                    }
                    break;
                case XMLEvent.END_ELEMENT:
                    if (cursorScript.getLocalName().equals(currentScriptTag)) {
                        if (type == ScriptType.SELECTION) {
                            return new SelectionScript(toReturn, isDynamic);
                        } else {
                            return toReturn;
                        }
                    }
                    break;
            }
        }
        return toReturn;
    } catch (JobCreationException jce) {
        jce.pushTag(current);
        throw jce;
    } catch (Exception e) {
        throw new JobCreationException(current, attrtmp, e);
    }
}
Also used : SelectionScript(org.ow2.proactive.scripting.SelectionScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) File(java.io.File) URL(java.net.URL) XMLStreamException(javax.xml.stream.XMLStreamException) JobValidationException(org.ow2.proactive.scheduler.common.exception.JobValidationException) FileNotFoundException(java.io.FileNotFoundException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) VerifierConfigurationException(org.iso_relax.verifier.VerifierConfigurationException)

Aggregations

SimpleScript (org.ow2.proactive.scripting.SimpleScript)99 TaskScript (org.ow2.proactive.scripting.TaskScript)78 Test (org.junit.Test)68 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)64 NodeDataSpacesURIs (org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs)31 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)31 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)21 TaskLauncherInitializer (org.ow2.proactive.scheduler.task.TaskLauncherInitializer)19 InProcessTaskExecutor (org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor)19 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)18 File (java.io.File)16 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)13 Serializable (java.io.Serializable)12 ScriptTask (org.ow2.proactive.scheduler.common.task.ScriptTask)10 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)10 TestTaskOutput (org.ow2.proactive.scheduler.task.TestTaskOutput)9 ForkedTaskExecutor (org.ow2.proactive.scheduler.task.executors.ForkedTaskExecutor)9 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)8 HashMap (java.util.HashMap)7 JobId (org.ow2.proactive.scheduler.common.job.JobId)7