Search in sources :

Example 31 with JavaTask

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;
}
Also used : JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask)

Example 32 with JavaTask

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());
}
Also used : InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) Test(org.junit.Test)

Example 33 with JavaTask

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);
}
Also used : SelectionScript(org.ow2.proactive.scripting.SelectionScript) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleScript(org.ow2.proactive.scripting.SimpleScript) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 34 with JavaTask

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"));
}
Also used : InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) SimpleScript(org.ow2.proactive.scripting.SimpleScript) Test(org.junit.Test)

Example 35 with JavaTask

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);
        }
    }
}
Also used : InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) ThresholdProximityDescriptor(org.ow2.proactive.topology.descriptor.ThresholdProximityDescriptor) TopologyDescriptor(org.ow2.proactive.topology.descriptor.TopologyDescriptor) Test(org.junit.Test)

Aggregations

JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)96 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)92 Test (org.junit.Test)40 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)22 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)18 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)17 JobId (org.ow2.proactive.scheduler.common.job.JobId)14 NativeTask (org.ow2.proactive.scheduler.common.task.NativeTask)12 EmptyTask (org.ow2.proactive.scheduler.examples.EmptyTask)11 SelectionScript (org.ow2.proactive.scripting.SelectionScript)10 SimpleScript (org.ow2.proactive.scripting.SimpleScript)10 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)9 File (java.io.File)8 HashMap (java.util.HashMap)7 Task (org.ow2.proactive.scheduler.common.task.Task)7 JobResult (org.ow2.proactive.scheduler.common.job.JobResult)6 EmptyExecutable (functionaltests.executables.EmptyExecutable)5 JobDescriptor (org.ow2.proactive.scheduler.common.JobDescriptor)5 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)5 TaskDescriptor (org.ow2.proactive.scheduler.common.TaskDescriptor)4