Search in sources :

Example 16 with Type

use of org.ow2.proactive_grid_cloud_portal.cli.json.FieldMetaDataView.Type in project scheduling by ow2-proactive.

the class InternalJobFactory method createJob.

/**
 * Create a new internal job with the given job (user).
 *
 * @param job the user job that will be used to create the internal job.
 * @return the created internal job.
 * @throws JobCreationException an exception if the factory cannot create the given job.
 */
public static InternalJob createJob(Job job, Credentials cred) throws JobCreationException {
    InternalJob iJob;
    if (logger.isDebugEnabled()) {
        logger.debug("Create job '" + job.getName() + "' - " + job.getClass().getName());
    }
    switch(job.getType()) {
        case PARAMETER_SWEEPING:
            logger.error("The type of the given job is not yet implemented !");
            throw new JobCreationException("The type of the given job is not yet implemented !");
        case TASKSFLOW:
            iJob = createJob((TaskFlowJob) job);
            break;
        default:
            logger.error("The type of the given job is unknown !");
            throw new JobCreationException("The type of the given job is unknown !");
    }
    try {
        // set the job common properties
        iJob.setCredentials(cred);
        setJobCommonProperties(job, iJob);
        return iJob;
    } catch (Exception e) {
        logger.error("", e);
        throw new InternalException("Error while creating the internalJob !", e);
    }
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) InternalException(org.ow2.proactive.scheduler.common.exception.InternalException) InternalException(org.ow2.proactive.scheduler.common.exception.InternalException)

Example 17 with Type

use of org.ow2.proactive_grid_cloud_portal.cli.json.FieldMetaDataView.Type in project scheduling by ow2-proactive.

the class TestJobDataspaceSubmission method testJobDataspaceSubmission.

/**
 * Tests start here.
 *
 * @throws Throwable any exception that can be thrown during the test.
 */
