Search in sources :

Example 51 with ScriptExecutableContainer

use of org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer in project scheduling by ow2-proactive.

the class TaskData method createTaskData.

static TaskData createTaskData(JobData jobRuntimeData, InternalScriptTask task) {
    TaskData taskData = new TaskData();
    TaskData.DBTaskId taskId = new DBTaskId();
    taskId.setJobId(jobRuntimeData.getId());
    taskId.setTaskId(task.getTaskInfo().getTaskId().longValue());
    taskData.setId(taskId);
    taskData.setOwner(jobRuntimeData.getOwner());
    taskData.setDescription(task.getDescription());
    taskData.setTag(task.getTag());
    taskData.setParallelEnvironment(task.getParallelEnvironment());
    taskData.setFlowBlock(task.getFlowBlock());
    taskData.setRestartMode(task.getRestartTaskOnError());
    taskData.setPreciousLogs(task.isPreciousLogs());
    taskData.setPreciousResult(task.isPreciousResult());
    taskData.setRunAsMe(task.isRunAsMe());
    taskData.setWallTime(task.getWallTime());
    taskData.setOnTaskErrorString(task.getOnTaskErrorProperty().getValue());
    taskData.setRetryDelay(task.getTaskRetryDelay());
    taskData.setMaxNumberOfExecution(task.getMaxNumberOfExecution());
    taskData.setJobData(jobRuntimeData);
    taskData.setNumberOfExecutionOnFailureLeft(PASchedulerProperties.NUMBER_OF_EXECUTION_ON_FAILURE.getValueAsInt());
    taskData.setNumberOfExecutionLeft(task.getMaxNumberOfExecution());
    taskData.setGenericInformation(task.getGenericInformation());
    HashMap<String, TaskDataVariable> variables = new LinkedHashMap<>();
    for (Map.Entry<String, TaskVariable> entry : task.getVariables().entrySet()) {
        variables.put(entry.getKey(), TaskDataVariable.create(entry.getKey(), entry.getValue(), taskData));
    }
    taskData.setVariables(variables);
    // set the scheduledTime if the START_AT property exists
    Map<String, String> genericInfos = taskData.getGenericInformation();
    if (genericInfos != null && genericInfos.containsKey(CommonAttribute.GENERIC_INFO_START_AT_KEY) && !genericInfos.get(CommonAttribute.GENERIC_INFO_START_AT_KEY).contains(VariableSubstitutor.SUBSITUTE_PREFIX_SIMPLE)) {
        // parse the START_AT if it's available and not dynamically defined
        long scheduledTime = ISO8601DateUtil.toDate(genericInfos.get(CommonAttribute.GENERIC_INFO_START_AT_KEY)).getTime();
        taskData.setScheduledTime(scheduledTime);
        task.setScheduledTime(scheduledTime);
    }
    taskData.updateMutableAttributes(task);
    if (task.getSelectionScripts() != null) {
        List<SelectionScriptData> scripts = new ArrayList<>(task.getSelectionScripts().size());
        long order = 0;
        for (SelectionScript selectionScript : task.getSelectionScripts()) {
            final SelectionScriptData aSelectionScript = SelectionScriptData.createForSelectionScript(selectionScript, taskData);
            aSelectionScript.setOrder(order++);
            scripts.add(aSelectionScript);
        }
        taskData.setSelectionScripts(scripts);
    }
    if (task.getExecutableContainer() != null) {
        taskData.setScript(ScriptData.createForScript(((ScriptExecutableContainer) task.getExecutableContainer()).getScript(), taskData));
    }
    if (task.getPreScript() != null) {
        taskData.setPreScript(ScriptData.createForScript(task.getPreScript(), taskData));
    }
    if (task.getPostScript() != null) {
        taskData.setPostScript(ScriptData.createForScript(task.getPostScript(), taskData));
    }
    if (task.getCleaningScript() != null) {
        taskData.setCleanScript(ScriptData.createForScript(task.getCleaningScript(), taskData));
    }
    if (task.getFlowScript() != null) {
        taskData.setFlowScript(ScriptData.createForFlowScript(task.getFlowScript(), taskData));
    }
    List<SelectorData> selectorsData = new ArrayList<>();
    if (task.getInputFilesList() != null) {
        for (InputSelector selector : task.getInputFilesList()) {
            selectorsData.add(SelectorData.createForInputSelector(selector, taskData));
        }
    }
    if (task.getOutputFilesList() != null) {
        for (OutputSelector selector : task.getOutputFilesList()) {
            selectorsData.add(SelectorData.createForOutputSelector(selector, taskData));
        }
    }
    long order = 0;
    for (SelectorData selectorData : selectorsData) {
        selectorData.setOrder(order++);
    }
    taskData.setDataspaceSelectors(selectorsData);
    ForkEnvironment forkEnvironment = task.getForkEnvironment();
    if (forkEnvironment != null) {
        taskData.setAdditionalClasspath(forkEnvironment.getAdditionalClasspath());
        taskData.setJavaHome(forkEnvironment.getJavaHome());
        taskData.setJvmArguments(forkEnvironment.getJVMArguments());
        taskData.setWorkingDir(forkEnvironment.getWorkingDir());
        if (forkEnvironment.getEnvScript() != null) {
            taskData.setEnvScript(ScriptData.createForScript(forkEnvironment.getEnvScript(), taskData));
        }
        Map<String, String> systemEnvironment = forkEnvironment.getSystemEnvironment();
        if (systemEnvironment != null) {
            List<EnvironmentModifierData> envModifiers = new ArrayList<>(systemEnvironment.size());
            for (Map.Entry<String, String> entry : systemEnvironment.entrySet()) {
                envModifiers.add(EnvironmentModifierData.create(new PropertyModifier(entry.getKey(), entry.getValue()), taskData));
            }
            taskData.setEnvModifiers(new HashSet<>(envModifiers));
        }
    }
    taskData.initTaskType(task);
    return taskData;
}
Also used : PropertyModifier(org.ow2.proactive.scheduler.common.task.PropertyModifier) InputSelector(org.ow2.proactive.scheduler.common.task.dataspaces.InputSelector) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) TaskVariable(org.ow2.proactive.scheduler.common.task.TaskVariable) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) SelectionScript(org.ow2.proactive.scripting.SelectionScript) OutputSelector(org.ow2.proactive.scheduler.common.task.dataspaces.OutputSelector)

