Search in sources :

Example 61 with TaskResult

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

the class TestTaskNotExecuted method testTaskNotExecuted.

private void testTaskNotExecuted(String jobDescriptorPath1, String jobDescriptorPath2, String jobDescriptorPath3) throws Exception {
    log("Submitting job 1");
    JobId id1 = schedulerHelper.submitJob(jobDescriptorPath1);
    log("Wait for event job 1 submitted");
    schedulerHelper.waitForEventJobSubmitted(id1);
    log("Wait for event t1 running");
    schedulerHelper.waitForEventTaskRunning(id1, "t0");
    schedulerHelper.waitForEventTaskFinished(id1, "t0");
    schedulerHelper.waitForEventJobFinished(id1);
    TaskResult tr1 = schedulerHelper.getSchedulerInterface().getTaskResult(id1, "t1");
    assertTrue(tr1.getException() instanceof TaskCouldNotStartException);
    log("Submitting job 2");
    JobId id2 = schedulerHelper.submitJob(jobDescriptorPath2);
    log("Wait for event job 2 submitted");
    schedulerHelper.waitForEventJobSubmitted(id2);
    log("Wait for event t2 running");
    schedulerHelper.waitForEventTaskRunning(id2, "t2");
    log("Restarting task");
    schedulerHelper.getSchedulerInterface().restartTask(id2, "t2", Integer.MAX_VALUE);
    TaskInfo ti2 = schedulerHelper.waitForEventTaskWaitingForRestart(id2, "t2");
    schedulerHelper.getSchedulerInterface().killJob(id2);
    schedulerHelper.waitForEventJobFinished(id2);
    JobState jobState = schedulerHelper.getSchedulerInterface().getJobState(id2);
    Assert.assertEquals(TaskStatus.NOT_RESTARTED, jobState.getTasks().get(0).getStatus());
    TaskResult tr2 = schedulerHelper.getSchedulerInterface().getTaskResult(id2, "t2");
    assertTrue(tr2.getException() instanceof TaskCouldNotRestartException);
    log("Submitting job 3");
    JobId id3 = schedulerHelper.submitJob(jobDescriptorPath3);
    log("Wait for event job 3 submitted");
    schedulerHelper.waitForEventJobSubmitted(id3);
    log("Wait for event T T1 T2 finished");
    schedulerHelper.waitForEventTaskFinished(id3, "T");
    schedulerHelper.waitForEventTaskFinished(id3, "T1");
    TaskResult tr3_1 = schedulerHelper.getSchedulerInterface().getTaskResult(id3, "T1");
    TaskResult tr3_2 = schedulerHelper.getSchedulerInterface().getTaskResult(id3, "T2");
    assertNull(tr3_1.getException());
    assertTrue(tr3_2.getException() instanceof TaskSkippedException);
}
Also used : TaskInfo(org.ow2.proactive.scheduler.common.task.TaskInfo) TaskCouldNotStartException(org.ow2.proactive.scheduler.common.exception.TaskCouldNotStartException) TaskCouldNotRestartException(org.ow2.proactive.scheduler.common.exception.TaskCouldNotRestartException) TaskSkippedException(org.ow2.proactive.scheduler.common.exception.TaskSkippedException) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) JobState(org.ow2.proactive.scheduler.common.job.JobState) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 62 with TaskResult

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

the class TestTaskRestartOnNodeFailure method checkJobResult.

private void checkJobResult(Scheduler scheduler, JobId jobId) throws Exception {
    JobResult jobResult = scheduler.getJobResult(jobId);
    assertEquals("Unexpected number of task results", 1, jobResult.getAllResults().size());
    for (TaskResult taskResult : jobResult.getAllResults().values()) {
        log("Task " + taskResult.getTaskId());
        assertNull("Unexpected task result exception", taskResult.getException());
        String output = taskResult.getOutput().getAllLogs(false);
        log("Task output:");
        log(output);
        assertTrue("Unxepected output", output.contains("OK"));
    }
}
Also used : JobResult(org.ow2.proactive.scheduler.common.job.JobResult) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult)

Example 63 with TaskResult

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

the class TestPreciousLogs method testPreciousLogs.

private void testPreciousLogs(boolean createJavaTask, boolean forkEnv) 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);
        expectedTaskOutput.add(postOutput);
        Task task;
        if (createJavaTask) {
            JavaTask javaTask = new JavaTask();
            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;
        }
        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);
    }
    JobId jobId = schedulerHelper.testJobSubmission(job);
    Scheduler scheduler = schedulerHelper.getSchedulerInterface();
    String userURI = scheduler.getUserSpaceURIs().get(0);
    String userPath = new File(new URI(userURI)).getAbsolutePath();
    JobResult jobResult = scheduler.getJobResult(jobId);
    Map<String, TaskResult> results = jobResult.getAllResults();
    for (String taskName : expectedOutput.keySet()) {
        File taskLog = new File(userPath + "/" + jobId.value(), String.format("TaskLogs-%s-%s.log", jobId.value(), results.get(taskName).getTaskId().value()));
        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));
        }
    }
}
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 64 with TaskResult

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

the class JavaSpawnExecutable method execute.

