use of org.ow2.proactive.scheduler.common.job.JobInfo in project scheduling by ow2-proactive.
the class SchedulerTHelper method cleanJobs.
public void cleanJobs() throws Exception {
Scheduler userInt = getSchedulerInterface();
JobFilterCriteria criteria = new JobFilterCriteria(false, true, true, true);
List<JobInfo> jobs = userInt.getJobs(0, 1000, criteria, ImmutableList.of(new SortParameter<>(JobSortParameter.ID, SortOrder.ASC))).getList();
for (JobInfo job : jobs) {
userInt.removeJob(job.getJobId());
}
}
use of org.ow2.proactive.scheduler.common.job.JobInfo in project scheduling by ow2-proactive.
the class SchedulerTHelper method testJobSubmission.
/**
* Creates and submit a job from an XML job descriptor, and check, with assertions,
* event related to this job submission :
* 1/ job submitted event
* 2/ job passing from pending to running (with state set to running).
* 3/ job passing from running to finished (with state set to finished).
* 4/ every task finished with or without error (configurable)
* <p>
* Then returns.
* <p>
* This is the simplest events sequence of a job submission. If you need to test
* specific events or task states (failures, rescheduling etc, you must not use this
* helper and check events sequence with waitForEvent**() functions.
*
* @param userInt scheduler interface
* @param jobToSubmit job object to schedule.
* @param acceptSkipped if true then skipped task will not fail the test
* @param failIfTaskError if true then the test will fail if a task was in error
* @return JobId, the job's identifier.
* @throws Exception if an error occurs at job submission, or during
* verification of events sequence.
*/
public JobId testJobSubmission(Scheduler userInt, Job jobToSubmit, boolean acceptSkipped, boolean failIfTaskError) throws Exception {
JobId id = userInt.submit(jobToSubmit);
log("Job submitted, id " + id.toString());
log("Waiting for jobSubmitted");
JobState receivedState = waitForEventJobSubmitted(id);
Assert.assertEquals(id, receivedState.getId());
log("Waiting for job running");
JobInfo jInfo = waitForEventJobRunning(id);
Assert.assertEquals(jInfo.getJobId(), id);
Assert.assertEquals("Job " + jInfo.getJobId(), JobStatus.RUNNING, jInfo.getStatus());
log("Waiting for job finished");
jInfo = waitForEventJobFinished(userInt, id);
Assert.assertEquals("Job " + jInfo.getJobId(), JobStatus.FINISHED, jInfo.getStatus());
log("Job finished");
boolean taskError = false;
String message = "";
if (jobToSubmit instanceof TaskFlowJob) {
JobState jobState = userInt.getJobState(id);
for (TaskState t : jobState.getTasks()) {
log("Looking at the result of task : " + t.getName());
if (t.getStatus() == TaskStatus.FAULTY) {
TaskResult tres = userInt.getTaskResult(jInfo.getJobId(), t.getName());
if (tres == null) {
message = "Task result of " + t.getName() + " should not be null.";
taskError = true;
break;
}
if (tres.getOutput() != null) {
System.err.println("Output of failing task (" + t.getName() + ") :");
System.err.println(tres.getOutput().getAllLogs(true));
}
if (tres.hadException()) {
System.err.println("Exception occurred in task (" + t.getName() + ") :");
tres.getException().printStackTrace(System.err);
message = "Exception occurred in task (" + t.getName() + ")";
taskError = true;
break;
}
} else if (acceptSkipped && t.getStatus() == TaskStatus.SKIPPED) {
// do nothing
} else if (t.getStatus() != TaskStatus.FINISHED) {
message = "Invalid task status for task " + t.getName() + " : " + t.getStatus();
taskError = true;
break;
} else {
TaskResult tres = userInt.getTaskResult(jInfo.getJobId(), t.getName());
System.out.println("Output of task (" + t.getName() + ") :");
System.out.println(tres.getOutput().getAllLogs(true));
}
}
}
if (taskError && failIfTaskError) {
fail(message);
}
return id;
}
use of org.ow2.proactive.scheduler.common.job.JobInfo in project scheduling by ow2-proactive.
the class TRepJobs method testJobs.
public void testJobs(TRepCase... testCases) throws Throwable {
for (TRepCase tcase : testCases) {
String path = new File(TWorkflowJobs.class.getResource(tcase.jobPath).toURI()).getAbsolutePath();
Job job = JobFactory.getFactory().createJob(path);
JobId id = schedulerHelper.submitJob(job);
SchedulerTHelper.log("Job submitted, id " + id.toString());
JobState receivedstate = schedulerHelper.waitForEventJobSubmitted(id);
Assert.assertEquals(id, receivedstate.getId());
JobInfo jInfo = schedulerHelper.waitForEventJobRunning(id);
Assert.assertEquals(jInfo.getJobId(), id);
Assert.assertEquals(JobStatus.RUNNING, jInfo.getStatus());
jInfo = schedulerHelper.waitForEventJobFinished(id);
Assert.assertEquals(JobStatus.FINISHED, jInfo.getStatus());
SchedulerTHelper.log("Job finished");
JobResult res = schedulerHelper.getJobResult(id);
Assert.assertFalse(schedulerHelper.getJobResult(id).hadException());
JobState js = schedulerHelper.getSchedulerInterface().getJobState(id);
// final number of tasks
Assert.assertEquals(tcase.total, js.getTasks().size());
// to be checked against this.tasks
HashMap<String, Long> finalTaskCount = new HashMap<>();
// to be checked against this.results
HashMap<String, Long> finalResSum = new HashMap<>();
for (TaskState ts : js.getTasks()) {
String baseName = InternalTask.getInitialName(ts.getName());
long count = 0;
long sum = 0;
if (finalTaskCount.containsKey(baseName)) {
count = finalTaskCount.get(baseName);
sum = finalResSum.get(baseName);
}
finalTaskCount.put(baseName, count + 1);
long tr = 0;
if (ts.getStatus().equals(TaskStatus.SKIPPED)) {
tr = -1;
} else {
Serializable sr = res.getAllResults().get(ts.getName()).value();
if (sr instanceof Long) {
tr = ((Long) sr).longValue();
}
}
finalResSum.put(baseName, sum + tr);
}
Assert.assertEquals(tcase.tasks.size(), finalTaskCount.size());
Assert.assertEquals(tcase.results.size(), finalResSum.size());
Assert.assertEquals(finalTaskCount.size(), finalResSum.size());
for (Entry<String, Long> entry : finalTaskCount.entrySet()) {
Assert.assertTrue(tcase.tasks.containsKey(entry.getKey()));
long val = tcase.tasks.get(entry.getKey());
Assert.assertEquals(val, entry.getValue().longValue());
}
for (Entry<String, Long> entry : finalResSum.entrySet()) {
Assert.assertTrue(tcase.results.containsKey(entry.getKey()));
long val = tcase.results.get(entry.getKey());
Assert.assertEquals(val, entry.getValue().longValue());
}
schedulerHelper.removeJob(id);
schedulerHelper.waitForEventJobRemoved(id);
}
}
use of org.ow2.proactive.scheduler.common.job.JobInfo in project scheduling by ow2-proactive.
the class TestJobCoverage method testJobCoverage.
@Test
public void testJobCoverage() throws Throwable {
JobState jstate;
TaskInfo tinfo;
JobInfo jinfo;
// removing temp file if existing
File w3File = new File(System.getProperty("java.io.tmpdir"), "WorkingAt3rdT2_13031984.tmp");
if (w3File.exists()) {
FileUtils.forceDelete(w3File);
}
// job submission
log("Submitting job...");
TaskFlowJob job = (TaskFlowJob) StaxJobFactory.getFactory().createJob(new File(jobDescriptor.toURI()).getAbsolutePath());
JobId id = schedulerHelper.submitJob(job);
// checking all processes
log("Checking all received events :");
jstate = schedulerHelper.waitForEventJobSubmitted(id);
assertEquals(JobStatus.PENDING, jstate.getStatus());
// checking task 1
log("Checking task1 process...");
tinfo = schedulerHelper.waitForEventTaskRunning(id, "task1");
jstate.update(tinfo);
jstate.update(tinfo.getJobInfo());
assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
assertEquals(JobStatus.RUNNING, jstate.getStatus());
tinfo = schedulerHelper.waitForEventTaskFinished(id, "task1");
jstate.update(tinfo);
assertEquals(TaskStatus.FINISHED, tinfo.getStatus());
// checking task 2
log("Checking task2 process...");
tinfo = schedulerHelper.waitForEventTaskRunning(id, "task2");
jstate.update(tinfo);
assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
tinfo = schedulerHelper.waitForEventTaskWaitingForRestart(id, "task2");
jstate.update(tinfo);
assertEquals(TaskStatus.WAITING_ON_ERROR, tinfo.getStatus());
tinfo = schedulerHelper.waitForEventTaskRunning(id, "task2");
jstate.update(tinfo);
assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
tinfo = schedulerHelper.waitForEventTaskFinished(id, "task2");
jstate.update(tinfo);
assertEquals(TaskStatus.FAULTY, tinfo.getStatus());
// checking task 3
log("Checking task3 process...");
tinfo = schedulerHelper.waitForEventTaskRunning(id, "task3");
jstate.update(tinfo);
assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
tinfo = schedulerHelper.waitForEventTaskWaitingForRestart(id, "task3");
jstate.update(tinfo);
assertEquals(TaskStatus.WAITING_ON_ERROR, tinfo.getStatus());
tinfo = schedulerHelper.waitForEventTaskRunning(id, "task3");
jstate.update(tinfo);
assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
tinfo = schedulerHelper.waitForEventTaskWaitingForRestart(id, "task3");
jstate.update(tinfo);
assertEquals(TaskStatus.WAITING_ON_ERROR, tinfo.getStatus());
tinfo = schedulerHelper.waitForEventTaskRunning(id, "task3");
jstate.update(tinfo);
assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
tinfo = schedulerHelper.waitForEventTaskFinished(id, "task3");
jstate.update(tinfo);
assertEquals(TaskStatus.FINISHED, tinfo.getStatus());
// checking task 4
log("Checking task4 process...");
tinfo = schedulerHelper.waitForEventTaskRunning(id, "task4");
jstate.update(tinfo);
assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
tinfo = schedulerHelper.waitForEventTaskFinished(id, "task4");
jstate.update(tinfo);
assertEquals(TaskStatus.FAULTY, tinfo.getStatus());
// checking task 5
log("Checking task5 process...");
tinfo = schedulerHelper.waitForEventTaskRunning(id, "task5");
jstate.update(tinfo);
assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
String hostName = tinfo.getExecutionHostName();
tinfo = schedulerHelper.waitForEventTaskWaitingForRestart(id, "task5");
jstate.update(tinfo);
assertEquals(TaskStatus.WAITING_ON_ERROR, tinfo.getStatus());
tinfo = schedulerHelper.waitForEventTaskRunning(id, "task5");
jstate.update(tinfo);
assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
Assert.assertFalse(hostName.equals(tinfo.getExecutionHostName()));
hostName = tinfo.getExecutionHostName();
tinfo = schedulerHelper.waitForEventTaskWaitingForRestart(id, "task5");
jstate.update(tinfo);
assertEquals(TaskStatus.WAITING_ON_ERROR, tinfo.getStatus());
tinfo = schedulerHelper.waitForEventTaskRunning(id, "task5");
jstate.update(tinfo);
assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
Assert.assertFalse(hostName.equals(tinfo.getExecutionHostName()));
tinfo = schedulerHelper.waitForEventTaskFinished(id, "task5");
jstate.update(tinfo);
assertEquals(TaskStatus.FAULTY, tinfo.getStatus());
// checking task 6
log("Checking task6 process...");
tinfo = schedulerHelper.waitForEventTaskRunning(id, "task6");
jstate.update(tinfo);
assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
tinfo = schedulerHelper.waitForEventTaskFinished(id, "task6");
jstate.update(tinfo);
assertEquals(TaskStatus.FINISHED, tinfo.getStatus());
// checking task 7
log("Checking task7 process...");
tinfo = schedulerHelper.waitForEventTaskRunning(id, "task7");
jstate.update(tinfo);
assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
tinfo = schedulerHelper.waitForEventTaskFinished(id, "task7");
jstate.update(tinfo);
assertEquals(TaskStatus.FAULTY, tinfo.getStatus());
// checking task 8
log("Checking task8 process...");
tinfo = schedulerHelper.waitForEventTaskRunning(id, "task8");
jstate.update(tinfo);
assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
tinfo = schedulerHelper.waitForEventTaskWaitingForRestart(id, "task8");
jstate.update(tinfo);
assertEquals(TaskStatus.WAITING_ON_ERROR, tinfo.getStatus());
tinfo = schedulerHelper.waitForEventTaskRunning(id, "task8");
jstate.update(tinfo);
assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
tinfo = schedulerHelper.waitForEventTaskFinished(id, "task8");
jstate.update(tinfo);
assertEquals(TaskStatus.FAULTY, tinfo.getStatus());
// waiting for job termination
log("Waiting for job to finish...");
jinfo = schedulerHelper.waitForEventJobFinished(id);
// checking results
log("Checking results...");
JobResult result = schedulerHelper.getJobResult(id);
assertEquals(8, result.getAllResults().size());
assertEquals(2, result.getPreciousResults().size());
assertNotNull(result.getPreciousResults().get("task1"));
assertNotNull(result.getPreciousResults().get("task6"));
assertEquals("Working", result.getPreciousResults().get("task1").value());
assertTrue(StackTraceUtil.getStackTrace(result.getResult("task2").getException()).contains("WorkingAt3rd - Status : Number is 1"));
assertTrue(result.getResult("task3").value().toString().contains("WorkingAt3rd - Status : OK / File deleted :"));
assertTrue(result.getResult("task4").getException().getCause().getMessage().contains("Throwing"));
assertTrue(result.getResult("task5").getException().getCause().getMessage().contains("Throwing"));
assertNotNull(result.getResult("task7").getException());
assertNotNull(result.getResult("task8").getException());
// checking end of the job...
jstate.update(jinfo);
assertEquals(0, jinfo.getNumberOfPendingTasks());
assertEquals(0, jinfo.getNumberOfRunningTasks());
assertEquals(8, jinfo.getNumberOfFinishedTasks());
assertEquals(8, jinfo.getTotalNumberOfTasks());
assertEquals(JobStatus.FINISHED, jinfo.getStatus());
assertEquals(0, jstate.getNumberOfPendingTasks());
assertEquals(0, jstate.getNumberOfRunningTasks());
assertEquals(8, jstate.getNumberOfFinishedTasks());
assertEquals(8, jstate.getTotalNumberOfTasks());
assertEquals(JobStatus.FINISHED, jstate.getStatus());
}
use of org.ow2.proactive.scheduler.common.job.JobInfo in project scheduling by ow2-proactive.
the class TestLoadJobs method testLoadJobs.
@Test
public void testLoadJobs() throws Exception {
long time = System.currentTimeMillis();
Scheduler scheduler = schedulerHelper.getSchedulerInterface();
FileLock fileLock = new FileLock();
Path lock = fileLock.lock();
String fileLockPath = lock.toString();
logger.info("File lock location is " + fileLockPath);
JobInfo job;
List<JobInfo> jobs = scheduler.getJobs(0, 1, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs);
JobId firstJob = scheduler.submit(createJob(fileLockPath));
schedulerHelper.waitForEventTaskRunning(firstJob, "Test");
jobs = scheduler.getJobs(0, 1, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, firstJob);
job = jobs.get(0);
assertEquals(this.getClass().getSimpleName(), job.getJobId().getReadableName());
assertEquals(1, job.getTotalNumberOfTasks());
assertEquals(0, job.getNumberOfFinishedTasks());
assertEquals(0, job.getNumberOfPendingTasks());
assertEquals(1, job.getNumberOfRunningTasks());
assertEquals(JobStatus.RUNNING, job.getStatus());
assertTrue("Unexpected submit time: " + job.getSubmittedTime(), job.getSubmittedTime() > time && job.getSubmittedTime() < System.currentTimeMillis());
assertTrue("Unexpected start time: " + job.getStartTime(), job.getStartTime() > time && job.getStartTime() < System.currentTimeMillis());
assertEquals(-1, job.getFinishedTime());
assertEquals(-1, job.getRemovedTime());
assertEquals(TestUsers.DEMO.username, job.getJobOwner());
assertEquals(JobPriority.NORMAL, job.getPriority());
JobId secondJob = scheduler.submit(createJob(fileLockPath));
JobId thirdJob = scheduler.submit(createJob(fileLockPath));
jobs = scheduler.getJobs(0, 10, criteria(true, false, false, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs);
jobs = scheduler.getJobs(1, 10, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, secondJob, thirdJob);
jobs = scheduler.getJobs(1, 1, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, secondJob);
jobs = scheduler.getJobs(0, 10, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, firstJob, secondJob, thirdJob);
jobs = scheduler.getJobs(0, 10, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, firstJob, secondJob, thirdJob);
jobs = scheduler.getJobs(0, 10, criteria(true, true, true, true), SORT_BY_ID_DESC).getList();
checkJobs(jobs, thirdJob, secondJob, firstJob);
fileLock.unlock();
for (JobInfo jobInfo : jobs) {
schedulerHelper.waitForEventJobFinished(jobInfo.getJobId(), 30000);
}
jobs = scheduler.getJobs(0, 10, criteria(true, true, true, false), SORT_BY_ID_ASC).getList();
checkJobs(jobs);
jobs = scheduler.getJobs(0, 10, criteria(true, false, false, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, firstJob, secondJob, thirdJob);
scheduler.disconnect();
// connect as another user
SchedulerMonitorsHandler monitorsHandler = new SchedulerMonitorsHandler();
SchedulerAuthenticationInterface auth = schedulerHelper.getSchedulerAuth();
Credentials cred = Credentials.createCredentials(new CredData(TestUsers.USER.username, TestUsers.USER.password), auth.getPublicKey());
scheduler = auth.login(cred);
eventReceiver = new MonitorEventReceiver(monitorsHandler);
eventReceiver = PAActiveObject.turnActive(eventReceiver);
SchedulerState state = scheduler.addEventListener(eventReceiver, true, true);
monitorsHandler.init(state);
jobs = scheduler.getJobs(0, 10, criteria(false, true, true, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, firstJob, secondJob, thirdJob);
jobs = scheduler.getJobs(0, 10, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs);
fileLockPath = fileLock.lock().toString();
JobId fourthJob = scheduler.submit(createJob(fileLockPath));
monitorsHandler.waitForEventTask(SchedulerEvent.TASK_PENDING_TO_RUNNING, fourthJob, "Test", 30000);
jobs = scheduler.getJobs(0, 10, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, fourthJob);
jobs = scheduler.getJobs(0, 10, criteria(true, false, false, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs);
jobs = scheduler.getJobs(0, 10, criteria(false, true, true, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, firstJob, secondJob, thirdJob, fourthJob);
jobs = scheduler.getJobs(2, 10, criteria(false, true, true, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, thirdJob, fourthJob);
fileLock.unlock();
monitorsHandler.waitForFinishedJob(fourthJob, 30000);
jobs = scheduler.getJobs(0, 10, criteria(true, false, false, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, fourthJob);
jobs = scheduler.getJobs(0, 10, criteria(false, false, false, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, firstJob, secondJob, thirdJob, fourthJob);
jobs = scheduler.getJobs(1, 1, criteria(false, false, false, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, secondJob);
jobs = scheduler.getJobs(1, 2, criteria(false, false, false, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, secondJob, thirdJob);
jobs = scheduler.getJobs(2, 1, criteria(false, false, false, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, thirdJob);
jobs = scheduler.getJobs(2, 2, criteria(false, false, false, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, thirdJob, fourthJob);
scheduler.disconnect();
PAActiveObject.terminateActiveObject(eventReceiver, true);
// connect as a user who can see only its own jobs
cred = Credentials.createCredentials(new CredData("guest", "pwd"), auth.getPublicKey());
scheduler = auth.login(cred);
monitorsHandler = new SchedulerMonitorsHandler();
eventReceiver = new MonitorEventReceiver(monitorsHandler);
eventReceiver = PAActiveObject.turnActive(eventReceiver);
state = scheduler.addEventListener(eventReceiver, true, true);
monitorsHandler.init(state);
JobId myjob = scheduler.submit(createJob(fileLockPath));
jobs = scheduler.getJobs(0, 10, criteria(true, true, true, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, myjob);
jobs = scheduler.getJobs(0, 10, criteria(false, true, true, true), SORT_BY_ID_ASC).getList();
checkJobs(jobs, myjob);
scheduler.disconnect();
}
Aggregations