Search in sources :

Example 46 with InvalidScriptException

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

the class TestDataspaceConcurrentKilling method createJobWithFileTransfers.

public Job createJobWithFileTransfers() throws UserException, InvalidScriptException {
    TaskFlowJob job = new TaskFlowJob();
    job.setName(JOB_NAME);
    job.setOnTaskError(OnTaskError.CONTINUE_JOB_EXECUTION);
    for (int i = 0; i < NB_TASKS; i++) {
        ScriptTask st = new ScriptTask();
        st.setName(TASK_NAME + i);
        st.setScript(new TaskScript(new SimpleScript("new File(localspace, \"" + FILE_NAME + i + "\").createNewFile(); java.lang.Thread.sleep(1000)", "groovy")));
        st.addOutputFiles(FILE_NAME + i, OutputAccessMode.TransferToUserSpace);
        job.addTask(st);
    }
    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)

Example 47 with InvalidScriptException

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

the class SchedulerDBManager method toInternalTasks.

private Collection<InternalTask> toInternalTasks(boolean loadFullState, InternalJob internalJob, List<TaskData> taskRuntimeDataList) {
    Map<DBTaskId, InternalTask> tasks = new HashMap<>(taskRuntimeDataList.size());
    try {
        for (TaskData taskData : taskRuntimeDataList) {
            InternalTask internalTask = taskData.toInternalTask(internalJob, loadFullState);
            if (loadFullState) {
                internalTask.setParallelEnvironment(taskData.getParallelEnvironment());
                internalTask.setGenericInformation(taskData.getGenericInformation());
                for (SelectionScriptData scriptData : taskData.getSelectionScripts()) {
                    internalTask.addSelectionScript(scriptData.createSelectionScript());
                }
                if (taskData.getCleanScript() != null) {
                    internalTask.setCleaningScript(taskData.getCleanScript().createSimpleScript());
                }
                if (taskData.getPreScript() != null) {
                    internalTask.setPreScript(taskData.getPreScript().createSimpleScript());
                }
                if (taskData.getPostScript() != null) {
                    internalTask.setPostScript(taskData.getPostScript().createSimpleScript());
                }
                if (taskData.getFlowScript() != null) {
                    internalTask.setFlowScript(taskData.getFlowScript().createFlowScript());
                }
                for (SelectorData selectorData : taskData.getDataspaceSelectors()) {
                    if (selectorData.isInput()) {
                        InputSelector selector = selectorData.createInputSelector();
                        internalTask.addInputFiles(selector.getInputFiles(), selector.getMode());
                    } else {
                        OutputSelector selector = selectorData.createOutputSelector();
                        internalTask.addOutputFiles(selector.getOutputFiles(), selector.getMode());
                    }
                }
            }
            tasks.put(taskData.getId(), internalTask);
        }
    } catch (InvalidScriptException e) {
        throw new DatabaseManagerException("Failed to initialize loaded script", e);
    }
    for (TaskData taskData : taskRuntimeDataList) {
        InternalTask internalTask = tasks.get(taskData.getId());
        if (!taskData.getDependentTasks().isEmpty()) {
            for (DBTaskId dependent : taskData.getDependentTasks()) {
                internalTask.addDependence(tasks.get(dependent));
            }
        }
        if (loadFullState) {
            if (taskData.getIfBranch() != null) {
                internalTask.setIfBranch(tasks.get(taskData.getIfBranch().getId()));
            }
            if (!taskData.getJoinedBranches().isEmpty()) {
                List<InternalTask> branches = new ArrayList<>(taskData.getJoinedBranches().size());
                for (DBTaskId joinedBranch : taskData.getJoinedBranches()) {
                    branches.add(tasks.get(joinedBranch));
                }
                internalTask.setJoinedBranches(branches);
            }
            internalTask.setName(internalTask.getName());
        }
    }
    return tasks.values();
}
Also used : InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) HashMap(java.util.HashMap) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) ArrayList(java.util.ArrayList) DatabaseManagerException(org.ow2.proactive.db.DatabaseManagerException) DBTaskId(org.ow2.proactive.scheduler.core.db.TaskData.DBTaskId) OutputSelector(org.ow2.proactive.scheduler.common.task.dataspaces.OutputSelector) InputSelector(org.ow2.proactive.scheduler.common.task.dataspaces.InputSelector)

