use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.
the class StaxJobFactory method createParallelEnvironment.
/**
* Creates the parallel environment from the xml descriptor.
*/
private ParallelEnvironment createParallelEnvironment(XMLStreamReader cursorTask, Map<String, String> variables) throws JobCreationException {
int event = -1;
int nodesNumber = 0;
TopologyDescriptor topologyDescriptor = null;
// parallelEnvironment -> <topology>
try {
// cursor is parallelEnvironment
for (int i = 0; i < cursorTask.getAttributeCount(); i++) {
String attrName = cursorTask.getAttributeLocalName(i);
if (XMLAttributes.TASK_NB_NODES.matches(attrName)) {
String value = replace(cursorTask.getAttributeValue(i), variables);
nodesNumber = Integer.parseInt(value);
}
}
while (cursorTask.hasNext()) {
event = cursorTask.next();
if (event == XMLEvent.START_ELEMENT) {
break;
} else if (event == XMLEvent.END_ELEMENT && XMLTags.PARALLEL_ENV.matches(cursorTask.getLocalName())) {
return new ParallelEnvironment(nodesNumber, TopologyDescriptor.ARBITRARY);
}
}
if (XMLTags.TOPOLOGY.matches(cursorTask.getLocalName())) {
// topology element found
while (cursorTask.hasNext()) {
event = cursorTask.next();
if (event == XMLEvent.START_ELEMENT) {
break;
} else if (event == XMLEvent.END_ELEMENT && XMLTags.TOPOLOGY.matches(cursorTask.getLocalName())) {
throw new RuntimeException("Incorrect topology description");
}
}
// arbitrary : no attributes
if (XMLTags.TOPOLOGY_ARBITRARY.matches(cursorTask.getLocalName())) {
topologyDescriptor = TopologyDescriptor.ARBITRARY;
} else // bestProximity : no attributes
if (XMLTags.TOPOLOGY_BEST_PROXIMITY.matches(cursorTask.getLocalName())) {
topologyDescriptor = TopologyDescriptor.BEST_PROXIMITY;
} else // thresholdProximity : elements threshold
if (XMLTags.TOPOLOGY_THRESHOLD_PROXIMITY.matches(cursorTask.getLocalName())) {
// attribute threshold
for (int i = 0; i < cursorTask.getAttributeCount(); i++) {
String attrName = cursorTask.getAttributeLocalName(i);
if (XMLAttributes.TOPOLOGY_THRESHOLD.matches(attrName)) {
String value = replace(cursorTask.getAttributeValue(i), variables);
long threshold = Long.parseLong(value);
topologyDescriptor = new ThresholdProximityDescriptor(threshold);
}
}
} else // singleHost : no attributes
if (XMLTags.TOPOLOGY_SINGLE_HOST.matches(cursorTask.getLocalName())) {
topologyDescriptor = TopologyDescriptor.SINGLE_HOST;
} else // singleHostExclusive : no attributes
if (XMLTags.TOPOLOGY_SINGLE_HOST_EXCLUSIVE.matches(cursorTask.getLocalName())) {
topologyDescriptor = TopologyDescriptor.SINGLE_HOST_EXCLUSIVE;
} else // multipleHostsExclusive : no attributes
if (XMLTags.TOPOLOGY_MULTIPLE_HOSTS_EXCLUSIVE.matches(cursorTask.getLocalName())) {
topologyDescriptor = TopologyDescriptor.MULTIPLE_HOSTS_EXCLUSIVE;
} else // oneNodePerHostHostsExclusive : no attributes
if (XMLTags.TOPOLOGY_DIFFERENT_HOSTS_EXCLUSIVE.matches(cursorTask.getLocalName())) {
topologyDescriptor = TopologyDescriptor.DIFFERENT_HOSTS_EXCLUSIVE;
}
}
} catch (Exception e) {
throw new JobCreationException(XMLTags.TOPOLOGY.getXMLName(), null, e);
}
return new ParallelEnvironment(nodesNumber, topologyDescriptor);
}
use of org.ow2.proactive.scheduler.common.exception.JobCreationException 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.exception.JobCreationException in project scheduling by ow2-proactive.
the class SchedulerClient method submit.
@Override
public JobId submit(URL job, Map<String, String> variables, Map<String, String> requestHeaderParams) throws NotConnectedException, PermissionException, SubmissionClosedException, JobCreationException {
JobIdData jobIdData = null;
try {
URLConnection urlConnection = job.openConnection();
for (Map.Entry<String, String> requestHeaderEntry : requestHeaderParams.entrySet()) {
urlConnection.addRequestProperty(requestHeaderEntry.getKey(), requestHeaderEntry.getValue());
}
InputStream is = urlConnection.getInputStream();
jobIdData = restApiClient().submitXml(sid, is, variables);
} catch (Exception e) {
throwNCEOrPEOrSCEOrJCE(e);
}
return jobId(jobIdData);
}
use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.
the class SchedulerClient method submitFromCatalog.
@Override
public JobId submitFromCatalog(String catalogRestURL, String bucketName, String workflowName, Map<String, String> variables) throws NotConnectedException, PermissionException, SubmissionClosedException, JobCreationException {
JobIdData jobIdData = null;
HttpGet httpGet = new HttpGet(catalogRestURL + "/buckets/" + bucketName + "/resources/" + workflowName + "/raw");
httpGet.addHeader("sessionid", sid);
try (CloseableHttpClient httpclient = HttpClients.createDefault();
CloseableHttpResponse response = httpclient.execute(httpGet)) {
jobIdData = restApiClient().submitXml(sid, response.getEntity().getContent(), variables);
} catch (Exception e) {
throwNCEOrPEOrSCEOrJCE(e);
}
return jobId(jobIdData);
}
use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.
the class ValidationUtil method validate.
/**
* Validates the job descriptor file against the specified schema.
*
* @param jobFile
* the job descriptor file
* @param schemaIs
* the job schema
*
* @throws JobCreationException
* if the job descriptor is invalid
*/
public static void validate(File jobFile, InputStream schemaIs) throws SAXException, IOException, JobCreationException {
try {
XMLReader reader = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
VerifierFactory vfactory = new com.sun.msv.verifier.jarv.TheFactoryImpl();
Schema schema = vfactory.compileSchema(schemaIs);
Verifier verifier = schema.newVerifier();
VerifierHandler handler = verifier.getVerifierHandler();
ContentHandlerDecorator contentHandlerDecorator = new ContentHandlerDecorator(handler);
reader.setContentHandler(contentHandlerDecorator);
ValidationErrorHandler errHandler = new ValidationErrorHandler(contentHandlerDecorator);
verifier.setErrorHandler(errHandler);
reader.parse(jobFile.getAbsolutePath());
} catch (SAXException se) {
Throwable cause = se.getCause();
if (cause != null && cause instanceof JobCreationException) {
// unwrap
throw (JobCreationException) cause;
} else {
throw se;
}
} catch (VerifierConfigurationException e) {
throw new IllegalStateException(e);
}
}
Aggregations