Search in sources :

Example 51 with JobCreationException

use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.

the class StaxJobFactory method getJobVisualization.

/**
 * Get job's SVG visualization as HTML String from Workflows's Metadata.
 * Leave the method with the cursor at the end of 'VISUALIZATION' tag.
 *
 * @param cursorMetadata the streamReader with the cursor on the 'VISUALIZATION' tag.
 * @return the Workflow's visualization HTML String between the tags.
 */
private String getJobVisualization(XMLStreamReader cursorMetadata) throws JobCreationException {
    try {
        String visualization = "";
        // if visualization tag exists, then we have a characters event next.
        int eventType = cursorMetadata.next();
        if (eventType == XMLEvent.CHARACTERS) {
            visualization = cursorMetadata.getText();
        } else if (eventType == XMLEvent.END_ELEMENT) {
            return visualization;
        }
        // go to the description END_ELEMENT
        while (cursorMetadata.next() != XMLEvent.END_ELEMENT) ;
        return visualization;
    } catch (Exception e) {
        throw new JobCreationException((String) null, null, e);
    }
}
Also used : 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) IOException(java.io.IOException)

Example 52 with JobCreationException

use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.

the class StaxJobFactory method validate.

/*
     * Validate the given job descriptor
     */
private TaskFlowJob validate(TaskFlowJob job, Scheduler scheduler, SchedulerSpaceInterface space, String sessionId) throws JobCreationException {
    Map<String, JobValidatorService> factories;
    try {
        factories = JobValidatorRegistry.getInstance().getRegisteredFactories();
    } catch (Exception e) {
        throw new JobCreationException(MSG_UNABLE_TO_INSTANCIATE_JOB_VALIDATION_FACTORIES, e);
    }
    TaskFlowJob updatedJob = job;
    try {
        for (JobValidatorService factory : factories.values()) {
            updatedJob = factory.validateJob(updatedJob, scheduler, space, sessionId);
        }
    } catch (JobValidationException e) {
        fillUpdatedVariables(e, job);
        throw e;
    } catch (Exception e) {
        JobValidationException validationException = new JobValidationException(e);
        fillUpdatedVariables(validationException, job);
        throw validationException;
    }
    return updatedJob;
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) JobValidatorService(org.ow2.proactive.scheduler.common.job.factories.spi.JobValidatorService) JobValidationException(org.ow2.proactive.scheduler.common.exception.JobValidationException) 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) IOException(java.io.IOException)

Example 53 with JobCreationException

use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.

the class StaxJobFactory method createScript.

/**
 * Get the script defined at the specified cursor.
 * Leave the method with cursor at the end of the corresponding script.
 *
 * @param cursorScript the streamReader with the cursor on the corresponding script tag (pre, post, cleaning, selection, generation).
 * @param type         nature of the script
 * @return the script  defined at the specified cursor.
 */
