use of org.ow2.proactive.scheduler.common.SchedulerSpaceInterface in project scheduling by ow2-proactive.
the class StaxJobFactory method createJobFromInputStream.
private Job createJobFromInputStream(InputStream jobInputStream, Map<String, String> replacementVariables, Map<String, String> replacementGenericInfos, Scheduler scheduler, SchedulerSpaceInterface space, String sessionId) throws JobCreationException, IOException, XMLStreamException {
long t0 = System.currentTimeMillis();
byte[] bytes = ValidationUtil.getInputStreamBytes(jobInputStream);
String md5Job = DigestUtils.md5Hex(bytes);
String md5Variables = DigestUtils.md5Hex(Object2ByteConverter.convertObject2Byte(replacementVariables));
String md5GenericInfo = DigestUtils.md5Hex(Object2ByteConverter.convertObject2Byte(replacementGenericInfos));
String md5GlobalVariables = "";
if (handleGlobalVariables) {
md5GlobalVariables = GlobalVariablesParser.getInstance().getMD5();
}
String md5 = md5Job + "_" + md5Variables + "_" + md5GenericInfo + "_" + md5GlobalVariables;
long t1 = System.currentTimeMillis();
if (!validationCache.containsKey(md5)) {
try {
try (ByteArrayInputStream jobInputStreamForValidation = new ByteArrayInputStream(bytes)) {
validate(jobInputStreamForValidation);
}
validationCache.put(md5, EMPTY_EXCEPTION);
} catch (JobCreationException e) {
validationCache.put(md5, e);
throw e;
}
} else {
JobCreationException e = validationCache.get(md5);
if (e != EMPTY_EXCEPTION) {
throw e;
}
}
long t2 = System.currentTimeMillis();
long t3;
Job job;
if (!jobCache.containsKey(md5)) {
Map<String, ArrayList<String>> dependencies = new LinkedHashMap<>();
try (ByteArrayInputStream jobInpoutStreamForParsing = new ByteArrayInputStream(bytes)) {
XMLStreamReader xmlsr = xmlInputFactory.createXMLStreamReader(jobInpoutStreamForParsing, FILE_ENCODING);
job = createJob(xmlsr, replacementVariables, replacementGenericInfos, dependencies, new String(bytes));
xmlsr.close();
}
t3 = System.currentTimeMillis();
makeDependences(job, dependencies);
jobCache.put(md5, job);
} else {
job = jobCache.get(md5);
t3 = System.currentTimeMillis();
}
long t4 = System.currentTimeMillis();
validate((TaskFlowJob) job, scheduler, space, sessionId);
long t5 = System.currentTimeMillis();
long d1 = t1 - t0;
long d2 = t2 - t1;
long d3 = t3 - t2;
long d4 = t4 - t3;
long d5 = t5 - t4;
logger.debug("Job successfully created!");
logger.debug(String.format("timer;%d;%d;%d;%d;%d", d1, d2, d3, d4, d5));
// debug mode only
displayJobInfo(job);
return job;
}
use of org.ow2.proactive.scheduler.common.SchedulerSpaceInterface 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.SchedulerSpaceInterface 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);
}
use of org.ow2.proactive.scheduler.common.SchedulerSpaceInterface in project scheduling by ow2-proactive.
the class OptionalParserValidatorTest method init.
@Before
public void init() throws SchedulerException, IOException {
MockitoAnnotations.initMocks(this);
when(context.getSpace()).thenReturn(schedulerSpaceInterface);
when(schedulerSpaceInterface.checkFileExists(USERSPACE_NAME, existUserFilePath)).thenReturn(true);
when(schedulerSpaceInterface.checkFileExists(USERSPACE_NAME, notExistUserFilePath)).thenReturn(false);
when(schedulerSpaceInterface.checkFileExists(GLOBALSPACE_NAME, existGlobalFilePath)).thenReturn(true);
when(schedulerSpaceInterface.checkFileExists(GLOBALSPACE_NAME, notExistGlobalFilePath)).thenReturn(false);
when(context.getScheduler()).thenReturn(scheduler);
when(scheduler.thirdPartyCredentialsKeySet()).thenReturn(Collections.singleton(existCredential));
modelFile = testFolder.newFile("modelFile");
FileUtils.writeStringToFile(modelFile, validModel, Charset.defaultCharset());
StandardEvaluationContext spelContext = new StandardEvaluationContext();
spelContext.setTypeLocator(new RestrictedTypeLocator());
spelContext.setMethodResolvers(Collections.singletonList(new RestrictedMethodResolver()));
spelContext.addPropertyAccessor(new RestrictedPropertyAccessor());
when(context.getSpELContext()).thenReturn(spelContext);
}
use of org.ow2.proactive.scheduler.common.SchedulerSpaceInterface in project scheduling by ow2-proactive.
the class ValidationUtil method validateJob.
public static JobValidationData validateJob(String jobFilePath, Map<String, String> jobVariables, Scheduler scheduler, SchedulerSpaceInterface space, String sessionId) {
JobValidationData data = new JobValidationData();
Job job = null;
try {
JobFactory factory = JobFactory.getFactory();
job = factory.createJob(jobFilePath, jobVariables, null, scheduler, space, sessionId);
if (job instanceof TaskFlowJob) {
fillUpdatedVariables((TaskFlowJob) job, data);
validateJob((TaskFlowJob) job, data);
} else {
data.setValid(true);
}
} catch (JobCreationException e) {
data.setTaskName(e.getTaskName());
setJobValidationDataErrorMessage(data, e);
}
return data;
}
Aggregations