Search in sources :

Example 56 with JavaTask

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

the class TestRestoreWorkflowJobs method createJob.

private TaskFlowJob createJob() throws Exception {
    TaskFlowJob job = new TaskFlowJob();
    JavaTask t = task("T");
    JavaTask t1 = task("T1");
    JavaTask t2 = task("T2");
    JavaTask t3 = task("T3");
    JavaTask t4 = task("T4");
    t1.addDependence(t);
    t2.addDependence(t1);
    t3.addDependence(t2);
    t4.addDependence(t3);
    String replicateScript = String.format("runs = %d", 2);
    t.setFlowScript(FlowScript.createReplicateFlowScript(replicateScript));
    t1.setFlowBlock(FlowBlock.START);
    t1.setFlowScript(FlowScript.createReplicateFlowScript(replicateScript));
    t3.setFlowBlock(FlowBlock.END);
    job.addTask(t);
    job.addTask(t1);
    job.addTask(t2);
    job.addTask(t3);
    job.addTask(t4);
    return job;
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask)

Example 57 with JavaTask

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

the class TestPreciousLogs method testPreciousLogs.

private void testPreciousLogs(boolean createJavaTask, boolean forkEnv, boolean generateError) throws Exception {
    TaskFlowJob job = new TaskFlowJob();
    job.setName(this.getClass().getSimpleName());
    Map<String, List<String>> expectedOutput = new LinkedHashMap<>();
    for (int i = 0; i < 3; i++) {
        String forkOutput = "forkOutput-" + i;
        String preOutput = "preOutput-" + i;
        String postOutput = "postOutput-" + i;
        List<String> expectedTaskOutput = new ArrayList<>();
        expectedTaskOutput.add(TASK_OUTPUT);
        expectedTaskOutput.add(preOutput);
        if (!generateError) {
            expectedTaskOutput.add(postOutput);
        }
        Task task;
        if (createJavaTask) {
            JavaTask javaTask = new JavaTask();
            if (generateError) {
                javaTask.setExecutableClassName(TestJavaTaskWithError.class.getName());
            } else {
                javaTask.setExecutableClassName(TestJavaTask.class.getName());
            }
            if (forkEnv) {
                ForkEnvironment env = new ForkEnvironment();
                env.setEnvScript(createScript(forkOutput));
                javaTask.setForkEnvironment(env);
                expectedTaskOutput.add(forkOutput);
            }
            task = javaTask;
        } else {
            NativeTask nativeTask = new NativeTask();
            File script = new File(getClass().getResource("/functionaltests/executables/test_echo_task.sh").getFile());
            if (!script.exists()) {
                Assert.fail("Can't find script " + script.getAbsolutePath());
            }
            nativeTask.setCommandLine(script.getAbsolutePath());
            task = nativeTask;
        }
        if (generateError) {
            task.setMaxNumberOfExecution(NB_EXECUTIONS);
        } else {
            task.setMaxNumberOfExecution(1);
            task.setOnTaskError(OnTaskError.CANCEL_JOB);
        }
        task.setPreciousLogs(true);
        task.setName("Task-" + i);
        task.setPreScript(createScript(preOutput));
        task.setPostScript(createScript(postOutput));
        expectedOutput.put(task.getName(), expectedTaskOutput);
        job.addTask(task);
    }
    Scheduler scheduler = schedulerHelper.getSchedulerInterface();
    String userURI = scheduler.getUserSpaceURIs().get(0);
    File userFile = new File(new URI(userURI));
    // Clean all log files in user space
    for (File logFile : FileUtils.listFiles(userFile, new String[] { "log" }, true)) {
        FileUtils.deleteQuietly(logFile);
    }
    JobId jobId = schedulerHelper.testJobSubmission(job, true, false);
    JobResult jobResult = scheduler.getJobResult(jobId);
    Map<String, TaskResult> results = jobResult.getAllResults();
    List<File> logFiles = new ArrayList<>();
    for (String taskName : expectedOutput.keySet()) {
        File taskLog = new File(userFile.toString() + "/" + jobId.value(), String.format("TaskLogs-%s-%s.log", jobId.value(), results.get(taskName).getTaskId().value()));
        logFiles.add(taskLog);
        if (!taskLog.exists()) {
            Assert.fail("Task log file " + taskLog.getAbsolutePath() + " doesn't exist");
        }
        String output = new String(FileToBytesConverter.convertFileToByteArray(taskLog));
        System.out.println("Log file for " + taskName + ":");
        System.out.println(output);
        for (String expectedLine : expectedOutput.get(taskName)) {
            Assert.assertTrue("Output doesn't contain line " + expectedLine, output.contains(expectedLine));
            int expectedOccurrences = (generateError ? NB_EXECUTIONS : 1);
            Assert.assertEquals("Output doesn't contain " + expectedOccurrences + " occurrences of line " + expectedLine, expectedOccurrences, StringUtils.countMatches(output, expectedLine));
        }
    }
    // Test log removal
    schedulerHelper.removeJob(jobId);
    waitUntilAllLogsWereRemoved(jobId, logFiles);
}
Also used : JobResult(org.ow2.proactive.scheduler.common.job.JobResult) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) ArrayList(java.util.ArrayList) URI(java.net.URI) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 58 with JavaTask

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

