Search in sources :

Example 41 with Script

use of org.ow2.proactive_grid_cloud_portal.studio.Script in project scheduling by ow2-proactive.

the class TestScriptTask method forkedTasks.

private void forkedTasks() throws Throwable {
    TaskFlowJob job = (TaskFlowJob) StaxJobFactory.getFactory().createJob(new File(jobDescriptor.toURI()).getAbsolutePath());
    JobId id = schedulerHelper.submitJob(job);
    schedulerHelper.waitForEventJobFinished(id);
    JobResult jobResult = schedulerHelper.getJobResult(id);
    // Hello Work script task
    TaskResult simpleTaskResult = jobResult.getResult("simple");
    assertEquals(true, simpleTaskResult.value());
    assertTrue(simpleTaskResult.getOutput().getAllLogs(false).contains("hello"));
    // return binding should be used as task result
    TaskResult returnTaskResult = jobResult.getResult("return");
    assertEquals("42", returnTaskResult.value().toString());
    // results binding should be avaible in dependent tasks
    TaskResult resultFromDependentTaskTaskResult = jobResult.getResult("results_from_dependent_task");
    assertEquals("42", resultFromDependentTaskTaskResult.value().toString());
    // pas properties are exposed in the script task
    TaskResult propertiesTaskResult = jobResult.getResult("properties");
    String logs = propertiesTaskResult.getOutput().getAllLogs(false);
    assertThat(logs, containsString("PA_JOB_ID=" + jobResult.getJobId().value()));
    assertThat(logs, containsString("PA_JOB_NAME=" + jobResult.getName()));
    assertThat(logs, containsString("PA_TASK_ID=" + propertiesTaskResult.getTaskId().value()));
    assertThat(logs, containsString("PA_TASK_NAME=" + propertiesTaskResult.getTaskId().getReadableName()));
    assertThat(logs, containsString("PA_TASK_ITERATION=0"));
    assertThat(logs, containsString("PA_TASK_REPLICATION=0"));
    // the script can be a file
    TaskResult fileTaskResult = jobResult.getResult("file");
    assertTrue(fileTaskResult.getOutput().getAllLogs(false).contains("Beginning of clean script"));
    TaskResult fileAndArgsTaskResult = jobResult.getResult("file_and_args");
    assertTrue(fileAndArgsTaskResult.getOutput().getAllLogs(false).contains("My_Magic_Arg"));
    // dataspaces binding should be available
    TaskResult dataspacesTaskResult = jobResult.getResult("dataspaces");
    String dataspacesLogs = dataspacesTaskResult.getOutput().getAllLogs(false);
    System.out.println(dataspacesLogs);
    String schedulerHome = System.getProperty("pa.scheduler.home");
    assertTrue(dataspacesLogs.contains("global=" + schedulerHome));
    assertTrue(dataspacesLogs.contains("user=" + schedulerHome));
    assertTrue(dataspacesLogs.contains("input=" + schedulerHome));
    assertTrue(dataspacesLogs.contains("output=" + schedulerHome));
    TaskResult multiNodeTaskResult = jobResult.getResult("multi-node");
    String mnLogs = multiNodeTaskResult.getOutput().getAllLogs(false);
    assertTrue("Invalid binding for nodesurl", mnLogs.contains("nodesurl=" + (SchedulerStartForFunctionalTest.RM_NODE_NUMBER - 1)));
    // script task should be forked by default, ie it will not kill the scheduler on system.exit
    JobState jobState = schedulerHelper.getSchedulerInterface().getJobState(id);
    TaskResult killJVMTaskResult = jobResult.getResult("killJVM");
    assertTrue(killJVMTaskResult.getException() instanceof ForkedJvmProcessException);
    TaskState killJVMTaskState = jobState.getHMTasks().get(killJVMTaskResult.getTaskId());
    assertEquals(TaskStatus.FAULTY, killJVMTaskState.getStatus());
}
Also used : ForkedJvmProcessException(org.ow2.proactive.scheduler.task.exceptions.ForkedJvmProcessException) JobResult(org.ow2.proactive.scheduler.common.job.JobResult) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) JobState(org.ow2.proactive.scheduler.common.job.JobState) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 42 with Script

use of org.ow2.proactive_grid_cloud_portal.studio.Script in project scheduling by ow2-proactive.

the class TestUnauthorizedScripts method testUnAuthorizedSelectionScripts.

@Test
public void testUnAuthorizedSelectionScripts() throws Exception {
    Job job = createJobSelection(unauthorizedSelectionScriptContent);
    JobId id = schedulerHelper.submitJob(job);
    Thread.sleep(10000);
    File selectionOut = new File(folder.getRoot().getAbsolutePath(), "selection.out");
    Assert.assertFalse("File created by the unauthorized selection script should NOT exist", selectionOut.exists());
    Assert.assertEquals(JobStatus.PENDING, schedulerHelper.getSchedulerInterface().getJobState(id).getStatus());
    schedulerHelper.getSchedulerInterface().killJob(id);
}
Also used : Job(org.ow2.proactive.scheduler.common.job.Job) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 43 with Script

