use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.
the class StaxJobFactory method getDescription.
/**
* Get the description of the entity.
* Leave the method with the cursor at the end of 'ELEMENT_COMMON_DESCRIPTION' tag.
*
* @param cursorVariables the streamReader with the cursor on the 'ELEMENT_COMMON_DESCRIPTION' tag.
* @return the description between the tags.
*/
private String getDescription(XMLStreamReader cursorVariables, Map<String, String> variables) throws JobCreationException {
try {
String description = "";
// if description tag exists, then we have a characters event next.
int eventType = cursorVariables.next();
if (eventType == XMLEvent.CHARACTERS) {
description = replace(cursorVariables.getText(), variables);
} else if (eventType == XMLEvent.END_ELEMENT) {
return description;
}
// go to the description END_ELEMENT
while (cursorVariables.next() != XMLEvent.END_ELEMENT) ;
return description;
} catch (JobCreationException jce) {
throw jce;
} catch (Exception e) {
throw new JobCreationException((String) null, null, e);
}
}
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;
default:
}
}
} 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 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.exception.JobCreationException in project scheduling by ow2-proactive.
the class FlatJobFactory method createNativeJobFromCommandsFile.
/**
* Create a job from a String representing file path, this text file contains native commands to launch
* Every line of the text file is taken and considered as a native command from which a native task is built,
* except lines beginning with {@link FlatJobFactory#JOB_DEFAULT_NAME_PREFIX} and empty lines.
* So job in result is made of several native tasks without dependencies.
*
* @param commandFilePath a string representing a text file containing native commands.
* @param jobName A String representing a name to give to the job. If null, default job name is made of
* {@link FlatJobFactory#JOB_DEFAULT_NAME_PREFIX} + userName parameter.
* @param selectionScriptPath a Path to a file containing a selection script, or null if
* no script is needed.
* @param userName name of connected user that asked job creation, null otherwise. This parameter
* is only used for default job's name creation.
* @return a job object representing created job and ready-to-schedule job.
* @throws JobCreationException with a relevant error message if an error occurs.
*/
public Job createNativeJobFromCommandsFile(String commandFilePath, String jobName, String selectionScriptPath, String userName) throws JobCreationException {
if (jobName == null) {
jobName = JOB_DEFAULT_NAME_PREFIX + userName;
}
Job nativeJob = new TaskFlowJob();
nativeJob.setName(jobName);
logger.debug("Job : " + nativeJob.getName());
try {
File commandFile = new File(commandFilePath);
if (!commandFile.isFile()) {
throw new JobCreationException("Error occured during Job creation, " + "check that file " + commandFilePath + " exists and is a readable file");
}
String commandLine;
int task_number = 0;
ArrayList<String> commandList = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new FileReader(commandFile))) {
while ((commandLine = reader.readLine()) != null) {
commandLine = commandLine.trim();
if (!commandLine.startsWith(CMD_FILE_COMMENT_CHAR, 0) && !"".equals(commandLine)) {
commandList.add(commandLine);
}
}
}
if (commandList.size() == 0) {
throw new JobCreationException("Error occured during Job creation, " + "No any valid command line has been built from" + commandFilePath + "");
}
// compute padding for task number
int numberOfDigit = Integer.toString(commandList.size()).length();
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumIntegerDigits(numberOfDigit);
nf.setMinimumIntegerDigits(numberOfDigit);
for (String command : commandList) {
NativeTask t = createNativeTaskFromCommandString(command, "task_" + (nf.format(++task_number)), selectionScriptPath);
t.setPreciousResult(true);
((TaskFlowJob) nativeJob).addTask(t);
logger.debug("-> Task Name = " + t.getName());
logger.debug("-> command = " + t.getCommandLine() + "\n");
}
} catch (Exception e) {
throw new JobCreationException(e);
}
return nativeJob;
}
use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.
the class FlatJobFactory method createNativeJobFromCommand.
/**
* Creates a job from a String representing a native command to launch. So job in result is made
* of one native task.
*
* @param command a string representing an executable command to launch.
* @param jobName A String representing a name to give to the job, if null. default job name is made of
* {link FlatJobFactory#JOB_DEFAULT_NAME_PREFIX} + userName parameter.
* @param selectionScriptPath A Path to a file containing a selection script, or null if
* no script is needed.
* @param userName name of connected user that asked job creation, null otherwise. This parameter
* is just used for default job's name creation.
* @return a job object representing created job and ready-to-schedule job.
* @throws JobCreationException with a relevant error message if an error occurs.
*/
public Job createNativeJobFromCommand(String command, String jobName, String selectionScriptPath, String userName) throws JobCreationException {
if (command == null || "".equalsIgnoreCase(command)) {
throw new JobCreationException("Error, command cannot be null");
}
if (jobName == null) {
jobName = JOB_DEFAULT_NAME_PREFIX + userName;
}
Job nativeJob = new TaskFlowJob();
nativeJob.setName(jobName);
logger.debug("Job : " + nativeJob.getName());
try {
NativeTask t = createNativeTaskFromCommandString(command, "task1", selectionScriptPath);
t.setPreciousResult(true);
((TaskFlowJob) nativeJob).addTask(t);
logger.debug("-> Task Name = " + t.getName());
logger.debug("-> command = " + t.getCommandLine() + "\n");
} catch (Exception e) {
throw new JobCreationException(e);
}
return nativeJob;
}
Aggregations