use of org.ow2.proactive.scheduler.common.task.flow.FlowScript in project scheduling by ow2-proactive.
the class StaxJobFactory method createControlFlowScript.
private FlowScript createControlFlowScript(XMLStreamReader cursorTask, Task tmpTask, Map<String, String> variables) throws JobCreationException {
String type = null;
String target = null;
String targetElse = null;
String targetJoin = null;
int event = -1;
for (int i = 0; i < cursorTask.getAttributeCount(); i++) {
String attrName = cursorTask.getAttributeLocalName(i);
if (XMLAttributes.FLOW_BLOCK.matches(attrName)) {
tmpTask.setFlowBlock(FlowBlock.parse(replace(cursorTask.getAttributeValue(i), variables)));
}
}
// <control> => <if> | <loop> | <replicate>
try {
while (cursorTask.hasNext()) {
event = cursorTask.next();
if (event == XMLEvent.START_ELEMENT) {
break;
} else if (event == XMLEvent.END_ELEMENT && XMLTags.FLOW.matches(cursorTask.getLocalName())) {
return null;
}
}
} catch (Exception e) {
throw new JobCreationException(XMLTags.FLOW.getXMLName(), null, e);
}
if (event != XMLEvent.START_ELEMENT) {
throw new JobCreationException(XMLTags.FLOW.getXMLName(), null, null);
}
String tag = null;
// REPLICATE: no attribute
if (XMLTags.FLOW_REPLICATE.matches(cursorTask.getLocalName())) {
type = FlowActionType.REPLICATE.toString();
tag = XMLTags.FLOW_REPLICATE.getXMLName();
} else // IF: attributes TARGET_IF and TARGET_ELSE and TARGET_JOIN
if (XMLTags.FLOW_IF.matches(cursorTask.getLocalName())) {
type = FlowActionType.IF.toString();
tag = XMLTags.FLOW_IF.getXMLName();
for (int i = 0; i < cursorTask.getAttributeCount(); i++) {
String attrName = cursorTask.getAttributeLocalName(i);
if (XMLAttributes.FLOW_TARGET.matches(attrName)) {
target = cursorTask.getAttributeValue(i);
} else if (XMLAttributes.FLOW_ELSE.matches(attrName)) {
targetElse = cursorTask.getAttributeValue(i);
} else if (XMLAttributes.FLOW_CONTINUATION.matches(attrName)) {
targetJoin = cursorTask.getAttributeValue(i);
}
}
} else // LOOP: attribute TARGET
if (XMLTags.FLOW_LOOP.matches(cursorTask.getLocalName())) {
type = FlowActionType.LOOP.toString();
tag = XMLTags.FLOW_LOOP.getXMLName();
for (int i = 0; i < cursorTask.getAttributeCount(); i++) {
String attrName = cursorTask.getAttributeLocalName(i);
if (XMLAttributes.FLOW_TARGET.matches(attrName)) {
target = cursorTask.getAttributeValue(i);
}
}
}
FlowScript sc = null;
Script<?> internalScript;
try {
internalScript = createScript(cursorTask, ScriptType.FLOW, variables);
switch(FlowActionType.parse(type)) {
case IF:
sc = FlowScript.createIfFlowScript(internalScript, target, targetElse, targetJoin);
break;
case REPLICATE:
sc = FlowScript.createReplicateFlowScript(internalScript);
break;
case LOOP:
sc = FlowScript.createLoopFlowScript(internalScript, target);
break;
default:
break;
}
} catch (Exception e) {
throw new JobCreationException(tag, null, e);
}
// </script> --> </if> | </replicate> | </loop>
try {
while (cursorTask.hasNext()) {
event = cursorTask.next();
if (event == XMLEvent.END_ELEMENT) {
break;
}
}
} catch (XMLStreamException e) {
throw new JobCreationException(tag, null, e);
}
if (event != XMLEvent.END_ELEMENT) {
throw new JobCreationException(tag, null, null);
}
return sc;
}
use of org.ow2.proactive.scheduler.common.task.flow.FlowScript in project scheduling by ow2-proactive.
the class FlowScript method createContinueFlowScript.
public static FlowScript createContinueFlowScript() throws InvalidScriptException {
FlowScript fs = new FlowScript(new SimpleScript("", "javascript"));
fs.setActionType(FlowActionType.CONTINUE);
return fs;
}
use of org.ow2.proactive.scheduler.common.task.flow.FlowScript in project scheduling by ow2-proactive.
the class TestWorkflowFailedScript method testIf.
/**
* Creates a job with 3 tasks : A B C
* Workflow : A -> if (B) else (C)
* Flowscript on A throws an Exception
* B is supposed to be executed as cancelJobOnError==false
* C is supposed to be skipped as it is the default ELSE branch
* A is supposed to provide a task result value containing an exception
*/
private void testIf() throws Throwable {
TaskFlowJob job = new TaskFlowJob();
job.setName(this.getClass().getSimpleName());
job.setMaxNumberOfExecution(1);
job.setOnTaskError(OnTaskError.CONTINUE_JOB_EXECUTION);
JavaTask A = new JavaTask();
A.setOnTaskError(OnTaskError.NONE);
A.setMaxNumberOfExecution(1);
A.setName("A");
A.setExecutableClassName("org.ow2.proactive.scheduler.examples.EmptyTask");
FlowScript ifScript = FlowScript.createIfFlowScript(ifScriptContent, "B", "C", null);
A.setFlowScript(ifScript);
job.addTask(A);
JavaTask B = new JavaTask();
B.setName("B");
B.setExecutableClassName("org.ow2.proactive.scheduler.examples.EmptyTask");
job.addTask(B);
JavaTask C = new JavaTask();
C.setName("C");
C.setExecutableClassName("org.ow2.proactive.scheduler.examples.EmptyTask");
job.addTask(C);
JobId id = schedulerHelper.submitJob(job);
schedulerHelper.waitForEventJobFinished(id);
JobResult res = schedulerHelper.getJobResult(id);
Map<String, TaskResult> results = res.getAllResults();
// tasks A and B should produce a result, C should be SKIPPED
Assert.assertTrue("Expected 2 results, got " + results.size(), results.size() == 2);
for (Entry<String, TaskResult> result : results.entrySet()) {
if (result.getKey().equals("A")) {
// A should produce an exception
Assert.assertTrue("Task " + result.getKey() + " should have had an exception!", result.getValue().hadException());
} else {
// task should be B and not C
Assert.assertTrue("Expected result for task B, got task " + result.getKey(), result.getKey().equals("B"));
// Task B should run without exception
Assert.assertFalse("Task " + result.getKey() + " had an exception!", result.getValue().hadException());
}
}
}
use of org.ow2.proactive.scheduler.common.task.flow.FlowScript in project scheduling by ow2-proactive.
the class CheckEligibleTaskDescriptorScriptTest method testOnlyCleanScriptContainsAPIBinding.
@Test
public void testOnlyCleanScriptContainsAPIBinding() throws InvalidScriptException {
Script s = scriptWithApiBindingClient();
Script s2 = scriptWithoutApiBinding();
FlowScript fs = flowScriptWithoutApiBinding();
Mockito.when(it.getPreScript()).thenReturn(s2);
Mockito.when(it.getPostScript()).thenReturn(s2);
Mockito.when(it.getCleaningScript()).thenReturn(s);
Mockito.when(sec.getScript()).thenReturn(s2);
Mockito.when(fe.getEnvScript()).thenReturn(s2);
Mockito.when(it.getFlowScript()).thenReturn(fs);
assertTrue(new CheckEligibleTaskDescriptorScript().isTaskContainsAPIBinding(etd));
}
use of org.ow2.proactive.scheduler.common.task.flow.FlowScript in project scheduling by ow2-proactive.
the class CheckEligibleTaskDescriptorScriptTest method testOnlyFlowScriptContainsAPIBinding.
@Test
public void testOnlyFlowScriptContainsAPIBinding() throws InvalidScriptException {
Script s = scriptWithoutApiBinding();
FlowScript fs = flowScriptWithApiBindingUser();
Mockito.when(it.getPreScript()).thenReturn(s);
Mockito.when(it.getPostScript()).thenReturn(s);
Mockito.when(it.getCleaningScript()).thenReturn(s);
Mockito.when(fe.getEnvScript()).thenReturn(s);
Mockito.when(sec.getScript()).thenReturn(s);
Mockito.when(it.getFlowScript()).thenReturn(fs);
assertTrue(new CheckEligibleTaskDescriptorScript().isTaskContainsAPIBinding(etd));
}
Aggregations