@org.junit.Test
public void testJobDataspaceSubmission() throws Throwable {
    // create initial directories and files
    setup();
    TaskFlowJob job = new TaskFlowJob();
    FileSystemServerDeployer filesServerIn = new FileSystemServerDeployer(IN, IOSPACE + IN, true, true);
    String url = filesServerIn.getVFSRootURL();
    job.setInputSpace(url);
    FileSystemServerDeployer filesServerOut = new FileSystemServerDeployer(OUT, IOSPACE + OUT, true);
    url = filesServerOut.getVFSRootURL();
    job.setOutputSpace(url);
    FileSystemServerDeployer filesServerGlob = new FileSystemServerDeployer(GLOB, IOSPACE + GLOB, true);
    url = filesServerGlob.getVFSRootURL();
    job.setGlobalSpace(url);
    FileSystemServerDeployer filesServerUser = new FileSystemServerDeployer(USER, IOSPACE + USER, true);
    url = filesServerUser.getVFSRootURL();
    job.setUserSpace(url);
    job.setName(this.getClass().getSimpleName());
    NativeTask t1 = new NativeTask();
    t1.addInputFiles(in1, InputAccessMode.TransferFromInputSpace);
    t1.addOutputFiles(out1, OutputAccessMode.TransferToOutputSpace);
    t1.setName("native_java1");
    switch(OperatingSystem.getOperatingSystem()) {
        case windows:
            t1.setCommandLine(new String[] { "cmd", "/C", "type " + in1 + " > " + out1 });
            break;
        case unix:
            t1.setCommandLine(new String[] { "/bin/bash", "-c", "cat " + in1 + " > " + out1 });
            break;
        default:
            throw new IllegalStateException("Unsupported operating system");
    }
    job.addTask(t1);
    NativeTask t2 = new NativeTask();
    t2.addInputFiles(in2, InputAccessMode.TransferFromOutputSpace);
    t2.addOutputFiles(out2, OutputAccessMode.TransferToOutputSpace);
    t2.setName("native_java2");
    switch(OperatingSystem.getOperatingSystem()) {
        case windows:
            t2.setCommandLine(new String[] { "cmd", "/C", "type " + in2 + " > " + out2 });
            break;
        case unix:
            t2.setCommandLine(new String[] { "/bin/bash", "-c", "cat " + in2 + " > " + out2 });
            break;
        default:
            throw new IllegalStateException("Unsupported operating system");
    }
    job.addTask(t2);
    NativeTask t3 = new NativeTask();
    t3.addInputFiles(in3, InputAccessMode.TransferFromGlobalSpace);
    t3.addOutputFiles(out3, OutputAccessMode.TransferToGlobalSpace);
    t3.setName("native_java3");
    switch(OperatingSystem.getOperatingSystem()) {
        case windows:
            t3.setCommandLine(new String[] { "cmd", "/C", "type " + in3 + " > " + out3 });
            break;
        case unix:
            t3.setCommandLine(new String[] { "/bin/bash", "-c", "cat " + in3 + " > " + out3 });
            break;
        default:
            throw new IllegalStateException("Unsupported operating system");
    }
    job.addTask(t3);
    NativeTask t4 = new NativeTask();
    t4.addInputFiles(in4, InputAccessMode.TransferFromUserSpace);
    t4.addOutputFiles(out4, OutputAccessMode.TransferToUserSpace);
    t4.setName("native_java4");
    switch(OperatingSystem.getOperatingSystem()) {
        case windows:
            t4.setCommandLine(new String[] { "cmd", "/C", "type " + in4 + " > " + out4 });
            break;
        case unix:
            t4.setCommandLine(new String[] { "/bin/bash", "-c", "cat " + in4 + " > " + out4 });
            break;
        default:
            throw new IllegalStateException("Unsupported operating system");
    }
    job.addTask(t4);
    NativeTask t10 = new NativeTask();
    t10.addDependence(t2);
    t10.addInputFiles(in1, InputAccessMode.TransferFromInputSpace);
    t10.addInputFiles(new FileSelector("*b.txt"), InputAccessMode.TransferFromOutputSpace);
    t10.addOutputFiles("*aa.txt", OutputAccessMode.TransferToOutputSpace);
    t10.setName("native_java10");
    switch(OperatingSystem.getOperatingSystem()) {
        case windows:
            t10.setCommandLine(new String[] { "cmd", "/C", "type " + in1 + " " + out2 + " > " + out10 });
            break;
        case unix:
            t10.setCommandLine(new String[] { "/bin/bash", "-c", "cat " + in1 + " " + out2 + " > " + out10 });
            break;
        default:
            throw new IllegalStateException("Unsupported operating system");
    }
    job.addTask(t10);
    NativeTask t11 = new NativeTask();
    t11.addDependence(t3);
    t11.addInputFiles(in1, InputAccessMode.TransferFromInputSpace);
    t11.addInputFiles(new FileSelector("*c.txt"), InputAccessMode.TransferFromGlobalSpace);
    t11.addOutputFiles("*bb.txt", OutputAccessMode.TransferToGlobalSpace);
    t11.setName("native_java11");
    switch(OperatingSystem.getOperatingSystem()) {
        case windows:
            t11.setCommandLine(new String[] { "cmd", "/C", "type " + in1 + " " + out3 + " > " + out11 });
            break;
        case unix:
            t11.setCommandLine(new String[] { "/bin/bash", "-c", "cat " + in1 + " " + out3 + " > " + out11 });
            break;
        default:
            throw new IllegalStateException("Unsupported operating system");
    }
    job.addTask(t11);
    NativeTask t12 = new NativeTask();
    t12.addDependence(t4);
    t12.addInputFiles(in1, InputAccessMode.TransferFromInputSpace);
    t12.addInputFiles(new FileSelector("*d.txt"), InputAccessMode.TransferFromUserSpace);
    t12.addOutputFiles("*cc.txt", OutputAccessMode.TransferToUserSpace);
    t12.setName("native_java7");
    switch(OperatingSystem.getOperatingSystem()) {
        case windows:
            t12.setCommandLine(new String[] { "cmd", "/C", "type " + in1 + " " + out4 + " > " + out12 });
            break;
        case unix:
            t12.setCommandLine(new String[] { "/bin/bash", "-c", "cat " + in1 + " " + out4 + " > " + out12 });
            break;
        default:
            throw new IllegalStateException("Unsupported operating system");
    }
    job.addTask(t12);
    JobId id = schedulerHelper.testJobSubmission(job);
    // check results are 0
    JobResult res = schedulerHelper.getJobResult(id);
    Assert.assertFalse(schedulerHelper.getJobResult(id).hadException());
    for (Map.Entry<String, TaskResult> entry : res.getAllResults().entrySet()) {
        Assert.assertEquals(0, entry.getValue().value());
    }
    // remove job
    schedulerHelper.removeJob(id);
    schedulerHelper.waitForEventJobRemoved(id);
    // check files
    File fout = new File(outputDir.getAbsolutePath() + File.separator + out1);
    Assert.assertEquals(in1, getContent(fout));
    fout = new File(outputDir.getAbsolutePath() + File.separator + out2);
    Assert.assertEquals(in2, getContent(fout));
    fout = new File(globalDir.getAbsolutePath() + File.separator + out3);
    Assert.assertEquals(in3, getContent(fout));
    fout = new File(userDir.getAbsolutePath() + File.separator + out4);
    Assert.assertEquals(in4, getContent(fout));
    fout = new File(outputDir.getAbsolutePath() + File.separator + out10);
    Assert.assertEquals(in1 + in2, getContent(fout));
    fout = new File(globalDir.getAbsolutePath() + File.separator + out11);
    Assert.assertEquals(in1 + in3, getContent(fout));
    fout = new File(userDir.getAbsolutePath() + File.separator + out12);
    Assert.assertEquals(in1 + in4, getContent(fout));
    // fout = new File(outputDir.getAbsolutePath() + File.separator + out20);
    // Assert.assertEquals(in1 + in2, getContent(fout));
    // fout = new File(globalDir.getAbsolutePath() + File.separator + out21);
    // Assert.assertEquals(in1 + in3, getContent(fout));
    // fout = new File(userDir.getAbsolutePath() + File.separator + out22);
    // Assert.assertEquals(in1 + in4, getContent(fout));
    filesServerIn.terminate();
    filesServerOut.terminate();
    filesServerGlob.terminate();
    filesServerUser.terminate();
    // and clean tmp space
    clean();
}
Also used : FileSystemServerDeployer(org.objectweb.proactive.extensions.vfsprovider.FileSystemServerDeployer) JobResult(org.ow2.proactive.scheduler.common.job.JobResult) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) FileSelector(org.objectweb.proactive.extensions.dataspaces.vfs.selector.FileSelector) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) Map(java.util.Map) File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 18 with Type

