Search in sources :

Example 6 with ScriptTask

use of org.ow2.proactive.scheduler.common.task.ScriptTask in project scheduling by ow2-proactive.

the class TestUnauthorizedScripts method createJobSelection.

public Job createJobSelection(String selectionScriptContent) throws InvalidScriptException, UserException {
    TaskFlowJob job = new TaskFlowJob();
    job.setName(this.getClass().getSimpleName() + "_selection");
    ScriptTask taskWithSelection = new ScriptTask();
    taskWithSelection.setScript(new TaskScript(new SimpleScript("println 'Hello'", "groovy")));
    taskWithSelection.addSelectionScript(new SelectionScript(new SimpleScript(selectionScriptContent, "groovy"), true));
    job.addTask(taskWithSelection);
    return job;
}
Also used : SelectionScript(org.ow2.proactive.scripting.SelectionScript) 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)

Example 7 with ScriptTask

use of org.ow2.proactive.scheduler.common.task.ScriptTask 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 8 with ScriptTask

use of org.ow2.proactive.scheduler.common.task.ScriptTask 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 9 with ScriptTask

use of org.ow2.proactive.scheduler.common.task.ScriptTask 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 10 with ScriptTask

use of org.ow2.proactive.scheduler.common.task.ScriptTask in project scheduling by ow2-proactive.

the class Attribute method createTaskElement.

/**
 * Creates the task element, corressponding to <define name="task">
 */
