Search in sources :

Example 26 with MantisJobStore

use of io.mantisrx.server.master.persistence.MantisJobStore in project mantis by Netflix.

the class JobClusterTest method testGetLastSubmittedJobSubject.

// //////////////////////////////// JOB SUBMIT OPERATIONS END/////////////////////////////////////////////////////////////
// //////////////////////////////// OTHER JOB OPERATIONS //////////////////////////////////////////////////////////////
@Test
public void testGetLastSubmittedJobSubject() {
    TestKit probe = new TestKit(system);
    String clusterName = "testGetLastSubmittedJobSubject";
    MantisScheduler schedulerMock = mock(MantisScheduler.class);
    MantisJobStore jobStoreMock = mock(MantisJobStore.class);
    final JobClusterDefinitionImpl fakeJobCluster = createFakeJobClusterDefn(clusterName);
    ActorRef jobClusterActor = system.actorOf(props(clusterName, jobStoreMock, schedulerMock, eventPublisher));
    jobClusterActor.tell(new JobClusterProto.InitializeJobClusterRequest(fakeJobCluster, user, probe.getRef()), probe.getRef());
    JobClusterProto.InitializeJobClusterResponse createResp = probe.expectMsgClass(JobClusterProto.InitializeJobClusterResponse.class);
    assertEquals(SUCCESS, createResp.responseCode);
    try {
        jobClusterActor.tell(new GetLastSubmittedJobIdStreamRequest(clusterName), probe.getRef());
        GetLastSubmittedJobIdStreamResponse getLastSubmittedJobIdStreamResponse = probe.expectMsgClass(GetLastSubmittedJobIdStreamResponse.class);
        assertEquals(SUCCESS, getLastSubmittedJobIdStreamResponse.responseCode);
        CountDownLatch jobIdLatch = new CountDownLatch(1);
        assertTrue(getLastSubmittedJobIdStreamResponse.getjobIdBehaviorSubject().isPresent());
        BehaviorSubject<JobId> jobIdBehaviorSubject = getLastSubmittedJobIdStreamResponse.getjobIdBehaviorSubject().get();
        jobIdBehaviorSubject.subscribeOn(Schedulers.io()).subscribe((jId) -> {
            System.out.println("Got Jid ------> " + jId);
            String jIdStr = jId.getId();
            assertEquals(clusterName + "-1", jIdStr);
            jobIdLatch.countDown();
        });
        final JobDefinition jobDefn = createJob(clusterName, 1, MantisJobDurationType.Transient);
        String jobId = clusterName + "-1";
        JobTestHelper.submitJobAndVerifySuccess(probe, clusterName, jobClusterActor, jobDefn, jobId);
        JobTestHelper.getJobDetailsAndVerify(probe, jobClusterActor, jobId, SUCCESS, JobState.Accepted);
        jobIdLatch.await(1000, TimeUnit.SECONDS);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        fail();
    }
// Mockito.doThrow(IOException.class).when(jobStoreMock).storeNewJob(any());
}
Also used : JobClusterProto(io.mantisrx.master.jobcluster.proto.JobClusterProto) GetLastSubmittedJobIdStreamResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLastSubmittedJobIdStreamResponse) ActorRef(akka.actor.ActorRef) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) TestKit(akka.testkit.javadsl.TestKit) Matchers.anyString(org.mockito.Matchers.anyString) CountDownLatch(java.util.concurrent.CountDownLatch) InvalidJobException(io.mantisrx.runtime.command.InvalidJobException) GetLastSubmittedJobIdStreamRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLastSubmittedJobIdStreamRequest) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) Test(org.junit.Test)

Example 27 with MantisJobStore

use of io.mantisrx.server.master.persistence.MantisJobStore in project mantis by Netflix.

the class JobClusterTest method testJobClusterCreate.