use of org.ow2.proactive_grid_cloud_portal.cli.json.FieldMetaDataView.Type in project scheduling by ow2-proactive.

the class StaxJobFactory method displayJobInfo.

private void displayJobInfo(Job job) {
    if (logger.isDebugEnabled()) {
        logger.debug("type: " + job.getType());
        logger.debug("name: " + job.getName());
        logger.debug("description: " + job.getDescription());
        logger.debug("projectName: " + job.getProjectName());
        logger.debug("variables: " + job.getVariables());
        logger.debug("priority: " + job.getPriority());
        logger.debug("onTaskError: " + job.getOnTaskErrorProperty().getValue().toString());
        logger.debug("restartTaskOnError: " + job.getRestartTaskOnError());
        logger.debug("maxNumberOfExecution: " + job.getMaxNumberOfExecution());
        logger.debug("inputSpace: " + job.getInputSpace());
        logger.debug("outputSpace: " + job.getOutputSpace());
        logger.debug("genericInformation: " + job.getGenericInformation());
        logger.debug("TASKS ------------------------------------------------");
        ArrayList<Task> tasks = new ArrayList<>();
        switch(job.getType()) {
            case TASKSFLOW:
                tasks.addAll(((TaskFlowJob) job).getTasks());
                break;
            default:
                break;
        }
        for (Task t : tasks) {
            logger.debug("name: " + t.getName());
            logger.debug("description: " + t.getDescription());
            logger.debug("parallel: " + t.isParallel());
            logger.debug("nbNodes: " + (t.getParallelEnvironment() == null ? "1" : t.getParallelEnvironment().getNodesNumber()));
            logger.debug("onTaskError: " + t.getOnTaskErrorProperty().getValue().toString());
            logger.debug("preciousResult: " + t.isPreciousResult());
            logger.debug("preciousLogs: " + t.isPreciousLogs());
            logger.debug("restartTaskOnError: " + t.getRestartTaskOnError());
            logger.debug("maxNumberOfExecution: " + t.getMaxNumberOfExecution());
            logger.debug("walltime: " + t.getWallTime());
            logger.debug("selectionScripts: " + t.getSelectionScripts());
            logger.debug("preScript: " + t.getPreScript());
            logger.debug("postScript: " + t.getPostScript());
            logger.debug("cleaningScript: " + t.getCleaningScript());
            try {
                logger.debug("inputFileList: length=" + t.getInputFilesList().size());
            } catch (NullPointerException ignored) {
            }
            try {
                logger.debug("outputFileList: length=" + t.getOutputFilesList().size());
            } catch (NullPointerException ignored) {
            }
            if (t.getDependencesList() != null) {
                String dep = "dependence: ";
                for (Task tdep : t.getDependencesList()) {
                    dep += tdep.getName() + " ";
                }
                logger.debug(dep);
            } else {
                logger.debug("dependence: null");
            }
            logger.debug("genericInformation: " + t.getGenericInformation());
            logger.debug("variables: " + t.getVariables());
            if (t instanceof JavaTask) {
                logger.debug("class: " + ((JavaTask) t).getExecutableClassName());
                try {
                    logger.debug("args: " + ((JavaTask) t).getArguments());
                } catch (Exception e) {
                    logger.debug("Cannot get args: " + e.getMessage(), e);
                }
                logger.debug("fork: " + ((JavaTask) t).isFork());
            } else if (t instanceof NativeTask) {
                logger.debug("commandLine: " + Arrays.toString(((NativeTask) t).getCommandLine()));
            } else if (t instanceof ScriptTask) {
                logger.debug("script: " + ((ScriptTask) t).getScript());
            }
            ForkEnvironment forkEnvironment = t.getForkEnvironment();
            if (forkEnvironment != null) {
                logger.debug("javaHome: " + forkEnvironment.getJavaHome());
                logger.debug("systemEnvironment: " + forkEnvironment.getSystemEnvironment());
                logger.debug("jvmArguments: " + forkEnvironment.getJVMArguments());
                logger.debug("classpath: " + forkEnvironment.getAdditionalClasspath());
                logger.debug("envScript: " + forkEnvironment.getEnvScript());
            }
            logger.debug("--------------------------------------------------");
        }
    }
}
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) ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) ArrayList(java.util.ArrayList) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) 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) VerifierConfigurationException(org.iso_relax.verifier.VerifierConfigurationException)