Example 48 with InvalidScriptException

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

the class TaskData method createForkEnvironment.

public ForkEnvironment createForkEnvironment() throws InvalidScriptException {
    ForkEnvironment forkEnv = new ForkEnvironment();
    forkEnv.setJavaHome(javaHome);
    forkEnv.setWorkingDir(workingDir);
    List<String> additionalClasspath = getAdditionalClasspath();
    if (additionalClasspath != null) {
        for (String classpath : additionalClasspath) {
            forkEnv.addAdditionalClasspath(classpath);
        }
    }
    List<String> jvmArguments = getJvmArguments();
    if (jvmArguments != null) {
        for (String jvmArg : jvmArguments) {
            forkEnv.addJVMArgument(jvmArg);
        }
    }
    List<EnvironmentModifierData> envModifiers = getEnvModifiers();
    if (envModifiers != null) {
        for (EnvironmentModifierData envModifier : envModifiers) {
            forkEnv.addSystemEnvironmentVariable(envModifier.getName(), envModifier.getValue());
        }
    }
    if (envScript != null) {
        forkEnv.setEnvScript(envScript.createSimpleScript());
    }
    return forkEnv;
}
Also used : ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment)

Example 49 with InvalidScriptException

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

the class TestRestoreWorkflowJobs method createJobWithAllKindOfScripts.

private TaskFlowJob createJobWithAllKindOfScripts() throws InvalidScriptException, UserException {
    TaskFlowJob jobDef = new TaskFlowJob();
    JavaTask t = task("T");
    ForkEnvironment forkEnvironment = new ForkEnvironment();
    SimpleScript aScript = new SimpleScript("", "");
    forkEnvironment.setEnvScript(aScript);
    t.setPreScript(aScript);
    t.setPostScript(aScript);
    t.setCleaningScript(aScript);
    t.setSelectionScript(new SelectionScript("", ""));
    t.setFlowScript(FlowScript.createContinueFlowScript());
    t.setForkEnvironment(forkEnvironment);
    jobDef.addTask(t);
    return jobDef;
}
Also used : SelectionScript(org.ow2.proactive.scripting.SelectionScript) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleScript(org.ow2.proactive.scripting.SimpleScript) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment)

Example 50 with InvalidScriptException

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

the class TagTest method createLoopTask.

private InternalScriptTask createLoopTask(String name, String scriptContent, InternalTask[] dependences, String targetName, boolean block) throws InvalidScriptException {
    FlowBlock fb = null;
    if (block) {
        fb = FlowBlock.END;
    }
    InternalScriptTask result = createTask(name, dependences, fb, targetName);
    FlowScript loop = FlowScript.createLoopFlowScript(scriptContent, targetName);
    result.setFlowScript(loop);
    return result;
}
Also used : FlowBlock(org.ow2.proactive.scheduler.common.task.flow.FlowBlock) InternalScriptTask(org.ow2.proactive.scheduler.task.internal.InternalScriptTask) FlowScript(org.ow2.proactive.scheduler.common.task.flow.FlowScript)

Aggregations

Test (org.junit.Test)27 SimpleScript (org.ow2.proactive.scripting.SimpleScript)27 VariablesMap (org.ow2.proactive.scheduler.task.utils.VariablesMap)15 ScriptHandler (org.ow2.proactive.scripting.ScriptHandler)15 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)14 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)14 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)14 TaskLauncherInitializer (org.ow2.proactive.scheduler.task.TaskLauncherInitializer)12 NodeDataSpacesURIs (org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs)12 TaskScript (org.ow2.proactive.scripting.TaskScript)12 FlowScript (org.ow2.proactive.scheduler.common.task.flow.FlowScript)11 Script (org.ow2.proactive.scripting.Script)11 HashMap (java.util.HashMap)6 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)6 InternalScriptTask (org.ow2.proactive.scheduler.task.internal.InternalScriptTask)6 InvalidScriptException (org.ow2.proactive.scripting.InvalidScriptException)6 ScriptTask (org.ow2.proactive.scheduler.common.task.ScriptTask)5 File (java.io.File)4 SelectionScript (org.ow2.proactive.scripting.SelectionScript)4 Serializable (java.io.Serializable)3