Search in sources :

Example 76 with TaskFlowJob

use of org.ow2.proactive.scheduler.common.job.TaskFlowJob 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 77 with TaskFlowJob

use of org.ow2.proactive.scheduler.common.job.TaskFlowJob in project scheduling by ow2-proactive.

the class TestScriptTask method test_getTaskResult_nullReturningScriptTask_shouldSucceed.

/**
 * SCHEDULING-2199 NPE is thrown when retrieving the result of a ScriptTask,
 *  if the result is 'null'.
 */
private void test_getTaskResult_nullReturningScriptTask_shouldSucceed() throws Throwable {
    TaskFlowJob job = (TaskFlowJob) StaxJobFactory.getFactory().createJob(new File(job_null_returning_script_task.toURI()).getAbsolutePath());
    JobId id = schedulerHelper.submitJob(job);
    schedulerHelper.waitForEventJobFinished(id);
    TaskResult taskResult = schedulerHelper.getTaskResult(id, "task");
    assertNull(taskResult.value());
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 78 with TaskFlowJob

use of org.ow2.proactive.scheduler.common.job.TaskFlowJob in project scheduling by ow2-proactive.

the class TestUnauthorizedScripts method createJob.

public Job createJob(String forkScriptContent, String cleanScriptContent) throws InvalidScriptException, UserException {
    TaskFlowJob job = new TaskFlowJob();
    job.setName(this.getClass().getSimpleName() + "_forkAndClean");
    ScriptTask taskWithFork = new ScriptTask();
    taskWithFork.setScript(new TaskScript(new SimpleScript("println 'Hello'", "groovy")));
    ForkEnvironment forkEnvironment = new ForkEnvironment();
    forkEnvironment.setEnvScript(new SimpleScript(forkScriptContent, "groovy"));
    taskWithFork.setForkEnvironment(forkEnvironment);
    ScriptTask taskWithClean = new ScriptTask();
    taskWithClean.setScript(new TaskScript(new SimpleScript("println 'Hello'", "groovy")));
    taskWithClean.setCleaningScript(new SimpleScript(cleanScriptContent, "groovy"));
    job.addTask(taskWithFork);
    job.addTask(taskWithClean);
    return job;
}
Also used : ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) TaskScript(org.ow2.proactive.scripting.TaskScript) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment)

Example 79 with TaskFlowJob

use of org.ow2.proactive.scheduler.common.job.TaskFlowJob in project scheduling by ow2-proactive.

the class TestUnauthorizedScripts method createJobSelection.

public Job createJobSelection(String selectionScriptContent) throws InvalidScriptException, UserException {
    TaskFlowJob job = new TaskFlowJob();
    job.setName(this.getClass().getSimpleName() + "_selection");
    ScriptTask taskWithSelection = new ScriptTask();
    taskWithSelection.setScript(new TaskScript(new SimpleScript("println 'Hello'", "groovy")));
    taskWithSelection.addSelectionScript(new SelectionScript(new SimpleScript(selectionScriptContent, "groovy"), true));
    job.addTask(taskWithSelection);
    return job;
}
Also used : SelectionScript(org.ow2.proactive.scripting.SelectionScript) ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) TaskScript(org.ow2.proactive.scripting.TaskScript) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleScript(org.ow2.proactive.scripting.SimpleScript)

Example 80 with TaskFlowJob

use of org.ow2.proactive.scheduler.common.job.TaskFlowJob in project scheduling by ow2-proactive.

the class TestNonForkedScriptTask method nonForkedTasks_SystemExitScript_KillsANode.

@Ignore
@Test
public void nonForkedTasks_SystemExitScript_KillsANode() throws Throwable {
    TaskFlowJob job = (TaskFlowJob) StaxJobFactory.getFactory().createJob(new File(nonForked_jobDescriptor.toURI()).getAbsolutePath());
    schedulerHelper.submitJob(job);
    // busy event when task is scheduler
    schedulerHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
    // down event when node is killed
    RMNodeEvent nodeKilledEvent = schedulerHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
    assertEquals(NodeState.DOWN, nodeKilledEvent.getNodeState());
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) File(java.io.File) RMNodeEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeEvent) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)184 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)92 Test (org.junit.Test)81 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)49 JobId (org.ow2.proactive.scheduler.common.job.JobId)33 File (java.io.File)31 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)25 NativeTask (org.ow2.proactive.scheduler.common.task.NativeTask)22 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)21 SimpleScript (org.ow2.proactive.scripting.SimpleScript)20 JobResult (org.ow2.proactive.scheduler.common.job.JobResult)18 ScriptTask (org.ow2.proactive.scheduler.common.task.ScriptTask)16 Task (org.ow2.proactive.scheduler.common.task.Task)16 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)13 TaskScript (org.ow2.proactive.scripting.TaskScript)13 JobState (org.ow2.proactive.scheduler.common.job.JobState)12 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)12 ArrayList (java.util.ArrayList)11 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)11 HashMap (java.util.HashMap)10