Search in sources :

Example 1 with JobVariable

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

the class ValidationUtil method fillUpdatedVariables.

private void fillUpdatedVariables(TaskFlowJob job, JobValidationData data) {
    HashMap<String, String> updatedVariables = new HashMap<>();
    for (JobVariable jobVariable : job.getVariables().values()) {
        updatedVariables.put(jobVariable.getName(), jobVariable.getValue());
    }
    for (Task task : job.getTasks()) {
        for (TaskVariable taskVariable : task.getVariables().values()) {
            updatedVariables.put(task.getName() + ":" + taskVariable.getName(), taskVariable.getValue());
        }
    }
    data.setUpdatedVariables(updatedVariables);
}
Also used : Task(org.ow2.proactive.scheduler.common.task.Task) HashMap(java.util.HashMap) TaskVariable(org.ow2.proactive.scheduler.common.task.TaskVariable) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable)

Example 2 with JobVariable

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

the class StaxJobFactory method createJobVariables.

/**
 * Create a map of variables from XML variables.
 * Leave the method with the cursor at the end of 'ELEMENT_VARIABLES' tag
 *
 * @param cursorVariables the streamReader with the cursor on the 'ELEMENT_VARIABLES' tag.
 * @param replacementVariables variables which have precedence over the one defined in the job
 * @return the map in which the variables were added.
 * @throws JobCreationException
 */
private Map<String, JobVariable> createJobVariables(XMLStreamReader cursorVariables, Map<String, String> replacementVariables) throws JobCreationException {
    HashMap<String, JobVariable> variablesMap = new LinkedHashMap<>();
    try {
        int eventType;
        while (cursorVariables.hasNext()) {
            eventType = cursorVariables.next();
            switch(eventType) {
                case XMLEvent.START_ELEMENT:
                    if (XMLTags.VARIABLE.matches(cursorVariables.getLocalName())) {
                        Map<String, String> attributesAsMap = getAttributesAsMap(cursorVariables, null);
                        String name = attributesAsMap.get(XMLAttributes.VARIABLE_NAME.getXMLName());
                        String value = attributesAsMap.get(XMLAttributes.VARIABLE_VALUE.getXMLName());
                        String model = attributesAsMap.get(XMLAttributes.VARIABLE_MODEL.getXMLName());
                        variablesMap.put(name, new JobVariable(name, value, model));
                    }
                    break;
                case XMLEvent.END_ELEMENT:
                    if (XMLTags.VARIABLES.matches(cursorVariables.getLocalName())) {
                        return replaceVariablesInJobVariablesMap(variablesMap, replacementVariables);
                    }
                    break;
            }
        }
    } catch (JobCreationException jce) {
        jce.pushTag(cursorVariables.getLocalName());
        throw jce;
    } catch (Exception e) {
        String attrtmp = null;
        if (cursorVariables.isStartElement() && cursorVariables.getAttributeCount() == 1) {
            attrtmp = cursorVariables.getAttributeLocalName(0);
        }
        throw new JobCreationException(cursorVariables.getLocalName(), attrtmp, e);
    }
    return variablesMap;
}
Also used : JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable) XMLStreamException(javax.xml.stream.XMLStreamException) JobValidationException(org.ow2.proactive.scheduler.common.exception.JobValidationException) FileNotFoundException(java.io.FileNotFoundException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) VerifierConfigurationException(org.iso_relax.verifier.VerifierConfigurationException) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with JobVariable

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

the class DefaultModelJobValidatorServiceProvider method validateJob.

@Override
public TaskFlowJob validateJob(TaskFlowJob job) throws JobValidationException {
    ModelValidatorContext context = new ModelValidatorContext(job);
    for (JobVariable jobVariable : job.getVariables().values()) {
        checkVariableFormat(null, jobVariable, context);
        context.updateJobWithContext(job);
    }
    for (Task task : job.getTasks()) {
        context = new ModelValidatorContext(task);
        for (TaskVariable taskVariable : task.getVariables().values()) {
            checkVariableFormat(task, taskVariable, context);
            context.updateTaskWithContext(task);
        }
    }
    return job;
}
Also used : Task(org.ow2.proactive.scheduler.common.task.Task) TaskVariable(org.ow2.proactive.scheduler.common.task.TaskVariable) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable)