// CLUSTER CRUD TESTS ///////////////////////////////////////////////////////////////////////////
@Test
public void testJobClusterCreate() throws Exception {
    String name = "testJobClusterCreate";
    TestKit probe = new TestKit(system);
    MantisScheduler schedulerMock = mock(MantisScheduler.class);
    MantisJobStore jobStoreMock = mock(MantisJobStore.class);
    final JobClusterDefinitionImpl fakeJobCluster = createFakeJobClusterDefn(name);
    ActorRef jobClusterActor = system.actorOf(props(name, jobStoreMock, schedulerMock, eventPublisher));
    jobClusterActor.tell(new JobClusterProto.InitializeJobClusterRequest(fakeJobCluster, user, probe.getRef()), probe.getRef());
    JobClusterProto.InitializeJobClusterResponse createResp = probe.expectMsgClass(JobClusterProto.InitializeJobClusterResponse.class);
    assertEquals(SUCCESS, createResp.responseCode);
    jobClusterActor.tell(new GetJobClusterRequest(name), probe.getRef());
    GetJobClusterResponse resp2 = probe.expectMsgClass(GetJobClusterResponse.class);
    System.out.println("resp2 " + resp2);
    assertEquals(SUCCESS, resp2.responseCode);
    assertEquals(name, resp2.getJobCluster().get().getName());
    assertEquals("Nick", resp2.getJobCluster().get().getOwner().getName());
    assertTrue(resp2.getJobCluster().get().getLabels().isEmpty());
    assertEquals(1, resp2.getJobCluster().get().getJars().size());
    jobClusterActor.tell(new JobClusterProto.DeleteJobClusterRequest(user, name, probe.getRef()), probe.getRef());
    JobClusterProto.DeleteJobClusterResponse resp3 = probe.expectMsgClass(JobClusterProto.DeleteJobClusterResponse.class);
    assertEquals(SUCCESS, resp3.responseCode);
    assertEquals(jobClusterActor, probe.getLastSender());
    // verify(jobStoreMock, times(1)).storeNewJob(any());
    verify(jobStoreMock, times(1)).createJobCluster(any());
    verify(jobStoreMock, times(1)).deleteJobCluster(name);
    probe.getSystem().stop(jobClusterActor);
}
Also used : JobClusterProto(io.mantisrx.master.jobcluster.proto.JobClusterProto) GetJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterResponse) ActorRef(akka.actor.ActorRef) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) Matchers.anyString(org.mockito.Matchers.anyString) TestKit(akka.testkit.javadsl.TestKit) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) GetJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterRequest) Test(org.junit.Test)

Example 28 with MantisJobStore

use of io.mantisrx.server.master.persistence.MantisJobStore in project mantis by Netflix.

the class JobClusterTest method testJobSubmit.

// //////////////////////////////////// CLUSTER UPDATE FLAVORS END ////////////////////////////////////////////////////
// //////////////////////////////////// JOB SUBMIT OPERATIONS /////////////////////////////////////////////////////////////
@Test
public void testJobSubmit() {
    TestKit probe = new TestKit(system);
    String clusterName = "testJobSubmit";
    MantisScheduler schedulerMock = mock(MantisScheduler.class);
    MantisJobStore jobStoreMock = mock(MantisJobStore.class);
    final JobClusterDefinitionImpl fakeJobCluster = createFakeJobClusterDefn(clusterName);
    ActorRef jobClusterActor = system.actorOf(props(clusterName, jobStoreMock, schedulerMock, eventPublisher));
    jobClusterActor.tell(new JobClusterProto.InitializeJobClusterRequest(fakeJobCluster, user, probe.getRef()), probe.getRef());
    JobClusterProto.InitializeJobClusterResponse createResp = probe.expectMsgClass(JobClusterProto.InitializeJobClusterResponse.class);
    assertEquals(SUCCESS, createResp.responseCode);
    try {
        final JobDefinition jobDefn = createJob(clusterName, 1, MantisJobDurationType.Transient);
        String jobId = clusterName + "-1";
        JobTestHelper.submitJobAndVerifySuccess(probe, clusterName, jobClusterActor, jobDefn, jobId);
        JobTestHelper.getJobDetailsAndVerify(probe, jobClusterActor, jobId, SUCCESS, JobState.Accepted);
        JobTestHelper.killJobSendWorkerTerminatedAndVerify(probe, clusterName, new JobId(clusterName, 1), jobClusterActor, new WorkerId(jobId, 0, 1));
        Thread.sleep(500);
        verify(jobStoreMock, times(1)).createJobCluster(any());
        verify(jobStoreMock, times(1)).updateJobCluster(any());
        verify(jobStoreMock, timeout(2000).times(1)).archiveJob(any());
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        fail();
    }
// Mockito.doThrow(IOException.class).when(jobStoreMock).storeNewJob(any());
}
Also used : JobClusterProto(io.mantisrx.master.jobcluster.proto.JobClusterProto) ActorRef(akka.actor.ActorRef) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) TestKit(akka.testkit.javadsl.TestKit) Matchers.anyString(org.mockito.Matchers.anyString) WorkerId(io.mantisrx.server.core.domain.WorkerId) InvalidJobException(io.mantisrx.runtime.command.InvalidJobException) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) Test(org.junit.Test)

