Search in sources :

Example 1 with JobUsage

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;
}
Also used : JobUsage(org.ow2.proactive.scheduler.common.usage.JobUsage)

Example 2 with JobUsage

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;
}
Also used : TaskUsage(org.ow2.proactive.scheduler.common.usage.TaskUsage) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) JobUsage(org.ow2.proactive.scheduler.common.usage.JobUsage)

Example 3 with 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) {
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) JobUsage(org.ow2.proactive.scheduler.common.usage.JobUsage) Date(java.util.Date)

Example 4 with JobUsage

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();
}
Also used : NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) CredData(org.ow2.proactive.authentication.crypto.CredData) SchedulerAuthenticationInterface(org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface) JobUsage(org.ow2.proactive.scheduler.common.usage.JobUsage) Date(java.util.Date) JobId(org.ow2.proactive.scheduler.common.job.JobId) Credentials(org.ow2.proactive.authentication.crypto.Credentials) Test(org.junit.Test)

Example 5 with JobUsage

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);
}
Also used : TaskUsage(org.ow2.proactive.scheduler.common.usage.TaskUsage) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) JobUsage(org.ow2.proactive.scheduler.common.usage.JobUsage) Date(java.util.Date) Test(org.junit.Test)

Aggregations

JobUsage (org.ow2.proactive.scheduler.common.usage.JobUsage)6 Date (java.util.Date)4 Test (org.junit.Test)3 TaskUsage (org.ow2.proactive.scheduler.common.usage.TaskUsage)2 CredData (org.ow2.proactive.authentication.crypto.CredData)1 Credentials (org.ow2.proactive.authentication.crypto.Credentials)1 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)1 SchedulerAuthenticationInterface (org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface)1 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)1 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)1 JobId (org.ow2.proactive.scheduler.common.job.JobId)1 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)1 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)1 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)1