use of org.ow2.proactive.scheduler.common.usage.JobUsage in project scheduling by ow2-proactive.
the class DataUtility method jobUsage.
public static JobUsage jobUsage(JobUsageData d) {
JobUsage impl = new JobUsage(d.getOwner(), d.getProject(), d.getJobId(), d.getJobName(), d.getJobDuration());
List<TaskUsageData> taskUsageDataList = d.getTaskUsages();
for (TaskUsageData taskUsageData : taskUsageDataList) {
impl.add(taskUsage(taskUsageData));
}
return impl;
}
use of org.ow2.proactive.scheduler.common.usage.JobUsage in project scheduling by ow2-proactive.
the class JobData method toJobUsage.
JobUsage toJobUsage() {
JobIdImpl jobId = new JobIdImpl(getId(), getJobName());
JobUsage jobUsage = new JobUsage(getOwner(), getProjectName(), jobId.value(), getJobName(), getFinishedTime() - getStartTime());
for (TaskData taskData : getTasks()) {
TaskUsage taskUsage = taskData.toTaskUsage(jobId);
jobUsage.add(taskUsage);
}
return jobUsage;
}
use of org.ow2.proactive.scheduler.common.usage.JobUsage in project scheduling by ow2-proactive.
the class SchedulerUsageTest method fallbackToMyAccountUsage.
private void fallbackToMyAccountUsage(Scheduler scheduler) throws NotConnectedException, PermissionException {
List<JobUsage> asAUser = scheduler.getMyAccountUsage(new Date(0), new Date(0));
assertNotNull(asAUser);
// fallback to my account usage
List<JobUsage> forMyUser = scheduler.getAccountUsage(TestUsers.USER.username, new Date(0), new Date(0));
assertNotNull(forMyUser);
try {
scheduler.getAccountUsage(TestUsers.DEMO.username, new Date(0), new Date(0));
fail("Should throw permission exception");
} catch (PermissionException e) {
}
}
use of org.ow2.proactive.scheduler.common.usage.JobUsage in project scheduling by ow2-proactive.
the class TestGetUsage method testGetMyAccountUsage.
@Test
public void testGetMyAccountUsage() throws Exception {
Date beforeJobExecution = new Date();
// put some data in the database
Scheduler firstUser = schedulerHelper.getSchedulerInterface();
JobId jobId = firstUser.submit(createJob());
schedulerHelper.waitForEventJobFinished(jobId, 30000);
Date afterJobExecution = new Date();
// We try to retrieve usage on the job I just ran
List<JobUsage> adminUsages = firstUser.getMyAccountUsage(beforeJobExecution, afterJobExecution);
assertFalse(adminUsages.isEmpty());
// Do we properly check for user connection ?
firstUser.disconnect();
try {
firstUser.getMyAccountUsage(beforeJobExecution, afterJobExecution);
fail("Should throw a not connected exception because i just disconnected");
} catch (NotConnectedException e) {
// Ok that is expected
}
// another user
SchedulerAuthenticationInterface auth = schedulerHelper.getSchedulerAuth();
Credentials cred = Credentials.createCredentials(new CredData(TestUsers.USER.username, TestUsers.USER.password), auth.getPublicKey());
Scheduler otherUser = auth.login(cred);
// This user has not ran any job
List<JobUsage> userUsages = otherUser.getMyAccountUsage(beforeJobExecution, afterJobExecution);
assertTrue(userUsages.isEmpty());
otherUser.disconnect();
}
use of org.ow2.proactive.scheduler.common.usage.JobUsage in project scheduling by ow2-proactive.
the class TestUsageData method testNonEmptyDatabase.
@Test
public void testNonEmptyDatabase() throws Exception {
Date beforeJobExecution = new Date();
InternalJob job = defaultSubmitJob(createJob("job", "task1", "task2", "task3"), USER_WITH_JOBS);
// not started and killed job, should not appear in usage data
InternalJob jobToBeKilled = defaultSubmitJob(createJob("job2", "task1"), USER_WITH_JOBS);
killJob(jobToBeKilled);
job.start();
for (InternalTask task : job.getITasks()) {
startTask(job, task);
finishTask(job, task);
}
Date afterJobExecution = new Date();
List<JobUsage> usagesBeforeJobRan = dbManager.getUsage(USER_WITH_JOBS, beforeJobExecution, beforeJobExecution);
assertTrue(usagesBeforeJobRan.isEmpty());
List<JobUsage> usagesAfterJobRan = dbManager.getUsage(USER_WITH_JOBS, afterJobExecution, afterJobExecution);
assertTrue(usagesAfterJobRan.isEmpty());
List<JobUsage> usagesForDifferentUser = dbManager.getUsage(USER_WITHOUT_JOBS, beforeJobExecution, afterJobExecution);
assertTrue(usagesForDifferentUser.isEmpty());
List<JobUsage> usagesWithinJobRun = dbManager.getUsage(USER_WITH_JOBS, beforeJobExecution, afterJobExecution);
assertEquals(1, usagesWithinJobRun.size());
assertEquals(3, usagesWithinJobRun.get(0).getTaskUsages().size());
JobUsage onlyOneUsage = usagesWithinJobRun.get(0);
assertEquals("job", onlyOneUsage.getJobName());
assertTrue(onlyOneUsage.getJobDuration() > 0);
TaskUsage onlyOneTaskUsage = onlyOneUsage.getTaskUsages().get(0);
assertTrue(onlyOneTaskUsage.getTaskName().contains("task"));
assertEquals(1, onlyOneTaskUsage.getTaskNodeNumber());
assertTrue(onlyOneTaskUsage.getTaskExecutionDuration() > 0);
}
Aggregations