use of org.ow2.proactive.scheduler.common.job.TaskFlowJob 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.job.TaskFlowJob in project scheduling by ow2-proactive.
the class TestRestoreWorkflowJobs2 method createJob.
private TaskFlowJob createJob() throws Exception {
TaskFlowJob job = new TaskFlowJob();
JavaTask A = task("A");
FlowScript ifScript = FlowScript.createIfFlowScript("branch = \"if\";", "B", "C", null);
A.setFlowScript(ifScript);
job.addTask(A);
JavaTask B = task("B");
job.addTask(B);
JavaTask C = task("C");
job.addTask(C);
return job;
}
use of org.ow2.proactive.scheduler.common.job.TaskFlowJob in project scheduling by ow2-proactive.
the class TestRestoreWorkflowJobs2 method test.
@Test
public void test() throws Exception {
TaskFlowJob jobDef = createJob();
InternalJob job = defaultSubmitJobAndLoadInternal(true, jobDef);
job.start();
InternalTask mainTask = job.getTask("A");
startTask(job, mainTask);
dbManager.jobTaskStarted(job, mainTask, true);
TaskResultImpl result = new TaskResultImpl(mainTask.getId(), "ok", null, 0);
FlowAction action = new FlowAction(FlowActionType.IF);
action.setDupNumber(1);
action.setTarget("B");
action.setTargetElse("C");
ChangedTasksInfo changesInfo = job.terminateTask(false, mainTask.getId(), null, action, result);
dbManager.updateAfterWorkflowTaskFinished(job, changesInfo, result);
SchedulerStateRecoverHelper recoverHelper = new SchedulerStateRecoverHelper(dbManager);
RecoveredSchedulerState state = recoverHelper.recover(-1);
job = state.getRunningJobs().get(0);
System.out.println("OK");
}
use of org.ow2.proactive.scheduler.common.job.TaskFlowJob in project scheduling by ow2-proactive.
the class TestTaskAttributes method testScripts.
@Test
public void testScripts() throws Exception {
TaskFlowJob jobDef = new TaskFlowJob();
JavaTask task1 = createDefaultTask("task1");
task1.addSelectionScript(new SelectionScript("selection1", "js", new String[] { "param1", "param2" }, true));
task1.addSelectionScript(new SelectionScript("selection2", "js", new String[] { "param3" }, false));
task1.addSelectionScript(new SelectionScript("selection3", "js"));
task1.setCleaningScript(new SimpleScript("cleanscript", "js", new String[] { "p1", "p2" }));
task1.setPreScript(new SimpleScript("prescript", "js", new String[] { "p1", "p2" }));
task1.setPostScript(new SimpleScript("postscript", "js", new String[] { "p1", "p2" }));
task1.setFlowScript(FlowScript.createContinueFlowScript());
jobDef.addTask(task1);
InternalJob job = defaultSubmitJobAndLoadInternal(true, jobDef);
InternalTask task = job.getTask("task1");
Assert.assertEquals("cleanscript", task.getCleaningScript().getScript());
Assert.assertArrayEquals(new String[] { "p1", "p2" }, task.getCleaningScript().getParameters());
Assert.assertEquals("prescript", task.getPreScript().getScript());
Assert.assertArrayEquals(new String[] { "p1", "p2" }, task.getPreScript().getParameters());
Assert.assertEquals("postscript", task.getPostScript().getScript());
Assert.assertArrayEquals(new String[] { "p1", "p2" }, task.getPostScript().getParameters());
Assert.assertEquals(FlowActionType.CONTINUE.toString(), task.getFlowScript().getActionType());
Assert.assertEquals(3, task.getSelectionScripts().size());
Set<String> scripts = new HashSet<>();
for (SelectionScript script : task.getSelectionScripts()) {
scripts.add(script.getScript());
if (script.getScript().equals("selection1")) {
Assert.assertArrayEquals(new String[] { "param1", "param2" }, script.getParameters());
}
if (script.getScript().equals("selection2")) {
Assert.assertArrayEquals(new String[] { "param3" }, script.getParameters());
}
if (script.getScript().equals("selection3")) {
Assert.assertArrayEquals(new String[] {}, script.getParameters());
}
}
Set<String> expected = new HashSet<>();
expected.add("selection1");
expected.add("selection2");
expected.add("selection3");
Assert.assertEquals(expected, scripts);
}
use of org.ow2.proactive.scheduler.common.job.TaskFlowJob in project scheduling by ow2-proactive.
the class TestTaskResultData method testMultipleResults.
@Test
public void testMultipleResults() throws Throwable {
TaskFlowJob job = new TaskFlowJob();
job.addTask(createDefaultTask("task1"));
job.addTask(createDefaultTask("task2"));
job.addTask(createDefaultTask("task3"));
InternalJob internalJob = defaultSubmitJobAndLoadInternal(true, job);
InternalTask task1 = internalJob.getTask("task1");
InternalTask task2 = internalJob.getTask("task2");
InternalTask task3 = internalJob.getTask("task3");
dbManager.updateAfterTaskFinished(internalJob, task1, new TaskResultImpl(null, new TestResult(0, "1_1"), null, 0));
dbManager.updateAfterTaskFinished(internalJob, task1, new TaskResultImpl(null, new TestResult(0, "1_2"), null, 0));
dbManager.updateAfterTaskFinished(internalJob, task1, new TaskResultImpl(null, new TestResult(0, "1_3"), null, 0));
dbManager.updateAfterTaskFinished(internalJob, task2, new TaskResultImpl(null, new TestResult(0, "2_1"), null, 0));
dbManager.updateAfterTaskFinished(internalJob, task2, new TaskResultImpl(null, new TestResult(0, "2_2"), null, 0));
dbManager.updateAfterTaskFinished(internalJob, task2, new TaskResultImpl(null, new TestResult(0, "2_3"), null, 0));
dbManager.updateAfterTaskFinished(internalJob, task3, new TaskResultImpl(null, new TestResult(0, "3_1"), null, 0));
dbManager.updateAfterTaskFinished(internalJob, task3, new TaskResultImpl(null, new TestResult(0, "3_2"), null, 0));
dbManager.updateAfterTaskFinished(internalJob, task3, new TaskResultImpl(null, new TestResult(0, "3_3"), null, 0));
TestResult result;
result = (TestResult) dbManager.loadLastTaskResult(task1.getId()).value();
Assert.assertEquals("1_3", result.getB());
result = (TestResult) dbManager.loadTaskResult(internalJob.getId(), task1.getName(), 0).value();
Assert.assertEquals("1_3", result.getB());
result = (TestResult) dbManager.loadLastTaskResult(task2.getId()).value();
Assert.assertEquals("2_3", result.getB());
result = (TestResult) dbManager.loadTaskResult(internalJob.getId(), task2.getName(), 0).value();
Assert.assertEquals("2_3", result.getB());
result = (TestResult) dbManager.loadLastTaskResult(task3.getId()).value();
Assert.assertEquals("3_3", result.getB());
result = (TestResult) dbManager.loadTaskResult(internalJob.getId(), task3.getName(), 0).value();
Assert.assertEquals("3_3", result.getB());
result = (TestResult) dbManager.loadTaskResult(task2.getId(), 0).value();
Assert.assertEquals("2_3", result.getB());
result = (TestResult) dbManager.loadTaskResult(internalJob.getId(), task2.getName(), 0).value();
Assert.assertEquals("2_3", result.getB());
result = (TestResult) dbManager.loadTaskResult(task2.getId(), 1).value();
Assert.assertEquals("2_2", result.getB());
result = (TestResult) dbManager.loadTaskResult(internalJob.getId(), task2.getName(), 1).value();
Assert.assertEquals("2_2", result.getB());
result = (TestResult) dbManager.loadTaskResult(task2.getId(), 2).value();
Assert.assertEquals("2_1", result.getB());
result = (TestResult) dbManager.loadTaskResult(internalJob.getId(), task2.getName(), 2).value();
Assert.assertEquals("2_1", result.getB());
Assert.assertNull(dbManager.loadTaskResult(task2.getId(), 3));
Assert.assertNull(dbManager.loadTaskResult(internalJob.getId(), task2.getName(), 3));
List<TaskId> taskIds = Arrays.asList(task1.getId(), task2.getId(), task3.getId());
System.out.println("Load results for 3 tasks");
Map<TaskId, TaskResult> results = dbManager.loadTasksResults(internalJob.getId(), taskIds);
Assert.assertEquals(3, results.size());
result = (TestResult) results.get(task1.getId()).value();
Assert.assertEquals("1_3", result.getB());
result = (TestResult) results.get(task2.getId()).value();
Assert.assertEquals("2_3", result.getB());
result = (TestResult) results.get(task3.getId()).value();
Assert.assertEquals("3_3", result.getB());
taskIds = Arrays.asList(task2.getId(), task3.getId());
System.out.println("Load results for 2 tasks");
results = dbManager.loadTasksResults(internalJob.getId(), taskIds);
Assert.assertEquals(2, results.size());
result = (TestResult) results.get(task2.getId()).value();
Assert.assertEquals("2_3", result.getB());
result = (TestResult) results.get(task3.getId()).value();
Assert.assertEquals("3_3", result.getB());
}
Aggregations