private Script<?> createScript(XMLStreamReader cursorScript, ScriptType type, Map<String, String> variables) throws JobCreationException {
    String attrtmp = null;
    String currentScriptTag = cursorScript.getLocalName();
    String current = null;
    try {
        boolean isDynamic = true;
        Script<?> toReturn = null;
        int eventType = -1;
        while (cursorScript.hasNext()) {
            if (type == ScriptType.SELECTION && eventType == -1) {
                eventType = cursorScript.getEventType();
            } else {
                eventType = cursorScript.next();
            }
            switch(eventType) {
                case XMLEvent.START_ELEMENT:
                    current = cursorScript.getLocalName();
                    if (XMLTags.SCRIPT_CODE.matches(current)) {
                        String language = null;
                        String content = "";
                        if (cursorScript.getAttributeCount() > 0) {
                            language = cursorScript.getAttributeValue(0);
                            attrtmp = cursorScript.getAttributeLocalName(0);
                        }
                        // goto script content
                        if (cursorScript.next() == XMLEvent.CHARACTERS) {
                            content = cursorScript.getText();
                        }
                        toReturn = new SimpleScript(content, language);
                        // fast forward to the end of tag
                        while (true) {
                            int ev = cursorScript.next();
                            if (XMLTags.SCRIPT_CODE.matches(current) && ev == XMLEvent.END_ELEMENT) {
                                break;
                            }
                        }
                    } else if (XMLTags.SCRIPT_FILE.matches(current)) {
                        String path = null;
                        String url = null;
                        String language = null;
                        for (int i = 0; i < cursorScript.getAttributeCount(); i++) {
                            attrtmp = cursorScript.getAttributeLocalName(i);
                            if (XMLAttributes.SCRIPT_URL.matches(attrtmp)) {
                                url = replace(cursorScript.getAttributeValue(i), variables);
                            } else if (XMLAttributes.LANGUAGE.matches(attrtmp)) {
                                language = replace(cursorScript.getAttributeValue(i), variables);
                            } else if (XMLAttributes.PATH.matches(attrtmp)) {
                                path = checkPath(cursorScript.getAttributeValue(i), variables);
                            } else {
                                throw new JobCreationException("Unrecognized attribute : " + attrtmp);
                            }
                        }
                        // go to the next 'arguments' start element or the 'file' end element
                        while (true) {
                            int ev = cursorScript.next();
                            if (((ev == XMLEvent.START_ELEMENT) && XMLTags.SCRIPT_ARGUMENTS.matches(cursorScript.getLocalName())) || (ev == XMLEvent.END_ELEMENT)) {
                                break;
                            }
                        }
                        if (url != null) {
                            if (language != null) {
                                toReturn = new SimpleScript(new URL(url), language, getArguments(cursorScript));
                            } else {
                                toReturn = new SimpleScript(new URL(url), getArguments(cursorScript));
                            }
                        } else if (path != null) {
                            // language is ignored if a File is provided, the script language will be determined based on the file extension
                            toReturn = new SimpleScript(new File(path), getArguments(cursorScript));
                        } else {
                            attrtmp = null;
                            throw new JobCreationException("Invalid script file definition, one of path/url attributes must be declared");
                        }
                    } else if (XMLTags.SCRIPT_ARGUMENTS.matches(current)) {
                        toReturn = new SimpleScript(toReturn.getScript(), toReturn.getEngineName(), getArguments(cursorScript));
                    } else if (XMLTags.SCRIPT_SCRIPT.matches(current) && cursorScript.getAttributeCount() > 0) {
                        isDynamic = !"static".equals(cursorScript.getAttributeValue(0));
                    }
                    break;
                case XMLEvent.END_ELEMENT:
                    if (cursorScript.getLocalName().equals(currentScriptTag)) {
                        if (type == ScriptType.SELECTION) {
                            return new SelectionScript(toReturn, isDynamic);
                        } else {
                            return toReturn;
                        }
                    }
                    break;
                default:
            }
        }
        return toReturn;
    } catch (JobCreationException jce) {
        jce.pushTag(current);
        throw jce;
    } catch (Exception e) {
        throw new JobCreationException(current, attrtmp, e);
    }
}
Also used : SelectionScript(org.ow2.proactive.scripting.SelectionScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) File(java.io.File) URL(java.net.URL) 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) IOException(java.io.IOException)

Example 54 with JobCreationException

use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.

the class StaxJobFactory method fillJobWithTasks.

/**
 * Fill the created Job with coming tasks..
 * Leave the method with the cursor at the end of the file (nothing more has to be parsed).
 *
 * @param cursorTask the streamReader with the cursor on the first 'ELEMENT_TASK' tag.
 */
private void fillJobWithTasks(XMLStreamReader cursorTask, Job job, Map<String, ArrayList<String>> dependencies, GlobalVariablesData globalVariablesData) throws JobCreationException {
    if (job == null) {
        throw new JobCreationException(XMLTags.JOB.getXMLName(), null, null);
    }
    XMLTags current = null;
    try {
        int eventType = -1;
        while (cursorTask.hasNext()) {
            // if use to keep the cursor on the task tag for the first loop
            if (eventType == -1) {
                eventType = cursorTask.getEventType();
            } else {
                eventType = cursorTask.next();
            }
            if (eventType == XMLEvent.START_ELEMENT && XMLTags.TASK.matches(cursorTask.getLocalName())) {
                Task t;
                switch(job.getType()) {
                    case TASKSFLOW:
                        current = XMLTags.TASK;
                        // create new task
                        t = createTask(cursorTask, job, dependencies, globalVariablesData);
                        // add task to the job
                        ((TaskFlowJob) job).addTask(t);
                        break;
                    case PARAMETER_SWEEPING:
                        current = XMLTags.TASK;
                        throw new RuntimeException("Job parameter sweeping is not yet implemented!");
                    default:
                }
            } else {
                // Leave the method with the cursor at the end of the taskflow tag
                break;
            }
        }
    } catch (JobCreationException jce) {
        jce.pushTag(current);
        throw jce;
    } catch (Exception e) {
        throw new JobCreationException(current, null, e);
    }
}
Also used : Task(org.ow2.proactive.scheduler.common.task.Task) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) 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) IOException(java.io.IOException)

