Search in sources :

Example 1 with SimpleTaskLogs

use of org.ow2.proactive.scheduler.common.task.SimpleTaskLogs 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)

Example 2 with SimpleTaskLogs

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

the class SchedulerStateRestJobLogsTest method createJobResult.

private JobResultImpl createJobResult(String taskOutput, String taskErrput) {
    JobResultImpl jobResult = new JobResultImpl();
    jobResult.addTaskResult("OneTask", new TaskResultImpl(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("123"), "OneTask", 1), "result", new SimpleTaskLogs(taskOutput, taskErrput), 100), false);
    return jobResult;
}
Also used : JobResultImpl(org.ow2.proactive.scheduler.job.JobResultImpl) SimpleTaskLogs(org.ow2.proactive.scheduler.common.task.SimpleTaskLogs) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl)

Example 3 with SimpleTaskLogs

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

the class NoVncSecuredTargetResolverTest method testMagicStringFoundInLogs_MagicStringOnSeveralLines.

@Test
public void testMagicStringFoundInLogs_MagicStringOnSeveralLines() throws Exception {
    String sessionId = SharedSessionStoreTestUtils.createValidSession(schedulerMock);
    when(schedulerMock.getTaskResult("42", "remoteVisuTask")).thenReturn(new TaskResultImpl(TaskIdImpl.createTaskId(new JobIdImpl(42, "job"), "remoteVisuTask", 1), new byte[0], new byte[0], new SimpleTaskLogs("PA_REMOTE_CONNECTION\nPA_REMOTE_CONNECTION;42;1;vnc;node.grid.com:5900", ""), true));
    InetSocketAddress targetVncHost = new NoVncSecuredTargetResolver().doResolve(sessionId, "42", "remoteVisuTask");
    assertEquals(5900, targetVncHost.getPort());
    assertEquals("node.grid.com", targetVncHost.getHostName());
}
Also used : SimpleTaskLogs(org.ow2.proactive.scheduler.common.task.SimpleTaskLogs) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) InetSocketAddress(java.net.InetSocketAddress) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) Test(org.junit.Test)

Example 4 with SimpleTaskLogs

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

the class NoVncSecuredTargetResolverTest method testMagicStringFoundInLiveLogs_MagicStringOnSeveralLines.

@Test
public void testMagicStringFoundInLiveLogs_MagicStringOnSeveralLines() throws Exception {
    String sessionId = SharedSessionStoreTestUtils.createValidSession(schedulerMock);
    SharedSessionStore.getInstance().get(sessionId).getJobsOutputController().addJobOutputAppender("42", createLiveLogs("PA_REMOTE_CONNECTION\nPA_REMOTE_CONNECTION;42;1;vnc;node.grid.com:5900 "));
    when(schedulerMock.getTaskResult("42", "remoteVisuTask")).thenReturn(new TaskResultImpl(TaskIdImpl.createTaskId(new JobIdImpl(42, "job"), "remoteVisuTask", 1), new byte[0], new byte[0], new SimpleTaskLogs("", ""), true));
    InetSocketAddress targetVncHost = new NoVncSecuredTargetResolver().doResolve(sessionId, "42", "remoteVisuTask");
    assertEquals(5900, targetVncHost.getPort());
    assertEquals("node.grid.com", targetVncHost.getHostName());
}
Also used : SimpleTaskLogs(org.ow2.proactive.scheduler.common.task.SimpleTaskLogs) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) InetSocketAddress(java.net.InetSocketAddress) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) Test(org.junit.Test)

Example 5 with SimpleTaskLogs

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

the class LiveJobs method preemptTask.

TerminationData preemptTask(JobId jobId, String taskName, int restartDelay) throws UnknownJobException, UnknownTaskException {
    JobData jobData = lockJob(jobId);
    if (jobData == null) {
        throw new UnknownJobException(jobId);
    }
    try {
        InternalTask task = jobData.job.getTask(taskName);
        tlogger.info(task.getId(), "preempting task " + task.getId());
        if (!task.getStatus().isTaskAlive()) {
            tlogger.info(task.getId(), "task isn't alive: " + task.getStatus());
            return emptyResult(task.getId());
        }
        RunningTaskData taskData = runningTasksData.remove(TaskIdWrapper.wrap(task.getId()));
        if (taskData == null) {
            throw new IllegalStateException("Task " + task.getId() + " is not running.");
        }
        TaskResultImpl taskResult = taskResultCreator.getTaskResult(dbManager, jobData.job, task, new TaskPreemptedException("Preempted by admin"), new SimpleTaskLogs("", "Preempted by admin"));
        TerminationData terminationData = createAndFillTerminationData(taskResult, taskData, jobData.job, TerminationData.TerminationStatus.ABORTED);
        long waitTime = restartDelay * 1000L;
        restartTaskOnError(jobData, task, TaskStatus.PENDING, taskResult, waitTime, terminationData);
        return terminationData;
    } finally {
        jobData.unlock();
    }
}
Also used : TaskPreemptedException(org.ow2.proactive.scheduler.common.exception.TaskPreemptedException) SimpleTaskLogs(org.ow2.proactive.scheduler.common.task.SimpleTaskLogs) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask)

Aggregations

SimpleTaskLogs (org.ow2.proactive.scheduler.common.task.SimpleTaskLogs)11 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)11 Test (org.junit.Test)5 InetSocketAddress (java.net.InetSocketAddress)4 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)4 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)4 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)4 TaskAbortedException (org.ow2.proactive.scheduler.common.exception.TaskAbortedException)2 TaskPreemptedException (org.ow2.proactive.scheduler.common.exception.TaskPreemptedException)2 TaskRestartedException (org.ow2.proactive.scheduler.common.exception.TaskRestartedException)2 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)2 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)2 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)2 ImmediateService (org.objectweb.proactive.annotation.ImmediateService)1 DatabaseManagerException (org.ow2.proactive.db.DatabaseManagerException)1 SchedulerEvent (org.ow2.proactive.scheduler.common.SchedulerEvent)1 TaskCouldNotRestartException (org.ow2.proactive.scheduler.common.exception.TaskCouldNotRestartException)1 TaskCouldNotStartException (org.ow2.proactive.scheduler.common.exception.TaskCouldNotStartException)1 TaskSkippedException (org.ow2.proactive.scheduler.common.exception.TaskSkippedException)1 JobId (org.ow2.proactive.scheduler.common.job.JobId)1