use of org.ow2.proactive.scheduler.common.task.ParallelEnvironment in project scheduling by ow2-proactive.
the class JobComparator method isEqualParallelEnvironment.
private boolean isEqualParallelEnvironment(ParallelEnvironment e1, ParallelEnvironment e2) {
if ((e1 == null) && (e2 == null))
return true;
if ((e1 == null) ^ (e2 == null)) {
stack.push("One value out of 2 is null");
return false;
}
if (e1.getNodesNumber() != e2.getNodesNumber()) {
stack.push("nodes number");
return false;
}
// check same instance of topology decsriptor
TopologyDescriptor topologyDescriptor1 = e1.getTopologyDescriptor();
TopologyDescriptor topologyDescriptor2 = e2.getTopologyDescriptor();
if (topologyDescriptor1 == null && topologyDescriptor2 == null) {
return true;
}
if (topologyDescriptor1 == null ^ topologyDescriptor2 == null) {
return isEqualClass(TopologyDescriptor.ARBITRARY.getClass(), (topologyDescriptor1 == null ? topologyDescriptor2.getClass() : topologyDescriptor1.getClass()));
}
if (!isEqualClass(topologyDescriptor1.getClass(), topologyDescriptor2.getClass())) {
stack.push("topology descriptor type");
return false;
}
if (topologyDescriptor1 instanceof ThresholdProximityDescriptor) {
if (!(topologyDescriptor2 instanceof ThresholdProximityDescriptor)) {
stack.push("Only one is ThresholdProximityDescriptor type.");
return false;
}
if (((ThresholdProximityDescriptor) topologyDescriptor1).getThreshold() != ((ThresholdProximityDescriptor) topologyDescriptor2).getThreshold()) {
stack.push("ThresholdProximityDescriptor.threshold");
return false;
}
}
return true;
}
use of org.ow2.proactive.scheduler.common.task.ParallelEnvironment in project scheduling by ow2-proactive.
the class StaxJobFactory method createParallelEnvironment.
/**
* Creates the parallel environment from the xml descriptor.
*/
private ParallelEnvironment createParallelEnvironment(XMLStreamReader cursorTask, Map<String, String> variables) throws JobCreationException {
int event = -1;
int nodesNumber = 0;
TopologyDescriptor topologyDescriptor = null;
// parallelEnvironment -> <topology>
try {
// cursor is parallelEnvironment
for (int i = 0; i < cursorTask.getAttributeCount(); i++) {
String attrName = cursorTask.getAttributeLocalName(i);
if (XMLAttributes.TASK_NB_NODES.matches(attrName)) {
String value = replace(cursorTask.getAttributeValue(i), variables);
nodesNumber = Integer.parseInt(value);
}
}
while (cursorTask.hasNext()) {
event = cursorTask.next();
if (event == XMLEvent.START_ELEMENT) {
break;
} else if (event == XMLEvent.END_ELEMENT && XMLTags.PARALLEL_ENV.matches(cursorTask.getLocalName())) {
return new ParallelEnvironment(nodesNumber, TopologyDescriptor.ARBITRARY);
}
}
if (XMLTags.TOPOLOGY.matches(cursorTask.getLocalName())) {
// topology element found
while (cursorTask.hasNext()) {
event = cursorTask.next();
if (event == XMLEvent.START_ELEMENT) {
break;
} else if (event == XMLEvent.END_ELEMENT && XMLTags.TOPOLOGY.matches(cursorTask.getLocalName())) {
throw new RuntimeException("Incorrect topology description");
}
}
// arbitrary : no attributes
if (XMLTags.TOPOLOGY_ARBITRARY.matches(cursorTask.getLocalName())) {
topologyDescriptor = TopologyDescriptor.ARBITRARY;
} else // bestProximity : no attributes
if (XMLTags.TOPOLOGY_BEST_PROXIMITY.matches(cursorTask.getLocalName())) {
topologyDescriptor = TopologyDescriptor.BEST_PROXIMITY;
} else // thresholdProximity : elements threshold
if (XMLTags.TOPOLOGY_THRESHOLD_PROXIMITY.matches(cursorTask.getLocalName())) {
// attribute threshold
for (int i = 0; i < cursorTask.getAttributeCount(); i++) {
String attrName = cursorTask.getAttributeLocalName(i);
if (XMLAttributes.TOPOLOGY_THRESHOLD.matches(attrName)) {
String value = replace(cursorTask.getAttributeValue(i), variables);
long threshold = Long.parseLong(value);
topologyDescriptor = new ThresholdProximityDescriptor(threshold);
}
}
} else // singleHost : no attributes
if (XMLTags.TOPOLOGY_SINGLE_HOST.matches(cursorTask.getLocalName())) {
topologyDescriptor = TopologyDescriptor.SINGLE_HOST;
} else // singleHostExclusive : no attributes
if (XMLTags.TOPOLOGY_SINGLE_HOST_EXCLUSIVE.matches(cursorTask.getLocalName())) {
topologyDescriptor = TopologyDescriptor.SINGLE_HOST_EXCLUSIVE;
} else // multipleHostsExclusive : no attributes
if (XMLTags.TOPOLOGY_MULTIPLE_HOSTS_EXCLUSIVE.matches(cursorTask.getLocalName())) {
topologyDescriptor = TopologyDescriptor.MULTIPLE_HOSTS_EXCLUSIVE;
} else // oneNodePerHostHostsExclusive : no attributes
if (XMLTags.TOPOLOGY_DIFFERENT_HOSTS_EXCLUSIVE.matches(cursorTask.getLocalName())) {
topologyDescriptor = TopologyDescriptor.DIFFERENT_HOSTS_EXCLUSIVE;
}
}
} catch (Exception e) {
throw new JobCreationException(XMLTags.TOPOLOGY.getXMLName(), null, e);
}
return new ParallelEnvironment(nodesNumber, topologyDescriptor);
}
use of org.ow2.proactive.scheduler.common.task.ParallelEnvironment in project scheduling by ow2-proactive.
the class TestTaskAttributes method testParallelEnv.
@Test
public void testParallelEnv() throws Exception {
JavaTask task = createDefaultTask("task");
ParallelEnvironment env = new ParallelEnvironment(5);
task.setParallelEnvironment(env);
InternalTask taskData = saveSingleTask(task).getTask(task.getName());
Assert.assertEquals(5, taskData.getParallelEnvironment().getNodesNumber());
Assert.assertNull(taskData.getParallelEnvironment().getTopologyDescriptor());
TopologyDescriptor[] descs = { TopologyDescriptor.ARBITRARY, TopologyDescriptor.BEST_PROXIMITY, TopologyDescriptor.DIFFERENT_HOSTS_EXCLUSIVE, TopologyDescriptor.MULTIPLE_HOSTS_EXCLUSIVE, TopologyDescriptor.SINGLE_HOST, TopologyDescriptor.SINGLE_HOST_EXCLUSIVE, new ThresholdProximityDescriptor(123) };
for (TopologyDescriptor desc : descs) {
task = createDefaultTask("task");
env = new ParallelEnvironment(10, desc);
task.setParallelEnvironment(env);
taskData = saveSingleTask(task).getTask(task.getName());
Assert.assertEquals(10, taskData.getParallelEnvironment().getNodesNumber());
Assert.assertEquals(taskData.getParallelEnvironment().getTopologyDescriptor().getClass(), desc.getClass());
if (desc instanceof ThresholdProximityDescriptor) {
Assert.assertEquals(((ThresholdProximityDescriptor) taskData.getParallelEnvironment().getTopologyDescriptor()).getThreshold(), 123);
}
}
}
use of org.ow2.proactive.scheduler.common.task.ParallelEnvironment in project scheduling by ow2-proactive.
the class Attribute method createParallelEnvironment.
/**
* Creates the parallel environment element for the given task. Corresponds
* to <define name="parallel">
*
* @return the {@link XMLTags#PARALLEL_ENV} element if the task has a
* parallel environment, null otherwise
*/
private Element createParallelEnvironment(Document doc, Task task) {
ParallelEnvironment penv = task.getParallelEnvironment();
if (penv == null)
return null;
Element parallelEnvE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.PARALLEL_ENV.getXMLName());
setAttribute(parallelEnvE, XMLAttributes.TASK_NB_NODES, Integer.toString(penv.getNodesNumber()));
// <ref name="topology"/>
TopologyDescriptor topologyDescr = penv.getTopologyDescriptor();
if (topologyDescr != null) {
// <choice>
// <ref name="arbitrary"/>
// <ref name="bestProximity"/>
// <ref name="thresholdProximity"/>
// <ref name="singleHost"/>
// <ref name="singleHostExclusive"/>
// <ref name="multipleHostsExclusive"/>
// <ref name="differentHostsExclusive"/>
// </choice>
Element topologyE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.TOPOLOGY.getXMLName());
Element topologyDescrE = null;
if (topologyDescr instanceof ArbitraryTopologyDescriptor) {
topologyDescrE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.TOPOLOGY_ARBITRARY.getXMLName());
} else if (topologyDescr instanceof ThresholdProximityDescriptor) {
topologyDescrE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.TOPOLOGY_THRESHOLD_PROXIMITY.getXMLName());
long threshold = ((ThresholdProximityDescriptor) topologyDescr).getThreshold();
topologyDescrE.setAttribute(XMLAttributes.TOPOLOGY_THRESHOLD.getXMLName(), Long.toString(threshold));
} else if (topologyDescr instanceof BestProximityDescriptor) {
topologyDescrE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.TOPOLOGY_BEST_PROXIMITY.getXMLName());
} else if (topologyDescr instanceof SingleHostExclusiveDescriptor) {
topologyDescrE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.TOPOLOGY_SINGLE_HOST_EXCLUSIVE.getXMLName());
} else if (topologyDescr instanceof SingleHostDescriptor) {
topologyDescrE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.TOPOLOGY_SINGLE_HOST.getXMLName());
} else if (topologyDescr instanceof MultipleHostsExclusiveDescriptor) {
topologyDescrE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.TOPOLOGY_MULTIPLE_HOSTS_EXCLUSIVE.getXMLName());
}
if (topologyDescr instanceof DifferentHostsExclusiveDescriptor) {
topologyDescrE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.TOPOLOGY_DIFFERENT_HOSTS_EXCLUSIVE.getXMLName());
}
if (topologyDescrE != null) {
topologyE.appendChild(topologyDescrE);
}
parallelEnvE.appendChild(topologyE);
}
return parallelEnvE;
}
use of org.ow2.proactive.scheduler.common.task.ParallelEnvironment in project scheduling by ow2-proactive.
the class StaxJobFactory method createTask.
/**
* Fill the given task by the information that are at the given cursorTask.
* Leave the method with the cursor at the end of 'ELEMENT_TASK' tag.
*
* @param cursorTask the streamReader with the cursor on the 'ELEMENT_TASK' tag.
* @return The newly created task that can be any type.
*/
private Task createTask(XMLStreamReader cursorTask, Job job, Map<String, ArrayList<String>> dependencies) throws JobCreationException {
int i = 0;
XMLTags currentTag = null;
String current = null;
String taskName = null;
try {
Task toReturn = null;
Task tmpTask = new Task() {
};
// parse job attributes and fill the temporary one
int attrLen = cursorTask.getAttributeCount();
for (i = 0; i < attrLen; i++) {
String attributeName = cursorTask.getAttributeLocalName(i);
String attributeValue = cursorTask.getAttributeValue(i);
if (XMLAttributes.COMMON_NAME.matches(attributeName)) {
tmpTask.setName(attributeValue);
taskName = attributeValue;
} else if (XMLAttributes.TASK_NB_NODES.matches(attributeName)) {
int numberOfNodesNeeded = Integer.parseInt(replace(attributeValue, tmpTask.getVariablesOverriden(job)));
tmpTask.setParallelEnvironment(new ParallelEnvironment(numberOfNodesNeeded));
} else if (XMLAttributes.COMMON_CANCEL_JOB_ON_ERROR.matches(attributeName)) {
handleCancelJobOnErrorAttribute(tmpTask, attributeValue);
} else if (XMLAttributes.COMMON_ON_TASK_ERROR.matches(attributeName)) {
tmpTask.setOnTaskError(OnTaskError.getInstance(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
} else if (XMLAttributes.COMMON_RESTART_TASK_ON_ERROR.matches(attributeName)) {
tmpTask.setRestartTaskOnError(RestartMode.getMode(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
} else if (XMLAttributes.COMMON_MAX_NUMBER_OF_EXECUTION.matches(attributeName)) {
tmpTask.setMaxNumberOfExecution(Integer.parseInt(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
} else if (XMLAttributes.TASK_PRECIOUS_RESULT.matches(attributeName)) {
tmpTask.setPreciousResult(Boolean.parseBoolean(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
} else if (XMLAttributes.TASK_PRECIOUS_LOGS.matches(attributeName)) {
tmpTask.setPreciousLogs(Boolean.parseBoolean(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
} else if (XMLAttributes.TASK_WALLTIME.matches(attributeName)) {
tmpTask.setWallTime(Tools.formatDate(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
} else if (XMLAttributes.TASK_RUN_AS_ME.matches(attributeName)) {
tmpTask.setRunAsMe(Boolean.parseBoolean(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
}
}
int eventType;
boolean shouldContinue = true;
while (shouldContinue && cursorTask.hasNext()) {
eventType = cursorTask.next();
switch(eventType) {
case XMLEvent.START_ELEMENT:
current = cursorTask.getLocalName();
currentTag = null;
if (XMLTags.COMMON_GENERIC_INFORMATION.matches(current)) {
tmpTask.setGenericInformation(getGenericInformation(cursorTask, tmpTask.getVariablesOverriden(job)));
} else if (XMLTags.VARIABLES.matches(current)) {
Map<String, TaskVariable> taskVariablesMap = createTaskVariables(cursorTask, tmpTask.getVariablesOverriden(job));
tmpTask.setVariables(taskVariablesMap);
} else if (XMLTags.COMMON_DESCRIPTION.matches(current)) {
tmpTask.setDescription(getDescription(cursorTask, tmpTask.getVariablesOverriden(job)));
} else if (XMLTags.DS_INPUT_FILES.matches(current)) {
setIOFIles(cursorTask, XMLTags.DS_INPUT_FILES.getXMLName(), tmpTask, tmpTask.getVariablesOverriden(job));
} else if (XMLTags.DS_OUTPUT_FILES.matches(current)) {
setIOFIles(cursorTask, XMLTags.DS_OUTPUT_FILES.getXMLName(), tmpTask, tmpTask.getVariablesOverriden(job));
} else if (XMLTags.PARALLEL_ENV.matches(current)) {
tmpTask.setParallelEnvironment(createParallelEnvironment(cursorTask, tmpTask.getVariablesOverriden(job)));
} else if (XMLTags.SCRIPT_SELECTION.matches(current)) {
tmpTask.setSelectionScripts(createSelectionScript(cursorTask, tmpTask.getVariablesOverriden(job)));
} else if (XMLTags.FORK_ENVIRONMENT.matches(current)) {
tmpTask.setForkEnvironment(createForkEnvironment(cursorTask, tmpTask.getVariablesOverriden(job)));
} else if (XMLTags.SCRIPT_PRE.matches(current)) {
tmpTask.setPreScript(createScript(cursorTask, tmpTask.getVariablesOverriden(job)));
} else if (XMLTags.SCRIPT_POST.matches(current)) {
tmpTask.setPostScript(createScript(cursorTask, tmpTask.getVariablesOverriden(job)));
} else if (XMLTags.SCRIPT_CLEANING.matches(current)) {
tmpTask.setCleaningScript(createScript(cursorTask, tmpTask.getVariablesOverriden(job)));
} else if (XMLTags.FLOW.matches(current)) {
tmpTask.setFlowScript(createControlFlowScript(cursorTask, tmpTask, tmpTask.getVariablesOverriden(job)));
} else if (XMLTags.TASK_DEPENDENCES.matches(current)) {
currentTag = XMLTags.TASK_DEPENDENCES;
dependencies.putAll(createDependences(cursorTask, tmpTask));
} else if (XMLTags.JAVA_EXECUTABLE.matches(current)) {
toReturn = new JavaTask();
setJavaExecutable((JavaTask) toReturn, cursorTask, tmpTask.getVariablesOverriden(job));
} else if (XMLTags.NATIVE_EXECUTABLE.matches(current)) {
toReturn = new NativeTask();
setNativeExecutable((NativeTask) toReturn, cursorTask);
} else if (XMLTags.SCRIPT_EXECUTABLE.matches(current)) {
toReturn = new ScriptTask();
((ScriptTask) toReturn).setScript(new TaskScript(createScript(cursorTask, tmpTask.getVariablesOverriden(job))));
}
break;
case XMLEvent.END_ELEMENT:
current = cursorTask.getLocalName();
if (XMLTags.TASK.matches(cursorTask.getLocalName())) {
shouldContinue = false;
}
break;
}
}
// fill the real task with common attribute if it is a new one
autoCopyfields(CommonAttribute.class, tmpTask, toReturn);
autoCopyfields(Task.class, tmpTask, toReturn);
if (toReturn != null) {
if (toReturn.getRestartTaskOnErrorProperty().isSet()) {
toReturn.setRestartTaskOnError(toReturn.getRestartTaskOnError());
}
if (toReturn.getMaxNumberOfExecutionProperty().isSet()) {
toReturn.setMaxNumberOfExecution(toReturn.getMaxNumberOfExecution());
}
}
return toReturn;
} catch (JobCreationException jce) {
jce.setTaskName(taskName);
if (currentTag != null) {
jce.pushTag(currentTag);
} else {
jce.pushTag(current);
}
throw jce;
} catch (Exception e) {
String attrtmp = null;
if (cursorTask.isStartElement() && cursorTask.getAttributeCount() > i) {
attrtmp = cursorTask.getAttributeLocalName(i);
}
if (currentTag != null) {
throw new JobCreationException(currentTag, attrtmp, e);
} else {
throw new JobCreationException(current, attrtmp, e);
}
}
}
Aggregations