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);
}
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations