Search in sources :

Example 1 with SchedulerSpaceInterface

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;
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) Job(org.ow2.proactive.scheduler.common.job.Job) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with SchedulerSpaceInterface

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;
}
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 3 with SchedulerSpaceInterface

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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Serializable(java.io.Serializable) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with SchedulerSpaceInterface

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);
}
Also used : RestrictedTypeLocator(org.ow2.proactive.scheduler.common.job.factories.spi.model.utils.RestrictedTypeLocator) RestrictedMethodResolver(org.ow2.proactive.scheduler.common.job.factories.spi.model.utils.RestrictedMethodResolver) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) RestrictedPropertyAccessor(org.ow2.proactive.scheduler.common.job.factories.spi.model.utils.RestrictedPropertyAccessor) Before(org.junit.Before)

Example 5 with SchedulerSpaceInterface

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;
}
Also used : JobFactory(org.ow2.proactive.scheduler.common.job.factories.JobFactory) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) JobValidationData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobValidationData) Job(org.ow2.proactive.scheduler.common.job.Job) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob)

Aggregations

JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)4 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)4 Job (org.ow2.proactive.scheduler.common.job.Job)3 LinkedHashMap (java.util.LinkedHashMap)2 JobVariable (org.ow2.proactive.scheduler.common.job.JobVariable)2 JobFactory (org.ow2.proactive.scheduler.common.job.factories.JobFactory)2 JobValidationData (org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobValidationData)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 Before (org.junit.Before)1 SchedulerSpaceInterface (org.ow2.proactive.scheduler.common.SchedulerSpaceInterface)1 JobValidationException (org.ow2.proactive.scheduler.common.exception.JobValidationException)1 JobValidatorService (org.ow2.proactive.scheduler.common.job.factories.spi.JobValidatorService)1 ModelValidatorContext (org.ow2.proactive.scheduler.common.job.factories.spi.model.ModelValidatorContext)1