use of org.ow2.proactive.scheduler.common.JobDescriptor in project scheduling by ow2-proactive.
the class BaseServiceTest method taskStarted.
void taskStarted(JobDescriptor jobDesc, EligibleTaskDescriptor taskDesc) throws Exception {
InternalTask task = ((EligibleTaskDescriptorImpl) taskDesc).getInternal();
TaskLauncher launcher = Mockito.mock(TaskLauncher.class);
task.setExecuterInformation(new ExecuterInformation(launcher, NodeFactory.getDefaultNode()));
service.taskStarted(((JobDescriptorImpl) jobDesc).getInternal(), task, launcher);
}
use of org.ow2.proactive.scheduler.common.JobDescriptor in project scheduling by ow2-proactive.
the class SchedulingServiceTest1 method testSimpleJob.
@Test
public void testSimpleJob() throws Exception {
service.submitJob(createJob(createTestJob()));
listener.assertEvents(SchedulerEvent.JOB_SUBMITTED);
Map<JobId, JobDescriptor> jobsMap;
JobDescriptor jobDesc;
jobsMap = service.lockJobsToSchedule();
assertEquals(1, jobsMap.size());
jobDesc = jobsMap.values().iterator().next();
Assert.assertEquals(1, jobDesc.getEligibleTasks().size());
taskStarted(jobDesc, (EligibleTaskDescriptor) jobDesc.getEligibleTasks().iterator().next());
service.unlockJobsToSchedule(jobsMap.values());
jobsMap = service.lockJobsToSchedule();
assertEquals(1, jobsMap.size());
jobDesc = jobsMap.values().iterator().next();
Assert.assertEquals(0, jobDesc.getEligibleTasks().size());
service.unlockJobsToSchedule(jobsMap.values());
TaskId taskId = ((JobDescriptorImpl) jobDesc).getInternal().getTask("task1").getId();
service.taskTerminatedWithResult(taskId, new TaskResultImpl(taskId, "Result", null, 0));
jobsMap = service.lockJobsToSchedule();
// when a job finishes, it isn't removed from the hibernate context unless
// the housekeeping mechanism is enabled
assertEquals(1, jobsMap.size());
listener.assertEvents(SchedulerEvent.JOB_PENDING_TO_RUNNING, SchedulerEvent.JOB_UPDATED, SchedulerEvent.TASK_PENDING_TO_RUNNING, SchedulerEvent.TASK_RUNNING_TO_FINISHED, SchedulerEvent.JOB_RUNNING_TO_FINISHED, SchedulerEvent.JOB_UPDATED);
infrastructure.assertRequests(1);
}
use of org.ow2.proactive.scheduler.common.JobDescriptor in project scheduling by ow2-proactive.
the class SchedulingServiceTest4 method testTaskRestart1.
@Test
public void testTaskRestart1() throws Exception {
service.submitJob(createJob(createTestJob()));
listener.assertEvents(SchedulerEvent.JOB_SUBMITTED);
JobDescriptor jobDesc = startTask();
try {
service.restartTask(jobDesc.getJobId(), "invalid task name", 100);
Assert.fail();
} catch (UnknownTaskException e) {
}
try {
service.restartTask(JobIdImpl.makeJobId("1234567"), "javaTask", 100);
Assert.fail();
} catch (UnknownJobException e) {
}
service.restartTask(jobDesc.getJobId(), "javaTask", 100);
listener.assertEvents(SchedulerEvent.JOB_PENDING_TO_RUNNING, SchedulerEvent.JOB_UPDATED, SchedulerEvent.TASK_PENDING_TO_RUNNING, SchedulerEvent.TASK_WAITING_FOR_RESTART);
infrastructure.assertRequests(1);
startTask();
TaskId taskId = ((JobDescriptorImpl) jobDesc).getInternal().getTask("javaTask").getId();
service.taskTerminatedWithResult(taskId, new TaskResultImpl(taskId, "OK", null, 0));
listener.assertEvents(SchedulerEvent.TASK_PENDING_TO_RUNNING, SchedulerEvent.TASK_RUNNING_TO_FINISHED, SchedulerEvent.JOB_RUNNING_TO_FINISHED, SchedulerEvent.JOB_UPDATED);
infrastructure.assertRequests(1);
}
use of org.ow2.proactive.scheduler.common.JobDescriptor in project scheduling by ow2-proactive.
the class SchedulerFrontend method getTasksToSchedule.
@Override
public List<TaskDescriptor> getTasksToSchedule() throws NotConnectedException, PermissionException {
Policy policy = null;
List<TaskDescriptor> eligibleTasks = new ArrayList<>();
Map<JobId, JobDescriptor> jobMap = null;
try {
jobMap = schedulingService.lockJobsToSchedule();
policy = (Policy) Class.forName(getCurrentPolicy()).newInstance();
// we wait for next scheduling loop
if (jobMap.isEmpty()) {
return eligibleTasks;
}
List<JobDescriptor> descriptors = new ArrayList<>(jobMap.values());
LinkedList<EligibleTaskDescriptor> taskRetrievedFromPolicy = policy.getOrderedTasks(descriptors);
// if there is no task to scheduled, return
if (taskRetrievedFromPolicy.isEmpty()) {
return eligibleTasks;
}
eligibleTasks = (List) taskRetrievedFromPolicy;
} catch (Exception e) {
logger.error("Error Loading Current Policy:", e);
} finally {
schedulingService.unlockJobsToSchedule(jobMap.values());
}
return eligibleTasks;
}
Aggregations