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);
}
}
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);
}
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);
}
Aggregations