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);
}
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;
}
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;
}
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;
}
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);
}
Aggregations