use of org.ow2.proactive.scheduler.common.job.JobType 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.JobType 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 submittedJobVariables job submission variables map taking priority on those defined in the xml
* @param submittedGenericInfos job submission generic infos map taking priority on those defined in the xml
* @param jobContent contains xml representation of this job
* @throws JobCreationException if an exception occurs during job creation.
*/
private Job createAndFillJob(XMLStreamReader cursorJob, Map<String, String> submittedJobVariables, Map<String, String> submittedGenericInfos, String jobContent, GlobalVariablesData globalVariablesData) throws JobCreationException {
// A temporary job
Job commonPropertiesHolder = new Job() {
@Override
public JobId getId() {
throw new RuntimeException("Not Available!");
}
@Override
public JobType getType() {
throw new RuntimeException("Not Available!");
}
};
// To allow variable replacements on the job attributes, store them until job variables are parsed
Map<String, String> delayedJobAttributes = new LinkedHashMap<>();
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);
}
Job job = commonPropertiesHolder;
try {
int eventType;
// Start by adding to the temporary job, the global variables (with internal references enabled)
commonPropertiesHolder.getVariables().putAll(replaceVariablesInJobVariablesMap(globalVariablesData.getVariables(), convertToReplacementMap(globalVariablesData.getVariables())));
commonPropertiesHolder.addGenericInformations(getResolvedGenericInformations(globalVariablesData.getGenericInformation(), commonPropertiesHolder.getVariablesAsReplacementMap()));
// Then add job submission variables, which will override eventually global variables
if (submittedJobVariables != null) {
for (String variableName : submittedJobVariables.keySet()) {
if (commonPropertiesHolder.getVariables().containsKey(variableName)) {
commonPropertiesHolder.getVariables().get(variableName).setValue(submittedJobVariables.get(variableName));
} else {
commonPropertiesHolder.getVariables().put(variableName, new JobVariable(variableName, submittedJobVariables.get(variableName), null));
}
}
// enable referencing of global variables by submitted variables
commonPropertiesHolder.getVariables().putAll(replaceVariablesInJobVariablesMap(commonPropertiesHolder.getVariables(), commonPropertiesHolder.getVariablesAsReplacementMap()));
}
// Then add job submission generic information, resolved using job submission and global variables
if (submittedGenericInfos != null) {
commonPropertiesHolder.addGenericInformations(getResolvedGenericInformations(submittedGenericInfos, commonPropertiesHolder.getVariablesAsReplacementMap()));
}
// Continue to fill the temporary job with xml elements
while (cursorJob.hasNext()) {
eventType = cursorJob.next();
if (eventType == XMLEvent.START_ELEMENT) {
String current = cursorJob.getLocalName();
if (XMLTags.VARIABLES.matches(current)) {
// Add resolved job variables using the job submission variables
// the final value of the variable can either be overwritten by a value of the job submission variables map or
// use in a pattern such value
Map<String, JobVariable> unresolvedJobVariablesMap = createUnresolvedJobVariables(cursorJob, globalVariablesData);
commonPropertiesHolder.getUnresolvedVariables().putAll(unresolvedJobVariablesMap);
Map<String, JobVariable> jobVariablesMap = replaceVariablesInJobVariablesMap(unresolvedJobVariablesMap, submittedJobVariables);
// this is to ensure preserving the order of variables defined in the workflow
for (String key : jobVariablesMap.keySet()) {
commonPropertiesHolder.getVariables().remove(key);
}
commonPropertiesHolder.getVariables().putAll(jobVariablesMap);
} else if (XMLTags.COMMON_GENERIC_INFORMATION.matches(current)) {
// Resolve the generic infos in the xml with the resolved variables
Map<String, String> resolvedJobVariables = commonPropertiesHolder.getVariablesAsReplacementMap();
Map<String, String> unresolvedGenericInformationsDefinedInWorkflow = getUnresolvedGenericInformations(cursorJob, false, globalVariablesData);
Map<String, String> resolvedGenericInformationsDefinedInWorkflow = getResolvedGenericInformations(unresolvedGenericInformationsDefinedInWorkflow, resolvedJobVariables);
// Then add/replace the resolved generic infos in the xml with the ones specified at job submission
if (submittedGenericInfos != null) {
Map<String, String> submittedGenericInformations = getResolvedGenericInformations(submittedGenericInfos, commonPropertiesHolder.getVariablesAsReplacementMap());
resolvedGenericInformationsDefinedInWorkflow.putAll(submittedGenericInformations);
}
// Update the temporary job
commonPropertiesHolder.setGenericInformation(resolvedGenericInformationsDefinedInWorkflow);
commonPropertiesHolder.setUnresolvedGenericInformation(unresolvedGenericInformationsDefinedInWorkflow);
} 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();
// Stop cursor at the beginning of 'taskflow' tag, at this level all job properties are extracted except metadata
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());
if (commonPropertiesHolder.getTaskRetryDelayProperty().isSet()) {
job.setTaskRetryDelay(commonPropertiesHolder.getTaskRetryDelay());
}
job.setMaxNumberOfExecution(commonPropertiesHolder.getMaxNumberOfExecution());
job.setGenericInformation(commonPropertiesHolder.getGenericInformation());
job.setUnresolvedGenericInformation(commonPropertiesHolder.getUnresolvedGenericInformation());
job.setInputSpace(commonPropertiesHolder.getInputSpace());
job.setOutputSpace(commonPropertiesHolder.getOutputSpace());
job.setGlobalSpace(commonPropertiesHolder.getGlobalSpace());
job.setUserSpace(commonPropertiesHolder.getUserSpace());
job.setVariables(commonPropertiesHolder.getVariables());
job.setUnresolvedVariables(commonPropertiesHolder.getUnresolvedVariables());
job.setVisualization(commonPropertiesHolder.getVisualization());
String updatedJobContent = getJobContentFactory.replaceVarsAndGenericInfo(jobContent, commonPropertiesHolder.getVariables(), commonPropertiesHolder.getGenericInformation());
job.setJobContent(updatedJobContent);
}
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.JobType in project scheduling by ow2-proactive.
the class DozerMappingTest method createJobState.
private JobState createJobState() {
return new ClientJobState(new JobState() {
@Override
public void update(TaskInfo taskInfo) {
}
@Override
public void update(JobInfo jobInfo) {
}
@Override
public JobInfo getJobInfo() {
return new JobInfoImpl();
}
@Override
public ArrayList<TaskState> getTasks() {
return new ArrayList<>(getHMTasks().values());
}
@Override
public Map<TaskId, TaskState> getHMTasks() {
TaskId taskId = TaskIdImpl.createTaskId(new JobIdImpl(42, "job"), "remoteVisuTask", 1);
TaskState value = new ClientTaskState(new TaskState() {
@Override
public void update(TaskInfo taskInfo) {
}
@Override
public List<TaskState> getDependences() {
return null;
}
@Override
public TaskInfo getTaskInfo() {
TaskInfoImpl taskInfo = new TaskInfoImpl();
taskInfo.setTaskId(TaskIdImpl.createTaskId(new JobIdImpl(42, "job"), "remoteVisuTask", 1));
return taskInfo;
}
@Override
public int getMaxNumberOfExecutionOnFailure() {
return 0;
}
@Override
public TaskState replicate() throws Exception {
return null;
}
@Override
public int getIterationIndex() {
return 0;
}
@Override
public int getReplicationIndex() {
return 0;
}
});
return Collections.singletonMap(taskId, value);
}
@Override
public String getOwner() {
return null;
}
@Override
public JobType getType() {
return null;
}
});
}
use of org.ow2.proactive.scheduler.common.job.JobType in project scheduling by ow2-proactive.
the class ClientJobStateTest method createJobState.
private JobState createJobState(final JobInfoImpl jobInfo) {
return new JobState() {
@Override
public void update(TaskInfo info) {
}
@Override
public void update(JobInfo jobInfo) {
}
@Override
public JobInfo getJobInfo() {
return jobInfo;
}
@Override
public List<TaskState> getTasks() {
List<TaskState> tasks = new ArrayList<>(0);
tasks.add(new TaskState() {
@Override
public void update(TaskInfo taskInfo) {
}
@Override
public List<TaskState> getDependences() {
return null;
}
@Override
public TaskInfo getTaskInfo() {
TaskInfoImpl taskInfo = new TaskInfoImpl();
taskInfo.setJobInfo(jobInfo);
taskInfo.setTaskId(TaskIdImpl.createTaskId(jobInfo.getJobId(), "task", 1));
return taskInfo;
}
@Override
public int getMaxNumberOfExecutionOnFailure() {
return 0;
}
@Override
public TaskState replicate() throws Exception {
return null;
}
@Override
public int getIterationIndex() {
return 0;
}
@Override
public int getReplicationIndex() {
return 0;
}
});
return tasks;
}
@Override
public Map<TaskId, TaskState> getHMTasks() {
return null;
}
@Override
public String getOwner() {
return null;
}
@Override
public JobType getType() {
return null;
}
};
}
Aggregations