use of org.ow2.proactive.scheduler.task.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);
}
use of org.ow2.proactive.scheduler.task.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;
}
use of org.ow2.proactive.scheduler.task.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;
File taskLogFile = null;
try {
taskStarted.set(true);
logger.info("Task started " + taskId.getJobId().getReadableName() + " : " + taskId.getReadableName());
wallTimer = new WallTimer(initializer.getWalltime(), taskKiller);
taskStopwatchForFailures = Stopwatch.createUnstarted();
taskLauncherRebinder = new TaskLauncherRebinder(taskId, terminateNotificationNodeURL, taskRecoverable);
addShutdownHook();
if (decrypter != null) {
decrypter.setCredentials(executableContainer.getCredentials());
}
// lock the cache space cleaning mechanism
DataSpaceNodeConfigurationAgent.lockCacheSpaceCleaning();
dataspaces = factory.createTaskDataspaces(taskId, initializer.getNamingService(), executableContainer.isRunAsUser(), decrypter, taskLogger);
copyTaskLogsFromUserSpace(taskLogger.createLogFilePath(dataspaces.getScratchFolder()), dataspaces);
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(), new NodeInfo(getHostName(), getNodeUrl(), getNodeName(), getNodeSourceName()), 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)));
TaskExecutor taskExecutor = factory.createTaskExecutor(workingDir);
initializer.fetchUrlsIfNeeded();
((ScriptExecutableContainer) executableContainer).getScript().fetchUrlIfNeeded();
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);
copyTaskLogsToUserSpace(taskLogFile, dataspaces);
sendResultToScheduler(rebindedTerminateNotification, taskResult);
return;
case KILLED_MANUALLY:
// killed by Scheduler, no need to send results back
copyTaskLogsToUserSpace(taskLogFile, dataspaces);
return;
}
dataspaces.copyScratchDataToOutput(initializer.getFilteredOutputFiles(fileSelectorsFilters(context, taskResult)));
wallTimer.stop();
copyTaskLogsToUserSpace(taskLogFile, dataspaces);
sendResultToScheduler(rebindedTerminateNotification, taskResult);
} catch (Throwable taskFailure) {
if (wallTimer != null) {
wallTimer.stop();
}
switch(taskKiller.getStatus()) {
case WALLTIME_REACHED:
taskResult = getWalltimedTaskResult(context, taskStopwatchForFailures);
copyTaskLogsToUserSpace(taskLogFile, dataspaces);
sendResultToScheduler(terminateNotification, taskResult);
break;
case KILLED_MANUALLY:
// killed by Scheduler, no need to send results back
copyTaskLogsToUserSpace(taskLogFile, dataspaces);
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();
}
}
}
use of org.ow2.proactive.scheduler.task.TaskResultImpl in project scheduling by ow2-proactive.
the class TaskLauncher method sendResultToScheduler.
private void sendResultToScheduler(TaskTerminateNotification terminateNotification, TaskResultImpl taskResult) {
if (isNodeShuttingDown()) {
return;
}
int pingAttempts = initializer.getPingAttempts();
int pingPeriodMs = initializer.getPingPeriod() * 1000;
taskLogger.close();
taskResult.setLogs(taskLogger.getLogs());
// We are going to contact the recipient of the task result. This
// recipient is the TaskTerminateNotification, an active object on the
// scheduler side. If the scheduler experienced a transient failure
// while the task was computing, then the reference to this
// TaskTerminateNotification is obsolete and we need to update it. This
// is what the following code does.
TaskTerminateNotification currentTerminateNotification = terminateNotification;
for (int i = 0; i < pingAttempts; i++) {
try {
currentTerminateNotification.terminate(taskId, taskResult);
logger.debug("Successfully notified task termination " + taskId);
// termination has succeeded, exit the method
return;
} catch (Throwable t) {
logger.warn("Cannot notify task termination, trying to rebind to the task termination handler");
TaskTerminateNotification rebindedTerminateNotification = taskLauncherRebinder.getReboundTaskTerminateNotificationHandler(t);
if (rebindedTerminateNotification != null) {
currentTerminateNotification = rebindedTerminateNotification;
} else {
decreasePingAttemptsAndWait(pingAttempts, pingPeriodMs, i, t);
}
}
}
logger.error("Cannot notify task termination " + taskId + " after " + pingAttempts + " attempts, terminating task launcher now");
}
use of org.ow2.proactive.scheduler.task.TaskResultImpl in project scheduling by ow2-proactive.
the class TestTaskResultData method testExceptionResult.
@Test
public void testExceptionResult() throws Throwable {
InternalJob job = saveSingleTask(createDefaultTask("task"));
TaskResultImpl result = new TaskResultImpl(null, new TestException("message", "data"), null, 0);
InternalTask task = (InternalTask) job.getTasks().get(0);
dbManager.updateAfterTaskFinished(job, task, result);
TaskResult restoredResult = dbManager.loadLastTaskResult(task.getId());
TestException exception = (TestException) restoredResult.getException();
Assert.assertNotNull(exception);
Assert.assertEquals("message", exception.getMessage());
Assert.assertEquals("data", exception.getData());
try {
restoredResult.value();
Assert.fail("Exception is expected");
} catch (TestException e) {
}
Assert.assertNull(restoredResult.getOutput());
}
Aggregations