use of org.ow2.proactive.scheduler.common.job.Job in project scheduling by ow2-proactive.
the class StaxJobFactory method createJob.
private Job createJob(File file, Map<String, String> replacementVariables) throws JobCreationException {
try {
// Check if the file exist
if (!file.exists()) {
throw new FileNotFoundException("This file has not been found: " + file.getAbsolutePath());
}
// validate content using the proper XML schema
File updatedFile = validate(file);
// set relative path
relativePathRoot = updatedFile.getParentFile().getAbsolutePath();
// create and get XML STAX reader
XMLStreamReader xmlsr;
Map<String, ArrayList<String>> dependencies = new HashMap<>();
Job job;
try (InputStream inputStream = new FileInputStream(updatedFile)) {
// use the server side property to accept encoding
if (PASchedulerProperties.FILE_ENCODING.isSet()) {
xmlsr = xmlInputFactory.createXMLStreamReader(inputStream, PASchedulerProperties.FILE_ENCODING.getValueAsString());
} else {
xmlsr = xmlInputFactory.createXMLStreamReader(inputStream);
}
// Create the job starting at the first cursor position of the XML Stream reader
job = createJob(xmlsr, replacementVariables, dependencies);
// Close the stream
xmlsr.close();
}
// make dependencies
makeDependences(job, dependencies);
validate((TaskFlowJob) job);
logger.debug("Job successfully created!");
// debug mode only
displayJobInfo(job);
return job;
} catch (JobCreationException jce) {
jce.pushTag(XMLTags.JOB.getXMLName());
throw jce;
} catch (Exception e) {
throw new JobCreationException(e);
}
}
use of org.ow2.proactive.scheduler.common.job.Job in project scheduling by ow2-proactive.
the class StaxJobFactory method createJobVariables.
/**
* Create a map of variables from XML variables.
* Leave the method with the cursor at the end of 'ELEMENT_VARIABLES' tag
*
* @param cursorVariables the streamReader with the cursor on the 'ELEMENT_VARIABLES' tag.
* @param replacementVariables variables which have precedence over the one defined in the job
* @return the map in which the variables were added.
* @throws JobCreationException
*/
private Map<String, JobVariable> createJobVariables(XMLStreamReader cursorVariables, Map<String, String> replacementVariables) throws JobCreationException {
HashMap<String, JobVariable> variablesMap = new LinkedHashMap<>();
try {
int eventType;
while (cursorVariables.hasNext()) {
eventType = cursorVariables.next();
switch(eventType) {
case XMLEvent.START_ELEMENT:
if (XMLTags.VARIABLE.matches(cursorVariables.getLocalName())) {
Map<String, String> attributesAsMap = getAttributesAsMap(cursorVariables, null);
String name = attributesAsMap.get(XMLAttributes.VARIABLE_NAME.getXMLName());
String value = attributesAsMap.get(XMLAttributes.VARIABLE_VALUE.getXMLName());
String model = attributesAsMap.get(XMLAttributes.VARIABLE_MODEL.getXMLName());
variablesMap.put(name, new JobVariable(name, value, model));
}
break;
case XMLEvent.END_ELEMENT:
if (XMLTags.VARIABLES.matches(cursorVariables.getLocalName())) {
return replaceVariablesInJobVariablesMap(variablesMap, replacementVariables);
}
break;
}
}
} catch (JobCreationException jce) {
jce.pushTag(cursorVariables.getLocalName());
throw jce;
} catch (Exception e) {
String attrtmp = null;
if (cursorVariables.isStartElement() && cursorVariables.getAttributeCount() == 1) {
attrtmp = cursorVariables.getAttributeLocalName(0);
}
throw new JobCreationException(cursorVariables.getLocalName(), attrtmp, e);
}
return variablesMap;
}
use of org.ow2.proactive.scheduler.common.job.Job in project scheduling by ow2-proactive.
the class StaxJobFactory method replaceVariablesInJobVariablesMap.
protected Map<String, JobVariable> replaceVariablesInJobVariablesMap(Map<String, JobVariable> variablesMap, Map<String, String> replacementVariables) throws JobCreationException {
HashMap<String, String> updatedReplacementVariables = new HashMap<>();
HashMap<String, JobVariable> updatedVariablesMap = new HashMap<>(variablesMap);
// replacements will include at first variables defined in the job
for (JobVariable variable : updatedVariablesMap.values()) {
updatedReplacementVariables.put(variable.getName(), variable.getValue());
}
if (replacementVariables != null) {
// overwritten by variables used at job submission
updatedReplacementVariables.putAll(replacementVariables);
}
for (Map.Entry<String, String> replacementVariable : updatedReplacementVariables.entrySet()) {
if (updatedVariablesMap.containsKey(replacementVariable.getKey())) {
// if the variable is already defined in the job, overwrite its value by the replacement variable,
// eventually using other variables as pattern replacements
JobVariable jobVariable = updatedVariablesMap.get(replacementVariable.getKey());
jobVariable.setValue(replace(replacementVariable.getValue(), updatedReplacementVariables));
if (jobVariable.getModel() != null) {
// model of an existing variable can use other variables as pattern replacements
jobVariable.setModel(replace(jobVariable.getModel(), updatedReplacementVariables));
}
} else {
// if the variable is not defined in the job, create a new job variable with an empty model
updatedVariablesMap.put(replacementVariable.getKey(), new JobVariable(replacementVariable.getKey(), replace(replacementVariable.getValue(), updatedReplacementVariables), null));
}
}
return updatedVariablesMap;
}
use of org.ow2.proactive.scheduler.common.job.Job in project scheduling by ow2-proactive.
the class BatchJobInfrastructure method removeNode.
/**
* {@inheritDoc}
*/
@Override
public void removeNode(Node node) throws RMException {
String deleteCmd = getDeleteJobCommand();
String jobID = null;
String nodeName = node.getNodeInformation().getName();
if ((jobID = getCurrentNode(nodeName)) != null) {
try {
deleteJob(jobID);
} catch (RMException e) {
logger.warn(deleteCmd + " command failed, cannot ensure job " + jobID + " is deleted. Anyway, node " + nodeName + " is removed from the infrastructure manager.", e);
}
// atomic remove is important, furthermore we ensure consistent
// trace
writeLock.lock();
try {
removeCurrentNode(nodeName);
logger.debug("Node " + nodeName + " removed. # of current nodes: " + getCurrentNodesSize() + " # of deploying nodes: " + getNbDeployingNodes());
} catch (RuntimeException e) {
logger.error("Exception while removing a node: " + e.getMessage());
throw e;
} finally {
writeLock.unlock();
}
} else {
logger.error("Node " + nodeName + " is not known as a Node belonging to this " + getClass().getSimpleName());
}
}
use of org.ow2.proactive.scheduler.common.job.Job in project scheduling by ow2-proactive.
the class GetJobOutputCommand method execute.
@Override
public void execute(ApplicationContext currentContext) throws CLIException {
SchedulerRestInterface scheduler = currentContext.getRestClient().getScheduler();
try {
String output = null;
if (this.tag == null) {
output = scheduler.jobLogs(currentContext.getSessionId(), jobId);
} else {
output = scheduler.taskLogByTag(currentContext.getSessionId(), jobId, tag);
}
resultStack(currentContext).push(output);
if (!currentContext.isSilent()) {
writeLine(currentContext, "%s", output);
}
} catch (Exception e) {
handleError(String.format("An error occurred while retrieving %s output:", job()), e, currentContext);
}
}
Aggregations