Example 19 with Type

use of org.ow2.proactive_grid_cloud_portal.cli.json.FieldMetaDataView.Type in project scheduling by ow2-proactive.

the class StaxJobFactory method createTask.

/**
 * Fill the given task by the information that are at the given cursorTask.
 * Leave the method with the cursor at the end of 'ELEMENT_TASK' tag.
 *
 * @param cursorTask the streamReader with the cursor on the 'ELEMENT_TASK' tag.
 * @return The newly created task that can be any type.
 */
private Task createTask(XMLStreamReader cursorTask, Job job, Map<String, ArrayList<String>> dependencies) throws JobCreationException {
    int i = 0;
    XMLTags currentTag = null;
    String current = null;
    String taskName = null;
    try {
        Task toReturn = null;
        Task tmpTask = new Task() {
        };
        // parse job attributes and fill the temporary one
        int attrLen = cursorTask.getAttributeCount();
        for (i = 0; i < attrLen; i++) {
            String attributeName = cursorTask.getAttributeLocalName(i);
            String attributeValue = cursorTask.getAttributeValue(i);
            if (XMLAttributes.COMMON_NAME.matches(attributeName)) {
                tmpTask.setName(attributeValue);
                taskName = attributeValue;
            } else if (XMLAttributes.TASK_NB_NODES.matches(attributeName)) {
                int numberOfNodesNeeded = Integer.parseInt(replace(attributeValue, tmpTask.getVariablesOverriden(job)));
                tmpTask.setParallelEnvironment(new ParallelEnvironment(numberOfNodesNeeded));
            } else if (XMLAttributes.COMMON_CANCEL_JOB_ON_ERROR.matches(attributeName)) {
                handleCancelJobOnErrorAttribute(tmpTask, attributeValue);
            } else if (XMLAttributes.COMMON_ON_TASK_ERROR.matches(attributeName)) {
                tmpTask.setOnTaskError(OnTaskError.getInstance(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
            } else if (XMLAttributes.COMMON_RESTART_TASK_ON_ERROR.matches(attributeName)) {
                tmpTask.setRestartTaskOnError(RestartMode.getMode(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
            } else if (XMLAttributes.COMMON_MAX_NUMBER_OF_EXECUTION.matches(attributeName)) {
                tmpTask.setMaxNumberOfExecution(Integer.parseInt(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
            } else if (XMLAttributes.TASK_PRECIOUS_RESULT.matches(attributeName)) {
                tmpTask.setPreciousResult(Boolean.parseBoolean(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
            } else if (XMLAttributes.TASK_PRECIOUS_LOGS.matches(attributeName)) {
                tmpTask.setPreciousLogs(Boolean.parseBoolean(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
            } else if (XMLAttributes.TASK_WALLTIME.matches(attributeName)) {
                tmpTask.setWallTime(Tools.formatDate(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
            } else if (XMLAttributes.TASK_RUN_AS_ME.matches(attributeName)) {
                tmpTask.setRunAsMe(Boolean.parseBoolean(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
            }
        }
        int eventType;
        boolean shouldContinue = true;
        while (shouldContinue && cursorTask.hasNext()) {
            eventType = cursorTask.next();
            switch(eventType) {
                case XMLEvent.START_ELEMENT:
                    current = cursorTask.getLocalName();
                    currentTag = null;
                    if (XMLTags.COMMON_GENERIC_INFORMATION.matches(current)) {
                        tmpTask.setGenericInformation(getGenericInformation(cursorTask, tmpTask.getVariablesOverriden(job)));
                    } else if (XMLTags.VARIABLES.matches(current)) {
                        Map<String, TaskVariable> taskVariablesMap = createTaskVariables(cursorTask, tmpTask.getVariablesOverriden(job));
                        tmpTask.setVariables(taskVariablesMap);
                    } else if (XMLTags.COMMON_DESCRIPTION.matches(current)) {
                        tmpTask.setDescription(getDescription(cursorTask, tmpTask.getVariablesOverriden(job)));
                    } else if (XMLTags.DS_INPUT_FILES.matches(current)) {
                        setIOFIles(cursorTask, XMLTags.DS_INPUT_FILES.getXMLName(), tmpTask, tmpTask.getVariablesOverriden(job));
                    } else if (XMLTags.DS_OUTPUT_FILES.matches(current)) {
                        setIOFIles(cursorTask, XMLTags.DS_OUTPUT_FILES.getXMLName(), tmpTask, tmpTask.getVariablesOverriden(job));
                    } else if (XMLTags.PARALLEL_ENV.matches(current)) {
                        tmpTask.setParallelEnvironment(createParallelEnvironment(cursorTask, tmpTask.getVariablesOverriden(job)));
                    } else if (XMLTags.SCRIPT_SELECTION.matches(current)) {
                        tmpTask.setSelectionScripts(createSelectionScript(cursorTask, tmpTask.getVariablesOverriden(job)));
                    } else if (XMLTags.FORK_ENVIRONMENT.matches(current)) {
                        tmpTask.setForkEnvironment(createForkEnvironment(cursorTask, tmpTask.getVariablesOverriden(job)));
                    } else if (XMLTags.SCRIPT_PRE.matches(current)) {
                        tmpTask.setPreScript(createScript(cursorTask, tmpTask.getVariablesOverriden(job)));
                    } else if (XMLTags.SCRIPT_POST.matches(current)) {
                        tmpTask.setPostScript(createScript(cursorTask, tmpTask.getVariablesOverriden(job)));
                    } else if (XMLTags.SCRIPT_CLEANING.matches(current)) {
                        tmpTask.setCleaningScript(createScript(cursorTask, tmpTask.getVariablesOverriden(job)));
                    } else if (XMLTags.FLOW.matches(current)) {
                        tmpTask.setFlowScript(createControlFlowScript(cursorTask, tmpTask, tmpTask.getVariablesOverriden(job)));
                    } else if (XMLTags.TASK_DEPENDENCES.matches(current)) {
                        currentTag = XMLTags.TASK_DEPENDENCES;
                        dependencies.putAll(createDependences(cursorTask, tmpTask));
                    } else if (XMLTags.JAVA_EXECUTABLE.matches(current)) {
                        toReturn = new JavaTask();
                        setJavaExecutable((JavaTask) toReturn, cursorTask, tmpTask.getVariablesOverriden(job));
                    } else if (XMLTags.NATIVE_EXECUTABLE.matches(current)) {
                        toReturn = new NativeTask();
                        setNativeExecutable((NativeTask) toReturn, cursorTask);
                    } else if (XMLTags.SCRIPT_EXECUTABLE.matches(current)) {
                        toReturn = new ScriptTask();
                        ((ScriptTask) toReturn).setScript(new TaskScript(createScript(cursorTask, tmpTask.getVariablesOverriden(job))));
                    }
                    break;
                case XMLEvent.END_ELEMENT:
                    current = cursorTask.getLocalName();
                    if (XMLTags.TASK.matches(cursorTask.getLocalName())) {
                        shouldContinue = false;
                    }
                    break;
            }
        }
        // fill the real task with common attribute if it is a new one
        autoCopyfields(CommonAttribute.class, tmpTask, toReturn);
        autoCopyfields(Task.class, tmpTask, toReturn);
        if (toReturn != null) {
            if (toReturn.getRestartTaskOnErrorProperty().isSet()) {
                toReturn.setRestartTaskOnError(toReturn.getRestartTaskOnError());
            }
            if (toReturn.getMaxNumberOfExecutionProperty().isSet()) {
                toReturn.setMaxNumberOfExecution(toReturn.getMaxNumberOfExecution());
            }
        }
        return toReturn;
    } catch (JobCreationException jce) {
        jce.setTaskName(taskName);
        if (currentTag != null) {
            jce.pushTag(currentTag);
        } else {
            jce.pushTag(current);
        }
        throw jce;
    } catch (Exception e) {
        String attrtmp = null;
        if (cursorTask.isStartElement() && cursorTask.getAttributeCount() > i) {
            attrtmp = cursorTask.getAttributeLocalName(i);
        }
        if (currentTag != null) {
            throw new JobCreationException(currentTag, attrtmp, e);
        } else {
            throw new JobCreationException(current, attrtmp, 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) TaskScript(org.ow2.proactive.scripting.TaskScript) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) 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) VerifierConfigurationException(org.iso_relax.verifier.VerifierConfigurationException) ParallelEnvironment(org.ow2.proactive.scheduler.common.task.ParallelEnvironment) ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 20 with Type

use of org.ow2.proactive_grid_cloud_portal.cli.json.FieldMetaDataView.Type 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)) {
                        if (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;
            }
        }
        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) VerifierConfigurationException(org.iso_relax.verifier.VerifierConfigurationException)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)7 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)7 File (java.io.File)6 XMLStreamException (javax.xml.stream.XMLStreamException)6 VerifierConfigurationException (org.iso_relax.verifier.VerifierConfigurationException)6 JobValidationException (org.ow2.proactive.scheduler.common.exception.JobValidationException)6 HashMap (java.util.HashMap)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 GET (javax.ws.rs.GET)3 FileObject (org.apache.commons.vfs2.FileObject)3 GZIP (org.jboss.resteasy.annotations.GZIP)3 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)3 SchedulerEventListener (org.ow2.proactive.scheduler.common.SchedulerEventListener)3 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)3 KeyException (java.security.KeyException)2