Example 29 with MantisJobStore

use of io.mantisrx.server.master.persistence.MantisJobStore in project mantis by Netflix.

the class JobClusterTest method testJobClusterDeletePurgesCompletedJobs.

@Test
public void testJobClusterDeletePurgesCompletedJobs() throws Exception {
    TestKit probe = new TestKit(system);
    List<Label> labels = Lists.newLinkedList();
    Label l = new Label("labelname", "labelvalue");
    labels.add(l);
    String clusterName = "testJobClusterDeletePurgesCompletedJobs";
    MantisScheduler schedulerMock = mock(MantisScheduler.class);
    MantisJobStore jobStoreMock = mock(MantisJobStore.class);
    final JobClusterDefinitionImpl fakeJobCluster = createFakeJobClusterDefn(clusterName, labels);
    ActorRef jobClusterActor = system.actorOf(props(clusterName, jobStoreMock, schedulerMock, eventPublisher));
    jobClusterActor.tell(new JobClusterProto.InitializeJobClusterRequest(fakeJobCluster, user, probe.getRef()), probe.getRef());
    JobClusterProto.InitializeJobClusterResponse createResp = probe.expectMsgClass(JobClusterProto.InitializeJobClusterResponse.class);
    assertEquals(SUCCESS, createResp.responseCode);
    final JobDefinition jobDefn = createJob(clusterName, 1, MantisJobDurationType.Transient);
    String jobId = clusterName + "-1";
    JobTestHelper.submitJobAndVerifySuccess(probe, clusterName, jobClusterActor, jobDefn, jobId);
    JobTestHelper.getJobDetailsAndVerify(probe, jobClusterActor, jobId, SUCCESS, JobState.Accepted);
    jobClusterActor.tell(new DisableJobClusterRequest(clusterName, "user"), probe.getRef());
    DisableJobClusterResponse disableResp = probe.expectMsgClass(DisableJobClusterResponse.class);
    assertEquals(SUCCESS, disableResp.responseCode);
    Thread.sleep(1000);
    jobClusterActor.tell(new JobClusterProto.DeleteJobClusterRequest(user, clusterName, probe.getRef()), probe.getRef());
    JobClusterProto.DeleteJobClusterResponse resp4 = probe.expectMsgClass(JobClusterProto.DeleteJobClusterResponse.class);
    assertEquals(SUCCESS, resp4.responseCode);
    assertEquals(jobClusterActor, probe.getLastSender());
    verify(jobStoreMock, times(1)).createJobCluster(any());
    verify(jobStoreMock, times(2)).updateJobCluster(any());
    verify(jobStoreMock, times(1)).deleteJobCluster(clusterName);
    verify(jobStoreMock, times(1)).storeCompletedJobForCluster(any(), any());
    verify(jobStoreMock, times(1)).deleteJob("testJobClusterDeletePurgesCompletedJobs-1");
}
Also used : JobClusterProto(io.mantisrx.master.jobcluster.proto.JobClusterProto) ActorRef(akka.actor.ActorRef) Label(io.mantisrx.common.Label) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) TestKit(akka.testkit.javadsl.TestKit) Matchers.anyString(org.mockito.Matchers.anyString) DisableJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DisableJobClusterResponse) DisableJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DisableJobClusterRequest) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) Test(org.junit.Test)

Example 30 with MantisJobStore

use of io.mantisrx.server.master.persistence.MantisJobStore in project mantis by Netflix.

the class JobClusterTest method testJobClusterArtifactUpdateNotUniqueFails.