Example 4 with JobVariable

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

the class DefaultModelJobValidatorServiceProvider method validateJob.

@Override
public TaskFlowJob validateJob(TaskFlowJob job, Scheduler scheduler, SchedulerSpaceInterface space, String sessionId) throws JobValidationException {
    ModelValidatorContext context = new ModelValidatorContext(job, scheduler, space, sessionId);
    for (JobVariable jobVariable : job.getVariables().values()) {
        checkVariableFormat(null, jobVariable, context);
        context.updateJobWithContext(job);
    }
    for (Task task : job.getTasks()) {
        context = new ModelValidatorContext(task, scheduler, space, sessionId);
        for (TaskVariable taskVariable : task.getVariables().values()) {
            checkVariableFormat(task, taskVariable, context);
            context.updateTaskWithContext(task);
        }
    }
    return job;
}
Also used : Task(org.ow2.proactive.scheduler.common.task.Task) TaskVariable(org.ow2.proactive.scheduler.common.task.TaskVariable) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable)

Example 5 with JobVariable

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

the class DefaultModelJobValidatorServiceProvider method validateVariables.

public void validateVariables(List<JobVariable> variableList, Map<String, Serializable> userValues, Scheduler scheduler, SchedulerSpaceInterface space) throws JobValidationException {
    if (variableList == null || variableList.isEmpty() || userValues == null || userValues.isEmpty()) {
        return;
    }
    Map<String, String> models = variableList.stream().collect(Collectors.toMap(JobVariable::getName, JobVariable::getModel));
    Set<String> groupNames = new LinkedHashSet<>();
    variableList.forEach(e -> {
        if (!Strings.isNullOrEmpty(e.getGroup())) {
            groupNames.add(e.getGroup());
        }
    });
    Map<String, Serializable> variableReplacement = new LinkedHashMap<>();
    Map<String, Serializable> updatedVariables = new LinkedHashMap<>();
    variableList.forEach(jobVariable -> {
        if (userValues.containsKey(jobVariable.getName())) {
            variableReplacement.put(jobVariable.getName(), userValues.get(jobVariable.getName()));
        } else {
            variableReplacement.put(jobVariable.getName(), jobVariable.getValue());
        }
    });
    variableList.forEach(jobVariable -> {
        jobVariable.setValue(userValues.containsKey(jobVariable.getName()) ? VariableSubstitutor.filterAndUpdate((String) userValues.get(jobVariable.getName()), variableReplacement) : VariableSubstitutor.filterAndUpdate(jobVariable.getValue(), variableReplacement));
        updatedVariables.put(jobVariable.getName(), jobVariable.getValue());
    });
    ModelValidatorContext context = new ModelValidatorContext(updatedVariables, models, groupNames, scheduler, space, null);
    for (JobVariable jobVariable : variableList) {
        checkVariableFormat(null, jobVariable, context);
    }
    context.updateJobVariablesWithContext(variableList);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Serializable(java.io.Serializable) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

JobVariable (org.ow2.proactive.scheduler.common.job.JobVariable)51 Test (org.junit.Test)19 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)17 HashMap (java.util.HashMap)15 LinkedHashMap (java.util.LinkedHashMap)9 Job (org.ow2.proactive.scheduler.common.job.Job)8 JobId (org.ow2.proactive.scheduler.common.job.JobId)8 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)7 JobValidationException (org.ow2.proactive.scheduler.common.exception.JobValidationException)6 Task (org.ow2.proactive.scheduler.common.task.Task)6 TaskVariable (org.ow2.proactive.scheduler.common.task.TaskVariable)6 IOException (java.io.IOException)5 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)5 SimpleScript (org.ow2.proactive.scripting.SimpleScript)5 TaskScript (org.ow2.proactive.scripting.TaskScript)5 NonTerminatingJob (functionaltests.jobs.NonTerminatingJob)4 SimpleJob (functionaltests.jobs.SimpleJob)4 FileNotFoundException (java.io.FileNotFoundException)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)4