Search in sources :

Example 1 with JobCreationException

use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.

the class SchedulerFrontendState method jobSubmitted.

synchronized void jobSubmitted(InternalJob job, UserIdentificationImpl ident) throws NotConnectedException, PermissionException, SubmissionClosedException, JobCreationException {
    // put the job inside the frontend management list
    jobs.put(job.getId(), new IdentifiedJob(job.getId(), ident, job.getGenericInformation()));
    // increase number of submit for this user
    ident.addSubmit();
    // send update user event
    usersUpdated(new NotificationData<UserIdentification>(SchedulerEvent.USERS_UPDATE, ident));
    jlogger.info(job.getId(), "submitted: name '" + job.getName() + "', tasks '" + job.getTotalNumberOfTasks() + "', owner '" + job.getOwner() + "'");
    try {
        jlogger.info(job.getId(), job.display());
    } catch (Exception e) {
        jlogger.error(job.getId(), "Error while displaying the job :", e);
    }
}
Also used : IdentifiedJob(org.ow2.proactive.scheduler.job.IdentifiedJob) UserIdentification(org.ow2.proactive.scheduler.common.job.UserIdentification) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) JobAlreadyFinishedException(org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) AlreadyConnectedException(org.ow2.proactive.scheduler.common.exception.AlreadyConnectedException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) IOException(java.io.IOException) SchedulerException(org.ow2.proactive.scheduler.common.exception.SchedulerException)

Example 2 with JobCreationException

use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.

the class SchedulerStateRest method submitFlat.

/**
 * Submit job using flat command file
 *
 * @param sessionId
 *            valid session id
 * @param commandFileContent
 *            content of a command file: endline separated native commands
 * @param jobName
 *            name of the job to create
 * @param selectionScriptContent
 *            content of a selection script, or null
 * @param selectionScriptExtension
 *            extension of the selectionscript to determine script engine
 *            ("js", "py", "rb")
 * @return Id of the submitted job
 * @throws NotConnectedRestException
 * @throws IOException
 * @throws JobCreationRestException
 * @throws PermissionRestException
 * @throws SubmissionClosedRestException
 */
@Override
@POST
@Path("submitflat")
@Produces("application/json")
public JobIdData submitFlat(@HeaderParam("sessionid") String sessionId, @FormParam("commandFileContent") String commandFileContent, @FormParam("jobName") String jobName, @FormParam("selectionScriptContent") String selectionScriptContent, @FormParam("selectionScriptExtension") String selectionScriptExtension) throws NotConnectedRestException, IOException, JobCreationRestException, PermissionRestException, SubmissionClosedRestException {
    Scheduler s = checkAccess(sessionId, "submitflat");
    try {
        File command = File.createTempFile("flatsubmit_commands_", ".txt");
        command.deleteOnExit();
        String selectionPath = null;
        File selection = null;
        if (selectionScriptContent != null && selectionScriptContent.trim().length() > 0) {
            selection = File.createTempFile("flatsubmit_selection_", "." + selectionScriptExtension);
            selection.deleteOnExit();
            try (PrintWriter pw = new PrintWriter(new FileOutputStream(selection))) {
                pw.print(selectionScriptContent);
            }
            selectionPath = selection.getAbsolutePath();
        }
        try (PrintWriter pw = new PrintWriter(new FileOutputStream(command))) {
            pw.print(commandFileContent);
        }
        Job j = FlatJobFactory.getFactory().createNativeJobFromCommandsFile(command.getAbsolutePath(), jobName, selectionPath, null);
        JobId id = s.submit(j);
        command.delete();
        if (selection != null) {
            selection.delete();
        }
        return mapper.map(id, JobIdData.class);
    } catch (IOException e) {
        throw new IOException("I/O Error: " + e.getMessage(), e);
    } catch (JobCreationException e) {
        throw new JobCreationRestException(e);
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    } catch (SubmissionClosedException e) {
        throw new SubmissionClosedRestException(e);
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) IOException(java.io.IOException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException) JobCreationRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.JobCreationRestException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) FileOutputStream(java.io.FileOutputStream) SubmissionClosedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SubmissionClosedRestException) Job(org.ow2.proactive.scheduler.common.job.Job) File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId) PrintWriter(java.io.PrintWriter) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 3 with JobCreationException

