use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.
the class InternalJobFactory method createTask.
/**
* Create an internal native Task with the given native task (user)
*
* @param task the user native task that will be used to create the internal native task.
* @return the created internal task.
* @throws JobCreationException an exception if the factory cannot create the given task.
*/
private static InternalTask createTask(Job userJob, InternalJob internalJob, NativeTask task) throws JobCreationException {
if (((task.getCommandLine() == null) || (task.getCommandLine().length == 0))) {
String msg = "The command line is null or empty and not generated !";
logger.info(msg);
throw new JobCreationException(msg);
}
try {
String commandAndArguments = "\"" + Joiner.on("\" \"").join(task.getCommandLine()) + "\"";
InternalTask scriptTask;
if (isForkingTask()) {
scriptTask = new InternalForkedScriptTask(new ScriptExecutableContainer(new TaskScript(new SimpleScript(commandAndArguments, "native"))), internalJob);
configureRunAsMe(task);
} else {
scriptTask = new InternalScriptTask(new ScriptExecutableContainer(new TaskScript(new SimpleScript(commandAndArguments, "native"))), internalJob);
}
ForkEnvironment forkEnvironment = new ForkEnvironment();
scriptTask.setForkEnvironment(forkEnvironment);
// set task common properties
setTaskCommonProperties(userJob, task, scriptTask);
return scriptTask;
} catch (Exception e) {
throw new JobCreationException(e);
}
}
use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.
the class InternalJobFactory method createTask.
/**
* Create an internal java Task with the given java task (user)
*
* @param task the user java task that will be used to create the internal java task.
* @return the created internal task.
* @throws JobCreationException an exception if the factory cannot create the given task.
*/
@SuppressWarnings("unchecked")
private static InternalTask createTask(Job userJob, InternalJob internalJob, JavaTask task) throws JobCreationException {
InternalTask javaTask;
if (task.getExecutableClassName() != null) {
HashMap<String, byte[]> args = task.getSerializedArguments();
try {
if (isForkingTask()) {
javaTask = new InternalForkedScriptTask(new ScriptExecutableContainer(new TaskScript(new SimpleScript(task.getExecutableClassName(), JavaClassScriptEngineFactory.JAVA_CLASS_SCRIPT_ENGINE_NAME, new Serializable[] { args }))), internalJob);
javaTask.setForkEnvironment(task.getForkEnvironment());
configureRunAsMe(task);
} else {
javaTask = new InternalScriptTask(new ScriptExecutableContainer(new TaskScript(new SimpleScript(task.getExecutableClassName(), JavaClassScriptEngineFactory.JAVA_CLASS_SCRIPT_ENGINE_NAME, new Serializable[] { args }))), internalJob);
}
} catch (InvalidScriptException e) {
throw new JobCreationException(e);
}
} else {
String msg = "You must specify your own executable task class to be launched (in every task)!";
logger.info(msg);
throw new JobCreationException(msg);
}
// set task common properties
try {
setTaskCommonProperties(userJob, task, javaTask);
} catch (Exception e) {
throw new JobCreationException(e);
}
return javaTask;
}
use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.
the class SchedulerStateRecoverHelperTest method testRecoverWithCopyAndSortThrowingRuntimeException.
@Test
public void testRecoverWithCopyAndSortThrowingRuntimeException() throws KeyException, JobCreationException {
RecoveredSchedulerState recoveredState = new Scenario(createJob(JobStatus.RUNNING)).execute(new SchedulerStateRecoverHelperSupplier() {
@Override
public SchedulerStateRecoverHelper get(SchedulerDBManager dbManager) {
return new SchedulerStateRecoverHelper(dbManager) {
@Override
protected List<InternalTask> copyAndSort(List<InternalTask> tasks) {
throw new RuntimeException("bouh!");
}
};
}
}, false);
assertThat(recoveredState.getFinishedJobs()).hasSize(1);
assertThat(recoveredState.getPendingJobs()).hasSize(0);
assertThat(recoveredState.getRunningJobs()).hasSize(0);
assertThat(recoveredState.getFinishedJobs().get(0).getStatus()).isEqualTo(JobStatus.CANCELED);
}
use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.
the class SchedulerFrontend method submit.
/**
* {@inheritDoc}
*/
@Override
@ImmediateService
public JobId submit(Job userJob) throws NotConnectedException, PermissionException, SubmissionClosedException, JobCreationException {
try {
if (logger.isDebugEnabled()) {
logger.debug("New job submission requested : " + userJob.getName());
}
// check if the scheduler is stopped
if (!schedulingService.isSubmitPossible()) {
String msg = "Scheduler is stopped, cannot submit job";
logger.info(msg);
throw new SubmissionClosedException(msg);
}
UserIdentificationImpl ident = frontendState.checkPermission("submit", YOU_DO_NOT_HAVE_PERMISSION_TO_SUBMIT_A_JOB);
InternalJob job = frontendState.createJob(userJob, ident);
schedulingService.submitJob(job);
frontendState.jobSubmitted(job, ident);
return job.getId();
} catch (Exception e) {
logger.warn("Error when submitting job.", e);
throw e;
}
}
use of org.ow2.proactive.scheduler.common.exception.JobCreationException in project scheduling by ow2-proactive.
the class SchedulerFrontendState method createJob.
synchronized InternalJob createJob(Job userJob, UserIdentificationImpl ident) throws NotConnectedException, PermissionException, SubmissionClosedException, JobCreationException {
UniqueID id = checkAccess();
// get the internal job.
InternalJob job = InternalJobFactory.createJob(userJob, this.credentials.get(id));
// setting job informations
if (job.getTasks().size() == 0) {
String msg = "Job " + job.getId().value() + " contains no task. You need to insert at least one task before submitting job";
logger.info(msg);
throw new JobCreationException(msg);
}
// job.
try {
ident.checkPermission(new ChangePriorityPermission(job.getPriority().ordinal()), ident.getUsername() + " does not have rights to set job priority " + job.getPriority());
} catch (PermissionException ex) {
logger.info(ex.getMessage());
throw ex;
}
// setting the job properties
job.setOwner(ident.getUsername());
return job;
}
Aggregations