Search in sources :

Example 26 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 27 with JobCreationException

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

the class FlatJobFactory method createNativeJobFromCommand.

/**
 * Creates a job from a String representing a native command to launch. So job in result is made
 * of one native task.
 *
 * @param command a string representing an executable command to launch.
 * @param jobName A String representing a name to give to the job, if null. default job name is made of
 * {link FlatJobFactory#JOB_DEFAULT_NAME_PREFIX} + userName parameter.
 * @param selectionScriptPath A Path to a file containing a selection script, or null if
 * no script is needed.
 * @param userName name of connected user that asked job creation, null otherwise. This parameter
 * is just used for default job's name creation.
 * @return a job object representing created job and ready-to-schedule job.
 * @throws JobCreationException with a relevant error message if an error occurs.
 */
public Job createNativeJobFromCommand(String command, String jobName, String selectionScriptPath, String userName) throws JobCreationException {
    if (command == null || "".equalsIgnoreCase(command)) {
        throw new JobCreationException("Error, command cannot be null");
    }
    if (jobName == null) {
        jobName = JOB_DEFAULT_NAME_PREFIX + userName;
    }
    Job nativeJob = new TaskFlowJob();
    nativeJob.setName(jobName);
    logger.debug("Job : " + nativeJob.getName());
    try {
        NativeTask t = createNativeTaskFromCommandString(command, "task1", selectionScriptPath);
        t.setPreciousResult(true);
        ((TaskFlowJob) nativeJob).addTask(t);
        logger.debug("-> Task Name = " + t.getName());
        logger.debug("-> command = " + t.getCommandLine() + "\n");
    } catch (Exception e) {
        throw new JobCreationException(e);
    }
    return nativeJob;
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) Job(org.ow2.proactive.scheduler.common.job.Job) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException)

Example 28 with JobCreationException

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

the class FlatJobFactory method createNativeJobFromCommandsFile.

/**
 * Create a job from a String representing file path, this text file contains native commands to launch
 * Every line of the text file is taken and considered as a native command from which a native task is built,
 * except lines beginning with {@link FlatJobFactory#JOB_DEFAULT_NAME_PREFIX} and empty lines.
 * So job in result is made of several native tasks without dependencies.
 *
 * @param commandFilePath a string representing a text file containing native commands.
 * @param jobName A String representing a name to give to the job. If null, default job name is made of
 * {@link FlatJobFactory#JOB_DEFAULT_NAME_PREFIX} + userName parameter.
 * @param selectionScriptPath a Path to a file containing a selection script, or null if
 * no script is needed.
 * @param userName name of connected user that asked job creation, null otherwise. This parameter
 * is only used for default job's name creation.
 * @return a job object representing created job and ready-to-schedule job.
 * @throws JobCreationException with a relevant error message if an error occurs.
 */
public Job createNativeJobFromCommandsFile(String commandFilePath, String jobName, String selectionScriptPath, String userName) throws JobCreationException {
    if (jobName == null) {
        jobName = JOB_DEFAULT_NAME_PREFIX + userName;
    }
    Job nativeJob = new TaskFlowJob();
    nativeJob.setName(jobName);
    logger.debug("Job : " + nativeJob.getName());
    try {
        File commandFile = new File(commandFilePath);
        if (!commandFile.isFile()) {
            throw new JobCreationException("Error occured during Job creation, " + "check that file " + commandFilePath + " exists and is a readable file");
        }
        String commandLine;
        int task_number = 0;
        ArrayList<String> commandList = new ArrayList<>();
        try (BufferedReader reader = new BufferedReader(new FileReader(commandFile))) {
            while ((commandLine = reader.readLine()) != null) {
                commandLine = commandLine.trim();
                if (!commandLine.startsWith(CMD_FILE_COMMENT_CHAR, 0) && !"".equals(commandLine)) {
                    commandList.add(commandLine);
                }
            }
        }
        if (commandList.size() == 0) {
            throw new JobCreationException("Error occured during Job creation, " + "No any valid command line has been built from" + commandFilePath + "");
        }
        // compute padding for task number
        int numberOfDigit = Integer.toString(commandList.size()).length();
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumIntegerDigits(numberOfDigit);
        nf.setMinimumIntegerDigits(numberOfDigit);
        for (String command : commandList) {
            NativeTask t = createNativeTaskFromCommandString(command, "task_" + (nf.format(++task_number)), selectionScriptPath);
            t.setPreciousResult(true);
            ((TaskFlowJob) nativeJob).addTask(t);
            logger.debug("-> Task Name = " + t.getName());
            logger.debug("-> command = " + t.getCommandLine() + "\n");
        }
    } catch (Exception e) {
        throw new JobCreationException(e);
    }
    return nativeJob;
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) ArrayList(java.util.ArrayList) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Job(org.ow2.proactive.scheduler.common.job.Job) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) File(java.io.File) NumberFormat(java.text.NumberFormat)

Example 29 with JobCreationException

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

the class StaxJobFactory method getDescription.

/**
 * Get the description of the entity.
 * Leave the method with the cursor at the end of 'ELEMENT_COMMON_DESCRIPTION' tag.
 *
 * @param cursorVariables the streamReader with the cursor on the 'ELEMENT_COMMON_DESCRIPTION' tag.
 * @return the description between the tags.
 */
private String getDescription(XMLStreamReader cursorVariables, Map<String, String> variables) throws JobCreationException {
    try {
        String description = "";
        // if description tag exists, then we have a characters event next.
        int eventType = cursorVariables.next();
        if (eventType == XMLEvent.CHARACTERS) {
            description = replace(cursorVariables.getText(), variables);
        } else if (eventType == XMLEvent.END_ELEMENT) {
            return description;
        }
        // go to the description END_ELEMENT
        while (cursorVariables.next() != XMLEvent.END_ELEMENT) ;
        return description;
    } catch (JobCreationException jce) {
        throw jce;
    } catch (Exception e) {
        throw new JobCreationException((String) null, null, e);
    }
}
Also used : 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 30 with JobCreationException

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

the class StaxJobFactory method validate.

/*
     * Validate the given job descriptor
     */
private File validate(File file) throws VerifierConfigurationException, JobCreationException {
    Map<String, JobValidatorService> factories;
    try {
        factories = JobValidatorRegistry.getInstance().getRegisteredFactories();
    } catch (Exception e) {
        logger.error(MSG_UNABLE_TO_INSTANCIATE_JOB_VALIDATION_FACTORIES, e);
        throw new VerifierConfigurationException(MSG_UNABLE_TO_INSTANCIATE_JOB_VALIDATION_FACTORIES, e);
    }
    File updatedFile = file;
    try {
        for (JobValidatorService factory : factories.values()) {
            updatedFile = factory.validateJob(updatedFile);
        }
    } catch (JobValidationException e) {
        throw e;
    } catch (Exception e) {
        throw new JobValidationException(true, e);
    }
    return updatedFile;
}
Also used : JobValidatorService(org.ow2.proactive.scheduler.common.job.factories.spi.JobValidatorService) VerifierConfigurationException(org.iso_relax.verifier.VerifierConfigurationException) File(java.io.File) JobValidationException(org.ow2.proactive.scheduler.common.exception.JobValidationException) 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)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