use of org.ow2.proactive.scheduler.common.task.JavaTask in project scheduling by ow2-proactive.
the class TestGlobalSpace method testGlobalSpace.
@Test
public void testGlobalSpace() throws Throwable {
File in = tmpFolder.newFolder("input_space");
String inPath = in.getAbsolutePath();
File out = tmpFolder.newFolder("output_space");
String outPath = out.getAbsolutePath();
writeFiles(inFiles, inPath);
TaskFlowJob job = new TaskFlowJob();
job.setName(this.getClass().getSimpleName());
job.setInputSpace(in.toURI().toURL().toString());
job.setOutputSpace(out.toURI().toURL().toString());
JavaTask A = new JavaTask();
A.setExecutableClassName("org.ow2.proactive.scheduler.examples.EmptyTask");
A.setName("A");
for (String[] file : inFiles) {
A.addInputFiles(file[0], InputAccessMode.TransferFromInputSpace);
A.addOutputFiles(file[0] + ".glob.A", OutputAccessMode.TransferToGlobalSpace);
}
A.setPreScript(new SimpleScript(scriptA, "groovy"));
A.setForkEnvironment(new ForkEnvironment());
job.addTask(A);
JavaTask B = new JavaTask();
B.setExecutableClassName("org.ow2.proactive.scheduler.examples.EmptyTask");
B.setName("B");
B.addDependence(A);
for (String[] file : inFiles) {
B.addInputFiles(file[0] + ".glob.A", InputAccessMode.TransferFromGlobalSpace);
B.addOutputFiles(file[0] + ".out", OutputAccessMode.TransferToOutputSpace);
}
B.setPreScript(new SimpleScript(scriptB, "groovy"));
B.setForkEnvironment(new ForkEnvironment());
job.addTask(B);
Scheduler scheduler = schedulerHelper.getSchedulerInterface();
JobId id = scheduler.submit(job);
schedulerHelper.waitForEventJobFinished(id);
assertFalse(schedulerHelper.getJobResult(id).hadException());
/**
* check: inFiles > IN > LOCAL A > GLOBAL > LOCAL B > OUT
*/
for (String[] inFile : inFiles) {
File f = new File(outPath + File.separator + inFile[0] + ".out");
assertTrue("File does not exist: " + f.getAbsolutePath(), f.exists());
Assert.assertEquals("Original and copied files differ", inFile[1], FileUtils.readFileToString(f));
f.delete();
File inf = new File(inPath + File.separator + inFile[0]);
inf.delete();
}
/**
* check that the file produced is accessible in the global user space via the scheduler API
*/
String globalURI = scheduler.getGlobalSpaceURIs().get(0);
assertTrue(globalURI.startsWith("file:"));
String globalPath = new File(new URI(globalURI)).getAbsolutePath();
FileSystemManager fsManager = VFSFactory.createDefaultFileSystemManager();
for (String[] file : inFiles) {
FileObject outFile = fsManager.resolveFile(globalURI + "/" + file[0] + ".glob.A");
log("Checking existence of " + outFile.getURL());
assertTrue(outFile.getURL() + " exists", outFile.exists());
File outFile2 = new File(globalPath, file[0] + ".glob.A");
log("Checking existence of " + outFile2);
assertTrue(outFile2 + " exists", outFile2.exists());
}
}
use of org.ow2.proactive.scheduler.common.task.JavaTask in project scheduling by ow2-proactive.
the class TestWorkflowDataspace method testJavaTask.
private void testJavaTask() throws Throwable {
String tmpdir = System.getProperty("java.io.tmpdir");
File inputSpace = new File(tmpdir + File.separator + "inputSpace." + System.currentTimeMillis());
File outputSpace = new File(tmpdir + File.separator + "outputSpace." + System.currentTimeMillis());
inputSpace.mkdir();
outputSpace.mkdir();
for (int it = 0; it < 3; it++) {
for (int dup = 0; dup < 3; dup++) {
File f = new File(inputSpace.getCanonicalPath() + File.separator + it + "_" + dup + ".in");
f.createNewFile();
BufferedWriter out = new BufferedWriter(new FileWriter(f));
out.write("it " + it + " dup " + dup + "\n");
out.close();
}
}
TaskFlowJob job = new TaskFlowJob();
job.setName(TestWorkflowDataspace.class.getSimpleName());
job.setInputSpace(inputSpace.toURI().toURL().toString());
job.setOutputSpace(outputSpace.toURI().toURL().toString());
ForkEnvironment forkEnvironment = new ForkEnvironment();
JavaTask t = new JavaTask();
t.setName("T");
t.setExecutableClassName("org.ow2.proactive.scheduler.examples.EmptyTask");
t.setFlowScript(FlowScript.createReplicateFlowScript("runs = 3;"));
t.setFlowBlock(FlowBlock.START);
t.setForkEnvironment(forkEnvironment);
job.addTask(t);
JavaTask t1 = new JavaTask();
t1.setName("T1");
t1.setForkEnvironment(forkEnvironment);
t1.setExecutableClassName(JobWorkflowDataspace.class.getCanonicalName());
t1.setForkEnvironment(new ForkEnvironment());
t1.addDependence(t);
t1.addInputFiles("$PA_TASK_ITERATION_$PA_TASK_REPLICATION.in", InputAccessMode.TransferFromInputSpace);
t1.addOutputFiles("$PA_TASK_ITERATION_$PA_TASK_REPLICATION.out", OutputAccessMode.TransferToOutputSpace);
job.addTask(t1);
JavaTask t2 = new JavaTask();
t2.setName("T2");
t2.setForkEnvironment(forkEnvironment);
t2.setExecutableClassName("org.ow2.proactive.scheduler.examples.EmptyTask");
t2.addDependence(t1);
t2.setFlowScript(//
FlowScript.createLoopFlowScript(//
"if (variables.get('PA_TASK_ITERATION') < 2) {" + //
"loop = true;" + //
"} else {" + //
"loop = false;" + "}", "T"));
t2.setFlowBlock(FlowBlock.END);
job.addTask(t2);
JobId id = TWorkflowJobs.testJobSubmission(schedulerHelper, job, null);
Assert.assertFalse(schedulerHelper.getJobResult(id).hadException());
for (int it = 0; it < 3; it++) {
for (int dup = 0; dup < 3; dup++) {
File f = new File(outputSpace.getCanonicalPath() + File.separator + it + "_" + dup + ".out");
Assert.assertTrue("Missing output file " + f.getName(), f.exists());
BufferedReader in = new BufferedReader(new FileReader(f));
String line = in.readLine();
Assert.assertTrue("Wrong content for " + f.getCanonicalPath(), line.equals("it " + it + " dup " + dup));
}
}
}
use of org.ow2.proactive.scheduler.common.task.JavaTask in project scheduling by ow2-proactive.
the class BaseSchedulerDBTest method createDefaultTask.
protected static JavaTask createDefaultTask(String taskName) {
JavaTask task = new JavaTask();
task.setName(taskName);
task.setExecutableClassName(TestDummyExecutable.class.getName());
return task;
}
use of org.ow2.proactive.scheduler.common.task.JavaTask in project scheduling by ow2-proactive.
the class SchedulerDbManagerConcurrencyTest method createAndInsertJob.
public InternalJob createAndInsertJob() throws Exception {
TaskFlowJob jobDef = new TaskFlowJob();
JavaTask javaTask = createDefaultTask("java task");
javaTask.setExecutableClassName(TestDummyExecutable.class.getName());
jobDef.addTask(javaTask);
return defaultSubmitJob(jobDef);
}
use of org.ow2.proactive.scheduler.common.task.JavaTask in project scheduling by ow2-proactive.
the class SchedulerTasksStateRecoverIntegrationTest method testRecover.
@Test
public void testRecover() throws Exception {
SchedulerStateRecoverHelper recoverHelper = new SchedulerStateRecoverHelper(dbManager);
RecoveredSchedulerState state = recoverHelper.recover(-1);
Assert.assertEquals(0, state.getFinishedJobs().size());
Assert.assertEquals(0, state.getRunningJobs().size());
Assert.assertEquals(0, state.getPendingJobs().size());
TaskFlowJob job1 = new TaskFlowJob();
JavaTask task1 = createDefaultTask("task1");
JavaTask task2 = createDefaultTask("task2");
JavaTask task3 = createDefaultTask("task3");
task1.addDependence(task2);
task1.addDependence(task3);
task2.addDependence(task3);
job1.addTask(task1);
job1.addTask(task2);
job1.addTask(task3);
InternalJob job = defaultSubmitJob(job1);
JobStateMatcher expectedJob;
expectedJob = job(job.getId(), JobStatus.PENDING).withPending(task("task1", TaskStatus.SUBMITTED), false).withPending(task("task2", TaskStatus.SUBMITTED), false).withPending(task("task3", TaskStatus.SUBMITTED), false).withEligible("task3");
state = checkRecoveredState(recoverHelper.recover(-1), state().withPending(expectedJob));
job = state.getPendingJobs().get(0);
TaskDescriptor task = job.getJobDescriptor().getEligibleTasks().iterator().next();
Assert.assertEquals(2, task.getChildren().size());
Assert.assertEquals(0, task.getParents().size());
job.terminate();
dbManager.updateAfterTaskFinished(job, null, null);
expectedJob = job(job.getId(), JobStatus.FINISHED).withPending(task("task1", TaskStatus.SUBMITTED), false).withPending(task("task2", TaskStatus.SUBMITTED), false).withPending(task("task3", TaskStatus.SUBMITTED), false).withEligible("task3");
state = checkRecoveredState(recoverHelper.recover(-1), state().withFinished(expectedJob));
job = state.getFinishedJobs().get(0);
task = job.getJobDescriptor().getEligibleTasks().iterator().next();
Assert.assertEquals(2, task.getChildren().size());
Assert.assertEquals(0, task.getParents().size());
}
Aggregations