@Test
public void testJobClusterArtifactUpdateNotUniqueFails() throws Exception {
    TestKit probe = new TestKit(system);
    String clusterName = "testJobClusterArtifactUpdateNotUniqueFails";
    MantisScheduler schedulerMock = mock(MantisScheduler.class);
    MantisJobStore jobStoreMock = mock(MantisJobStore.class);
    final JobClusterDefinitionImpl fakeJobCluster = createFakeJobClusterDefn(clusterName);
    ActorRef jobClusterActor = system.actorOf(props(clusterName, jobStoreMock, schedulerMock, eventPublisher));
    jobClusterActor.tell(new JobClusterProto.InitializeJobClusterRequest(fakeJobCluster, user, probe.getRef()), probe.getRef());
    JobClusterProto.InitializeJobClusterResponse createResp = probe.expectMsgClass(JobClusterProto.InitializeJobClusterResponse.class);
    assertEquals(SUCCESS, createResp.responseCode);
    UpdateJobClusterArtifactRequest req = new UpdateJobClusterArtifactRequest(clusterName, "a1", "0.0.1", true, "user");
    jobClusterActor.tell(req, probe.getRef());
    UpdateJobClusterArtifactResponse resp = probe.expectMsgClass(UpdateJobClusterArtifactResponse.class);
    assertEquals(CLIENT_ERROR, resp.responseCode);
    assertEquals(jobClusterActor, probe.getLastSender());
    jobClusterActor.tell(new GetJobClusterRequest(clusterName), probe.getRef());
    GetJobClusterResponse resp3 = probe.expectMsgClass(GetJobClusterResponse.class);
    assertEquals(SUCCESS, resp3.responseCode);
    assertTrue(resp3.getJobCluster() != null);
    System.out.println("Job cluster " + resp3.getJobCluster());
    assertEquals(clusterName, resp3.getJobCluster().get().getName());
    System.out.println("job cluster " + resp3.getJobCluster());
    assertEquals(1, resp3.getJobCluster().get().getJars().size());
    // assertEquals("a1", resp3.getJobCluster().getJobClusterDefinition().getJobClusterConfig().getArtifactName());
    assertEquals("0.0.1", resp3.getJobCluster().get().getLatestVersion());
    verify(jobStoreMock, times(0)).updateJobCluster(any());
    verify(jobStoreMock, times(1)).createJobCluster(any());
}
Also used : JobClusterProto(io.mantisrx.master.jobcluster.proto.JobClusterProto) GetJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterResponse) ActorRef(akka.actor.ActorRef) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) UpdateJobClusterArtifactResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterArtifactResponse) TestKit(akka.testkit.javadsl.TestKit) Matchers.anyString(org.mockito.Matchers.anyString) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) UpdateJobClusterArtifactRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterArtifactRequest) GetJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterRequest) Test(org.junit.Test)

Aggregations

MantisJobStore (io.mantisrx.server.master.persistence.MantisJobStore)86 ActorRef (akka.actor.ActorRef)77 MantisScheduler (io.mantisrx.server.master.scheduler.MantisScheduler)76 Test (org.junit.Test)72 TestKit (akka.testkit.javadsl.TestKit)64 JobClusterProto (io.mantisrx.master.jobcluster.proto.JobClusterProto)47 InvalidJobException (io.mantisrx.runtime.command.InvalidJobException)45 Matchers.anyString (org.mockito.Matchers.anyString)44 WorkerId (io.mantisrx.server.core.domain.WorkerId)31 JobClusterManagerProto (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto)27 IOException (java.io.IOException)26 GetJobDetailsResponse (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsResponse)24 SchedulingInfo (io.mantisrx.runtime.descriptor.SchedulingInfo)21 JobId (io.mantisrx.server.master.domain.JobId)19 MachineDefinition (io.mantisrx.runtime.MachineDefinition)16 GetJobClusterRequest (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterRequest)15 GetJobClusterResponse (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterResponse)15 GetJobDetailsRequest (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsRequest)15 CountDownLatch (java.util.concurrent.CountDownLatch)13 FakeMantisScheduler (io.mantisrx.master.scheduler.FakeMantisScheduler)10