use of org.ow2.proactive.scheduler.common.job.factories.Job2XMLTransformer in project scheduling by ow2-proactive.
the class Job2XMLTransformerTest method argumentsInScript.
@Test
public void argumentsInScript() throws Exception {
File xmlFile = tmpFolder.newFile();
TaskFlowJob job = new TaskFlowJob();
job.setName("simpleJob");
String[] params = { "param1", "param2" };
SimpleScript script = new SimpleScript("\nprint('arguments[0]='+arguments[0])\n", "javascript", params);
ScriptTask task = new ScriptTask();
task.setName("testTask");
task.setScript(new TaskScript(script));
job.addTask(task);
new Job2XMLTransformer().job2xmlFile(job, xmlFile);
TaskFlowJob recreatedJob = (TaskFlowJob) (JobFactory.getFactory().createJob(xmlFile.getAbsolutePath()));
Assert.assertEquals("param1", ((ScriptTask) recreatedJob.getTask("testTask")).getScript().getParameters()[0].toString());
Assert.assertEquals("param2", ((ScriptTask) recreatedJob.getTask("testTask")).getScript().getParameters()[1].toString());
}
use of org.ow2.proactive.scheduler.common.job.factories.Job2XMLTransformer in project scheduling by ow2-proactive.
the class RestSmartProxyTest method printJobXmlRepresentation.
private void printJobXmlRepresentation(TaskFlowJob job) throws TransformerException, ParserConfigurationException, IOException {
// debugging the job produced
String jobXml = new Job2XMLTransformer().jobToxmlString(job);
System.out.println(jobXml);
}
use of org.ow2.proactive.scheduler.common.job.factories.Job2XMLTransformer in project scheduling by ow2-proactive.
the class SchedulerClient method submit.
@Override
public JobId submit(Job job) throws NotConnectedException, PermissionException, SubmissionClosedException, JobCreationException {
JobIdData jobIdData = null;
try {
InputStream is = (new Job2XMLTransformer()).jobToxml((TaskFlowJob) job);
jobIdData = restApiClient().submitXml(sid, is);
} catch (Exception e) {
throwNCEOrPEOrSCEOrJCE(e);
}
return jobId(jobIdData);
}
use of org.ow2.proactive.scheduler.common.job.factories.Job2XMLTransformer in project scheduling by ow2-proactive.
the class TestXMLTransformer method transformAndCompare.
/**
* The following operations are performed:
*
* 1. xmlFile to java => job1
*
* 2. job1 = > xmlFle2
*
* 3. xmlFile2 to java => job2
*
* 4. Compare job1 and job2
*/
private void transformAndCompare(File xmlFile) throws Exception {
// xml to java => job1
TaskFlowJob job1 = (TaskFlowJob) (JobFactory.getFactory().createJob(xmlFile.getAbsolutePath()));
// job1 to xmlFile2
File xmlFile2 = folder.newFile(xmlFile.getName());
Job2XMLTransformer transformer = new Job2XMLTransformer();
transformer.job2xmlFile(job1, xmlFile2);
// xmlFile2 to job2
TaskFlowJob job2;
try {
job2 = (TaskFlowJob) (JobFactory.getFactory().createJob(xmlFile2.getAbsolutePath()));
} catch (Exception e) {
e.printStackTrace();
String message = "Could not create Job object from generated xml. \n";
message += "Generated xml content was : \n ****** " + xmlFile2.getAbsolutePath() + " ***********\n ";
message += FileUtils.readFileToString(xmlFile2);
message += "\n *************************** ";
throw new Exception(message, e);
}
// compare job1 and job2
JobComparator comparator = new JobComparator();
if (!comparator.isEqualJob(job1, job2)) {
String message = "Jobs are not equal for file " + xmlFile + "\n";
message += "Reason: " + comparator.getDifferenceMessage() + "\n";
message += "Generated xml content was : \n ****** " + xmlFile2.getAbsolutePath() + " *********** \n ";
message += FileUtils.readFileToString(xmlFile2);
message += "\n *************************** ";
Assert.fail(message);
}
}
Aggregations