Search in sources :

Example 1 with TaskResultImpl

use of org.ow2.proactive.scheduler.rest.data.TaskResultImpl 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 2 with TaskResultImpl

use of org.ow2.proactive.scheduler.rest.data.TaskResultImpl in project scheduling by ow2-proactive.

the class SchedulerStateRestJobTaskResultTest method testValueOfTaskResult_ExceptionNoMessage.

@Test
public void testValueOfTaskResult_ExceptionNoMessage() throws Throwable {
    TaskResultImpl taskResultWithException = new TaskResultImpl(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("42"), "mytask", 1), null, new byte[0], null, false);
    when(mockOfScheduler.getTaskResult("42", "mytask")).thenReturn(taskResultWithException);
    String exceptionStackTrace = (String) restInterface.valueOfTaskResult(sessionId, "42", "mytask");
    assertNotNull(exceptionStackTrace);
}
Also used : TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) Test(org.junit.Test)

Example 3 with TaskResultImpl

use of org.ow2.proactive.scheduler.rest.data.TaskResultImpl 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 TaskResultImpl

use of org.ow2.proactive.scheduler.rest.data.TaskResultImpl 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 TaskResultImpl

use of org.ow2.proactive.scheduler.rest.data.TaskResultImpl in project scheduling by ow2-proactive.

the class TaskLauncher method doTask.

public void doTask(ExecutableContainer executableContainer, TaskResult[] previousTasksResults, TaskTerminateNotification terminateNotification, String terminateNotificationNodeURL, boolean taskRecoverable) {
    TaskResultImpl taskResult;
    WallTimer wallTimer = null;
    TaskContext context = null;
    Stopwatch taskStopwatchForFailures = null;
    TaskDataspaces dataspaces = null;
    try {
        taskStarted.set(true);
        logger.info("Task started " + taskId.getJobId().getReadableName() + " : " + taskId.getReadableName());
        this.taskKiller = this.replaceTaskKillerWithDoubleTimeoutValueIfRunAsMe(executableContainer.isRunAsUser());
        wallTimer = new WallTimer(initializer.getWalltime(), taskKiller);
        taskStopwatchForFailures = Stopwatch.createUnstarted();
        taskLauncherRebinder = new TaskLauncherRebinder(taskId, terminateNotificationNodeURL, taskRecoverable);
        addShutdownHook();
        // lock the cache space cleaning mechanism
        DataSpaceNodeConfigurationAgent.lockCacheSpaceCleaning();
        dataspaces = factory.createTaskDataspaces(taskId, initializer.getNamingService(), executableContainer.isRunAsUser());
        File taskLogFile = taskLogger.createFileAppender(dataspaces.getScratchFolder());
        progressFileReader.start(dataspaces.getScratchFolder(), taskId);
        context = new TaskContext(executableContainer, initializer, previousTasksResults, new NodeDataSpacesURIs(dataspaces.getScratchURI(), dataspaces.getCacheURI(), dataspaces.getInputURI(), dataspaces.getOutputURI(), dataspaces.getUserURI(), dataspaces.getGlobalURI()), progressFileReader.getProgressFile().toString(), getHostname(), decrypter);
        File workingDir = getTaskWorkingDir(context, dataspaces);
        logger.info("Task working dir: " + workingDir);
        logger.info("Cache space: " + context.getNodeDataSpaceURIs().getCacheURI());
        logger.info("Input space: " + context.getNodeDataSpaceURIs().getInputURI());
        logger.info("Output space: " + context.getNodeDataSpaceURIs().getOutputURI());
        logger.info("User space: " + context.getNodeDataSpaceURIs().getUserURI());
        logger.info("Global space: " + context.getNodeDataSpaceURIs().getGlobalURI());
        logger.info("Scheduler rest url: " + context.getSchedulerRestUrl());
        wallTimer.start();
        // should handle interrupt
        dataspaces.copyInputDataToScratch(initializer.getFilteredInputFiles(fileSelectorsFilters(context)));
        if (decrypter != null) {
            decrypter.setCredentials(executableContainer.getCredentials());
        }
        TaskExecutor taskExecutor = factory.createTaskExecutor(workingDir);
        taskStopwatchForFailures.start();
        taskResult = taskExecutor.execute(context, taskLogger.getOutputSink(), taskLogger.getErrorSink());
        taskStopwatchForFailures.stop();
        // by the time the task finishes, the scheduler might have had a
        // transient failure, so we need to make sure that the placeholder
        // for the task's result still exists, or get the new place for
        // the result if it does not exist anymore.
        TaskTerminateNotification rebindedTerminateNotification = taskLauncherRebinder.makeSureSchedulerIsConnected(terminateNotification);
        switch(taskKiller.getStatus()) {
            case WALLTIME_REACHED:
                taskResult = getWalltimedTaskResult(context, taskStopwatchForFailures);
                sendResultToScheduler(rebindedTerminateNotification, taskResult);
                return;
            case KILLED_MANUALLY:
                // killed by Scheduler, no need to send results back
                return;
        }
        dataspaces.copyScratchDataToOutput(initializer.getFilteredOutputFiles(fileSelectorsFilters(context, taskResult)));
        wallTimer.stop();
        copyTaskLogsToUserSpace(taskLogFile, dataspaces);
        taskResult.setLogs(taskLogger.getLogs());
        sendResultToScheduler(rebindedTerminateNotification, taskResult);
    } catch (Throwable taskFailure) {
        if (wallTimer != null) {
            wallTimer.stop();
        }
        switch(taskKiller.getStatus()) {
            case WALLTIME_REACHED:
                taskResult = getWalltimedTaskResult(context, taskStopwatchForFailures);
                sendResultToScheduler(terminateNotification, taskResult);
                break;
            case KILLED_MANUALLY:
                // killed by Scheduler, no need to send results back
                return;
            default:
                logger.info("Failed to execute task", taskFailure);
                long elapsedTime = 0;
                if (taskStopwatchForFailures != null) {
                    elapsedTime = taskStopwatchForFailures.elapsed(TimeUnit.MILLISECONDS);
                }
                taskFailure.printStackTrace(taskLogger.getErrorSink());
                Map<String, byte[]> serializedVariables = extractVariablesFromContext(context);
                taskResult = new TaskResultImpl(taskId, taskFailure, taskLogger.getLogs(), elapsedTime);
                taskResult.setPropagatedVariables(serializedVariables);
                sendResultToScheduler(terminateNotification, taskResult);
        }
    } finally {
        try {
            progressFileReader.stop();
            taskLogger.close();
            if (dataspaces != null) {
                dataspaces.close();
            }
            // unlocks the cache space cleaning thread
            DataSpaceNodeConfigurationAgent.unlockCacheSpaceCleaning();
            removeShutdownHook();
        } finally {
            terminate();
        }
    }
}
Also used : TaskTerminateNotification(org.ow2.proactive.scheduler.common.TaskTerminateNotification) TaskExecutor(org.ow2.proactive.scheduler.task.executors.TaskExecutor) TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskDataspaces(org.ow2.proactive.scheduler.task.data.TaskDataspaces) Stopwatch(com.google.common.base.Stopwatch) WallTimer(org.ow2.proactive.scheduler.task.utils.WallTimer) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) File(java.io.File) Map(java.util.Map)

Aggregations

TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)73 Test (org.junit.Test)70 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)32 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)30 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)26 SimpleScript (org.ow2.proactive.scripting.SimpleScript)26 TaskScript (org.ow2.proactive.scripting.TaskScript)26 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)25 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)25 NodeDataSpacesURIs (org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs)22 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)21 JobId (org.ow2.proactive.scheduler.common.job.JobId)16 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)16 InProcessTaskExecutor (org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor)15 HashMap (java.util.HashMap)13 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)13 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)13 SimpleTaskLogs (org.ow2.proactive.scheduler.common.task.SimpleTaskLogs)12 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)11 TaskLauncherInitializer (org.ow2.proactive.scheduler.task.TaskLauncherInitializer)10