use of org.ow2.proactive.scheduler.common.exception.JobCreationException 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);
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) Job(org.ow2.proactive.scheduler.common.job.Job) 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 4 with JobCreationException

use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.

the class StaxJobFactory method createTaskVariables.

/**
 * 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.
 * @return the map in which the variables were added.
 * @throws JobCreationException
 */
private Map<String, TaskVariable> createTaskVariables(XMLStreamReader cursorVariables, Map<String, String> variables) throws JobCreationException {
    Map<String, TaskVariable> variablesMap = new HashMap<>();
    try {
        int eventType;
        while (cursorVariables.hasNext()) {
            eventType = cursorVariables.next();
            if (eventType == XMLEvent.START_ELEMENT && XMLTags.VARIABLE.matches(cursorVariables.getLocalName())) {
                TaskVariable taskVariable = getTaskVariable(cursorVariables, variables);
                variablesMap.put(taskVariable.getName(), taskVariable);
            } else if (eventType == XMLEvent.END_ELEMENT && XMLTags.VARIABLES.matches(cursorVariables.getLocalName())) {
                return variablesMap;
            }
        }
    } 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;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TaskVariable(org.ow2.proactive.scheduler.common.task.TaskVariable) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) 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 5 with JobCreationException

use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.

the class StaxJobFactory method fillJobWithTasks.

/**
 * Fill the created Job with coming tasks..
 * Leave the method with the cursor at the end of the file (nothing more has to be parsed).
 *
 * @param cursorTask the streamReader with the cursor on the first 'ELEMENT_TASK' tag.
 */
private void fillJobWithTasks(XMLStreamReader cursorTask, Job job, Map<String, ArrayList<String>> dependencies) throws JobCreationException {
    if (job == null) {
        throw new JobCreationException(XMLTags.JOB.getXMLName(), null, null);
    }
    XMLTags current = null;
    try {
        int eventType = -1;
        while (cursorTask.hasNext()) {
            // if use to keep the cursor on the task tag for the first loop
            if (eventType == -1) {
                eventType = cursorTask.getEventType();
            } else {
                eventType = cursorTask.next();
            }
            if (eventType == XMLEvent.START_ELEMENT && XMLTags.TASK.matches(cursorTask.getLocalName())) {
                Task t;
                switch(job.getType()) {
                    case TASKSFLOW:
                        current = XMLTags.TASK;
                        // create new task
                        t = createTask(cursorTask, job, dependencies);
                        // add task to the job
                        ((TaskFlowJob) job).addTask(t);
                        break;
                    case PARAMETER_SWEEPING:
                        current = XMLTags.TASK;
                        throw new RuntimeException("Job parameter sweeping is not yet implemented!");
                    default:
                }
            }
        }
    } catch (JobCreationException jce) {
        jce.pushTag(current);
        throw jce;
    } catch (Exception e) {
        throw new JobCreationException(current, null, e);
    }
}
Also used : Task(org.ow2.proactive.scheduler.common.task.Task) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) 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)

Aggregations

JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)51 JobValidationException (org.ow2.proactive.scheduler.common.exception.JobValidationException)30 FileNotFoundException (java.io.FileNotFoundException)29 XMLStreamException (javax.xml.stream.XMLStreamException)29 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)25 IOException (java.io.IOException)24 LinkedHashMap (java.util.LinkedHashMap)16 Job (org.ow2.proactive.scheduler.common.job.Job)16 VerifierConfigurationException (org.iso_relax.verifier.VerifierConfigurationException)12 HashMap (java.util.HashMap)11 Test (org.junit.Test)10 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)9 GlobalVariablesParserTest (org.ow2.proactive.scheduler.common.job.factories.globalvariables.GlobalVariablesParserTest)9 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)8 SubmissionClosedException (org.ow2.proactive.scheduler.common.exception.SubmissionClosedException)8 JobVariable (org.ow2.proactive.scheduler.common.job.JobVariable)8 NativeTask (org.ow2.proactive.scheduler.common.task.NativeTask)8 ArrayList (java.util.ArrayList)7 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)7 Task (org.ow2.proactive.scheduler.common.task.Task)7