use of org.ow2.proactive.scheduler.common.task.ForkEnvironment in project scheduling by ow2-proactive.
the class AbstractRestFuncTestCase method createJob.
protected Job createJob(Class<?> clazz) throws Exception {
TaskFlowJob job = new TaskFlowJob();
job.setName(clazz.getSimpleName());
job.setPriority(JobPriority.NORMAL);
job.setOnTaskError(OnTaskError.CANCEL_JOB);
job.setDescription("Test " + clazz.getSimpleName());
job.setMaxNumberOfExecution(1);
JavaTask task = new JavaTask();
task.setName(getTaskNameForClass(clazz));
task.setExecutableClassName(clazz.getName());
task.setMaxNumberOfExecution(1);
task.setOnTaskError(OnTaskError.CANCEL_JOB);
String classpath = RestFuncTUtils.getClassPath(clazz);
ForkEnvironment forkEnvironment = new ForkEnvironment();
forkEnvironment.addAdditionalClasspath(classpath);
task.setForkEnvironment(forkEnvironment);
job.addTask(task);
return job;
}
use of org.ow2.proactive.scheduler.common.task.ForkEnvironment in project scheduling by ow2-proactive.
the class AbstractRestFuncTestCase method createJobManyTasks.
protected Job createJobManyTasks(String jobName, Class<?>... clazzes) throws Exception {
TaskFlowJob job = new TaskFlowJob();
job.setName(jobName);
job.setPriority(JobPriority.NORMAL);
job.setDescription("Test " + jobName);
job.setMaxNumberOfExecution(1);
for (Class<?> clazz : clazzes) {
JavaTask task = new JavaTask();
task.setName(clazz.getSimpleName() + "Task");
task.setExecutableClassName(clazz.getName());
task.setMaxNumberOfExecution(1);
String classpath = RestFuncTUtils.getClassPath(clazz);
ForkEnvironment forkEnvironment = new ForkEnvironment();
forkEnvironment.addAdditionalClasspath(classpath);
task.setForkEnvironment(forkEnvironment);
job.addTask(task);
}
return job;
}
use of org.ow2.proactive.scheduler.common.task.ForkEnvironment in project scheduling by ow2-proactive.
the class RestSmartProxyTest method createTestJob.
private TaskFlowJob createTestJob(boolean isolateOutputs) throws Exception {
TaskFlowJob job = new TaskFlowJob();
// add a special character to the job name to ensure the job is parsed
// correctly by the server
job.setName(this.getClass().getSimpleName() + " é");
for (int i = 0; i < NB_TASKS; i++) {
JavaTask testTask = new JavaTask();
testTask.setName(TASK_NAME + i);
testTask.setExecutableClassName(SimpleJavaExecutable.class.getName());
testTask.setForkEnvironment(new ForkEnvironment());
File inputFile = new File(inputLocalFolder, INPUT_FILE_BASE_NAME + "_" + i + INPUT_FILE_EXT);
String outputFileName = OUTPUT_FILE_BASE_NAME + "_" + i + OUTPUT_FILE_EXT;
// delete files after the test is finished
File outputFile = new File(outputLocalFolder, outputFileName);
outputFile.deleteOnExit();
inputFile.deleteOnExit();
FileWriter fileWriter = new FileWriter(inputFile);
for (int j = 0; j <= Math.round(Math.random() * 100) + 1; j++) {
fileWriter.write("Some random input");
}
fileWriter.close();
// Add dummy input files, make sure no error happen
testTask.addInputFiles("DUMMY", InputAccessMode.TransferFromInputSpace);
testTask.addInputFiles(inputFile.getName(), InputAccessMode.TransferFromInputSpace);
if (isolateOutputs) {
testTask.addOutputFiles("*.out", OutputAccessMode.TransferToOutputSpace);
} else {
testTask.addOutputFiles(outputFileName, OutputAccessMode.TransferToOutputSpace);
}
job.addTask(testTask);
}
job.setInputSpace(userspace);
job.setOutputSpace(userspace);
return job;
}
use of org.ow2.proactive.scheduler.common.task.ForkEnvironment in project scheduling by ow2-proactive.
the class Attribute method createTaskElement.
/**
* Creates the task element, corressponding to <define name="task">
*/
private Element createTaskElement(Document doc, Task task) {
Element taskE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.TASK.getXMLName());
if (task.getOnTaskErrorProperty().isSet()) {
setAttribute(taskE, XMLAttributes.COMMON_ON_TASK_ERROR, task.getOnTaskErrorProperty().getValue().toString(), true);
}
if (task.getMaxNumberOfExecutionProperty().isSet()) {
setAttribute(taskE, XMLAttributes.COMMON_MAX_NUMBER_OF_EXECUTION, Integer.toString(task.getMaxNumberOfExecution()));
}
setAttribute(taskE, XMLAttributes.COMMON_NAME, task.getName(), true);
if (task.getRestartTaskOnErrorProperty().isSet()) {
setAttribute(taskE, XMLAttributes.COMMON_RESTART_TASK_ON_ERROR, task.getRestartTaskOnError().toString());
}
// *** task attributes ***
if (task.getWallTime() != 0) {
setAttribute(taskE, XMLAttributes.TASK_WALLTIME, formatDate(task.getWallTime()));
}
if (task.isRunAsMe()) {
setAttribute(taskE, XMLAttributes.TASK_RUN_AS_ME, "true");
}
if (task.isPreciousResult()) {
setAttribute(taskE, XMLAttributes.TASK_PRECIOUS_RESULT, "true");
}
if (task.isPreciousLogs()) {
setAttribute(taskE, XMLAttributes.TASK_PRECIOUS_LOGS, "true");
}
// <ref name="taskDescription"/>
if (task.getDescription() != null) {
Element descrNode = createElement(doc, XMLTags.COMMON_DESCRIPTION.getXMLName(), task.getDescription());
taskE.appendChild(descrNode);
}
// <ref name="variables"/>
if (task.getVariables() != null && !task.getVariables().isEmpty()) {
Element variablesE = createTaskVariablesElement(doc, task.getVariables());
taskE.appendChild(variablesE);
}
// <ref name="genericInformation"/>
if ((task.getGenericInformation() != null) && (task.getGenericInformation().size() > 0)) {
Element genericInfoE = createGenericInformation(doc, task.getGenericInformation());
taskE.appendChild(genericInfoE);
}
// <ref name="depends"/>
List<Task> dependencies = task.getDependencesList();
if ((dependencies != null) && (dependencies.size() > 0)) {
Element dependsE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.TASK_DEPENDENCES.getXMLName());
for (Task dep : dependencies) {
Element dependsTask = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.TASK_DEPENDENCES_TASK.getXMLName());
setAttribute(dependsTask, XMLAttributes.TASK_DEPENDS_REF, dep.getName(), true);
dependsE.appendChild(dependsTask);
}
taskE.appendChild(dependsE);
}
// if has dependencies
// <ref name="inputFiles"/>
List<InputSelector> inputFiles = task.getInputFilesList();
if (inputFiles != null) {
Element inputFilesE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.DS_INPUT_FILES.getXMLName());
for (InputSelector inputSelector : inputFiles) {
FileSelector fs = inputSelector.getInputFiles();
Element filesE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.DS_FILES.getXMLName());
// pattern
if (!fs.getIncludes().isEmpty())
setAttribute(filesE, XMLAttributes.DS_INCLUDES, fs.getIncludes().iterator().next(), true);
if (!fs.getExcludes().isEmpty())
setAttribute(filesE, XMLAttributes.DS_EXCLUDES, fs.getExcludes().iterator().next(), true);
if (inputSelector.getMode() != null) {
setAttribute(filesE, XMLAttributes.DS_ACCESS_MODE, inputSelector.getMode().toString(), true);
}
inputFilesE.appendChild(filesE);
}
taskE.appendChild(inputFilesE);
}
// <ref name="parallel"/>
Element parallelEnvE = createParallelEnvironment(doc, task);
if (parallelEnvE != null)
taskE.appendChild(parallelEnvE);
// <ref name="selection"/>
List<SelectionScript> selectionScripts = task.getSelectionScripts();
if (selectionScripts != null && selectionScripts.size() > 0) {
Element selectionE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.SCRIPT_SELECTION.getXMLName());
for (SelectionScript selectionScript : selectionScripts) {
Element scriptE = createScriptElement(doc, selectionScript);
selectionE.appendChild(scriptE);
}
taskE.appendChild(selectionE);
}
// <ref name="forkEnvironment"/>
if (task.getForkEnvironment() != null) {
Element forkEnvE = createForkEnvironmentElement(doc, task.getForkEnvironment());
taskE.appendChild(forkEnvE);
}
// <ref name="pre"/>
Script preScript = task.getPreScript();
if (preScript != null) {
Element preE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.SCRIPT_PRE.getXMLName());
Element scriptE = createScriptElement(doc, preScript);
preE.appendChild(scriptE);
taskE.appendChild(preE);
}
// <ref name="executable"/>
Element executableE = null;
if (task instanceof JavaTask) {
executableE = createJavaExecutableElement(doc, (JavaTask) task);
} else if (task instanceof NativeTask) {
executableE = createNativeExecutableElement(doc, (NativeTask) task);
} else if (task instanceof ScriptTask) {
executableE = createScriptExecutableElement(doc, (ScriptTask) task);
}
taskE.appendChild(executableE);
// <ref name="flow"/>
Element controlFlowE = createFlowControlElement(doc, task);
if (controlFlowE != null)
taskE.appendChild(controlFlowE);
// <ref name="post"/>
Script postScript = task.getPostScript();
if (postScript != null) {
Element postE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.SCRIPT_POST.getXMLName());
Element scriptE = createScriptElement(doc, postScript);
postE.appendChild(scriptE);
taskE.appendChild(postE);
}
// <ref name="cleaning"/>
Script cleanScript = task.getCleaningScript();
if (cleanScript != null) {
Element cleanE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.SCRIPT_CLEANING.getXMLName());
Element scriptE = createScriptElement(doc, cleanScript);
cleanE.appendChild(scriptE);
taskE.appendChild(cleanE);
}
// <ref name="outputFiles"/>
List<OutputSelector> outputFiles = task.getOutputFilesList();
if (outputFiles != null) {
Element outputFilesE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.DS_OUTPUT_FILES.getXMLName());
for (OutputSelector outputSelector : outputFiles) {
FileSelector fs = outputSelector.getOutputFiles();
Element filesE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.DS_FILES.getXMLName());
// pattern
if (!fs.getIncludes().isEmpty())
setAttribute(filesE, XMLAttributes.DS_INCLUDES, fs.getIncludes().iterator().next(), true);
if (!fs.getExcludes().isEmpty())
setAttribute(filesE, XMLAttributes.DS_EXCLUDES, fs.getExcludes().iterator().next(), true);
if (outputSelector.getMode() != null) {
setAttribute(filesE, XMLAttributes.DS_ACCESS_MODE, outputSelector.getMode().toString(), true);
}
outputFilesE.appendChild(filesE);
}
taskE.appendChild(outputFilesE);
}
return taskE;
}
use of org.ow2.proactive.scheduler.common.task.ForkEnvironment in project scheduling by ow2-proactive.
the class StaxJobFactory method setJavaExecutable.
/**
* Add the Java Executable to this java Task.
* The cursor is currently at the beginning of the 'ELEMENT_JAVA_EXECUTABLE' tag.
*
* @param javaTask the task in which to add the Java Executable.
* @param cursorExec the streamReader with the cursor on the 'ELEMENT_JAVA_EXECUTABLE' tag.
*/
private void setJavaExecutable(JavaTask javaTask, XMLStreamReader cursorExec, Map<String, String> variables) throws JobCreationException {
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.TASK_CLASS_NAME.matches(attrName)) {
javaTask.setExecutableClassName(cursorExec.getAttributeValue(i));
}
}
// parsing executable tags
int eventType;
while (cursorExec.hasNext()) {
eventType = cursorExec.next();
switch(eventType) {
case XMLEvent.START_ELEMENT:
current = cursorExec.getLocalName();
if (XMLTags.FORK_ENVIRONMENT.matches(current)) {
ForkEnvironment forkEnv = createForkEnvironment(cursorExec, variables);
javaTask.setForkEnvironment(forkEnv);
} else if (XMLTags.TASK_PARAMETER.matches(current)) {
Map<String, String> attributesAsMap = getAttributesAsMap(cursorExec, variables);
String name = attributesAsMap.get(XMLAttributes.VARIABLE_NAME.getXMLName());
String value = attributesAsMap.get(XMLAttributes.VARIABLE_VALUE.getXMLName());
javaTask.addArgument(replace(name, variables), value);
}
break;
case XMLEvent.END_ELEMENT:
if (XMLTags.JAVA_EXECUTABLE.matches(cursorExec.getLocalName())) {
return;
}
break;
}
}
} 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);
}
}
Aggregations