Search in sources :

Example 46 with InternalTask

use of org.ow2.proactive.scheduler.task.internal.InternalTask 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 47 with InternalTask

use of org.ow2.proactive.scheduler.task.internal.InternalTask 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 48 with InternalTask

use of org.ow2.proactive.scheduler.task.internal.InternalTask 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 49 with InternalTask

use of org.ow2.proactive.scheduler.task.internal.InternalTask 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)

Example 50 with InternalTask

use of org.ow2.proactive.scheduler.task.internal.InternalTask in project scheduling by ow2-proactive.

the class TestTaskAttributes method testAttributes.

@Test
public void testAttributes() throws Exception {
    JavaTask task = createDefaultTask("task");
    task.setOnTaskError(OnTaskError.CANCEL_JOB);
    task.setDescription("desc");
    // TODO: create test using valid flow
    // task.setFlowBlock(FlowBlock.START);
    task.setMaxNumberOfExecution(7);
    task.setPreciousLogs(true);
    task.setPreciousResult(true);
    task.setRunAsMe(true);
    task.setWallTime(123);
    InternalTask taskData = saveSingleTask(task).getTask(task.getName());
    Assert.assertEquals(OnTaskError.CANCEL_JOB, taskData.getOnTaskErrorProperty().getValue());
    Assert.assertEquals("desc", taskData.getDescription());
    // Assert.assertEquals(FlowBlock.START, taskData.getFlowBlock());
    Assert.assertEquals(7, taskData.getMaxNumberOfExecution());
    Assert.assertEquals("task", taskData.getName());
    Assert.assertEquals(true, taskData.isPreciousLogs());
    Assert.assertEquals(true, taskData.isPreciousResult());
    Assert.assertEquals(true, taskData.isRunAsMe());
    Assert.assertEquals(123, taskData.getWallTime());
}
Also used : InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) Test(org.junit.Test)

Aggregations

InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)142 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)74 Test (org.junit.Test)72 InternalScriptTask (org.ow2.proactive.scheduler.task.internal.InternalScriptTask)39 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)37 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)32 InternalTaskFlowJob (org.ow2.proactive.scheduler.job.InternalTaskFlowJob)31 ArrayList (java.util.ArrayList)30 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)25 JobId (org.ow2.proactive.scheduler.common.job.JobId)22 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)18 ExecuterInformation (org.ow2.proactive.scheduler.task.internal.ExecuterInformation)16 TaskInfoImpl (org.ow2.proactive.scheduler.task.TaskInfoImpl)13 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)12 HashMap (java.util.HashMap)10 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)10 ProActiveTest (org.ow2.tests.ProActiveTest)10 TaskInfo (org.ow2.proactive.scheduler.common.task.TaskInfo)9 HashSet (java.util.HashSet)8 SchedulerStateRecoverHelper (org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper)8