Search in sources :

Example 6 with JobInfo

use of io.mantisrx.master.jobcluster.JobClusterActor.JobInfo in project mantis by Netflix.

the class JobManagerTest method testPurgeOldJobs.

@Test
public void testPurgeOldJobs() {
    String clusterName = "testPurgeOldJobs";
    MantisJobStore jobStoreMock = mock(MantisJobStore.class);
    JobClusterActor.JobManager jm = new JobManager(clusterName, context, scheduler, publisher, jobStoreMock);
    JobId jId1 = new JobId(clusterName, 1);
    JobInfo jInfo1 = new JobInfo(jId1, null, 0, null, JobState.Accepted, "nj");
    assertTrue(jm.markJobAccepted(jInfo1));
    assertTrue(jm.getAllNonTerminalJobsList().contains(jInfo1));
    JobId jId2 = new JobId(clusterName, 2);
    JobInfo jInfo2 = new JobInfo(jId2, null, 1, null, JobState.Accepted, "nj");
    assertTrue(jm.markJobAccepted(jInfo2));
    assertTrue(jm.getAllNonTerminalJobsList().contains(jInfo2));
    assertTrue(jm.getAllNonTerminalJobsList().size() == 2);
    assertEquals(jInfo1, jm.getAllNonTerminalJobsList().get(1));
    assertEquals(jInfo2, jm.getAllNonTerminalJobsList().get(0));
    jm.markJobTerminating(jInfo1, JobState.Terminating_abnormal);
    Instant completionInstant = Instant.now().minusSeconds(5);
    jm.markCompleted(jId1, completionInstant.toEpochMilli(), empty(), JobState.Completed);
    assertEquals(1, jm.getCompletedJobsList().size());
    assertEquals(jId1.getId(), jm.getCompletedJobsList().get(0).getJobId());
    jm.purgeOldCompletedJobs(Instant.now().minusSeconds(3).toEpochMilli());
    assertEquals(0, jm.getCompletedJobsList().size());
    try {
        verify(jobStoreMock, times(1)).deleteCompletedJob(clusterName, jId1.getId());
        verify(jobStoreMock, times(1)).deleteJob(jId1.getId());
    } catch (IOException e) {
        e.printStackTrace();
        fail();
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : JobManager(io.mantisrx.master.jobcluster.JobClusterActor.JobManager) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) JobInfo(io.mantisrx.master.jobcluster.JobClusterActor.JobInfo) Instant(java.time.Instant) JobManager(io.mantisrx.master.jobcluster.JobClusterActor.JobManager) IOException(java.io.IOException) JobId(io.mantisrx.server.master.domain.JobId) IOException(java.io.IOException) Test(org.junit.Test)

Example 7 with JobInfo

use of io.mantisrx.master.jobcluster.JobClusterActor.JobInfo in project mantis by Netflix.

the class JobManagerTest method testGetAcceptedJobList.

@Test
public void testGetAcceptedJobList() {
    JobClusterActor.JobManager jm = new JobManager("name", context, scheduler, publisher, jobStore);
    JobId jId1 = new JobId("name", 1);
    JobInfo jInfo1 = new JobInfo(jId1, null, 0, null, JobState.Accepted, "nj");
    assertTrue(jm.markJobAccepted(jInfo1));
    JobId jId2 = new JobId("name", 2);
    JobInfo jInfo2 = new JobInfo(jId2, null, 0, null, JobState.Accepted, "nj");
    assertTrue(jm.markJobAccepted(jInfo2));
    List<JobInfo> acceptedJobList = jm.getAcceptedJobsList();
    assertEquals(2, acceptedJobList.size());
    assertTrue(jId1.equals(acceptedJobList.get(0).jobId) || jId1.equals(acceptedJobList.get(1).jobId));
    assertTrue(jId2.equals(acceptedJobList.get(0).jobId) || jId2.equals(acceptedJobList.get(1).jobId));
    try {
        acceptedJobList.remove(0);
        fail();
    } catch (Exception e) {
    }
}
Also used : JobManager(io.mantisrx.master.jobcluster.JobClusterActor.JobManager) JobInfo(io.mantisrx.master.jobcluster.JobClusterActor.JobInfo) JobManager(io.mantisrx.master.jobcluster.JobClusterActor.JobManager) JobId(io.mantisrx.server.master.domain.JobId) IOException(java.io.IOException) Test(org.junit.Test)

Example 8 with JobInfo

use of io.mantisrx.master.jobcluster.JobClusterActor.JobInfo in project mantis by Netflix.

the class SLAEnforcerTest method testSorting.

@Test
public void testSorting() {
    Instant now = Instant.now();
    List<JobInfo> jobList = Lists.newArrayList(new JobInfo(new JobId("cname", 3), null, now.getMillis(), null, JobState.Accepted, null), new JobInfo(new JobId("cname", 1), null, now.getMillis(), null, JobState.Accepted, null), new JobInfo(new JobId("cname", 4), null, now.getMillis(), null, JobState.Launched, null), new JobInfo(new JobId("cname", 2), null, now.getMillis(), null, JobState.Launched, null));
    int min = 1;
    int max = 1;
    SLA sla = new SLA(min, max, null, null);
    SLAEnforcer slaEnforcer = new SLAEnforcer(sla);
    Set<JobInfo> sortJobsByIdDesc = slaEnforcer.sortJobsByIdDesc(jobList);
    String[] expectedOrder = { "cname-1", "cname-2", "cname-3", "cname-4" };
    JobInfo[] jobIdArray = sortJobsByIdDesc.toArray(new JobInfo[sortJobsByIdDesc.size()]);
    for (int i = 0; i < jobIdArray.length; i++) {
        System.out.println("[" + i + "] ->" + jobIdArray[i]);
        assertEquals(expectedOrder[i], (jobIdArray[i].jobId.getId()));
    }
}
Also used : JobInfo(io.mantisrx.master.jobcluster.JobClusterActor.JobInfo) Instant(org.joda.time.Instant) SLA(io.mantisrx.server.master.domain.SLA) JobId(io.mantisrx.server.master.domain.JobId) Test(org.junit.Test)

Example 9 with JobInfo

use of io.mantisrx.master.jobcluster.JobClusterActor.JobInfo in project mantis by Netflix.

the class SLAEnforcerTest method slaMaxDefaultsTest.

@Test
public void slaMaxDefaultsTest() {
    Instant now = Instant.now();
    int min = 0;
    int max = 0;
    SLA sla = new SLA(min, max, null, null);
    SLAEnforcer slaEnf = new SLAEnforcer(null);
    List<JobInfo> jobList = Lists.newArrayList(new JobInfo(new JobId("cname", 1), null, now.getMillis(), null, JobState.Accepted, null), new JobInfo(new JobId("cname", 2), null, now.getMillis(), null, JobState.Launched, null), new JobInfo(new JobId("cname", 3), null, now.getMillis(), null, JobState.Accepted, null), new JobInfo(new JobId("cname", 4), null, now.getMillis(), null, JobState.Launched, null));
    // sla not set nothing to enforce
    try {
        List<JobId> jobsToDelete = slaEnf.enforceSLAMax(jobList);
        assertTrue(jobsToDelete.isEmpty());
    } catch (Exception e) {
        fail();
    }
    slaEnf = new SLAEnforcer(sla);
    jobList = Lists.newArrayList(new JobInfo(new JobId("cname", 1), null, now.getMillis(), null, JobState.Accepted, null), new JobInfo(new JobId("cname", 2), null, now.getMillis(), null, JobState.Launched, null), new JobInfo(new JobId("cname", 3), null, now.getMillis(), null, JobState.Accepted, null), new JobInfo(new JobId("cname", 4), null, now.getMillis(), null, JobState.Launched, null));
    // sla max is 0 nothing to enforce
    List<JobId> jobsToDelete = slaEnf.enforceSLAMax(jobList);
    assertTrue(jobsToDelete.isEmpty());
}
Also used : JobInfo(io.mantisrx.master.jobcluster.JobClusterActor.JobInfo) Instant(org.joda.time.Instant) SLA(io.mantisrx.server.master.domain.SLA) JobId(io.mantisrx.server.master.domain.JobId) Test(org.junit.Test)

Example 10 with JobInfo

use of io.mantisrx.master.jobcluster.JobClusterActor.JobInfo in project mantis by Netflix.

the class SLAEnforcerTest method slaMaxTest2.

@Test
public void slaMaxTest2() {
    Instant now = Instant.now();
    int min = 0;
    int max = 2;
    SLA sla = new SLA(min, max, null, null);
    SLAEnforcer slaEnf = new SLAEnforcer(sla);
    List<JobInfo> jobList = Lists.newArrayList(new JobInfo(new JobId("cname", 1), null, now.getMillis(), null, JobState.Accepted, null), new JobInfo(new JobId("cname", 2), null, now.getMillis(), null, JobState.Launched, null), new JobInfo(new JobId("cname", 3), null, now.getMillis(), null, JobState.Launched, null), new JobInfo(new JobId("cname", 4), null, now.getMillis(), null, JobState.Launched, null));
    // 3 active and 1 accepted jobs, terminate job 2
    List<JobId> jobsToDelete = slaEnf.enforceSLAMax(jobList);
    assertEquals(2, jobsToDelete.size());
    boolean job1Found = false;
    boolean job2Found = false;
    for (JobId jId : jobsToDelete) {
        if (jId.getId().equals("cname-1")) {
            job1Found = true;
        } else if (jId.getId().equals("cname-2")) {
            job2Found = true;
        }
    }
    assertTrue(job1Found && job2Found);
}
Also used : JobInfo(io.mantisrx.master.jobcluster.JobClusterActor.JobInfo) Instant(org.joda.time.Instant) SLA(io.mantisrx.server.master.domain.SLA) JobId(io.mantisrx.server.master.domain.JobId) Test(org.junit.Test)

Aggregations

JobInfo (io.mantisrx.master.jobcluster.JobClusterActor.JobInfo)20 Test (org.junit.Test)18 JobId (io.mantisrx.server.master.domain.JobId)17 JobManager (io.mantisrx.master.jobcluster.JobClusterActor.JobManager)9 SLA (io.mantisrx.server.master.domain.SLA)6 Instant (org.joda.time.Instant)6 TestKit (akka.testkit.javadsl.TestKit)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Matchers.anyString (org.mockito.Matchers.anyString)3 MantisJobStore (io.mantisrx.server.master.persistence.MantisJobStore)2 Instant (java.time.Instant)2 JobClusterDefinitionImpl (io.mantisrx.server.master.domain.JobClusterDefinitionImpl)1 CompletedJob (io.mantisrx.server.master.domain.JobClusterDefinitionImpl.CompletedJob)1 JobDefinition (io.mantisrx.server.master.domain.JobDefinition)1