Example 52 with ScriptExecutableContainer

use of org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer in project scheduling by ow2-proactive.

the class WalltimeTaskLauncherTest method walltime_forked_task.

@Test(timeout = 5000)
public void walltime_forked_task() throws Throwable {
    ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("for(;;){}", "javascript")));
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setWalltime(500);
    initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
    TaskResult taskResult = runTaskLauncher(createLauncherWithInjectedMocks(initializer, new ForkingTaskLauncherFactory()), executableContainer);
    assertEquals(WalltimeExceededException.class, taskResult.getException().getClass());
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) Test(org.junit.Test)

Example 53 with ScriptExecutableContainer

use of org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer in project scheduling by ow2-proactive.

the class TaskContextVariableExtractorTest method testExtractWorkflowVariablesFromTaskLauncherInitializerInsideTaskContext.

@Test
public void testExtractWorkflowVariablesFromTaskLauncherInitializerInsideTaskContext() throws Exception {
    ScriptExecutableContainer scriptContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "javascript")));
    TaskLauncherInitializer taskLauncherInitializer = getTaskLauncherInitializerWithWorkflowVariables();
    TaskContext taskContext = new TaskContext(scriptContainer, taskLauncherInitializer, null, new NodeDataSpacesURIs(null, null, null, null, null, null), null, new NodeInfo(null, null, null, null));
    Map<String, Serializable> contextVariables = new TaskContextVariableExtractor().getAllVariables(taskContext);
    assertThat((String) contextVariables.get(testVariable1Key), is(testVariable1Value));
    assertThat((String) contextVariables.get(testVariable2Key), is(testVariable2Value));
}
Also used : Serializable(java.io.Serializable) TaskScript(org.ow2.proactive.scripting.TaskScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer) Test(org.junit.Test)

Example 54 with ScriptExecutableContainer

use of org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer in project scheduling by ow2-proactive.

the class TaskContextVariableExtractorTest method testExtractTaskResultVariablesFromTaskResult.