@Override
public Serializable execute(TaskResult... results) throws Throwable {
    org.apache.log4j.Logger.getLogger(ProcessTree.class).setLevel(Level.DEBUG);
    Process process = null;
    process = Runtime.getRuntime().exec(getNativeExecLauncher(false), null, getExecutablePath(launchersDir).getParentFile().getCanonicalFile());
    // redirect streams
    BufferedReader sout = new BufferedReader(new InputStreamReader(process.getInputStream()));
    BufferedReader serr = new BufferedReader(new InputStreamReader(process.getErrorStream()));
    Thread tsout = new Thread(new ThreadReader(sout, System.out));
    Thread tserr = new Thread(new ThreadReader(serr, System.err));
    tsout.setDaemon(true);
    tserr.setDaemon(true);
    tsout.start();
    tserr.start();
    process.waitFor();
    // we sleep 2 sec
    Thread.sleep(sleep * 1000);
    return true;
}
Also used : InputStreamReader(java.io.InputStreamReader) ProcessTree(org.ow2.proactive.process_tree_killer.ProcessTree) BufferedReader(java.io.BufferedReader) ThreadReader(org.ow2.proactive.scheduler.task.utils.ThreadReader)

Example 65 with TaskResult

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

the class SchedulerFrontend method getTaskResultFromIncarnation.

/**
 * {@inheritDoc}
 */
@Override
@ImmediateService
public TaskResult getTaskResultFromIncarnation(JobId jobId, String taskName, int inc) throws NotConnectedException, UnknownJobException, UnknownTaskException, PermissionException {
    // checking permissions
    frontendState.checkPermissions("getTaskResultFromIncarnation", frontendState.getIdentifiedJob(jobId), YOU_DO_NOT_HAVE_PERMISSION_TO_GET_THE_TASK_RESULT_OF_THIS_JOB);
    if (inc < 0) {
        throw new IllegalArgumentException("Incarnation must be 0 or greater.");
    }
    jlogger.debug(jobId, "trying to get the task result, incarnation " + inc);
    if (inc < 0) {
        throw new IllegalArgumentException("Incarnation must be 0 or greater.");
    }
    try {
        TaskResult result = dbManager.loadTaskResult(jobId, taskName, inc);
        // handling special statuses
        TaskState ts = frontendState.getTaskState(jobId, taskName);
        switch(ts.getStatus()) {
            case NOT_STARTED:
                if (result == null) {
                    return new TaskResultImpl(frontendState.getTaskId(jobId, taskName), new TaskCouldNotStartException(), new SimpleTaskLogs("", "The task could not start due to dependency failure"), 0);
                } else {
                    Throwable newException = new TaskCouldNotStartException("The task could not start due to dependency failure", result.getException());
                    ((TaskResultImpl) result).setException(newException);
                }
                break;
            case NOT_RESTARTED:
                if (result == null) {
                    return new TaskResultImpl(frontendState.getTaskId(jobId, taskName), new TaskCouldNotRestartException(), new SimpleTaskLogs("", "The task could not be restarted after an error during the previous execution"), 0);
                } else {
                    Throwable newException = new TaskCouldNotRestartException("The task could not be restarted after an error during the previous execution", result.getException());
                    ((TaskResultImpl) result).setException(newException);
                }
                break;
            case SKIPPED:
                // result should always be null
                return new TaskResultImpl(frontendState.getTaskId(jobId, taskName), new TaskSkippedException(), new SimpleTaskLogs("", "The task was skipped in the workflow"), 0);
        }
        if (result == null) {
            // otherwise the task is not finished
            jlogger.info(jobId, taskName + " is not finished");
            return null;
        } else {
            return result;
        }
    } catch (DatabaseManagerException e) {
        throw new UnknownTaskException("Unknown task " + taskName + ", job: " + jobId);
    }
}
Also used : SimpleTaskLogs(org.ow2.proactive.scheduler.common.task.SimpleTaskLogs) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) TaskCouldNotStartException(org.ow2.proactive.scheduler.common.exception.TaskCouldNotStartException) TaskCouldNotRestartException(org.ow2.proactive.scheduler.common.exception.TaskCouldNotRestartException) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) TaskSkippedException(org.ow2.proactive.scheduler.common.exception.TaskSkippedException) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) DatabaseManagerException(org.ow2.proactive.db.DatabaseManagerException) ImmediateService(org.objectweb.proactive.annotation.ImmediateService)

Aggregations

TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)99 Test (org.junit.Test)54 JobId (org.ow2.proactive.scheduler.common.job.JobId)38 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)28 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)25 SimpleScript (org.ow2.proactive.scripting.SimpleScript)25 File (java.io.File)24 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)23 TaskScript (org.ow2.proactive.scripting.TaskScript)23 HashMap (java.util.HashMap)22 JobResult (org.ow2.proactive.scheduler.common.job.JobResult)22 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)18 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)17 GET (javax.ws.rs.GET)16 Path (javax.ws.rs.Path)16 Produces (javax.ws.rs.Produces)16 GZIP (org.jboss.resteasy.annotations.GZIP)16 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)14 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)12 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)12