Search in sources :

Example 56 with JobCreationException

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

the class StaxJobFactory method getDescription.

/**
 * Get the description of the entity.
 * Leave the method with the cursor at the end of 'ELEMENT_COMMON_DESCRIPTION' tag.
 *
 * @param cursorVariables the streamReader with the cursor on the 'ELEMENT_COMMON_DESCRIPTION' tag.
 * @return the description between the tags.
 */
private String getDescription(XMLStreamReader cursorVariables, Map<String, String> variables) throws JobCreationException {
    try {
        String description = "";
        // if description tag exists, then we have a characters event next.
        int eventType = cursorVariables.next();
        if (eventType == XMLEvent.CHARACTERS) {
            description = replace(cursorVariables.getText(), variables);
        } else if (eventType == XMLEvent.END_ELEMENT) {
            return description;
        }
        // go to the description END_ELEMENT
        while (cursorVariables.next() != XMLEvent.END_ELEMENT) ;
        return description;
    } catch (JobCreationException jce) {
        throw jce;
    } 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 57 with JobCreationException

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

the class StaxJobFactory method setIOFIles.

/**
 * Create the list of includes/excludes pattern for the given INPUT/OUTPUT files
 * Leave the method with the cursor at the end of 'ELEMENT_DS_INPUT/OUTPUTFILES' tag.
 *
 * @param cursorTask the streamReader with the cursor on the 'ELEMENT_DS_INPUT/OUTPUTFILES' tag.
 * @param endTag     the final tag for this tag : ELEMENT_DS_INPUTFILES or ELEMENT_DS_INPUTFILES
 * @param task       the task in which to add the input/output files selector
 * @throws JobCreationException
 */
private void setIOFIles(XMLStreamReader cursorTask, String endTag, Task task, Map<String, String> variables) throws JobCreationException {
    int i = 0;
    try {
        int eventType;
        boolean shouldContinue = true;
        while (shouldContinue && cursorTask.hasNext()) {
            eventType = cursorTask.next();
            switch(eventType) {
                case XMLEvent.START_ELEMENT:
                    String current = cursorTask.getLocalName();
                    if (XMLTags.DS_FILES.matches(current)) {
                        int attrLen = cursorTask.getAttributeCount();
                        FileSelector selector = null;
                        String accessMode = null;
                        for (i = 0; i < attrLen; i++) {
                            String attrName = cursorTask.getAttributeLocalName(i);
                            if (XMLAttributes.DS_INCLUDES.matches(attrName)) {
                                if (selector == null) {
                                    selector = new FileSelector();
                                }
                                selector.setIncludes(cursorTask.getAttributeValue(i));
                            } else if (XMLAttributes.DS_EXCLUDES.matches(attrName)) {
                                if (selector == null) {
                                    selector = new FileSelector();
                                }
                                selector.setExcludes(replace(cursorTask.getAttributeValue(i), variables));
                            } else if (XMLAttributes.DS_ACCESS_MODE.matches(attrName)) {
                                accessMode = cursorTask.getAttributeValue(i);
                            }
                            if (selector != null && accessMode != null) {
                                if (XMLTags.DS_INPUT_FILES.matches(endTag)) {
                                    task.addInputFiles(selector, InputAccessMode.getAccessMode(accessMode));
                                } else {
                                    task.addOutputFiles(selector, OutputAccessMode.getAccessMode(accessMode));
                                }
                            }
                        }
                    }
                    break;
                case XMLEvent.END_ELEMENT:
                    if (cursorTask.getLocalName().equals(endTag)) {
                        shouldContinue = false;
                    }
                    break;
                default:
            }
        }
    } catch (JobCreationException jce) {
        jce.pushTag(cursorTask.getLocalName());
        throw jce;
    } catch (Exception e) {
        String attrtmp = null;
        if (cursorTask.isStartElement() && cursorTask.getAttributeCount() > i) {
            attrtmp = cursorTask.getAttributeLocalName(i);
        }
        throw new JobCreationException(cursorTask.getLocalName(), attrtmp, e);
    }
}
Also used : FileSelector(org.objectweb.proactive.extensions.dataspaces.vfs.selector.FileSelector) 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 58 with JobCreationException

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

the class StaxJobFactory method createControlFlowScript.

private FlowScript createControlFlowScript(XMLStreamReader cursorTask, Task tmpTask, Map<String, String> variables) throws JobCreationException {
    String type = null;
    String target = null;
    String targetElse = null;
    String targetJoin = null;
    int event = -1;
    for (int i = 0; i < cursorTask.getAttributeCount(); i++) {
        String attrName = cursorTask.getAttributeLocalName(i);
        if (XMLAttributes.FLOW_BLOCK.matches(attrName)) {
            tmpTask.setFlowBlock(FlowBlock.parse(replace(cursorTask.getAttributeValue(i), variables)));
        }
    }
    // <control>  =>  <if> | <loop> | <replicate>
    try {
        while (cursorTask.hasNext()) {
            event = cursorTask.next();
            if (event == XMLEvent.START_ELEMENT) {
                break;
            } else if (event == XMLEvent.END_ELEMENT && XMLTags.FLOW.matches(cursorTask.getLocalName())) {
                return null;
            }
        }
    } catch (Exception e) {
        throw new JobCreationException(XMLTags.FLOW.getXMLName(), null, e);
    }
    if (event != XMLEvent.START_ELEMENT) {
        throw new JobCreationException(XMLTags.FLOW.getXMLName(), null, null);
    }
    String tag = null;
    // REPLICATE: no attribute
    if (XMLTags.FLOW_REPLICATE.matches(cursorTask.getLocalName())) {
        type = FlowActionType.REPLICATE.toString();
        tag = XMLTags.FLOW_REPLICATE.getXMLName();
    } else // IF: attributes TARGET_IF and TARGET_ELSE and TARGET_JOIN
    if (XMLTags.FLOW_IF.matches(cursorTask.getLocalName())) {
        type = FlowActionType.IF.toString();
        tag = XMLTags.FLOW_IF.getXMLName();
        for (int i = 0; i < cursorTask.getAttributeCount(); i++) {
            String attrName = cursorTask.getAttributeLocalName(i);
            if (XMLAttributes.FLOW_TARGET.matches(attrName)) {
                target = cursorTask.getAttributeValue(i);
            } else if (XMLAttributes.FLOW_ELSE.matches(attrName)) {
                targetElse = cursorTask.getAttributeValue(i);
            } else if (XMLAttributes.FLOW_CONTINUATION.matches(attrName)) {
                targetJoin = cursorTask.getAttributeValue(i);
            }
        }
    } else // LOOP: attribute TARGET
    if (XMLTags.FLOW_LOOP.matches(cursorTask.getLocalName())) {
        type = FlowActionType.LOOP.toString();
        tag = XMLTags.FLOW_LOOP.getXMLName();
        for (int i = 0; i < cursorTask.getAttributeCount(); i++) {
            String attrName = cursorTask.getAttributeLocalName(i);
            if (XMLAttributes.FLOW_TARGET.matches(attrName)) {
                target = cursorTask.getAttributeValue(i);
            }
        }
    }
    FlowScript sc = null;
    Script<?> internalScript;
    try {
        internalScript = createScript(cursorTask, ScriptType.FLOW, variables);
        switch(FlowActionType.parse(type)) {
            case IF:
                sc = FlowScript.createIfFlowScript(internalScript, target, targetElse, targetJoin);
                break;
            case REPLICATE:
                sc = FlowScript.createReplicateFlowScript(internalScript);
                break;
            case LOOP:
                sc = FlowScript.createLoopFlowScript(internalScript, target);
                break;
            default:
                break;
        }
    } catch (Exception e) {
        throw new JobCreationException(tag, null, e);
    }
    // </script>  -->  </if> | </replicate> | </loop>
    try {
        while (cursorTask.hasNext()) {
            event = cursorTask.next();
            if (event == XMLEvent.END_ELEMENT) {
                break;
            }
        }
    } catch (XMLStreamException e) {
        throw new JobCreationException(tag, null, e);
    }
    if (event != XMLEvent.END_ELEMENT) {
        throw new JobCreationException(tag, null, null);
    }
    return sc;
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) 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) FlowScript(org.ow2.proactive.scheduler.common.task.flow.FlowScript)