use of org.ow2.proactive_grid_cloud_portal.studio.Script in project scheduling by ow2-proactive.

the class CheckEligibleTaskDescriptorScriptTest method testOnlyInternalScriptContainsAPIBinding.

@Test
public void testOnlyInternalScriptContainsAPIBinding() throws InvalidScriptException {
    Script s = scriptWithApiBindingGlobal();
    Script s2 = scriptWithoutApiBinding();
    FlowScript fs = flowScriptWithoutApiBinding();
    Mockito.when(((EligibleTaskDescriptorImpl) etd).getInternal()).thenReturn(ist);
    Mockito.when(ist.getPreScript()).thenReturn(s2);
    Mockito.when(ist.getPostScript()).thenReturn(s2);
    Mockito.when(it.getCleaningScript()).thenReturn(s2);
    Mockito.when(sec.getScript()).thenReturn(s);
    Mockito.when(fe.getEnvScript()).thenReturn(s2);
    Mockito.when(it.getFlowScript()).thenReturn(fs);
    assertTrue(new CheckEligibleTaskDescriptorScript().isTaskContainsAPIBinding(etd));
}
Also used : SimpleScript(org.ow2.proactive.scripting.SimpleScript) FlowScript(org.ow2.proactive.scheduler.common.task.flow.FlowScript) Script(org.ow2.proactive.scripting.Script) EligibleTaskDescriptorImpl(org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptorImpl) FlowScript(org.ow2.proactive.scheduler.common.task.flow.FlowScript) Test(org.junit.Test)

Example 44 with Script

use of org.ow2.proactive_grid_cloud_portal.studio.Script in project scheduling by ow2-proactive.

the class CheckEligibleTaskDescriptorScriptTest method testOnlyEnvScriptContainsAPIBinding.

@Test
public void testOnlyEnvScriptContainsAPIBinding() throws InvalidScriptException {
    Script s = scriptWithApiBindingUser();
    FlowScript fs = flowScriptWithoutApiBinding();
    Script s2 = scriptWithoutApiBinding();
    Mockito.when(it.getPreScript()).thenReturn(s2);
    Mockito.when(it.getPostScript()).thenReturn(s2);
    Mockito.when(it.getCleaningScript()).thenReturn(s2);
    Mockito.when(sec.getScript()).thenReturn(s2);
    Mockito.when(fe.getEnvScript()).thenReturn(s);
    Mockito.when(it.getFlowScript()).thenReturn(fs);
    assertTrue(new CheckEligibleTaskDescriptorScript().isTaskContainsAPIBinding(etd));
}
Also used : SimpleScript(org.ow2.proactive.scripting.SimpleScript) FlowScript(org.ow2.proactive.scheduler.common.task.flow.FlowScript) Script(org.ow2.proactive.scripting.Script) FlowScript(org.ow2.proactive.scheduler.common.task.flow.FlowScript) Test(org.junit.Test)

Example 45 with Script

use of org.ow2.proactive_grid_cloud_portal.studio.Script in project scheduling by ow2-proactive.

the class CheckEligibleTaskDescriptorScriptTest method testAllScriptsNull.

@Test
public void testAllScriptsNull() throws InvalidScriptException {
    Script s = null;
    FlowScript fs = null;
    Mockito.when(it.getPreScript()).thenReturn(s);
    Mockito.when(it.getPostScript()).thenReturn(s);
    Mockito.when(it.getCleaningScript()).thenReturn(s);
    Mockito.when(fe.getEnvScript()).thenReturn(s);
    Mockito.when(sec.getScript()).thenReturn(s);
    Mockito.when(it.getFlowScript()).thenReturn(fs);
    assertFalse(new CheckEligibleTaskDescriptorScript().isTaskContainsAPIBinding(etd));
}
Also used : SimpleScript(org.ow2.proactive.scripting.SimpleScript) FlowScript(org.ow2.proactive.scheduler.common.task.flow.FlowScript) Script(org.ow2.proactive.scripting.Script) FlowScript(org.ow2.proactive.scheduler.common.task.flow.FlowScript) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)38 SelectionScript (org.ow2.proactive.scripting.SelectionScript)32 File (java.io.File)31 SimpleScript (org.ow2.proactive.scripting.SimpleScript)28 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)25 ArrayList (java.util.ArrayList)16 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)15 Script (org.ow2.proactive.scripting.Script)15 ScriptResult (org.ow2.proactive.scripting.ScriptResult)15 FlowScript (org.ow2.proactive.scheduler.common.task.flow.FlowScript)13 HashMap (java.util.HashMap)12 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)11 IOException (java.io.IOException)10 JobId (org.ow2.proactive.scheduler.common.job.JobId)10 NodeSet (org.ow2.proactive.utils.NodeSet)10 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)9 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)9 Job (org.ow2.proactive.scheduler.common.job.Job)8 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)8 Serializable (java.io.Serializable)7