the class TestJobSchedulingStarvationAndPriority method createJobReplicate.

/*
     * Job high priority with one task and high priority
     */
private TaskFlowJob createJobReplicate(int nbRun, JobPriority priority) throws Exception {
    String jobDescriptorPath = new File(jobDescriptor.toURI()).getAbsolutePath();
    TaskFlowJob job = new TaskFlowJob();
    job.setName(this.getClass().getSimpleName() + "_High");
    job.setPriority(JobPriority.HIGHEST);
    JavaTask javaTask = new JavaTask();
    javaTask.setExecutableClassName(EmptyTask.class.getName());
    javaTask.setName("taskHigh");
    job.addTask(javaTask);
    return job;
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) EmptyTask(org.ow2.proactive.scheduler.examples.EmptyTask) File(java.io.File)

Example 59 with JavaTask

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

the class TestExecuteScriptsOnBusyNode method createJobWithLock.

private TaskFlowJob createJobWithLock(String communicationObjectUrl) throws Exception {
    TaskFlowJob job = new TaskFlowJob();
    job.setName(this.getClass().getSimpleName() + "_JobWithLock");
    job.setOnTaskError(OnTaskError.CANCEL_JOB);
    job.setMaxNumberOfExecution(1);
    JavaTask javaTask = new JavaTask();
    javaTask.setExecutableClassName(TestJavaTaskWithLock.class.getName());
    javaTask.setMaxNumberOfExecution(1);
    javaTask.setOnTaskError(OnTaskError.CANCEL_JOB);
    javaTask.setName("Test task");
    javaTask.addArgument("fileLockPath", communicationObjectUrl);
    job.addTask(javaTask);
    return job;
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask)

Example 60 with JavaTask

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

the class TestExecuteScriptsOnBusyNode method createNonBlockingJob.

private TaskFlowJob createNonBlockingJob(boolean withSelectionScript) throws Exception {
    TaskFlowJob job = new TaskFlowJob();
    job.setName(this.getClass().getSimpleName() + "_SimpleJob");
    job.setOnTaskError(OnTaskError.CANCEL_JOB);
    job.setMaxNumberOfExecution(1);
    JavaTask javaTask = new JavaTask();
    javaTask.setExecutableClassName(TestJavaTask.class.getName());
    javaTask.setMaxNumberOfExecution(1);
    javaTask.setOnTaskError(OnTaskError.CANCEL_JOB);
    javaTask.setName("Test task");
    if (withSelectionScript) {
        // we want to trigger a selection script execution on the unique node, as this will call node.clean()
        javaTask.addSelectionScript(new SelectionScript("selected = true", "groovy", true));
    }
    job.addTask(javaTask);
    return job;
}
Also used : SelectionScript(org.ow2.proactive.scripting.SelectionScript) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask)

Aggregations

TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)104 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)104 Test (org.junit.Test)44 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)24 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)20 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)18 JobId (org.ow2.proactive.scheduler.common.job.JobId)14 NativeTask (org.ow2.proactive.scheduler.common.task.NativeTask)14 EmptyTask (org.ow2.proactive.scheduler.examples.EmptyTask)13 SelectionScript (org.ow2.proactive.scripting.SelectionScript)12 SimpleScript (org.ow2.proactive.scripting.SimpleScript)12 File (java.io.File)11 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)11 HashMap (java.util.HashMap)10 Task (org.ow2.proactive.scheduler.common.task.Task)9 JobResult (org.ow2.proactive.scheduler.common.job.JobResult)7 ScriptTask (org.ow2.proactive.scheduler.common.task.ScriptTask)6 EmptyExecutable (functionaltests.executables.EmptyExecutable)5 JobDescriptor (org.ow2.proactive.scheduler.common.JobDescriptor)5 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)5