use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.
the class SchedulerEfficiencyMetricsTest method createJob.
public static TaskFlowJob createJob(int taskNumber, int taskDuration) throws Exception {
final TaskFlowJob job = new TaskFlowJob();
job.setName(String.format("EP_%d_NO_MERGE_%dSEC", taskNumber, taskDuration));
job.setOnTaskError(OnTaskError.CANCEL_JOB);
job.getVariables().put(OPTIMAL_JOB_DURATION, new JobVariable(OPTIMAL_JOB_DURATION, String.valueOf(taskDuration)));
for (int i = 0; i < taskNumber; i++) {
ScriptTask task = new ScriptTask();
task.setName("process_" + i);
task.setScript(new TaskScript(new SimpleScript(String.format("Thread.sleep(%s)", taskDuration), "groovy")));
job.addTask(task);
}
return job;
}
use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.
the class TestJobSchedulerHome method pahomeScriptTask.
public void pahomeScriptTask() throws Throwable {
log("Test ProActive Home Script Task...");
String tname = "pahomeScriptTask";
TaskFlowJob job = new TaskFlowJob();
job.setName(this.getClass().getSimpleName() + "_" + tname);
ScriptTask task1 = new ScriptTask();
task1.setName(tname);
Script pahomeScript = new SimpleScript(TestJobSchedulerHome.class.getResource("/functionaltests/scripts/schedulerHome.js"), new String[] { schedulerHomePath });
;
TaskScript ts = new TaskScript(pahomeScript);
task1.setScript(ts);
job.addTask(task1);
submitAndCheckJob(job, tname, false);
}
use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.
the class TestJobWalltime method walltimeScriptTask.
public JobId walltimeScriptTask() throws Throwable {
log("Test WallTime Script Task...");
String tname = "walltimeScriptTask";
// pre script interruption
TaskFlowJob job = new TaskFlowJob();
job.setName(this.getClass().getSimpleName() + "_" + tname);
ScriptTask task1 = new ScriptTask();
task1.setName(tname);
task1.setWallTime(5000);
task1.setScript(new TaskScript(new SimpleScript("while(true){java.lang.Thread.sleep(500);}", "javascript")));
job.addTask(task1);
return submitJob(job);
}
use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.
the class FlatJobFactory method createNativeTaskFromCommandString.
/**
* Creates a native task from a string representing a native command to execute.
* @param command a String representing a native command.
* @param taskName an eventual name for the task.
* @param selectionScriptPath path to an existing file containing a selection script code.
* @return a NativeTask object that can be put in a Job Object.
* @throws InvalidScriptException if an error occurs in definition of selection script
* from file path specified.
*/
private NativeTask createNativeTaskFromCommandString(String command, String taskName, String selectionScriptPath) throws InvalidScriptException {
NativeTask desc = new NativeTask();
desc.setCommandLine(Tools.parseCommandLine(command));
desc.setName(taskName);
if (selectionScriptPath != null) {
SelectionScript script = new SelectionScript(new SimpleScript(new File(selectionScriptPath), null), true);
desc.addSelectionScript(script);
}
return desc;
}
use of org.ow2.proactive.scripting.SimpleScript 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);
}
}
Aggregations