use of org.ow2.proactive.scheduler.common.task.TaskId in project scheduling by ow2-proactive.
the class TestLoadJobsPagination method testPagingAndFilteting.
@Test
public void testPagingAndFilteting() throws Exception {
InternalJob job;
InternalTask task;
// pending job - 1
defaultSubmitJob(createJob());
// job for user1 - 2
defaultSubmitJob(createJob(), "user1");
// running job - 3
job = defaultSubmitJob(createJob());
job.start();
task = startTask(job, job.getITasks().get(0));
dbManager.jobTaskStarted(job, task, true);
// killed job - 4
job = defaultSubmitJob(createJob());
job.failed(null, JobStatus.KILLED);
dbManager.updateAfterJobKilled(job, Collections.<TaskId>emptySet());
// job for user2 - 5
defaultSubmitJob(createJob(), "user2");
// finished job - 6
job = defaultSubmitJob(createJob());
job.start();
task = startTask(job, job.getITasks().get(0));
dbManager.jobTaskStarted(job, task, true);
TaskResultImpl result = new TaskResultImpl(null, new TestResult(0, "result"), null, 0);
job.terminateTask(false, task.getId(), null, null, result);
job.terminate();
dbManager.updateAfterTaskFinished(job, task, new TaskResultImpl(null, new TestResult(0, "result"), null, 0));
// canceled job - 7
job = defaultSubmitJob(createJob());
job.failed(job.getITasks().get(0).getId(), JobStatus.CANCELED);
dbManager.updateAfterJobKilled(job, Collections.<TaskId>emptySet());
// job marked as removed, method 'getJobs' shouldn't return it
job = defaultSubmitJob(createJob());
dbManager.removeJob(job.getId(), System.currentTimeMillis(), false);
List<JobInfo> jobs;
List<SortParameter<JobSortParameter>> sortParameters = new ArrayList<>();
sortParameters.add(new SortParameter<>(JobSortParameter.ID, SortOrder.ASC));
jobs = dbManager.getJobs(5, 1, null, true, true, true, sortParameters).getList();
JobInfo jobInfo = jobs.get(0);
Assert.assertEquals("6", jobInfo.getJobId().value());
Assert.assertEquals(JobStatus.FINISHED, jobInfo.getStatus());
Assert.assertEquals("TestLoadJobsPagination", jobInfo.getJobId().getReadableName());
Assert.assertEquals(1, jobInfo.getTotalNumberOfTasks());
Assert.assertEquals(1, jobInfo.getNumberOfFinishedTasks());
Assert.assertEquals(0, jobInfo.getNumberOfRunningTasks());
Assert.assertEquals(0, jobInfo.getNumberOfPendingTasks());
Assert.assertEquals(JobPriority.NORMAL, jobInfo.getPriority());
Assert.assertEquals(DEFAULT_USER_NAME, jobInfo.getJobOwner());
jobs = dbManager.getJobs(0, 10, null, true, true, true, sortParameters).getList();
checkJobs(jobs, 1, 2, 3, 4, 5, 6, 7);
jobs = dbManager.getJobs(-1, -1, null, true, true, true, sortParameters).getList();
checkJobs(jobs, 1, 2, 3, 4, 5, 6, 7);
jobs = dbManager.getJobs(-1, 5, null, true, true, true, sortParameters).getList();
checkJobs(jobs, 1, 2, 3, 4, 5);
jobs = dbManager.getJobs(2, -1, null, true, true, true, sortParameters).getList();
checkJobs(jobs, 3, 4, 5, 6, 7);
jobs = dbManager.getJobs(0, 0, null, true, true, true, sortParameters).getList();
checkJobs(jobs, 1, 2, 3, 4, 5, 6, 7);
jobs = dbManager.getJobs(0, 1, null, true, true, true, sortParameters).getList();
checkJobs(jobs, 1);
jobs = dbManager.getJobs(0, 3, null, true, true, true, sortParameters).getList();
checkJobs(jobs, 1, 2, 3);
jobs = dbManager.getJobs(1, 10, null, true, true, true, sortParameters).getList();
checkJobs(jobs, 2, 3, 4, 5, 6, 7);
jobs = dbManager.getJobs(5, 10, null, true, true, true, sortParameters).getList();
checkJobs(jobs, 6, 7);
jobs = dbManager.getJobs(6, 10, null, true, true, true, sortParameters).getList();
checkJobs(jobs, 7);
jobs = dbManager.getJobs(7, 10, null, true, true, true, sortParameters).getList();
checkJobs(jobs);
jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, true, true, true, sortParameters).getList();
checkJobs(jobs, 1, 3, 4, 6, 7);
jobs = dbManager.getJobs(0, 10, "user1", true, true, true, sortParameters).getList();
checkJobs(jobs, 2);
jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, true, false, false, sortParameters).getList();
checkJobs(jobs, 1);
jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, false, true, false, sortParameters).getList();
checkJobs(jobs, 3);
jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, false, false, true, sortParameters).getList();
checkJobs(jobs, 4, 6, 7);
jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, false, true, true, sortParameters).getList();
checkJobs(jobs, 3, 4, 6, 7);
jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, true, false, true, sortParameters).getList();
checkJobs(jobs, 1, 4, 6, 7);
jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, true, true, false, sortParameters).getList();
checkJobs(jobs, 1, 3);
jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, false, false, false, sortParameters).getList();
checkJobs(jobs);
}
use of org.ow2.proactive.scheduler.common.task.TaskId in project scheduling by ow2-proactive.
the class TestTaskResultData method testMultipleResults.
@Test
public void testMultipleResults() throws Throwable {
TaskFlowJob job = new TaskFlowJob();
job.addTask(createDefaultTask("task1"));
job.addTask(createDefaultTask("task2"));
job.addTask(createDefaultTask("task3"));
InternalJob internalJob = defaultSubmitJobAndLoadInternal(true, job);
InternalTask task1 = internalJob.getTask("task1");
InternalTask task2 = internalJob.getTask("task2");
InternalTask task3 = internalJob.getTask("task3");
dbManager.updateAfterTaskFinished(internalJob, task1, new TaskResultImpl(null, new TestResult(0, "1_1"), null, 0));
dbManager.updateAfterTaskFinished(internalJob, task1, new TaskResultImpl(null, new TestResult(0, "1_2"), null, 0));
dbManager.updateAfterTaskFinished(internalJob, task1, new TaskResultImpl(null, new TestResult(0, "1_3"), null, 0));
dbManager.updateAfterTaskFinished(internalJob, task2, new TaskResultImpl(null, new TestResult(0, "2_1"), null, 0));
dbManager.updateAfterTaskFinished(internalJob, task2, new TaskResultImpl(null, new TestResult(0, "2_2"), null, 0));
dbManager.updateAfterTaskFinished(internalJob, task2, new TaskResultImpl(null, new TestResult(0, "2_3"), null, 0));
dbManager.updateAfterTaskFinished(internalJob, task3, new TaskResultImpl(null, new TestResult(0, "3_1"), null, 0));
dbManager.updateAfterTaskFinished(internalJob, task3, new TaskResultImpl(null, new TestResult(0, "3_2"), null, 0));
dbManager.updateAfterTaskFinished(internalJob, task3, new TaskResultImpl(null, new TestResult(0, "3_3"), null, 0));
TestResult result;
result = (TestResult) dbManager.loadLastTaskResult(task1.getId()).value();
Assert.assertEquals("1_3", result.getB());
result = (TestResult) dbManager.loadTaskResult(internalJob.getId(), task1.getName(), 0).value();
Assert.assertEquals("1_3", result.getB());
result = (TestResult) dbManager.loadLastTaskResult(task2.getId()).value();
Assert.assertEquals("2_3", result.getB());
result = (TestResult) dbManager.loadTaskResult(internalJob.getId(), task2.getName(), 0).value();
Assert.assertEquals("2_3", result.getB());
result = (TestResult) dbManager.loadLastTaskResult(task3.getId()).value();
Assert.assertEquals("3_3", result.getB());
result = (TestResult) dbManager.loadTaskResult(internalJob.getId(), task3.getName(), 0).value();
Assert.assertEquals("3_3", result.getB());
result = (TestResult) dbManager.loadTaskResult(task2.getId(), 0).value();
Assert.assertEquals("2_3", result.getB());
result = (TestResult) dbManager.loadTaskResult(internalJob.getId(), task2.getName(), 0).value();
Assert.assertEquals("2_3", result.getB());
result = (TestResult) dbManager.loadTaskResult(task2.getId(), 1).value();
Assert.assertEquals("2_2", result.getB());
result = (TestResult) dbManager.loadTaskResult(internalJob.getId(), task2.getName(), 1).value();
Assert.assertEquals("2_2", result.getB());
result = (TestResult) dbManager.loadTaskResult(task2.getId(), 2).value();
Assert.assertEquals("2_1", result.getB());
result = (TestResult) dbManager.loadTaskResult(internalJob.getId(), task2.getName(), 2).value();
Assert.assertEquals("2_1", result.getB());
Assert.assertNull(dbManager.loadTaskResult(task2.getId(), 3));
Assert.assertNull(dbManager.loadTaskResult(internalJob.getId(), task2.getName(), 3));
List<TaskId> taskIds = Arrays.asList(task1.getId(), task2.getId(), task3.getId());
System.out.println("Load results for 3 tasks");
Map<TaskId, TaskResult> results = dbManager.loadTasksResults(internalJob.getId(), taskIds);
Assert.assertEquals(3, results.size());
result = (TestResult) results.get(task1.getId()).value();
Assert.assertEquals("1_3", result.getB());
result = (TestResult) results.get(task2.getId()).value();
Assert.assertEquals("2_3", result.getB());
result = (TestResult) results.get(task3.getId()).value();
Assert.assertEquals("3_3", result.getB());
taskIds = Arrays.asList(task2.getId(), task3.getId());
System.out.println("Load results for 2 tasks");
results = dbManager.loadTasksResults(internalJob.getId(), taskIds);
Assert.assertEquals(2, results.size());
result = (TestResult) results.get(task2.getId()).value();
Assert.assertEquals("2_3", result.getB());
result = (TestResult) results.get(task3.getId()).value();
Assert.assertEquals("3_3", result.getB());
}
use of org.ow2.proactive.scheduler.common.task.TaskId in project scheduling by ow2-proactive.
the class SchedulerDBManagerTest method testGetTaskStates.
@Test
public void testGetTaskStates() throws Throwable {
initExpectedResults("testGetTaskStates-Job", "TEST-TAG");
// no given statuses, no pagination, nothing should come up
crit = TaskFilterCriteria.TFCBuilder.newInstance().running(false).pending(false).finished(false).criterias();
actualPageState = getTaskStates(crit);
assertTaskStatePage(actualPageState, crit);
// all statuses, no pagination, everything should come up
crit = TaskFilterCriteria.TFCBuilder.newInstance().criterias();
actualPageState = getTaskStates(crit);
assertTaskStatePage(actualPageState, crit);
// all statuses, pagination [0,5[
crit = TaskFilterCriteria.TFCBuilder.newInstance().limit(5).criterias();
actualPageState = getTaskStates(crit);
assertTaskStatePage(actualPageState, crit);
// pending tasks only, no pagination
crit = TaskFilterCriteria.TFCBuilder.newInstance().running(false).finished(false).criterias();
actualPageState = getTaskStates(crit);
assertTaskStatePage(actualPageState, crit);
// running tasks only, no pagination
startJob(0);
crit = TaskFilterCriteria.TFCBuilder.newInstance().pending(false).finished(false).criterias();
actualPageState = getTaskStates(crit);
assertTaskStatePage(actualPageState, crit);
// running tasks only, pagination [0,5[
crit = TaskFilterCriteria.TFCBuilder.newInstance().limit(5).pending(false).finished(false).criterias();
actualPageState = getTaskStates(crit);
assertTaskStatePage(actualPageState, crit);
// finished tasks only, no pagination
terminateJob(1, 100L);
crit = TaskFilterCriteria.TFCBuilder.newInstance().pending(false).running(false).criterias();
actualPageState = getTaskStates(crit);
assertTaskStatePage(actualPageState, crit);
// finished tasks only, pagination [0,5[
crit = TaskFilterCriteria.TFCBuilder.newInstance().limit(5).pending(false).running(false).criterias();
actualPageState = getTaskStates(crit);
assertTaskStatePage(actualPageState, crit);
// finished tasks only, dates [0,100], no pagination
crit = TaskFilterCriteria.TFCBuilder.newInstance().from(0).to(100L).pending(false).running(false).criterias();
actualPageState = getTaskStates(crit);
assertTaskStatePage(actualPageState, crit);
// finished tasks only, dates [0,100], pagination [0,5[
crit = TaskFilterCriteria.TFCBuilder.newInstance().from(0).to(100L).offset(0).limit(5).pending(false).running(false).criterias();
actualPageState = getTaskStates(crit);
assertTaskStatePage(actualPageState, crit);
// default parameters, with tag "TEST-TAG"
crit = TaskFilterCriteria.TFCBuilder.newInstance().tag("TEST-TAG").criterias();
actualPageState = getTaskStates(crit);
assertTaskStatePage(actualPageState, crit);
// default parameters, with tag "NON-EXISTENT-TAG"
crit = TaskFilterCriteria.TFCBuilder.newInstance().tag("NON-EXISTENT-TAG").criterias();
actualPageState = getTaskStates(crit);
assertTaskStatePage(actualPageState, crit);
// all statuses, no pagination, everything should come up sorted by taskId
sortParameters = new ArrayList<>();
sortParameters.add(new SortSpecifierContainer("id.taskId,descending"));
crit = TaskFilterCriteria.TFCBuilder.newInstance().sortParameters(sortParameters).criterias();
actualPageState = getTaskStates(crit);
assertTaskStatePage(actualPageState, crit);
}
use of org.ow2.proactive.scheduler.common.task.TaskId in project scheduling by ow2-proactive.
the class SchedulingServiceTest3 method testTaskKill.
@Test
public void testTaskKill() throws Exception {
service.submitJob(createJob(createTestJob(false)));
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(2, jobDesc.getEligibleTasks().size());
for (TaskDescriptor taskDesc : jobDesc.getEligibleTasks()) {
taskStarted(jobDesc, (EligibleTaskDescriptor) taskDesc);
}
service.unlockJobsToSchedule(jobsMap.values());
try {
service.killTask(jobDesc.getJobId(), "invalid task name");
Assert.fail();
} catch (UnknownTaskException e) {
}
try {
service.killTask(JobIdImpl.makeJobId("1234567"), "javaTask");
Assert.fail();
} catch (UnknownJobException e) {
}
Assert.assertTrue(service.killTask(jobDesc.getJobId(), "javaTask"));
listener.assertEvents(SchedulerEvent.JOB_PENDING_TO_RUNNING, SchedulerEvent.JOB_UPDATED, SchedulerEvent.TASK_PENDING_TO_RUNNING, SchedulerEvent.TASK_PENDING_TO_RUNNING, SchedulerEvent.TASK_RUNNING_TO_FINISHED);
infrastructure.assertRequests(1);
Assert.assertFalse(service.killTask(jobDesc.getJobId(), "javaTask"));
TaskId nativeTaskId = ((JobDescriptorImpl) jobDesc).getInternal().getTask("nativeTask").getId();
service.taskTerminatedWithResult(nativeTaskId, new TaskResultImpl(nativeTaskId, new Integer(0), null, 0));
listener.assertEvents(SchedulerEvent.TASK_RUNNING_TO_FINISHED, SchedulerEvent.JOB_RUNNING_TO_FINISHED, SchedulerEvent.JOB_UPDATED);
infrastructure.assertRequests(1);
try {
service.killTask(jobDesc.getJobId(), "javaTask");
} catch (UnknownJobException e) {
Assert.fail("The job should still exist in the memory context as the auto Job removal feature isn't enabled");
}
}
use of org.ow2.proactive.scheduler.common.task.TaskId in project scheduling by ow2-proactive.
the class TerminateNotificationTest method testTerminate.
@Test
public void testTerminate() throws TerminateTaskException {
TaskId taskId = TaskIdImpl.createTaskId(new JobIdImpl(666, "readableName"), "task-name", 777L);
TaskResult taskResult = new TaskResultImpl(taskId, new Throwable());
terminateNotification.terminate(taskId, taskResult);
Mockito.verify(schedulingService, Mockito.times(1)).taskTerminatedWithResult(taskId, taskResult);
}
Aggregations