use of org.ow2.proactive.scheduler.common.task.TaskResult in project scheduling by ow2-proactive.
the class WalltimeTaskLauncherTest method walltime_during_file_copy.
@Test(timeout = 5000)
public void walltime_during_file_copy() throws Throwable {
ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("", "javascript")));
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setWalltime(500);
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
TaskResult taskResult = runTaskLauncher(createLauncherWithInjectedMocks(initializer, new SlowDataspacesTaskLauncherFactory()), executableContainer);
assertEquals(WalltimeExceededException.class, taskResult.getException().getClass());
}
use of org.ow2.proactive.scheduler.common.task.TaskResult in project scheduling by ow2-proactive.
the class TaskContextVariableExtractorTest method testExtractThrowsExceptionIfVariablesAreInvalidByteStream.
@Test(expected = Exception.class)
public void testExtractThrowsExceptionIfVariablesAreInvalidByteStream() throws Exception {
ScriptExecutableContainer scriptContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "javascript")));
TaskLauncherInitializer taskLauncherInitializer = getTaskLauncherInitializerWithWorkflowVariables();
Map<String, byte[]> taskResultVariables = new HashMap<>();
// The task result variables are expected to be converted to byte streams.
taskResultVariables.put(taskResultPropagatedVariables1Key, taskResultPropagatedVariables1Value.getBytes());
TaskResultImpl taskResult = new TaskResultImpl(taskLauncherInitializer.getTaskId(), new Exception("Exception"));
taskResult.setPropagatedVariables(taskResultVariables);
TaskResult[] taskResultArray = { taskResult };
TaskContext taskContext = new TaskContext(scriptContainer, taskLauncherInitializer, taskResultArray, new NodeDataSpacesURIs(null, null, null, null, null, null), null, null);
new TaskContextVariableExtractor().getAllVariables(taskContext);
}
use of org.ow2.proactive.scheduler.common.task.TaskResult in project scheduling by ow2-proactive.
the class InProcessTaskExecutor method execute.
/**
* Executes a task inside a task context.
*
* @param taskContext Task context to execute.
* @param output Standard output sink.
* @param error Error sink.
* @return Returns the task result.
*/
@Override
public TaskResultImpl execute(TaskContext taskContext, PrintStream output, PrintStream error) {
ScriptHandler scriptHandler = ScriptLoader.createLocalHandler();
String nodesFile = null;
SchedulerNodeClient schedulerNodeClient = null;
RemoteSpace userSpaceClient = null;
RemoteSpace globalSpaceClient = null;
try {
nodesFile = writeNodesFile(taskContext);
VariablesMap variables = new VariablesMap();
variables.setInheritedMap(taskContextVariableExtractor.getAllNonTaskVariablesInjectNodesFile(taskContext, nodesFile));
variables.setScopeMap(taskContextVariableExtractor.getScopeVariables(taskContext));
Map<String, String> resultMetadata = new HashMap<>();
Map<String, String> thirdPartyCredentials = forkedTaskVariablesManager.extractThirdPartyCredentials(taskContext);
schedulerNodeClient = forkedTaskVariablesManager.createSchedulerNodeClient(taskContext);
userSpaceClient = forkedTaskVariablesManager.createDataSpaceNodeClient(taskContext, schedulerNodeClient, IDataSpaceClient.Dataspace.USER);
globalSpaceClient = forkedTaskVariablesManager.createDataSpaceNodeClient(taskContext, schedulerNodeClient, IDataSpaceClient.Dataspace.GLOBAL);
forkedTaskVariablesManager.addBindingsToScriptHandler(scriptHandler, taskContext, variables, thirdPartyCredentials, schedulerNodeClient, userSpaceClient, globalSpaceClient, resultMetadata);
Stopwatch stopwatch = Stopwatch.createUnstarted();
TaskResultImpl taskResult;
try {
stopwatch.start();
Serializable result = execute(taskContext, output, error, scriptHandler, thirdPartyCredentials, variables);
stopwatch.stop();
taskResult = new TaskResultImpl(taskContext.getTaskId(), result, null, stopwatch.elapsed(TimeUnit.MILLISECONDS));
} catch (Throwable e) {
stopwatch.stop();
e.printStackTrace(error);
taskResult = new TaskResultImpl(taskContext.getTaskId(), e, null, stopwatch.elapsed(TimeUnit.MILLISECONDS));
}
executeFlowScript(taskContext.getControlFlowScript(), scriptHandler, output, error, taskResult);
taskResult.setPropagatedVariables(SerializationUtil.serializeVariableMap(variables.getPropagatedVariables()));
taskResult.setMetadata(resultMetadata);
return taskResult;
} catch (Throwable e) {
e.printStackTrace(error);
return new TaskResultImpl(taskContext.getTaskId(), e);
} finally {
if (nodesFile != null && !nodesFile.isEmpty()) {
FileUtils.deleteQuietly(new File(nodesFile));
}
}
}
use of org.ow2.proactive.scheduler.common.task.TaskResult in project scheduling by ow2-proactive.
the class EnabledListenJobLogsSupport method flushTaskLogs.
private void flushTaskLogs(TaskResult tr, Appender a, JobId jobId) {
// if taskResult is not awaited, task is terminated
TaskLogs logs = tr.getOutput();
if (logs instanceof Log4JTaskLogs) {
for (LoggingEvent le : ((Log4JTaskLogs) logs).getAllEvents()) {
// write into socket appender directly to avoid double lines on other listeners
a.doAppend(le);
}
} else {
a.doAppend(createLoggingEvent(jobId, logs.getStdoutLogs(false), Level.INFO));
a.doAppend(createLoggingEvent(jobId, logs.getStderrLogs(false), Level.DEBUG));
}
}
use of org.ow2.proactive.scheduler.common.task.TaskResult 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();
}
}
Aggregations