use of org.ow2.proactive.scheduler.common.job.TaskFlowJob in project scheduling by ow2-proactive.
the class StaxJobFactory method fillJobWithTasks.
/**
* Fill the created Job with coming tasks..
* Leave the method with the cursor at the end of the file (nothing more has to be parsed).
*
* @param cursorTask the streamReader with the cursor on the first 'ELEMENT_TASK' tag.
*/
private void fillJobWithTasks(XMLStreamReader cursorTask, Job job, Map<String, ArrayList<String>> dependencies) throws JobCreationException {
if (job == null) {
throw new JobCreationException(XMLTags.JOB.getXMLName(), null, null);
}
XMLTags current = null;
try {
int eventType = -1;
while (cursorTask.hasNext()) {
// if use to keep the cursor on the task tag for the first loop
if (eventType == -1) {
eventType = cursorTask.getEventType();
} else {
eventType = cursorTask.next();
}
if (eventType == XMLEvent.START_ELEMENT && XMLTags.TASK.matches(cursorTask.getLocalName())) {
Task t;
switch(job.getType()) {
case TASKSFLOW:
current = XMLTags.TASK;
// create new task
t = createTask(cursorTask, job, dependencies);
// add task to the job
((TaskFlowJob) job).addTask(t);
break;
case PARAMETER_SWEEPING:
current = XMLTags.TASK;
throw new RuntimeException("Job parameter sweeping is not yet implemented!");
default:
}
}
}
} catch (JobCreationException jce) {
jce.pushTag(current);
throw jce;
} catch (Exception e) {
throw new JobCreationException(current, null, e);
}
}
use of org.ow2.proactive.scheduler.common.job.TaskFlowJob in project scheduling by ow2-proactive.
the class StaxJobFactory method createJob.
private Job createJob(File file, Map<String, String> replacementVariables) throws JobCreationException {
try {
// Check if the file exist
if (!file.exists()) {
throw new FileNotFoundException("This file has not been found: " + file.getAbsolutePath());
}
// validate content using the proper XML schema
File updatedFile = validate(file);
// set relative path
relativePathRoot = updatedFile.getParentFile().getAbsolutePath();
// create and get XML STAX reader
XMLStreamReader xmlsr;
Map<String, ArrayList<String>> dependencies = new HashMap<>();
Job job;
try (InputStream inputStream = new FileInputStream(updatedFile)) {
// use the server side property to accept encoding
if (PASchedulerProperties.FILE_ENCODING.isSet()) {
xmlsr = xmlInputFactory.createXMLStreamReader(inputStream, PASchedulerProperties.FILE_ENCODING.getValueAsString());
} else {
xmlsr = xmlInputFactory.createXMLStreamReader(inputStream);
}
// Create the job starting at the first cursor position of the XML Stream reader
job = createJob(xmlsr, replacementVariables, dependencies);
// Close the stream
xmlsr.close();
}
// make dependencies
makeDependences(job, dependencies);
validate((TaskFlowJob) job);
logger.debug("Job successfully created!");
// debug mode only
displayJobInfo(job);
return job;
} catch (JobCreationException jce) {
jce.pushTag(XMLTags.JOB.getXMLName());
throw jce;
} catch (Exception e) {
throw new JobCreationException(e);
}
}
use of org.ow2.proactive.scheduler.common.job.TaskFlowJob in project scheduling by ow2-proactive.
the class SchedulerClientTest method nodeClientJob.
protected Job nodeClientJob(String groovyScript, String forkScript) throws Exception {
URL scriptURL = SchedulerClientTest.class.getResource(groovyScript);
URL forkScriptURL = SchedulerClientTest.class.getResource(forkScript);
TaskFlowJob job = new TaskFlowJob();
job.setName("NodeClientJob");
ScriptTask task = new ScriptTask();
task.setName("NodeClientTask");
ForkEnvironment forkEnvironment = new ForkEnvironment();
forkEnvironment.setEnvScript(new SimpleScript(IOUtils.toString(forkScriptURL.toURI()), "groovy"));
task.setForkEnvironment(forkEnvironment);
task.setScript(new TaskScript(new SimpleScript(IOUtils.toString(scriptURL.toURI()), "groovy")));
// add CleanScript to test external APIs
task.setCleaningScript(new SimpleScript("" + "schedulerapi.connect();\n" + "print(\"SCHEDULERAPI_URI_LIST_NOT_NULL=\"+(schedulerapi.getGlobalSpaceURIs()!=null));\n" + "\n" + "userspaceapi.connect();\n" + "print(\"USERSPACE_FILE_LIST_NOT_NULL=\"+(userspaceapi.listFiles(\".\", \"*\")!=null));\n" + "\n" + "globalspaceapi.connect();\n" + "print(\"GLOBALSPACE_FILE_LIST_NOT_NULL=\"+(globalspaceapi.listFiles(\".\", \"*\")!=null));\n" + "print(\"TEST_CREDS=\"+(credentials.get(\"TEST_CREDS\")));\n", "js"));
job.addTask(task);
return job;
}
use of org.ow2.proactive.scheduler.common.job.TaskFlowJob in project scheduling by ow2-proactive.
the class DefaultModelJobValidatorServiceProvider method validateJob.
@Override
public TaskFlowJob validateJob(TaskFlowJob job) throws JobValidationException {
ModelValidatorContext context = new ModelValidatorContext(job);
for (JobVariable jobVariable : job.getVariables().values()) {
checkVariableFormat(null, jobVariable, context);
context.updateJobWithContext(job);
}
for (Task task : job.getTasks()) {
context = new ModelValidatorContext(task);
for (TaskVariable taskVariable : task.getVariables().values()) {
checkVariableFormat(task, taskVariable, context);
context.updateTaskWithContext(task);
}
}
return job;
}
use of org.ow2.proactive.scheduler.common.job.TaskFlowJob in project scheduling by ow2-proactive.
the class Job2XMLTransformerTest method checkTaskVariables.
@Test
public void checkTaskVariables() throws Exception {
File xmlFile = tmpFolder.newFile();
Map<String, TaskVariable> variablesMap = new HashMap<>();
TaskVariable taskVariable1 = new TaskVariable();
taskVariable1.setName("name1");
taskVariable1.setValue("value1");
taskVariable1.setJobInherited(false);
taskVariable1.setModel("model1");
TaskVariable taskVariable2 = new TaskVariable();
taskVariable2.setName("name2");
taskVariable2.setValue("value2");
taskVariable2.setJobInherited(true);
taskVariable2.setModel("model2");
variablesMap.put(taskVariable1.getName(), taskVariable1);
variablesMap.put(taskVariable2.getName(), taskVariable2);
TaskFlowJob job = new TaskFlowJob();
JavaTask task = new JavaTask();
task.setName("task");
task.setExecutableClassName("oo.Bar");
task.setVariables(variablesMap);
job.addTask(task);
new Job2XMLTransformer().job2xmlFile(job, xmlFile);
TaskFlowJob recreatedJob = (TaskFlowJob) (JobFactory.getFactory().createJob(xmlFile.getAbsolutePath()));
Map<String, TaskVariable> resVariables = recreatedJob.getTask("task").getVariables();
assertEquals(2, resVariables.size());
assertEquals(taskVariable1, resVariables.get("name1"));
assertEquals(taskVariable2, resVariables.get("name2"));
}
Aggregations