use of org.ow2.proactive.scheduler.task.executors.TaskExecutor 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();
}
}
}
use of org.ow2.proactive.scheduler.task.executors.TaskExecutor in project scheduling by ow2-proactive.
the class ForkedTaskExecutorRunAsMeTest method runAsMe_PasswordMethod.
@Test
public void runAsMe_PasswordMethod() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
Decrypter decrypter = createCredentials(USERNAME, PASSWORD);
ForkedTaskExecutor taskExecutor = new ForkedTaskExecutor(tmpFolder.newFolder());
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId((TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L)));
ScriptExecutableContainer container = new ScriptExecutableContainer(new TaskScript(new SimpleScript("whoami", "native")));
container.setRunAsUser(true);
TaskContext taskContext = new TaskContext(container, initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", "", decrypter);
TaskResultImpl result = taskExecutor.execute(taskContext, taskOutput.outputStream, taskOutput.error);
assertTaskResultOk(result);
assertEquals("admin\n", taskOutput.output());
}
use of org.ow2.proactive.scheduler.task.executors.TaskExecutor in project scheduling by ow2-proactive.
the class ForkedTaskExecutorTest method nonDaemonThreadsForkedJVMExit.
/**
* This test ensures that the forked JVM exited properly when non-daemon threads are created inside the task
*
* @throws Exception
*/
@Test(timeout = 30000)
public void nonDaemonThreadsForkedJVMExit() throws Exception {
String taskScript = CharStreams.toString(new InputStreamReader(getClass().getResourceAsStream("/task-nondaemon-thread.groovy"), Charsets.UTF_8));
TestTaskOutput taskOutput = new TestTaskOutput();
File workingDir = tmpFolder.newFolder();
ForkedTaskExecutor taskExecutor = new ForkedTaskExecutor(workingDir);
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId((TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L)));
TaskResultImpl result = taskExecutor.execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript(taskScript, "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
Assert.assertFalse(result.hadException());
}
use of org.ow2.proactive.scheduler.task.executors.TaskExecutor in project scheduling by ow2-proactive.
the class ForkedTaskExecutorTest method failToFindJava.
@Test
public void failToFindJava() throws Throwable {
System.setProperty("java.home", "does not exist");
TestTaskOutput taskOutput = new TestTaskOutput();
ForkedTaskExecutor taskExecutor = new ForkedTaskExecutor(tmpFolder.newFolder());
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId((TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L)));
TaskResultImpl result = taskExecutor.execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "javascript"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
assertNotNull(result.getException());
}
use of org.ow2.proactive.scheduler.task.executors.TaskExecutor in project scheduling by ow2-proactive.
the class ForkedTaskExecutorTest method runAsMe_userDoesNotExist.
@Test
public void runAsMe_userDoesNotExist() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
Decrypter decrypter = createCredentials("somebody_that_does_not_exists");
ForkedTaskExecutor taskExecutor = new ForkedTaskExecutor(tmpFolder.newFolder());
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId((TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L)));
ScriptExecutableContainer container = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "javascript")));
container.setRunAsUser(true);
TaskContext taskContext = new TaskContext(container, initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", "", decrypter);
TaskResultImpl result = taskExecutor.execute(taskContext, taskOutput.outputStream, taskOutput.error);
assertNotNull(result.getException());
}
Aggregations