@Test
public void testExtractTaskResultVariablesFromTaskResult() throws Exception {
    ScriptExecutableContainer scriptContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "javascript")));
    TaskLauncherInitializer taskLauncherInitializer = getTaskLauncherInitializerWithWorkflowVariables();
    TaskContext taskContext = new TaskContext(scriptContainer, taskLauncherInitializer, null, new NodeDataSpacesURIs(null, null, null, null, null, null), null, new NodeInfo(null, null, null, null));
    Map<String, byte[]> taskResultVariables = new HashMap<>();
    // The task result variables are expected to be converted to byte streams.
    taskResultVariables.put(taskResultPropagatedVariables1Key, AllObjects2BytesConverterHandler.convertObject2Byte(taskResultPropagatedVariables1Key, taskResultPropagatedVariables1Value));
    TaskResultImpl taskResult = new TaskResultImpl(taskContext.getTaskId(), new Exception("Exception"));
    taskResult.setPropagatedVariables(taskResultVariables);
    Map<String, Serializable> contextVariables = new TaskContextVariableExtractor().getAllVariablesWithTaskResult(taskContext, taskResult);
    assertThat((String) contextVariables.get(taskResultPropagatedVariables1Key), is(taskResultPropagatedVariables1Value));
}
Also used : Serializable(java.io.Serializable) TaskScript(org.ow2.proactive.scripting.TaskScript) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) HashMap(java.util.HashMap) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer) Test(org.junit.Test)

Example 55 with ScriptExecutableContainer

use of org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer in project scheduling by ow2-proactive.

the class TaskContextVariableExtractorTest method testExtractNodefileVariablesAndProgressVariablesWithGivenNodesfile.

@Test
public void testExtractNodefileVariablesAndProgressVariablesWithGivenNodesfile() throws Exception {
    ScriptExecutableContainer scriptContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "javascript")));
    TaskLauncherInitializer taskLauncherInitializer = getTaskLauncherInitializerWithWorkflowVariables();
    TaskContext taskContext = new TaskContext(scriptContainer, taskLauncherInitializer, null, new NodeDataSpacesURIs(null, null, null, null, null, null), null, new NodeInfo(null, null, null, null), null);
    Map<String, Serializable> contextVariables = new TaskContextVariableExtractor().getAllNonTaskVariablesInjectNodesFile(taskContext, nodesfileContent);
    assertThat("Nodes number must be equal to number of other nodes + 1 (for the own node).", (int) contextVariables.get(SchedulerVars.PA_NODESNUMBER.toString()), is(taskContext.getOtherNodesURLs().size() + 1));
    assertThat("Node file content of passed node file must be represented as a variable.", (String) contextVariables.get(SchedulerVars.PA_NODESFILE.toString()), is(nodesfileContent));
    assertThat("Task progress path must be represented as a variable.", (String) contextVariables.get(SchedulerVars.PA_TASK_PROGRESS_FILE.toString()), is(taskContext.getProgressFilePath()));
}
Also used : Serializable(java.io.Serializable) TaskScript(org.ow2.proactive.scripting.TaskScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer) Test(org.junit.Test)

Aggregations

ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)84 Test (org.junit.Test)71 SimpleScript (org.ow2.proactive.scripting.SimpleScript)67 TaskScript (org.ow2.proactive.scripting.TaskScript)67 NodeDataSpacesURIs (org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs)46 NodeInfo (org.ow2.proactive.scheduler.task.context.NodeInfo)46 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)46 TaskLauncherInitializer (org.ow2.proactive.scheduler.task.TaskLauncherInitializer)29 InProcessTaskExecutor (org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor)22 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)18 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)17 File (java.io.File)12 Serializable (java.io.Serializable)11 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)11 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)10 TestTaskOutput (org.ow2.proactive.scheduler.task.TestTaskOutput)9 ForkedTaskExecutor (org.ow2.proactive.scheduler.task.executors.ForkedTaskExecutor)9 Decrypter (org.ow2.proactive.scheduler.task.utils.Decrypter)9 HashMap (java.util.HashMap)8 VariablesMap (org.ow2.proactive.scheduler.task.utils.VariablesMap)8