use of org.ow2.proactive.scheduler.common.job.Job in project scheduling by ow2-proactive.
the class JobState method getTags.
/**
* To get the list of available tags in a job.
* @return the list of tags.
*/
public List<String> getTags() {
Set<String> result = new HashSet<>();
String tag = null;
for (TaskState task : this.getTasks()) {
tag = task.getTag();
if (tag != null) {
result.add(task.getTag());
}
}
return new ArrayList<>(result);
}
use of org.ow2.proactive.scheduler.common.job.Job in project scheduling by ow2-proactive.
the class FlowChecker method checkBlocks.
/**
* Checks all declared blocks are correct
*
* @param job the job to check
* @return a list of valid blocks
* @throws FlowError
*/
private void checkBlocks() throws FlowError {
Set<String> done = new HashSet<>();
// detect blocks
for (TaskTree tt : roots) {
Stack<TaskTree> env = new Stack<>();
Stack<TaskTree> join = new Stack<>();
dfsBlocks(tt, done, env, join);
if (env.size() > 0) {
throw new FlowError("Unmatched start block", FlowErrorType.BLOCK, env.firstElement().element.getName());
}
}
// check blocks
for (Block b : blocks) {
checkBlockDown(b.end, b.start);
checkBlockUp(b.start, b.end);
}
}
use of org.ow2.proactive.scheduler.common.job.Job in project scheduling by ow2-proactive.
the class FlowChecker method checkReplicate.
/**
* Checks the provided taskflow against rules specific to the REPLICATE control flow action
*
* @param job the job to check
* @throws FlowError
*/
private void checkReplicate() throws FlowError {
for (TaskTree tree : tasksFlat) {
if (tree.element.getFlowScript() != null && tree.element.getFlowScript().getActionType().equals(FlowActionType.REPLICATE.toString())) {
for (TaskTree child : tree.children) {
if (child.parents.size() != 1) {
throw new FlowError("The Target of a REPLICATE must have only one dependency", FlowErrorType.REPLICATE, child.element.getName());
}
if (child.element.getFlowBlock().equals(FlowBlock.END)) {
throw new FlowError("The target of a REPLICATE cannot be the end of a task block", FlowErrorType.REPLICATE, child.element.getName());
}
Block block = null;
for (Block b : this.blocks) {
if (b.start.element.getName().equals(child.element.getName())) {
block = b;
}
}
TaskTree endBlock = null;
if (block != null) {
endBlock = block.end;
} else {
endBlock = child;
}
if (endBlock.children.size() < 1) {
throw new FlowError("No merge point for REPLICATE block", FlowErrorType.REPLICATE, endBlock.element.getName());
}
if (endBlock.element.getFlowScript() != null) {
if (endBlock.element.getFlowScript().getActionType().equals(FlowActionType.REPLICATE.toString()) || endBlock.element.getFlowScript().getActionType().equals(FlowActionType.IF.toString())) {
throw new FlowError("Last action of a REPLICATE block cannot perform IF or REPLICATE action", FlowErrorType.REPLICATE, endBlock.element.getName());
}
}
}
}
}
}
use of org.ow2.proactive.scheduler.common.job.Job in project scheduling by ow2-proactive.
the class StaxJobFactory method createAndFillJob.
/**
* Create the real job and fill it with its property. Leave the method at
* the first tag that define the real type of job.
*
* @param cursorJob the streamReader with the cursor on the job element.
* @param replacementVariables map of variables which has precedence over those that defined
* in Job descriptor
* @throws JobCreationException if an exception occurs during job creation.
*/
private Job createAndFillJob(XMLStreamReader cursorJob, Map<String, String> replacementVariables) throws JobCreationException {
// create a job that will just temporary store the common properties of the job
Job commonPropertiesHolder = new Job() {
@Override
public JobId getId() {
throw new RuntimeException("Not Available!");
}
@Override
public JobType getType() {
throw new RuntimeException("Not Available!");
}
};
// parse job attributes and fill the temporary one
// all attributes in the job element are saved and will be handled after the job variables are parsed.
// This is to allow variable replacements on these attributes
Map<String, String> delayedJobAttributes = new HashMap<>();
int attrLen = cursorJob.getAttributeCount();
int i = 0;
for (; i < attrLen; i++) {
String attributeName = cursorJob.getAttributeLocalName(i);
String attributeValue = cursorJob.getAttributeValue(i);
delayedJobAttributes.put(attributeName, attributeValue);
}
// parse job elements and fill the temporary one
Job job = commonPropertiesHolder;
try {
int eventType;
boolean shouldContinue = true;
while (shouldContinue && cursorJob.hasNext()) {
eventType = cursorJob.next();
switch(eventType) {
case XMLEvent.START_ELEMENT:
String current = cursorJob.getLocalName();
if (XMLTags.VARIABLES.matches(current)) {
// create job variables using the replacement map provided at job submission
// the final value of the variable can either be overwritten by a value of the replacement map or
// use in a pattern such value
commonPropertiesHolder.getVariables().putAll(createJobVariables(cursorJob, replacementVariables));
} else if (XMLTags.COMMON_GENERIC_INFORMATION.matches(current)) {
commonPropertiesHolder.setGenericInformation(getGenericInformation(cursorJob, commonPropertiesHolder.getVariablesAsReplacementMap()));
} else if (XMLTags.JOB_CLASSPATHES.matches(current)) {
logger.warn("Element " + XMLTags.JOB_CLASSPATHES.getXMLName() + " is no longer supported. Please define a " + XMLTags.FORK_ENVIRONMENT.getXMLName() + " per task if needed.");
} else if (XMLTags.COMMON_DESCRIPTION.matches(current)) {
commonPropertiesHolder.setDescription(getDescription(cursorJob, commonPropertiesHolder.getVariablesAsReplacementMap()));
} else if (XMLTags.DS_INPUT_SPACE.matches(current)) {
commonPropertiesHolder.setInputSpace(getIOSpace(cursorJob, commonPropertiesHolder.getVariablesAsReplacementMap()));
} else if (XMLTags.DS_OUTPUT_SPACE.matches(current)) {
commonPropertiesHolder.setOutputSpace(getIOSpace(cursorJob, commonPropertiesHolder.getVariablesAsReplacementMap()));
} else if (XMLTags.DS_GLOBAL_SPACE.matches(current)) {
commonPropertiesHolder.setGlobalSpace(getIOSpace(cursorJob, commonPropertiesHolder.getVariablesAsReplacementMap()));
} else if (XMLTags.DS_USER_SPACE.matches(current)) {
commonPropertiesHolder.setUserSpace(getIOSpace(cursorJob, commonPropertiesHolder.getVariablesAsReplacementMap()));
} else if (XMLTags.TASK_FLOW.matches(current)) {
job = new TaskFlowJob();
shouldContinue = false;
}
break;
}
}
handleJobAttributes(commonPropertiesHolder, delayedJobAttributes);
// if this point is reached, fill the real job using the temporary one
if (job != commonPropertiesHolder) {
job.setDescription(commonPropertiesHolder.getDescription());
job.setName(commonPropertiesHolder.getName());
job.setPriority(commonPropertiesHolder.getPriority());
job.setProjectName(commonPropertiesHolder.getProjectName());
job.setOnTaskError(commonPropertiesHolder.getOnTaskErrorProperty().getValue());
job.setRestartTaskOnError(commonPropertiesHolder.getRestartTaskOnError());
job.setMaxNumberOfExecution(commonPropertiesHolder.getMaxNumberOfExecution());
job.setGenericInformation(commonPropertiesHolder.getGenericInformation());
job.setInputSpace(commonPropertiesHolder.getInputSpace());
job.setOutputSpace(commonPropertiesHolder.getOutputSpace());
job.setGlobalSpace(commonPropertiesHolder.getGlobalSpace());
job.setUserSpace(commonPropertiesHolder.getUserSpace());
job.setVariables(commonPropertiesHolder.getVariables());
}
return job;
} catch (JobCreationException jce) {
jce.pushTag(cursorJob.getLocalName());
throw jce;
} catch (Exception e) {
String temporaryAttribute = null;
if (cursorJob.isStartElement() && cursorJob.getAttributeCount() > i) {
temporaryAttribute = cursorJob.getAttributeLocalName(i);
}
throw new JobCreationException(cursorJob.getLocalName(), temporaryAttribute, e);
}
}
use of org.ow2.proactive.scheduler.common.job.Job 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);
}
}
Aggregations