Example 55 with JobCreationException

use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.

the class StaxJobFactory method createJob.

/**
 * Start parsing and creating the job.
 *
 * @throws JobCreationException if an error occurred during job creation process.
 */
private Job createJob(XMLStreamReader cursorRoot, Map<String, String> replacementVariables, Map<String, String> replacementGenericInfos, Map<String, ArrayList<String>> dependencies, String jobContent) throws JobCreationException {
    String current = null;
    GlobalVariablesData globalVariablesData = getConfiguredGlobalVariablesData(jobContent);
    // start parsing
    try {
        int eventType;
        Job job = null;
        while (cursorRoot.hasNext()) {
            eventType = cursorRoot.next();
            if (eventType == XMLEvent.START_ELEMENT) {
                current = cursorRoot.getLocalName();
                if (XMLTags.JOB.matches(current)) {
                    // first tag of the job.
                    job = createAndFillJob(cursorRoot, replacementVariables, replacementGenericInfos, jobContent, globalVariablesData);
                } else if (XMLTags.TASK.matches(current)) {
                    // once here, the job instance has been created
                    fillJobWithTasks(cursorRoot, job, dependencies, globalVariablesData);
                } else if (XMLTags.METADATA_VISUALIZATION.matches(current) && job != null) {
                    // Add workflow visualization's embedded html
                    job.setVisualization(getJobVisualization(cursorRoot));
                    // Metadata is the last element to parse
                    break;
                }
            }
        }
        if (job != null) {
            resolveCleaningScripts((TaskFlowJob) job, job.getVariablesAsReplacementMap());
        }
        Map<String, JobVariable> globalVariables = new LinkedHashMap<>();
        for (String globalVariable : globalVariablesData.getVariables().keySet()) {
            globalVariables.put(globalVariable, job.getVariables().get(globalVariable));
        }
        job.setGlobalVariables(globalVariables);
        Map<String, String> globalGenericInfoMap = new LinkedHashMap<>();
        for (String globalGenericInfo : globalVariablesData.getGenericInformation().keySet()) {
            globalGenericInfoMap.put(globalGenericInfo, job.getGenericInformation().get(globalGenericInfo));
        }
        job.setGlobalGenericInformation(globalGenericInfoMap);
        return job;
    } catch (JobCreationException jce) {
        if (XMLTags.TASK.matches(current)) {
            jce.pushTag(XMLTags.TASK_FLOW.getXMLName());
        }
        throw jce;
    } catch (Exception e) {
        throw new JobCreationException(current, null, e);
    }
}
Also used : GlobalVariablesData(org.ow2.proactive.scheduler.common.job.factories.globalvariables.GlobalVariablesData) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) Job(org.ow2.proactive.scheduler.common.job.Job) 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) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)51 JobValidationException (org.ow2.proactive.scheduler.common.exception.JobValidationException)30 FileNotFoundException (java.io.FileNotFoundException)29 XMLStreamException (javax.xml.stream.XMLStreamException)29 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)25 IOException (java.io.IOException)24 LinkedHashMap (java.util.LinkedHashMap)16 Job (org.ow2.proactive.scheduler.common.job.Job)16 VerifierConfigurationException (org.iso_relax.verifier.VerifierConfigurationException)12 HashMap (java.util.HashMap)11 Test (org.junit.Test)10 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)9 GlobalVariablesParserTest (org.ow2.proactive.scheduler.common.job.factories.globalvariables.GlobalVariablesParserTest)9 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)8 SubmissionClosedException (org.ow2.proactive.scheduler.common.exception.SubmissionClosedException)8 JobVariable (org.ow2.proactive.scheduler.common.job.JobVariable)8 NativeTask (org.ow2.proactive.scheduler.common.task.NativeTask)8 ArrayList (java.util.ArrayList)7 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)7 Task (org.ow2.proactive.scheduler.common.task.Task)7