Search in sources :

Example 11 with JobCreationException

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);
}
Also used : ParallelEnvironment(org.ow2.proactive.scheduler.common.task.ParallelEnvironment) ThresholdProximityDescriptor(org.ow2.proactive.topology.descriptor.ThresholdProximityDescriptor) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) TopologyDescriptor(org.ow2.proactive.topology.descriptor.TopologyDescriptor) XMLStreamException(javax.xml.stream.XMLStreamException) JobValidationException(org.ow2.proactive.scheduler.common.exception.JobValidationException) FileNotFoundException(java.io.FileNotFoundException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) VerifierConfigurationException(org.iso_relax.verifier.VerifierConfigurationException)

Example 12 with JobCreationException

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;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 13 with JobCreationException

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);
}
Also used : JobIdData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobIdData) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Map(java.util.Map) AbstractMap(java.util.AbstractMap) URLConnection(java.net.URLConnection) KeyException(java.security.KeyException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) SchedulerRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) IOException(java.io.IOException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) TimeoutException(java.util.concurrent.TimeoutException) JobAlreadyFinishedException(org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException)

Example 14 with JobCreationException

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);
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) JobIdData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobIdData) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) KeyException(java.security.KeyException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) SchedulerRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) IOException(java.io.IOException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) TimeoutException(java.util.concurrent.TimeoutException) JobAlreadyFinishedException(org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException)

Example 15 with JobCreationException

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);
    }
}
Also used : VerifierFactory(org.iso_relax.verifier.VerifierFactory) VerifierHandler(org.iso_relax.verifier.VerifierHandler) Schema(org.iso_relax.verifier.Schema) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) Verifier(org.iso_relax.verifier.Verifier) VerifierConfigurationException(org.iso_relax.verifier.VerifierConfigurationException) SAXException(org.xml.sax.SAXException) XMLReader(org.xml.sax.XMLReader)

Aggregations

JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)37 VerifierConfigurationException (org.iso_relax.verifier.VerifierConfigurationException)21 FileNotFoundException (java.io.FileNotFoundException)20 XMLStreamException (javax.xml.stream.XMLStreamException)20 JobValidationException (org.ow2.proactive.scheduler.common.exception.JobValidationException)20 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)13 LinkedHashMap (java.util.LinkedHashMap)10 HashMap (java.util.HashMap)9 Job (org.ow2.proactive.scheduler.common.job.Job)9 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)8 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)7 SubmissionClosedException (org.ow2.proactive.scheduler.common.exception.SubmissionClosedException)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 JobAlreadyFinishedException (org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException)6 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)6 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)6 InvalidScriptException (org.ow2.proactive.scripting.InvalidScriptException)6 File (java.io.File)5 IOException (java.io.IOException)5