use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.
the class StaxJobFactory method createJob.
/**
* Start parsing and creating the job.
*
* @throws JobCreationException if an error occurred during job creation process.
*/
private Job createJob(XMLStreamReader cursorRoot, Map<String, String> replacementVariables, Map<String, ArrayList<String>> dependencies) throws JobCreationException {
String current = null;
// start parsing
try {
int eventType;
Job job = null;
while (cursorRoot.hasNext()) {
eventType = cursorRoot.next();
if (eventType == XMLEvent.START_ELEMENT) {
current = cursorRoot.getLocalName();
if (XMLTags.JOB.matches(current)) {
// first tag of the job.
job = createAndFillJob(cursorRoot, replacementVariables);
} else if (XMLTags.TASK.matches(current)) {
// once here, the job instance has been created
fillJobWithTasks(cursorRoot, job, dependencies);
}
}
}
if (job != null) {
resolveCleaningScripts((TaskFlowJob) job, job.getVariablesAsReplacementMap());
}
return job;
} catch (JobCreationException jce) {
if (XMLTags.TASK.matches(current)) {
jce.pushTag(XMLTags.TASK_FLOW.getXMLName());
}
throw jce;
} catch (Exception e) {
throw new JobCreationException(current, null, e);
}
}
use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.
the class StaxJobFactory method createSelectionScript.
/**
* Get the selection script defined at the specified cursor.
* Leave the method with cursor at the end of the 'ELEMENT_SCRIPT_SELECTION' script.
*
* @param cursorScript the streamReader with the cursor on the 'ELEMENT_SCRIPT_SELECTION' tag.
* @return the script defined at the specified cursor.
*/
private List<SelectionScript> createSelectionScript(XMLStreamReader cursorScript, Map<String, String> variables) throws JobCreationException {
List<SelectionScript> scripts = new ArrayList<>(0);
String selectionTag = cursorScript.getLocalName();
String current = null;
try {
SelectionScript newOne;
int eventType;
while (cursorScript.hasNext()) {
eventType = cursorScript.next();
switch(eventType) {
case XMLEvent.START_ELEMENT:
current = cursorScript.getLocalName();
if (XMLTags.SCRIPT_SCRIPT.matches(current)) {
newOne = (SelectionScript) createScript(cursorScript, ScriptType.SELECTION, variables);
scripts.add(newOne);
}
break;
case XMLEvent.END_ELEMENT:
current = cursorScript.getLocalName();
if (current.equals(selectionTag)) {
if (scripts.size() == 0) {
return null;
} else {
return scripts;
}
}
break;
}
}
} catch (JobCreationException jce) {
jce.pushTag(current);
throw jce;
} catch (Exception e) {
throw new JobCreationException(current, null, e);
}
return scripts;
}
use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.
the class StaxJobFactory method setIOFIles.
/**
* Create the list of includes/excludes pattern for the given INPUT/OUTPUT files
* Leave the method with the cursor at the end of 'ELEMENT_DS_INPUT/OUTPUTFILES' tag.
*
* @param cursorTask the streamReader with the cursor on the 'ELEMENT_DS_INPUT/OUTPUTFILES' tag.
* @param endTag the final tag for this tag : ELEMENT_DS_INPUTFILES or ELEMENT_DS_INPUTFILES
* @param task the task in which to add the input/output files selector
* @throws JobCreationException
*/
private void setIOFIles(XMLStreamReader cursorTask, String endTag, Task task, Map<String, String> variables) throws JobCreationException {
int i = 0;
try {
int eventType;
boolean shouldContinue = true;
while (shouldContinue && cursorTask.hasNext()) {
eventType = cursorTask.next();
switch(eventType) {
case XMLEvent.START_ELEMENT:
String current = cursorTask.getLocalName();
if (XMLTags.DS_FILES.matches(current)) {
int attrLen = cursorTask.getAttributeCount();
FileSelector selector = null;
String accessMode = null;
for (i = 0; i < attrLen; i++) {
String attrName = cursorTask.getAttributeLocalName(i);
if (XMLAttributes.DS_INCLUDES.matches(attrName)) {
if (selector == null) {
selector = new FileSelector();
}
selector.setIncludes(cursorTask.getAttributeValue(i));
} else if (XMLAttributes.DS_EXCLUDES.matches(attrName)) {
if (selector == null) {
selector = new FileSelector();
}
selector.setExcludes(replace(cursorTask.getAttributeValue(i), variables));
} else if (XMLAttributes.DS_ACCESS_MODE.matches(attrName)) {
accessMode = cursorTask.getAttributeValue(i);
}
if (selector != null && accessMode != null) {
if (XMLTags.DS_INPUT_FILES.matches(endTag)) {
task.addInputFiles(selector, InputAccessMode.getAccessMode(accessMode));
} else {
task.addOutputFiles(selector, OutputAccessMode.getAccessMode(accessMode));
}
}
}
}
break;
case XMLEvent.END_ELEMENT:
if (cursorTask.getLocalName().equals(endTag)) {
shouldContinue = false;
}
break;
}
}
} catch (JobCreationException jce) {
jce.pushTag(cursorTask.getLocalName());
throw jce;
} catch (Exception e) {
String attrtmp = null;
if (cursorTask.isStartElement() && cursorTask.getAttributeCount() > i) {
attrtmp = cursorTask.getAttributeLocalName(i);
}
throw new JobCreationException(cursorTask.getLocalName(), attrtmp, e);
}
}
use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.
the class StaxJobFactory method validate.
/*
* Validate the given job descriptor
*/
private TaskFlowJob validate(TaskFlowJob job) throws VerifierConfigurationException, JobCreationException {
Map<String, JobValidatorService> factories;
try {
factories = JobValidatorRegistry.getInstance().getRegisteredFactories();
} catch (Exception e) {
throw new VerifierConfigurationException(MSG_UNABLE_TO_INSTANCIATE_JOB_VALIDATION_FACTORIES, e);
}
TaskFlowJob updatedJob = job;
try {
for (JobValidatorService factory : factories.values()) {
updatedJob = factory.validateJob(updatedJob);
}
} catch (JobValidationException e) {
throw e;
} catch (Exception e) {
throw new JobValidationException(e);
}
return updatedJob;
}
use of org.ow2.proactive.scheduler.common.exception.JobCreationException 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