Example 59 with JobCreationException

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

the class FlatJobFactory method createNativeJobFromCommandsFile.

/**
 * Create a job from a String representing file path, this text file contains native commands to launch
 * Every line of the text file is taken and considered as a native command from which a native task is built,
 * except lines beginning with {@link FlatJobFactory#JOB_DEFAULT_NAME_PREFIX} and empty lines.
 * So job in result is made of several native tasks without dependencies.
 *
 * @param commandFilePath a string representing a text file containing native commands.
 * @param jobName A String representing a name to give to the job. If null, default job name is made of
 * {@link FlatJobFactory#JOB_DEFAULT_NAME_PREFIX} + userName parameter.
 * @param selectionScriptPath a Path to a file containing a selection script, or null if
 * no script is needed.
 * @param userName name of connected user that asked job creation, null otherwise. This parameter
 * is only used for default job's name creation.
 * @return a job object representing created job and ready-to-schedule job.
 * @throws JobCreationException with a relevant error message if an error occurs.
 */
public Job createNativeJobFromCommandsFile(String commandFilePath, String jobName, String selectionScriptPath, String userName) throws JobCreationException {
    if (jobName == null) {
        jobName = JOB_DEFAULT_NAME_PREFIX + userName;
    }
    Job nativeJob = new TaskFlowJob();
    nativeJob.setName(jobName);
    logger.debug("Job : " + nativeJob.getName());
    try {
        File commandFile = new File(commandFilePath);
        if (!commandFile.isFile()) {
            throw new JobCreationException("Error occured during Job creation, " + "check that file " + commandFilePath + " exists and is a readable file");
        }
        String commandLine;
        int task_number = 0;
        ArrayList<String> commandList = new ArrayList<>();
        try (BufferedReader reader = new BufferedReader(new FileReader(commandFile))) {
            while ((commandLine = reader.readLine()) != null) {
                commandLine = commandLine.trim();
                if (!commandLine.startsWith(CMD_FILE_COMMENT_CHAR, 0) && !"".equals(commandLine)) {
                    commandList.add(commandLine);
                }
            }
        }
        if (commandList.size() == 0) {
            throw new JobCreationException("Error occured during Job creation, " + "No any valid command line has been built from" + commandFilePath + "");
        }
        // compute padding for task number
        int numberOfDigit = Integer.toString(commandList.size()).length();
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumIntegerDigits(numberOfDigit);
        nf.setMinimumIntegerDigits(numberOfDigit);
        for (String command : commandList) {
            NativeTask t = createNativeTaskFromCommandString(command, "task_" + (nf.format(++task_number)), selectionScriptPath);
            t.setPreciousResult(true);
            ((TaskFlowJob) nativeJob).addTask(t);
            logger.debug("-> Task Name = " + t.getName());
            logger.debug("-> command = " + t.getCommandLine() + "\n");
        }
    } catch (Exception e) {
        throw new JobCreationException(e);
    }
    return nativeJob;
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) ArrayList(java.util.ArrayList) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Job(org.ow2.proactive.scheduler.common.job.Job) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) File(java.io.File) NumberFormat(java.text.NumberFormat)

