Search in sources :

Example 1 with ForkEnvironmentScript

use of org.ow2.proactive.scripting.ForkEnvironmentScript in project scheduling by ow2-proactive.

the class StaxJobFactory method createForkEnvironment.

/**
 * Create the forkEnvironment of a java task
 * The cursor is currently at the beginning of the 'FORK_ENVIRONMENT' tag.
 *
 * @param cursorExec the streamReader with the cursor on the 'FORK_ENVIRONMENT' tag.
 * @return The created ForkEnvironment
 */
private ForkEnvironment createForkEnvironment(XMLStreamReader cursorExec, Map<String, String> variables) throws JobCreationException {
    ForkEnvironment forkEnv = new ForkEnvironment();
    int i = 0;
    String current = cursorExec.getLocalName();
    try {
        // parsing executable attributes
        int attrCount = cursorExec.getAttributeCount();
        for (i = 0; i < attrCount; i++) {
            String attrName = cursorExec.getAttributeLocalName(i);
            if (XMLAttributes.FORK_JAVA_HOME.matches(attrName)) {
                forkEnv.setJavaHome(replace(cursorExec.getAttributeValue(i), variables));
            }
            if (XMLAttributes.TASK_WORKDING_DIR.matches(attrName)) {
                forkEnv.setWorkingDir(replace(cursorExec.getAttributeValue(i), variables));
            }
        }
        // parsing executable tags
        int eventType;
        while (cursorExec.hasNext()) {
            eventType = cursorExec.next();
            switch(eventType) {
                case XMLEvent.START_ELEMENT:
                    current = cursorExec.getLocalName();
                    if (XMLTags.FORK_SYSTEM_PROPERTY.matches(current)) {
                        attrCount = cursorExec.getAttributeCount();
                        String name = null, value = null;
                        for (i = 0; i < attrCount; i++) {
                            String attrName = cursorExec.getAttributeLocalName(i);
                            if (XMLAttributes.COMMON_NAME.matches(attrName)) {
                                name = replace(cursorExec.getAttributeValue(i), variables);
                            }
                            if (XMLAttributes.COMMON_VALUE.matches(attrName)) {
                                value = replace(cursorExec.getAttributeValue(i), variables);
                            }
                        }
                        forkEnv.addSystemEnvironmentVariable(name, value);
                    } else if (XMLTags.FORK_JVM_ARG.matches(current)) {
                        forkEnv.addJVMArgument(replace(cursorExec.getAttributeValue(0), variables));
                    } else if (XMLTags.JOB_PATH_ELEMENT.matches(current)) {
                        forkEnv.addAdditionalClasspath(replace(cursorExec.getAttributeValue(0), variables));
                    } else if (XMLTags.SCRIPT_ENV.matches(current)) {
                        forkEnv.setEnvScript(new ForkEnvironmentScript(createScript(cursorExec, variables)));
                    }
                    break;
                case XMLEvent.END_ELEMENT:
                    if (XMLTags.FORK_ENVIRONMENT.matches(cursorExec.getLocalName())) {
                        return forkEnv;
                    }
                    break;
            }
        }
        return forkEnv;
    } catch (JobCreationException jce) {
        jce.pushTag(current);
        throw jce;
    } catch (Exception e) {
        String attrtmp = null;
        if (cursorExec.isStartElement() && cursorExec.getAttributeCount() > 0) {
            attrtmp = cursorExec.getAttributeLocalName(i);
        }
        throw new JobCreationException(current, attrtmp, e);
    }
}
Also used : JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) ForkEnvironmentScript(org.ow2.proactive.scripting.ForkEnvironmentScript) 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 2 with ForkEnvironmentScript

use of org.ow2.proactive.scripting.ForkEnvironmentScript in project scheduling by ow2-proactive.

the class TaskContextTest method createTaskContext.

private TaskContext createTaskContext() throws NodeException, InvalidScriptException {
    TaskLauncherInitializer taskLauncherInitializer = new TaskLauncherInitializer();
    taskLauncherInitializer.setTaskId(TaskIdImpl.createTaskId(new JobIdImpl(1L, "testSerializeContextToFile"), "testSerializeContextToFile", 1L));
    // Invoke method to test it
    return new TaskContext(new ScriptExecutableContainer(new TaskScript(new ForkEnvironmentScript(new SimpleScript("", "python")))), taskLauncherInitializer, null, new NodeDataSpacesURIs(null, null, null, null, null, null), null, null);
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) ForkEnvironmentScript(org.ow2.proactive.scripting.ForkEnvironmentScript)

Example 3 with ForkEnvironmentScript

use of org.ow2.proactive.scripting.ForkEnvironmentScript in project scheduling by ow2-proactive.

the class TaskContextSerializerTest method createTaskContext.

private TaskContext createTaskContext() throws NodeException, InvalidScriptException {
    TaskLauncherInitializer taskLauncherInitializer = new TaskLauncherInitializer();
    taskLauncherInitializer.setTaskId(TaskIdImpl.createTaskId(new JobIdImpl(1L, "testSerializeContextToFile"), "testSerializeContextToFile", 1L));
    // Invoke method to test it
    return new TaskContext(new ScriptExecutableContainer(new TaskScript(new ForkEnvironmentScript(new SimpleScript("", "python")))), taskLauncherInitializer, null, new NodeDataSpacesURIs(null, null, null, null, null, null), null, null);
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer) ForkEnvironmentScript(org.ow2.proactive.scripting.ForkEnvironmentScript)

Aggregations

ForkEnvironmentScript (org.ow2.proactive.scripting.ForkEnvironmentScript)3 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)2 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)2 SimpleScript (org.ow2.proactive.scripting.SimpleScript)2 TaskScript (org.ow2.proactive.scripting.TaskScript)2 FileNotFoundException (java.io.FileNotFoundException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 VerifierConfigurationException (org.iso_relax.verifier.VerifierConfigurationException)1 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)1 JobValidationException (org.ow2.proactive.scheduler.common.exception.JobValidationException)1 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)1 TaskLauncherInitializer (org.ow2.proactive.scheduler.task.TaskLauncherInitializer)1 NodeDataSpacesURIs (org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs)1 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)1