Search in sources :

Example 11 with TaskVariable

use of org.ow2.proactive.scheduler.common.task.TaskVariable in project scheduling by ow2-proactive.

the class SpelValidatorTest method createTask.

private Task createTask() throws UserException {
    Task task = new JavaTask();
    task.setVariables(ImmutableMap.of("var1", new TaskVariable("var1", "value1"), "var2", new TaskVariable("var2", "value2"), "var3", new TaskVariable("var3", ""), "var4", new TaskVariable("var4", null)));
    task.setName("task1");
    return task;
}
Also used : Task(org.ow2.proactive.scheduler.common.task.Task) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) TaskVariable(org.ow2.proactive.scheduler.common.task.TaskVariable) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask)

Example 12 with TaskVariable

use of org.ow2.proactive.scheduler.common.task.TaskVariable in project scheduling by ow2-proactive.

the class TaskContextVariableExtractorTest method getTaskLauncherInitializerWithWorkflowVariables.

private TaskLauncherInitializer getTaskLauncherInitializerWithWorkflowVariables() {
    // Create and setup task launcher initializer
    TaskLauncherInitializer taskLauncherInitializer = createTaskLauncherInitializer();
    Map<String, JobVariable> variablesToPut = new HashMap<>();
    variablesToPut.put(testVariable1Key, new JobVariable(testVariable1Key, testVariable1Value));
    taskLauncherInitializer.setJobVariables(variablesToPut);
    Map<String, TaskVariable> variablesToPut2 = new HashMap<>();
    variablesToPut2.put(testVariable2Key, new TaskVariable(testVariable2Key, testVariable2Value, null, false));
    taskLauncherInitializer.setTaskVariables(variablesToPut2);
    return taskLauncherInitializer;
}
Also used : HashMap(java.util.HashMap) TaskVariable(org.ow2.proactive.scheduler.common.task.TaskVariable) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer)

Example 13 with TaskVariable

use of org.ow2.proactive.scheduler.common.task.TaskVariable in project scheduling by ow2-proactive.

the class TaskContextVariableExtractor method getScopeVariables.

/**
 * Return all variables in scope of a given taskContext.
 *
 * @param taskContext task context container.
 * @return Map containing all variables resolved.
 */
public Map<String, Serializable> getScopeVariables(TaskContext taskContext) {
    Map<String, Serializable> variables = new HashMap<>();
    Map<String, Serializable> inherited = new HashMap<>();
    Map<String, Serializable> dictionary = new HashMap<>();
    try {
        inherited.putAll(extractSystemVariables(taskContext, ""));
        inherited.putAll(extractJobVariables(taskContext));
        inherited.putAll(extractInheritedVariables(taskContext));
        for (TaskVariable taskVariable : taskContext.getInitializer().getTaskVariables().values()) {
            if (!taskVariable.isJobInherited()) {
                // add non inherited variables
                variables.put(taskVariable.getName(), taskVariable.getValue());
            } else if (!inherited.containsKey(taskVariable.getName())) {
                // but if the variable is inherited
                // replace by the inherited value if exists
                variables.put(taskVariable.getName(), taskVariable.getValue());
            }
        }
        dictionary = extractAllVariables(taskContext, null, "");
    } catch (IOException | ClassNotFoundException e) {
        logger.error(ERROR_READING_VARIABLES, e);
    }
    return VariableSubstitutor.resolveVariables(variables, dictionary);
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) TaskVariable(org.ow2.proactive.scheduler.common.task.TaskVariable) IOException(java.io.IOException)

Example 14 with TaskVariable

use of org.ow2.proactive.scheduler.common.task.TaskVariable 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.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.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 HashMap<>();
    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)) {
        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());
        for (SelectionScript selectionScript : task.getSelectionScripts()) {
            scripts.add(SelectionScriptData.createForSelectionScript(selectionScript, taskData));
        }
        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));
        }
    }
    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(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 15 with TaskVariable

use of org.ow2.proactive.scheduler.common.task.TaskVariable in project scheduling by ow2-proactive.

the class TaskData method taskDataVariableToTaskVariable.

private static TaskVariable taskDataVariableToTaskVariable(TaskDataVariable taskDataVariable) {
    if (taskDataVariable == null) {
        return null;
    }
    TaskVariable taskVariable = new TaskVariable();
    taskVariable.setJobInherited(taskDataVariable.isJobInherited());
    taskVariable.setModel(taskDataVariable.getModel());
    taskVariable.setValue(taskDataVariable.getValue());
    taskVariable.setName(taskDataVariable.getName());
    return taskVariable;
}
Also used : TaskVariable(org.ow2.proactive.scheduler.common.task.TaskVariable)

Aggregations

TaskVariable (org.ow2.proactive.scheduler.common.task.TaskVariable)13 HashMap (java.util.HashMap)6 Task (org.ow2.proactive.scheduler.common.task.Task)5 Test (org.junit.Test)3 JobVariable (org.ow2.proactive.scheduler.common.job.JobVariable)3 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)3 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)3 FileNotFoundException (java.io.FileNotFoundException)2 LinkedHashMap (java.util.LinkedHashMap)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 VerifierConfigurationException (org.iso_relax.verifier.VerifierConfigurationException)2 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)2 JobValidationException (org.ow2.proactive.scheduler.common.exception.JobValidationException)2 ScriptTask (org.ow2.proactive.scheduler.common.task.ScriptTask)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 File (java.io.File)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 Map (java.util.Map)1 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)1