use of org.ow2.proactive.scheduler.rest.data.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;
// 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.rest.data.TaskResultImpl in project scheduling by ow2-proactive.
the class ForkedTaskExecutor method execute.
@Override
public TaskResultImpl execute(TaskContext context, PrintStream outputSink, PrintStream errorSink) {
CookieBasedProcessTreeKiller taskProcessTreeKiller = null;
Process process = null;
ProcessStreamsReader processStreamsReader = null;
File serializedContext = null;
try {
if (!workingDir.exists()) {
FileUtils.forceMkdir(workingDir);
}
serializedContext = taskContextSerializer.serializeContext(context, workingDir);
OSProcessBuilder processBuilder = forkedJvmProcessBuilderCreator.createForkedProcessBuilder(context, serializedContext, outputSink, errorSink, workingDir);
TaskId taskId = context.getTaskId();
String cookieNameSuffix = "Job" + taskId.getJobId().value() + "Task" + taskId.value();
taskProcessTreeKiller = CookieBasedProcessTreeKiller.createProcessChildrenKiller(cookieNameSuffix, processBuilder.environment());
process = processBuilder.start();
processStreamsReader = new ProcessStreamsReader(taskId.toString(), process, outputSink, errorSink);
int exitCode = process.waitFor();
if (exitCode != 0) {
try {
Object error = deserializeTaskResult(serializedContext);
if (error instanceof TaskContext) {
return createTaskResult(context, new IOException("Forked JVM process returned with exit code " + exitCode + ", see task logs for more information"));
} else {
Throwable exception = (Throwable) error;
return createTaskResult(context, exception);
}
} catch (Throwable cannotDeserializeResult) {
return createTaskResult(context, cannotDeserializeResult);
}
}
return (TaskResultImpl) deserializeTaskResult(serializedContext);
} catch (Throwable throwable) {
return createTaskResult(context, throwable);
} finally {
FileUtils.deleteQuietly(serializedContext);
if (process != null) {
process.destroy();
}
if (taskProcessTreeKiller != null) {
taskProcessTreeKiller.kill();
}
if (processStreamsReader != null) {
processStreamsReader.close();
}
}
}
use of org.ow2.proactive.scheduler.rest.data.TaskResultImpl in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method variablesPropagation_fromParentTask.
@Test
public void variablesPropagation_fromParentTask() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId(TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L));
Map<String, Serializable> variablesFromParent = new HashMap<>();
variablesFromParent.put("var", "parent");
variablesFromParent.put(SchedulerVars.PA_TASK_ID.toString(), "1234");
TaskResult[] previousTasksResults = { new TaskResultImpl(null, null, null, null, null, SerializationUtil.serializeVariableMap(variablesFromParent), false) };
new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("print(variables.get('var'));print(variables.get('PA_TASK_ID'))", "groovy"))), initializer, previousTasksResults, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
assertEquals("parent42", taskOutput.output());
}
use of org.ow2.proactive.scheduler.rest.data.TaskResultImpl in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method nodesFileIsCreated.
@Test
public void nodesFileIsCreated() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
ScriptExecutableContainer printNodesFileTask = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print new File(variables.get('PA_NODESFILE')).text", "groovy")));
printNodesFileTask.setNodes(mockedNodeSet());
TaskContext context = new TaskContext(printNodesFileTask, initializer, null, new NodeDataSpacesURIs(tmpFolder.newFolder().getAbsolutePath(), "", "", "", "", ""), "", "thisHost");
TaskResultImpl taskResult = new InProcessTaskExecutor().execute(context, taskOutput.outputStream, taskOutput.error);
assertTaskResultOk(taskResult);
assertEquals(String.format("thisHost%ndummyhost%n"), taskOutput.output());
}
use of org.ow2.proactive.scheduler.rest.data.TaskResultImpl in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method variablesPropagation.
@Test
public void variablesPropagation() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setPreScript(new SimpleScript("print(variables.get('var')); variables.put('var', 'pre')", "groovy"));
initializer.setPostScript(new SimpleScript("print(variables.get('var')); variables.put('var', 'post')", "groovy"));
initializer.setTaskId(TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L));
initializer.setJobVariables(Collections.singletonMap("var", new JobVariable("var", "value")));
TaskResultImpl result = new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("print(variables.get('var')); variables.put('var', 'task')", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
assertEquals("valuepretask", taskOutput.output());
assertEquals("post", SerializationUtil.deserializeVariableMap(result.getPropagatedVariables()).get("var"));
}
Aggregations