private Element createTaskElement(Document doc, Task task) {
    Element taskE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.TASK.getXMLName());
    if (task.getOnTaskErrorProperty().isSet()) {
        setAttribute(taskE, XMLAttributes.COMMON_ON_TASK_ERROR, task.getOnTaskErrorProperty().getValue().toString(), true);
    }
    if (task.getMaxNumberOfExecutionProperty().isSet()) {
        setAttribute(taskE, XMLAttributes.COMMON_MAX_NUMBER_OF_EXECUTION, Integer.toString(task.getMaxNumberOfExecution()));
    }
    setAttribute(taskE, XMLAttributes.COMMON_NAME, task.getName(), true);
    if (task.getRestartTaskOnErrorProperty().isSet()) {
        setAttribute(taskE, XMLAttributes.COMMON_RESTART_TASK_ON_ERROR, task.getRestartTaskOnError().toString());
    }
    // *** task attributes ***
    if (task.getWallTime() != 0) {
        setAttribute(taskE, XMLAttributes.TASK_WALLTIME, formatDate(task.getWallTime()));
    }
    if (task.isRunAsMe()) {
        setAttribute(taskE, XMLAttributes.TASK_RUN_AS_ME, "true");
    }
    if (task.isPreciousResult()) {
        setAttribute(taskE, XMLAttributes.TASK_PRECIOUS_RESULT, "true");
    }
    if (task.isPreciousLogs()) {
        setAttribute(taskE, XMLAttributes.TASK_PRECIOUS_LOGS, "true");
    }
    // <ref name="taskDescription"/>
    if (task.getDescription() != null) {
        Element descrNode = createElement(doc, XMLTags.COMMON_DESCRIPTION.getXMLName(), task.getDescription());
        taskE.appendChild(descrNode);
    }
    // <ref name="variables"/>
    if (task.getVariables() != null && !task.getVariables().isEmpty()) {
        Element variablesE = createTaskVariablesElement(doc, task.getVariables());
        taskE.appendChild(variablesE);
    }
    // <ref name="genericInformation"/>
    if ((task.getGenericInformation() != null) && (task.getGenericInformation().size() > 0)) {
        Element genericInfoE = createGenericInformation(doc, task.getGenericInformation());
        taskE.appendChild(genericInfoE);
    }
    // <ref name="depends"/>
    List<Task> dependencies = task.getDependencesList();
    if ((dependencies != null) && (dependencies.size() > 0)) {
        Element dependsE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.TASK_DEPENDENCES.getXMLName());
        for (Task dep : dependencies) {
            Element dependsTask = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.TASK_DEPENDENCES_TASK.getXMLName());
            setAttribute(dependsTask, XMLAttributes.TASK_DEPENDS_REF, dep.getName(), true);
            dependsE.appendChild(dependsTask);
        }
        taskE.appendChild(dependsE);
    }
    // if has dependencies
    // <ref name="inputFiles"/>
    List<InputSelector> inputFiles = task.getInputFilesList();
    if (inputFiles != null) {
        Element inputFilesE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.DS_INPUT_FILES.getXMLName());
        for (InputSelector inputSelector : inputFiles) {
            FileSelector fs = inputSelector.getInputFiles();
            Element filesE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.DS_FILES.getXMLName());
            // pattern
            if (!fs.getIncludes().isEmpty())
                setAttribute(filesE, XMLAttributes.DS_INCLUDES, fs.getIncludes().iterator().next(), true);
            if (!fs.getExcludes().isEmpty())
                setAttribute(filesE, XMLAttributes.DS_EXCLUDES, fs.getExcludes().iterator().next(), true);
            if (inputSelector.getMode() != null) {
                setAttribute(filesE, XMLAttributes.DS_ACCESS_MODE, inputSelector.getMode().toString(), true);
            }
            inputFilesE.appendChild(filesE);
        }
        taskE.appendChild(inputFilesE);
    }
    // <ref name="parallel"/>
    Element parallelEnvE = createParallelEnvironment(doc, task);
    if (parallelEnvE != null)
        taskE.appendChild(parallelEnvE);
    // <ref name="selection"/>
    List<SelectionScript> selectionScripts = task.getSelectionScripts();
    if (selectionScripts != null && selectionScripts.size() > 0) {
        Element selectionE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.SCRIPT_SELECTION.getXMLName());
        for (SelectionScript selectionScript : selectionScripts) {
            Element scriptE = createScriptElement(doc, selectionScript);
            selectionE.appendChild(scriptE);
        }
        taskE.appendChild(selectionE);
    }
    // <ref name="forkEnvironment"/>
    if (task.getForkEnvironment() != null) {
        Element forkEnvE = createForkEnvironmentElement(doc, task.getForkEnvironment());
        taskE.appendChild(forkEnvE);
    }
    // <ref name="pre"/>
    Script preScript = task.getPreScript();
    if (preScript != null) {
        Element preE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.SCRIPT_PRE.getXMLName());
        Element scriptE = createScriptElement(doc, preScript);
        preE.appendChild(scriptE);
        taskE.appendChild(preE);
    }
    // <ref name="executable"/>
    Element executableE = null;
    if (task instanceof JavaTask) {
        executableE = createJavaExecutableElement(doc, (JavaTask) task);
    } else if (task instanceof NativeTask) {
        executableE = createNativeExecutableElement(doc, (NativeTask) task);
    } else if (task instanceof ScriptTask) {
        executableE = createScriptExecutableElement(doc, (ScriptTask) task);
    }
    taskE.appendChild(executableE);
    // <ref name="flow"/>
    Element controlFlowE = createFlowControlElement(doc, task);
    if (controlFlowE != null)
        taskE.appendChild(controlFlowE);
    // <ref name="post"/>
    Script postScript = task.getPostScript();
    if (postScript != null) {
        Element postE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.SCRIPT_POST.getXMLName());
        Element scriptE = createScriptElement(doc, postScript);
        postE.appendChild(scriptE);
        taskE.appendChild(postE);
    }
    // <ref name="cleaning"/>
    Script cleanScript = task.getCleaningScript();
    if (cleanScript != null) {
        Element cleanE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.SCRIPT_CLEANING.getXMLName());
        Element scriptE = createScriptElement(doc, cleanScript);
        cleanE.appendChild(scriptE);
        taskE.appendChild(cleanE);
    }
    // <ref name="outputFiles"/>
    List<OutputSelector> outputFiles = task.getOutputFilesList();
    if (outputFiles != null) {
        Element outputFilesE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.DS_OUTPUT_FILES.getXMLName());
        for (OutputSelector outputSelector : outputFiles) {
            FileSelector fs = outputSelector.getOutputFiles();
            Element filesE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.DS_FILES.getXMLName());
            // pattern
            if (!fs.getIncludes().isEmpty())
                setAttribute(filesE, XMLAttributes.DS_INCLUDES, fs.getIncludes().iterator().next(), true);
            if (!fs.getExcludes().isEmpty())
                setAttribute(filesE, XMLAttributes.DS_EXCLUDES, fs.getExcludes().iterator().next(), true);
            if (outputSelector.getMode() != null) {
                setAttribute(filesE, XMLAttributes.DS_ACCESS_MODE, outputSelector.getMode().toString(), true);
            }
            outputFilesE.appendChild(filesE);
        }
        taskE.appendChild(outputFilesE);
    }
    return taskE;
}
Also used : SelectionScript(org.ow2.proactive.scripting.SelectionScript) Script(org.ow2.proactive.scripting.Script) FlowScript(org.ow2.proactive.scheduler.common.task.flow.FlowScript) Task(org.ow2.proactive.scheduler.common.task.Task) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) Element(org.w3c.dom.Element) FileSelector(org.objectweb.proactive.extensions.dataspaces.vfs.selector.FileSelector) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) SelectionScript(org.ow2.proactive.scripting.SelectionScript) ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) OutputSelector(org.ow2.proactive.scheduler.common.task.dataspaces.OutputSelector) InputSelector(org.ow2.proactive.scheduler.common.task.dataspaces.InputSelector)

Aggregations

ScriptTask (org.ow2.proactive.scheduler.common.task.ScriptTask)16 TaskScript (org.ow2.proactive.scripting.TaskScript)15 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)14 SimpleScript (org.ow2.proactive.scripting.SimpleScript)13 Task (org.ow2.proactive.scheduler.common.task.Task)5 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)4 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)4 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)4 NativeTask (org.ow2.proactive.scheduler.common.task.NativeTask)4 File (java.io.File)3 JobId (org.ow2.proactive.scheduler.common.job.JobId)3 SelectionScript (org.ow2.proactive.scripting.SelectionScript)3 FileNotFoundException (java.io.FileNotFoundException)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 VerifierConfigurationException (org.iso_relax.verifier.VerifierConfigurationException)2 InternalException (org.ow2.proactive.scheduler.common.exception.InternalException)2 JobValidationException (org.ow2.proactive.scheduler.common.exception.JobValidationException)2 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)2 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)2 InternalForkedScriptTask (org.ow2.proactive.scheduler.task.internal.InternalForkedScriptTask)2