use of org.ow2.proactive.scheduler.common.task.JavaTask in project scheduling by ow2-proactive.
the class TestRestoreWorkflowJobs2 method task.
static JavaTask task(String name) {
JavaTask task = new JavaTask();
task.setExecutableClassName(TestTask.class.getName());
task.setName(name);
return task;
}
use of org.ow2.proactive.scheduler.common.task.JavaTask in project scheduling by ow2-proactive.
the class TestTaskAttributes method testTaskVariables.
@Test
public void testTaskVariables() throws Exception {
JavaTask task = createDefaultTask("task");
Map<String, TaskVariable> variables;
InternalTask taskData;
variables = new HashMap<>();
task.setVariables(variables);
taskData = saveSingleTask(task).getTask(task.getName());
Assert.assertNotNull(taskData.getVariables());
Assert.assertTrue(taskData.getVariables().isEmpty());
variables = new HashMap<>();
TaskVariable v1 = new TaskVariable();
v1.setName("p1");
v1.setValue("v1");
TaskVariable v2 = new TaskVariable();
v2.setName("p2");
v2.setValue("v2");
variables.put("p1", v1);
variables.put("p2", v2);
TaskVariable v3 = new TaskVariable();
v3.setName("emptyvar");
variables.put("emptyvar", v3);
task.setVariables(variables);
taskData = saveSingleTask(task).getTask(task.getName());
Assert.assertEquals(3, taskData.getVariables().size());
Assert.assertEquals("p1", taskData.getVariables().get("p1").getName());
Assert.assertEquals("p2", taskData.getVariables().get("p2").getName());
Assert.assertEquals("v1", taskData.getVariables().get("p1").getValue());
Assert.assertEquals("v2", taskData.getVariables().get("p2").getValue());
Assert.assertEquals("emptyvar", taskData.getVariables().get("emptyvar").getName());
Assert.assertNull(taskData.getVariables().get("emptyvar").getValue());
StringBuilder longString = buildLongString();
variables = new HashMap<>();
TaskVariable longVariable = new TaskVariable();
longVariable.setName("longProperty");
longVariable.setValue(longString.toString());
variables.put("longProperty", longVariable);
task.setVariables(variables);
taskData = saveSingleTask(task).getTask(task.getName());
Assert.assertEquals(1, taskData.getVariables().size());
Assert.assertEquals(longString.toString(), taskData.getVariables().get("longProperty").getValue());
}
use of org.ow2.proactive.scheduler.common.task.JavaTask 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.task.JavaTask in project scheduling by ow2-proactive.
the class TestTaskAttributes method testForkEnv.
@Test
public void testForkEnv() throws Exception {
JavaTask task = createDefaultTask("task");
ForkEnvironment env = new ForkEnvironment();
task.setForkEnvironment(env);
InternalTask taskData = saveSingleTask(task).getTask(task.getName());
Assert.assertNotNull(taskData.getForkEnvironment());
env = new ForkEnvironment();
env.setEnvScript(new SimpleScript("forkenvscript", "js", new String[] { "p1", "p2" }));
task.setForkEnvironment(env);
taskData = saveSingleTask(task).getTask(task.getName());
Assert.assertNotNull(taskData.getForkEnvironment().getEnvScript());
Assert.assertArrayEquals(new String[] { "p1", "p2" }, task.getForkEnvironment().getEnvScript().getParameters());
env = new ForkEnvironment();
env.setJavaHome("javahome");
env.setWorkingDir("workingdir");
env.addAdditionalClasspath("classpath");
env.addJVMArgument("jvmargument");
env.addSystemEnvironmentVariable("var1", "value1");
StringBuilder longString = buildLongString();
env.addSystemEnvironmentVariable("longvar", longString.toString());
task.setForkEnvironment(env);
taskData = saveSingleTask(task).getTask(task.getName());
Assert.assertEquals("javahome", taskData.getForkEnvironment().getJavaHome());
Assert.assertEquals("workingdir", taskData.getForkEnvironment().getWorkingDir());
Assert.assertEquals(1, taskData.getForkEnvironment().getAdditionalClasspath().size());
Assert.assertEquals("classpath", taskData.getForkEnvironment().getAdditionalClasspath().get(0));
Assert.assertEquals(1, taskData.getForkEnvironment().getJVMArguments().size());
Assert.assertEquals("jvmargument", taskData.getForkEnvironment().getJVMArguments().get(0));
Assert.assertEquals(2, taskData.getForkEnvironment().getSystemEnvironment().size());
Assert.assertEquals("value1", taskData.getForkEnvironment().getSystemEnvironment().get("var1"));
Assert.assertEquals(longString.toString(), taskData.getForkEnvironment().getSystemEnvironment().get("longvar"));
}
use of org.ow2.proactive.scheduler.common.task.JavaTask in project scheduling by ow2-proactive.
the class TestTaskAttributes method testParallelEnv.
@Test
public void testParallelEnv() throws Exception {
JavaTask task = createDefaultTask("task");
ParallelEnvironment env = new ParallelEnvironment(5);
task.setParallelEnvironment(env);
InternalTask taskData = saveSingleTask(task).getTask(task.getName());
Assert.assertEquals(5, taskData.getParallelEnvironment().getNodesNumber());
Assert.assertNull(taskData.getParallelEnvironment().getTopologyDescriptor());
TopologyDescriptor[] descs = { TopologyDescriptor.ARBITRARY, TopologyDescriptor.BEST_PROXIMITY, TopologyDescriptor.DIFFERENT_HOSTS_EXCLUSIVE, TopologyDescriptor.MULTIPLE_HOSTS_EXCLUSIVE, TopologyDescriptor.SINGLE_HOST, TopologyDescriptor.SINGLE_HOST_EXCLUSIVE, new ThresholdProximityDescriptor(123) };
for (TopologyDescriptor desc : descs) {
task = createDefaultTask("task");
env = new ParallelEnvironment(10, desc);
task.setParallelEnvironment(env);
taskData = saveSingleTask(task).getTask(task.getName());
Assert.assertEquals(10, taskData.getParallelEnvironment().getNodesNumber());
Assert.assertEquals(taskData.getParallelEnvironment().getTopologyDescriptor().getClass(), desc.getClass());
if (desc instanceof ThresholdProximityDescriptor) {
Assert.assertEquals(((ThresholdProximityDescriptor) taskData.getParallelEnvironment().getTopologyDescriptor()).getThreshold(), 123);
}
}
}
Aggregations