use of org.ow2.proactive.scheduler.common.task.TaskResult in project scheduling by ow2-proactive.
the class TestTaskNotExecuted method testTaskNotExecuted.
private void testTaskNotExecuted(String jobDescriptorPath1, String jobDescriptorPath2, String jobDescriptorPath3) throws Exception {
log("Submitting job 1");
JobId id1 = schedulerHelper.submitJob(jobDescriptorPath1);
log("Wait for event job 1 submitted");
schedulerHelper.waitForEventJobSubmitted(id1);
log("Wait for event t1 running");
schedulerHelper.waitForEventTaskRunning(id1, "t0");
schedulerHelper.waitForEventTaskFinished(id1, "t0");
schedulerHelper.waitForEventJobFinished(id1);
TaskResult tr1 = schedulerHelper.getSchedulerInterface().getTaskResult(id1, "t1");
assertTrue(tr1.getException() instanceof TaskCouldNotStartException);
log("Submitting job 2");
JobId id2 = schedulerHelper.submitJob(jobDescriptorPath2);
log("Wait for event job 2 submitted");
schedulerHelper.waitForEventJobSubmitted(id2);
log("Wait for event t2 running");
schedulerHelper.waitForEventTaskRunning(id2, "t2");
log("Restarting task");
schedulerHelper.getSchedulerInterface().restartTask(id2, "t2", Integer.MAX_VALUE);
TaskInfo ti2 = schedulerHelper.waitForEventTaskWaitingForRestart(id2, "t2");
schedulerHelper.getSchedulerInterface().killJob(id2);
schedulerHelper.waitForEventJobFinished(id2);
JobState jobState = schedulerHelper.getSchedulerInterface().getJobState(id2);
Assert.assertEquals(TaskStatus.NOT_RESTARTED, jobState.getTasks().get(0).getStatus());
TaskResult tr2 = schedulerHelper.getSchedulerInterface().getTaskResult(id2, "t2");
assertTrue(tr2.getException() instanceof TaskCouldNotRestartException);
log("Submitting job 3");
JobId id3 = schedulerHelper.submitJob(jobDescriptorPath3);
log("Wait for event job 3 submitted");
schedulerHelper.waitForEventJobSubmitted(id3);
log("Wait for event T T1 T2 finished");
schedulerHelper.waitForEventTaskFinished(id3, "T");
schedulerHelper.waitForEventTaskFinished(id3, "T1");
TaskResult tr3_1 = schedulerHelper.getSchedulerInterface().getTaskResult(id3, "T1");
TaskResult tr3_2 = schedulerHelper.getSchedulerInterface().getTaskResult(id3, "T2");
assertNull(tr3_1.getException());
assertTrue(tr3_2.getException() instanceof TaskSkippedException);
}
use of org.ow2.proactive.scheduler.common.task.TaskResult in project scheduling by ow2-proactive.
the class TestTaskRestartOnNodeFailure method checkJobResult.
private void checkJobResult(Scheduler scheduler, JobId jobId) throws Exception {
JobResult jobResult = scheduler.getJobResult(jobId);
assertEquals("Unexpected number of task results", 1, jobResult.getAllResults().size());
for (TaskResult taskResult : jobResult.getAllResults().values()) {
log("Task " + taskResult.getTaskId());
assertNull("Unexpected task result exception", taskResult.getException());
String output = taskResult.getOutput().getAllLogs(false);
log("Task output:");
log(output);
assertTrue("Unxepected output", output.contains("OK"));
}
}
use of org.ow2.proactive.scheduler.common.task.TaskResult in project scheduling by ow2-proactive.
the class TestPreciousLogs method testPreciousLogs.
private void testPreciousLogs(boolean createJavaTask, boolean forkEnv) throws Exception {
TaskFlowJob job = new TaskFlowJob();
job.setName(this.getClass().getSimpleName());
Map<String, List<String>> expectedOutput = new LinkedHashMap<>();
for (int i = 0; i < 3; i++) {
String forkOutput = "forkOutput-" + i;
String preOutput = "preOutput-" + i;
String postOutput = "postOutput-" + i;
List<String> expectedTaskOutput = new ArrayList<>();
expectedTaskOutput.add(TASK_OUTPUT);
expectedTaskOutput.add(preOutput);
expectedTaskOutput.add(postOutput);
Task task;
if (createJavaTask) {
JavaTask javaTask = new JavaTask();
javaTask.setExecutableClassName(TestJavaTask.class.getName());
if (forkEnv) {
ForkEnvironment env = new ForkEnvironment();
env.setEnvScript(createScript(forkOutput));
javaTask.setForkEnvironment(env);
expectedTaskOutput.add(forkOutput);
}
task = javaTask;
} else {
NativeTask nativeTask = new NativeTask();
File script = new File(getClass().getResource("/functionaltests/executables/test_echo_task.sh").getFile());
if (!script.exists()) {
Assert.fail("Can't find script " + script.getAbsolutePath());
}
nativeTask.setCommandLine(script.getAbsolutePath());
task = nativeTask;
}
task.setMaxNumberOfExecution(1);
task.setOnTaskError(OnTaskError.CANCEL_JOB);
task.setPreciousLogs(true);
task.setName("Task-" + i);
task.setPreScript(createScript(preOutput));
task.setPostScript(createScript(postOutput));
expectedOutput.put(task.getName(), expectedTaskOutput);
job.addTask(task);
}
JobId jobId = schedulerHelper.testJobSubmission(job);
Scheduler scheduler = schedulerHelper.getSchedulerInterface();
String userURI = scheduler.getUserSpaceURIs().get(0);
String userPath = new File(new URI(userURI)).getAbsolutePath();
JobResult jobResult = scheduler.getJobResult(jobId);
Map<String, TaskResult> results = jobResult.getAllResults();
for (String taskName : expectedOutput.keySet()) {
File taskLog = new File(userPath + "/" + jobId.value(), String.format("TaskLogs-%s-%s.log", jobId.value(), results.get(taskName).getTaskId().value()));
if (!taskLog.exists()) {
Assert.fail("Task log file " + taskLog.getAbsolutePath() + " doesn't exist");
}
String output = new String(FileToBytesConverter.convertFileToByteArray(taskLog));
System.out.println("Log file for " + taskName + ":");
System.out.println(output);
for (String expectedLine : expectedOutput.get(taskName)) {
Assert.assertTrue("Output doesn't contain line " + expectedLine, output.contains(expectedLine));
}
}
}
use of org.ow2.proactive.scheduler.common.task.TaskResult in project scheduling by ow2-proactive.
the class JavaSpawnExecutable method execute.
@Override
public Serializable execute(TaskResult... results) throws Throwable {
org.apache.log4j.Logger.getLogger(ProcessTree.class).setLevel(Level.DEBUG);
Process process = null;
process = Runtime.getRuntime().exec(getNativeExecLauncher(false), null, getExecutablePath(launchersDir).getParentFile().getCanonicalFile());
// redirect streams
BufferedReader sout = new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedReader serr = new BufferedReader(new InputStreamReader(process.getErrorStream()));
Thread tsout = new Thread(new ThreadReader(sout, System.out));
Thread tserr = new Thread(new ThreadReader(serr, System.err));
tsout.setDaemon(true);
tserr.setDaemon(true);
tsout.start();
tserr.start();
process.waitFor();
// we sleep 2 sec
Thread.sleep(sleep * 1000);
return true;
}
use of org.ow2.proactive.scheduler.common.task.TaskResult in project scheduling by ow2-proactive.
the class SchedulerFrontend method getTaskResultFromIncarnation.
/**
* {@inheritDoc}
*/
@Override
@ImmediateService
public TaskResult getTaskResultFromIncarnation(JobId jobId, String taskName, int inc) throws NotConnectedException, UnknownJobException, UnknownTaskException, PermissionException {
// checking permissions
frontendState.checkPermissions("getTaskResultFromIncarnation", frontendState.getIdentifiedJob(jobId), YOU_DO_NOT_HAVE_PERMISSION_TO_GET_THE_TASK_RESULT_OF_THIS_JOB);
if (inc < 0) {
throw new IllegalArgumentException("Incarnation must be 0 or greater.");
}
jlogger.debug(jobId, "trying to get the task result, incarnation " + inc);
if (inc < 0) {
throw new IllegalArgumentException("Incarnation must be 0 or greater.");
}
try {
TaskResult result = dbManager.loadTaskResult(jobId, taskName, inc);
// handling special statuses
TaskState ts = frontendState.getTaskState(jobId, taskName);
switch(ts.getStatus()) {
case NOT_STARTED:
if (result == null) {
return new TaskResultImpl(frontendState.getTaskId(jobId, taskName), new TaskCouldNotStartException(), new SimpleTaskLogs("", "The task could not start due to dependency failure"), 0);
} else {
Throwable newException = new TaskCouldNotStartException("The task could not start due to dependency failure", result.getException());
((TaskResultImpl) result).setException(newException);
}
break;
case NOT_RESTARTED:
if (result == null) {
return new TaskResultImpl(frontendState.getTaskId(jobId, taskName), new TaskCouldNotRestartException(), new SimpleTaskLogs("", "The task could not be restarted after an error during the previous execution"), 0);
} else {
Throwable newException = new TaskCouldNotRestartException("The task could not be restarted after an error during the previous execution", result.getException());
((TaskResultImpl) result).setException(newException);
}
break;
case SKIPPED:
// result should always be null
return new TaskResultImpl(frontendState.getTaskId(jobId, taskName), new TaskSkippedException(), new SimpleTaskLogs("", "The task was skipped in the workflow"), 0);
}
if (result == null) {
// otherwise the task is not finished
jlogger.info(jobId, taskName + " is not finished");
return null;
} else {
return result;
}
} catch (DatabaseManagerException e) {
throw new UnknownTaskException("Unknown task " + taskName + ", job: " + jobId);
}
}
Aggregations