Search in sources :

Example 91 with SimpleScript

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

the class RestSmartProxyTest method createInErrorJob.

private TaskFlowJob createInErrorJob() throws InvalidScriptException, UserException {
    TaskFlowJob job = new TaskFlowJob();
    job.setName("JobWithInErrorTask");
    ScriptTask scriptTask = new ScriptTask();
    scriptTask.setName(inerrorTaskName);
    scriptTask.setScript(new TaskScript(new SimpleScript("syntax error", "python")));
    scriptTask.setOnTaskError(OnTaskError.PAUSE_TASK);
    scriptTask.setMaxNumberOfExecution(2);
    job.addTask(scriptTask);
    job.setInputSpace(userspace);
    job.setOutputSpace(userspace);
    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 92 with SimpleScript

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

the class TestWorkflowIterationAwareness method testNativeJob.

/**
 * native task through xml
 */
private void testNativeJob(String jobDescriptorPath) throws Throwable {
    TaskFlowJob job = (TaskFlowJob) StaxJobFactory.getFactory().createJob(jobDescriptorPath);
    switch(OperatingSystem.getOperatingSystem()) {
        case windows:
            ((NativeTask) job.getTask("T1")).setPreScript(new SimpleScript(preScript, "groovy"));
            ((NativeTask) job.getTask("T1")).setPostScript(new SimpleScript(postScript, "groovy"));
            String[] tab = ((NativeTask) job.getTask("T1")).getCommandLine();
            tab[0] = "\"" + tab[0].replace("it.sh", "it.bat") + "\"";
            tab[1] = tmpFolder;
            ((NativeTask) job.getTask("T1")).setCommandLine(tab);
            break;
        case unix:
            job.getTask("T1").setPreScript(new SimpleScript(preScript, "groovy"));
            job.getTask("T1").setPostScript(new SimpleScript(postScript, "groovy"));
            break;
        default:
            throw new IllegalStateException("Unsupported operating system");
    }
    JobId id = TWorkflowJobs.testJobSubmission(schedulerHelper, job, null);
    JobResult res = schedulerHelper.getJobResult(id);
    Assert.assertFalse(schedulerHelper.getJobResult(id).hadException());
    int n = 4;
    for (Entry<String, TaskResult> result : res.getAllResults().entrySet()) {
        String path = "";
        switch(OperatingSystem.getOperatingSystem()) {
            case windows:
                File tmpdir = new File(tmpFolder, "native_result_");
                path = tmpdir.getAbsolutePath();
                break;
            case unix:
                path = System.getProperty("java.io.tmpdir") + "/native_result_";
                break;
            default:
                throw new IllegalStateException("Operating system not supported");
        }
        if (result.getKey().equals("T1")) {
            n--;
            File f = new File(path + "0_0");
            BufferedReader in = new BufferedReader(new FileReader(f));
            checkResult(in.readLine(), "T1", "0", "0");
            in.close();
            f.delete();
        } else if (result.getKey().equals("T1*1")) {
            n--;
            File f = new File(path + "0_1");
            BufferedReader in = new BufferedReader(new FileReader(f));
            checkResult(in.readLine(), "T1*1", "0", "1");
            in.close();
            f.delete();
        } else if (result.getKey().equals("T1#1")) {
            n--;
            File f = new File(path + "1_0");
            BufferedReader in = new BufferedReader(new FileReader(f));
            checkResult(in.readLine(), "T1#1", "1", "0");
            in.close();
            f.delete();
        } else if (result.getKey().equals("T1#1*1")) {
            n--;
            File f = new File(path + "1_1");
            BufferedReader in = new BufferedReader(new FileReader(f));
            checkResult(in.readLine(), "T1#1*1", "1", "1");
            in.close();
            f.delete();
        }
    }
    assertTrue("Expected 4 tasks, misses " + n, n == 0);
    schedulerHelper.removeJob(id);
    schedulerHelper.waitForEventJobRemoved(id);
}
Also used : JobResult(org.ow2.proactive.scheduler.common.job.JobResult) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleScript(org.ow2.proactive.scripting.SimpleScript) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) BufferedReader(java.io.BufferedReader) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) FileReader(java.io.FileReader) File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 93 with SimpleScript

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

the class TestWorkflowIterationAwareness method testJavaJob.

/**
 * java task through xml
 */
private void testJavaJob(String jobDescriptorPath) throws Throwable {
    TaskFlowJob job = (TaskFlowJob) StaxJobFactory.getFactory().createJob(jobDescriptorPath);
    ((JavaTask) job.getTask("T1")).setPreScript(new SimpleScript(preScript, "groovy"));
    ((JavaTask) job.getTask("T1")).setPostScript(new SimpleScript(postScript, "groovy"));
    JobId id = TWorkflowJobs.testJobSubmission(schedulerHelper, job, null);
    JobResult res = schedulerHelper.getJobResult(id);
    Assert.assertFalse(schedulerHelper.getJobResult(id).hadException());
    int n = 4;
    for (Entry<String, TaskResult> result : res.getAllResults().entrySet()) {
        if (result.getKey().equals("T1")) {
            n--;
            checkResult(result.getValue().toString(), "T1", "0", "0");
        } else if (result.getKey().equals("T1*1")) {
            n--;
            checkResult(result.getValue().toString(), "T1*1", "0", "1");
        } else if (result.getKey().equals("T1#1")) {
            n--;
            checkResult(result.getValue().toString(), "T1#1", "1", "0");
        } else if (result.getKey().equals("T1#1*1")) {
            n--;
            checkResult(result.getValue().toString(), "T1#1*1", "1", "1");
        }
    }
    assertTrue("Expected 4 tasks, misses " + n, n == 0);
    schedulerHelper.removeJob(id);
    schedulerHelper.waitForEventJobRemoved(id);
}
Also used : JobResult(org.ow2.proactive.scheduler.common.job.JobResult) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleScript(org.ow2.proactive.scripting.SimpleScript) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 94 with SimpleScript

use of org.ow2.proactive.scripting.SimpleScript 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 95 with SimpleScript

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

the class RunningTaskRecoveryWithDownNodeTest method submitJob.

private JobId submitJob() throws Exception {
    TaskFlowJob job = new TaskFlowJob();
    job.setName("JOB-" + RunningTaskRecoveryWithDownNodeTest.class.getSimpleName());
    for (int i = 0; i < NUMBER_OF_TASKS; i++) {
        ScriptTask st1 = new ScriptTask();
        st1.setName(TASK_BASE_NAME + i);
        st1.setScript(new TaskScript(new SimpleScript("Thread.sleep(60000)", "groovy")));
        job.addTask(st1);
    }
    JobId jobid = schedulerHelper.submitJob(job);
    schedulerHelper.waitForEventJobRunning(jobid);
    return jobid;
}
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) JobId(org.ow2.proactive.scheduler.common.job.JobId)

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