Example 60 with JobCreationException

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

the class FlatJobFactory method createNativeJobFromCommand.

/**
 * Creates a job from a String representing a native command to launch. So job in result is made
 * of one native task.
 *
 * @param command a string representing an executable command to launch.
 * @param jobName A String representing a name to give to the job, if null. default job name is made of
 * {link FlatJobFactory#JOB_DEFAULT_NAME_PREFIX} + userName parameter.
 * @param selectionScriptPath A Path to a file containing a selection script, or null if
 * no script is needed.
 * @param userName name of connected user that asked job creation, null otherwise. This parameter
 * is just used for default job's name creation.
 * @return a job object representing created job and ready-to-schedule job.
 * @throws JobCreationException with a relevant error message if an error occurs.
 */
public Job createNativeJobFromCommand(String command, String jobName, String selectionScriptPath, String userName) throws JobCreationException {
    if (command == null || "".equalsIgnoreCase(command)) {
        throw new JobCreationException("Error, command cannot be null");
    }
    if (jobName == null) {
        jobName = JOB_DEFAULT_NAME_PREFIX + userName;
    }
    Job nativeJob = new TaskFlowJob();
    nativeJob.setName(jobName);
    logger.debug("Job : " + nativeJob.getName());
    try {
        NativeTask t = createNativeTaskFromCommandString(command, "task1", selectionScriptPath);
        t.setPreciousResult(true);
        ((TaskFlowJob) nativeJob).addTask(t);
        logger.debug("-> Task Name = " + t.getName());
        logger.debug("-> command = " + t.getCommandLine() + "\n");
    } catch (Exception e) {
        throw new JobCreationException(e);
    }
    return nativeJob;
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) Job(org.ow2.proactive.scheduler.common.job.Job) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException)

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