use of org.ow2.proactive.scheduler.common.task.JavaTask in project scheduling by ow2-proactive.
the class TestRestoreWorkflowJobs method createJob.
private TaskFlowJob createJob() throws Exception {
TaskFlowJob job = new TaskFlowJob();
JavaTask t = task("T");
JavaTask t1 = task("T1");
JavaTask t2 = task("T2");
JavaTask t3 = task("T3");
JavaTask t4 = task("T4");
t1.addDependence(t);
t2.addDependence(t1);
t3.addDependence(t2);
t4.addDependence(t3);
String replicateScript = String.format("runs = %d", 2);
t.setFlowScript(FlowScript.createReplicateFlowScript(replicateScript));
t1.setFlowBlock(FlowBlock.START);
t1.setFlowScript(FlowScript.createReplicateFlowScript(replicateScript));
t3.setFlowBlock(FlowBlock.END);
job.addTask(t);
job.addTask(t1);
job.addTask(t2);
job.addTask(t3);
job.addTask(t4);
return job;
}
use of org.ow2.proactive.scheduler.common.task.JavaTask in project scheduling by ow2-proactive.
the class TestPreciousLogs method testPreciousLogs.
private void testPreciousLogs(boolean createJavaTask, boolean forkEnv, boolean generateError) 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);
if (!generateError) {
expectedTaskOutput.add(postOutput);
}
Task task;
if (createJavaTask) {
JavaTask javaTask = new JavaTask();
if (generateError) {
javaTask.setExecutableClassName(TestJavaTaskWithError.class.getName());
} else {
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;
}
if (generateError) {
task.setMaxNumberOfExecution(NB_EXECUTIONS);
} else {
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);
}
Scheduler scheduler = schedulerHelper.getSchedulerInterface();
String userURI = scheduler.getUserSpaceURIs().get(0);
File userFile = new File(new URI(userURI));
// Clean all log files in user space
for (File logFile : FileUtils.listFiles(userFile, new String[] { "log" }, true)) {
FileUtils.deleteQuietly(logFile);
}
JobId jobId = schedulerHelper.testJobSubmission(job, true, false);
JobResult jobResult = scheduler.getJobResult(jobId);
Map<String, TaskResult> results = jobResult.getAllResults();
List<File> logFiles = new ArrayList<>();
for (String taskName : expectedOutput.keySet()) {
File taskLog = new File(userFile.toString() + "/" + jobId.value(), String.format("TaskLogs-%s-%s.log", jobId.value(), results.get(taskName).getTaskId().value()));
logFiles.add(taskLog);
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));
int expectedOccurrences = (generateError ? NB_EXECUTIONS : 1);
Assert.assertEquals("Output doesn't contain " + expectedOccurrences + " occurrences of line " + expectedLine, expectedOccurrences, StringUtils.countMatches(output, expectedLine));
}
}
// Test log removal
schedulerHelper.removeJob(jobId);
waitUntilAllLogsWereRemoved(jobId, logFiles);
}
use of org.ow2.proactive.scheduler.common.task.JavaTask in project scheduling by ow2-proactive.
the class TestJobSchedulingStarvationAndPriority method createJobReplicate.
/*
* Job high priority with one task and high priority
*/
private TaskFlowJob createJobReplicate(int nbRun, JobPriority priority) throws Exception {
String jobDescriptorPath = new File(jobDescriptor.toURI()).getAbsolutePath();
TaskFlowJob job = new TaskFlowJob();
job.setName(this.getClass().getSimpleName() + "_High");
job.setPriority(JobPriority.HIGHEST);
JavaTask javaTask = new JavaTask();
javaTask.setExecutableClassName(EmptyTask.class.getName());
javaTask.setName("taskHigh");
job.addTask(javaTask);
return job;
}
use of org.ow2.proactive.scheduler.common.task.JavaTask in project scheduling by ow2-proactive.
the class TestExecuteScriptsOnBusyNode method createJobWithLock.
private TaskFlowJob createJobWithLock(String communicationObjectUrl) throws Exception {
TaskFlowJob job = new TaskFlowJob();
job.setName(this.getClass().getSimpleName() + "_JobWithLock");
job.setOnTaskError(OnTaskError.CANCEL_JOB);
job.setMaxNumberOfExecution(1);
JavaTask javaTask = new JavaTask();
javaTask.setExecutableClassName(TestJavaTaskWithLock.class.getName());
javaTask.setMaxNumberOfExecution(1);
javaTask.setOnTaskError(OnTaskError.CANCEL_JOB);
javaTask.setName("Test task");
javaTask.addArgument("fileLockPath", communicationObjectUrl);
job.addTask(javaTask);
return job;
}
use of org.ow2.proactive.scheduler.common.task.JavaTask in project scheduling by ow2-proactive.
the class TestExecuteScriptsOnBusyNode method createNonBlockingJob.
private TaskFlowJob createNonBlockingJob(boolean withSelectionScript) throws Exception {
TaskFlowJob job = new TaskFlowJob();
job.setName(this.getClass().getSimpleName() + "_SimpleJob");
job.setOnTaskError(OnTaskError.CANCEL_JOB);
job.setMaxNumberOfExecution(1);
JavaTask javaTask = new JavaTask();
javaTask.setExecutableClassName(TestJavaTask.class.getName());
javaTask.setMaxNumberOfExecution(1);
javaTask.setOnTaskError(OnTaskError.CANCEL_JOB);
javaTask.setName("Test task");
if (withSelectionScript) {
// we want to trigger a selection script execution on the unique node, as this will call node.clean()
javaTask.addSelectionScript(new SelectionScript("selected = true", "groovy", true));
}
job.addTask(javaTask);
return job;
}
Aggregations