Search in sources :

Example 1 with TaskVariable

use of org.ow2.proactive.scheduler.common.task.TaskVariable 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 TaskVariable

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

the class StaxJobFactory method createTaskVariables.

/**
 * 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.
 * @return the map in which the variables were added.
 * @throws JobCreationException
 */
private Map<String, TaskVariable> createTaskVariables(XMLStreamReader cursorVariables, Map<String, String> variables) throws JobCreationException {
    Map<String, TaskVariable> variablesMap = new HashMap<>();
    try {
        int eventType;
        while (cursorVariables.hasNext()) {
            eventType = cursorVariables.next();
            if (eventType == XMLEvent.START_ELEMENT && XMLTags.VARIABLE.matches(cursorVariables.getLocalName())) {
                TaskVariable taskVariable = getTaskVariable(cursorVariables, variables);
                variablesMap.put(taskVariable.getName(), taskVariable);
            } else if (eventType == XMLEvent.END_ELEMENT && XMLTags.VARIABLES.matches(cursorVariables.getLocalName())) {
                return variablesMap;
            }
        }
    } 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 : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TaskVariable(org.ow2.proactive.scheduler.common.task.TaskVariable) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) 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)

Example 3 with TaskVariable

use of org.ow2.proactive.scheduler.common.task.TaskVariable 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 TaskVariable

use of org.ow2.proactive.scheduler.common.task.TaskVariable 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 TaskVariable

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

the class Attribute method createTaskVariablesElement.

/**
 * Creates the task variables element
 */
private Element createTaskVariablesElement(Document doc, Map<String, TaskVariable> variables) {
    if (variables == null) {
        return null;
    }
    Element variablesE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.VARIABLES.getXMLName());
    for (TaskVariable variable : variables.values()) {
        List<Attribute> varAttributes = new ArrayList<>();
        varAttributes.add(new Attribute(XMLAttributes.VARIABLE_NAME.getXMLName(), variable.getName()));
        varAttributes.add(new Attribute(XMLAttributes.VARIABLE_VALUE.getXMLName(), variable.getValue()));
        varAttributes.add(new Attribute(XMLAttributes.VARIABLE_MODEL.getXMLName(), variable.getModel()));
        if (variable.getDescription() != null) {
            varAttributes.add(new Attribute(XMLAttributes.VARIABLE_DESCRIPTION.getXMLName(), variable.getDescription()));
        }
        if (variable.getGroup() != null) {
            varAttributes.add(new Attribute(XMLAttributes.VARIABLE_GROUP.getXMLName(), variable.getGroup()));
        }
        if (variable.isAdvanced()) {
            varAttributes.add(new Attribute(XMLAttributes.VARIABLE_ADVANCED.getXMLName(), String.valueOf(variable.isAdvanced())));
        }
        if (variable.isHidden()) {
            varAttributes.add(new Attribute(XMLAttributes.VARIABLE_HIDDEN.getXMLName(), String.valueOf(variable.isHidden())));
        }
        varAttributes.add(new Attribute(XMLAttributes.VARIABLE_JOB_INHERITED.getXMLName(), String.valueOf(variable.isJobInherited())));
        Element variableE = createElement(doc, XMLTags.VARIABLE.getXMLName(), null, varAttributes.toArray(new Attribute[0]));
        variablesE.appendChild(variableE);
    }
    return variablesE;
}
Also used : Element(org.w3c.dom.Element) TaskVariable(org.ow2.proactive.scheduler.common.task.TaskVariable) ArrayList(java.util.ArrayList)

Aggregations

TaskVariable (org.ow2.proactive.scheduler.common.task.TaskVariable)19 HashMap (java.util.HashMap)10 Task (org.ow2.proactive.scheduler.common.task.Task)9 LinkedHashMap (java.util.LinkedHashMap)6 JobVariable (org.ow2.proactive.scheduler.common.job.JobVariable)6 FileNotFoundException (java.io.FileNotFoundException)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 Test (org.junit.Test)4 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)4 JobValidationException (org.ow2.proactive.scheduler.common.exception.JobValidationException)4 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)4 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)4 ScriptTask (org.ow2.proactive.scheduler.common.task.ScriptTask)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 IOException (java.io.IOException)3 Map (java.util.Map)3 NativeTask (org.ow2.proactive.scheduler.common.task.NativeTask)3 LRUMap (org.apache.commons.collections4.map.LRUMap)2 VerifierConfigurationException (org.iso_relax.verifier.VerifierConfigurationException)2 GlobalVariablesParserTest (org.ow2.proactive.scheduler.common.job.factories.globalvariables.GlobalVariablesParserTest)2