Search in sources :

Example 21 with MantisJobStore

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

the class JobClusterManagerTest method testBootStrapJobClustersAndJobs1.

@Test
public void testBootStrapJobClustersAndJobs1() {
    TestKit probe = new TestKit(system);
    JobTestHelper.deleteAllFiles();
    MantisJobStore jobStore = new MantisJobStore(new MantisStorageProviderAdapter(new io.mantisrx.server.master.store.SimpleCachedFileStorageProvider(), eventPublisher));
    MantisJobStore jobStoreSpied = Mockito.spy(jobStore);
    MantisScheduler schedulerMock = mock(MantisScheduler.class);
    ActorRef jobClusterManagerActor = system.actorOf(JobClustersManagerActor.props(jobStoreSpied, eventPublisher));
    jobClusterManagerActor.tell(new JobClusterManagerProto.JobClustersManagerInitialize(schedulerMock, true), probe.getRef());
    JobClustersManagerInitializeResponse iResponse = probe.expectMsgClass(Duration.of(10, ChronoUnit.MINUTES), JobClustersManagerInitializeResponse.class);
    // List<String> clusterNames = Lists.newArrayList("testBootStrapJobClustersAndJobs1");
    String clusterWithNoJob = "testBootStrapJobClusterWithNoJob";
    createJobClusterAndAssert(jobClusterManagerActor, clusterWithNoJob);
    // kill 1 of the jobs to test archive path
    // Stop job cluster Manager Actor
    system.stop(jobClusterManagerActor);
    // create new instance
    jobClusterManagerActor = system.actorOf(JobClustersManagerActor.props(jobStore, eventPublisher));
    // initialize it
    jobClusterManagerActor.tell(new JobClusterManagerProto.JobClustersManagerInitialize(schedulerMock, true), probe.getRef());
    // JobClusterManagerProto.JobClustersManagerInitializeResponse initializeResponse = probe.expectMsgClass(JobClusterManagerProto.JobClustersManagerInitializeResponse.class);
    JobClustersManagerInitializeResponse initializeResponse = probe.expectMsgClass(Duration.of(10, ChronoUnit.MINUTES), JobClustersManagerInitializeResponse.class);
    assertEquals(SUCCESS, initializeResponse.responseCode);
    jobClusterManagerActor.tell(new GetJobClusterRequest(clusterWithNoJob), probe.getRef());
    GetJobClusterResponse jobClusterResponse = probe.expectMsgClass(Duration.of(10, ChronoUnit.MINUTES), GetJobClusterResponse.class);
    assertEquals(SUCCESS, jobClusterResponse.responseCode);
    assertTrue(jobClusterResponse.getJobCluster().isPresent());
    assertEquals(clusterWithNoJob, jobClusterResponse.getJobCluster().get().getName());
    try {
        // Mockito.verify(jobStoreSpied).loadAllArchivedJobsAsync();
        Mockito.verify(jobStoreSpied).loadAllJobClusters();
        Mockito.verify(jobStoreSpied).loadAllActiveJobs();
        Mockito.verify(jobStoreSpied).loadAllCompletedJobs();
    // Mockito.verify(jobStoreSpied).archiveWorker(any());
    // Mockito.verify(jobStoreSpied).archiveJob(any());
    } catch (IOException e) {
        e.printStackTrace();
        fail();
    }
}
Also used : GetJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterResponse) ActorRef(akka.actor.ActorRef) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) TestKit(akka.testkit.javadsl.TestKit) IOException(java.io.IOException) MantisStorageProviderAdapter(io.mantisrx.server.master.persistence.MantisStorageProviderAdapter) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) GetJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterRequest) JobClusterManagerProto(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto) JobClustersManagerInitializeResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.JobClustersManagerInitializeResponse) Test(org.junit.Test)

Example 22 with MantisJobStore

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

the class JobClusterManagerTest method testBootStrapJobClustersAndJobsNegativeTest.

@Test
public void testBootStrapJobClustersAndJobsNegativeTest() throws IOException {
    TestKit probe = new TestKit(system);
    JobTestHelper.deleteAllFiles();
    MantisStorageProviderAdapter storageProviderAdapter = mock(MantisStorageProviderAdapter.class);
    when(storageProviderAdapter.loadAllJobClusters()).thenThrow(new IOException("StorageException"));
    MantisJobStore jobStore = new MantisJobStore(storageProviderAdapter);
    MantisJobStore jobStoreSpied = Mockito.spy(jobStore);
    MantisScheduler schedulerMock = mock(MantisScheduler.class);
    ActorRef jobClusterManagerActor = system.actorOf(JobClustersManagerActor.props(jobStoreSpied, eventPublisher));
    jobClusterManagerActor.tell(new JobClusterManagerProto.JobClustersManagerInitialize(schedulerMock, true), probe.getRef());
    JobClustersManagerInitializeResponse iResponse = probe.expectMsgClass(Duration.of(10, ChronoUnit.MINUTES), JobClustersManagerInitializeResponse.class);
    assertEquals(BaseResponse.ResponseCode.SERVER_ERROR, iResponse.responseCode);
}
Also used : MantisStorageProviderAdapter(io.mantisrx.server.master.persistence.MantisStorageProviderAdapter) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) ActorRef(akka.actor.ActorRef) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) TestKit(akka.testkit.javadsl.TestKit) IOException(java.io.IOException) JobClusterManagerProto(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto) JobClustersManagerInitializeResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.JobClustersManagerInitializeResponse) Test(org.junit.Test)

Example 23 with MantisJobStore

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

the class JobClusterTest method testJobSubmitWithInheritInstanceFlagsMultiStage.

@Test
public void testJobSubmitWithInheritInstanceFlagsMultiStage() {
    TestKit probe = new TestKit(system);
    String clusterName = "testJobSubmitWithInheritInstance";
    MantisScheduler schedulerMock = mock(MantisScheduler.class);
    MantisJobStore jobStoreMock = mock(MantisJobStore.class);
    // default job with 3 stage == (2 worker)
    final SchedulingInfo schedulingInfo1 = new SchedulingInfo.Builder().numberOfStages(4).multiWorkerStage(2, DEFAULT_MACHINE_DEFINITION).multiWorkerStage(2, DEFAULT_MACHINE_DEFINITION).multiWorkerStage(2, DEFAULT_MACHINE_DEFINITION).multiWorkerStage(2, DEFAULT_MACHINE_DEFINITION).build();
    final JobClusterDefinitionImpl fakeJobCluster = createFakeJobClusterDefn(clusterName, Lists.newArrayList(), NO_OP_SLA, schedulingInfo1);
    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, MantisJobDurationType.Transient, schedulingInfo1);
        String jobId = clusterName + "-1";
        JobTestHelper.submitJobAndVerifySuccess(probe, clusterName, jobClusterActor, jobDefn, jobId);
        JobTestHelper.getJobDetailsAndVerify(probe, jobClusterActor, jobId, SUCCESS, JobState.Accepted);
        // submit another job this time with job, in which some stages with inheritInstance enabled
        final String jobId2 = clusterName + "-2";
        final SchedulingInfo schedulingInfo2 = new SchedulingInfo.Builder().numberOfStages(4).multiWorkerStage(3, DEFAULT_MACHINE_DEFINITION).multiWorkerStage(4, DEFAULT_MACHINE_DEFINITION).multiWorkerStage(5, DEFAULT_MACHINE_DEFINITION).multiWorkerStage(6, DEFAULT_MACHINE_DEFINITION).build();
        final DeploymentStrategy deploymentStrategy = DeploymentStrategy.builder().stage(1, StageDeploymentStrategy.builder().inheritInstanceCount(true).build()).stage(3, StageDeploymentStrategy.builder().inheritInstanceCount(true).build()).stage(4, StageDeploymentStrategy.builder().inheritInstanceCount(false).build()).build();
        final String artifactV2 = "artVer-2";
        final JobDefinition jobDefn2Workers = createJob(clusterName, MantisJobDurationType.Transient, schedulingInfo2, jobDefn.getArtifactName(), artifactV2, deploymentStrategy);
        JobTestHelper.submitJobAndVerifySuccess(probe, clusterName, jobClusterActor, jobDefn2Workers, jobId2);
        JobTestHelper.getJobDetailsAndVerify(probe, jobClusterActor, jobId2, SUCCESS, JobState.Accepted);
        // verify instance count is from previous job.
        final JobId jobId2Id = JobId.fromId(jobId2).get();
        jobClusterActor.tell(new JobClusterManagerProto.GetJobDetailsRequest("nj", jobId2Id), probe.getRef());
        JobClusterManagerProto.GetJobDetailsResponse detailsResp = probe.expectMsgClass(Duration.ofSeconds(60), JobClusterManagerProto.GetJobDetailsResponse.class);
        assertTrue(detailsResp.getJobMetadata().isPresent());
        assertEquals(jobId2, detailsResp.getJobMetadata().get().getJobId().getId());
        assertEquals(artifactV2, detailsResp.getJobMetadata().get().getJobDefinition().getVersion());
        final SchedulingInfo actualSchedulingInfo = detailsResp.getJobMetadata().get().getSchedulingInfo();
        assertEquals(4, actualSchedulingInfo.getStages().size());
        // stage 1/3 inherits from previous job while stage 2 should apply new instance count.
        assertEquals(2, actualSchedulingInfo.forStage(1).getNumberOfInstances());
        assertEquals(4, actualSchedulingInfo.forStage(2).getNumberOfInstances());
        assertEquals(2, actualSchedulingInfo.forStage(3).getNumberOfInstances());
        assertEquals(6, actualSchedulingInfo.forStage(4).getNumberOfInstances());
        JobTestHelper.killJobAndVerify(probe, clusterName, jobId2Id, jobClusterActor);
        verify(jobStoreMock, times(1)).createJobCluster(any());
        verify(jobStoreMock, times(2)).updateJobCluster(any());
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : JobClusterProto(io.mantisrx.master.jobcluster.proto.JobClusterProto) GetJobDetailsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsRequest) SchedulingInfo(io.mantisrx.runtime.descriptor.SchedulingInfo) ActorRef(akka.actor.ActorRef) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) TestKit(akka.testkit.javadsl.TestKit) Matchers.anyString(org.mockito.Matchers.anyString) InvalidJobException(io.mantisrx.runtime.command.InvalidJobException) StageDeploymentStrategy(io.mantisrx.runtime.descriptor.StageDeploymentStrategy) DeploymentStrategy(io.mantisrx.runtime.descriptor.DeploymentStrategy) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) GetJobDetailsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsResponse) JobClusterManagerProto(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto) Test(org.junit.Test)

Example 24 with MantisJobStore

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

the class JobClusterTest method testListJobIdsForCluster.

@Test
public void testListJobIdsForCluster() throws InvalidJobException {
    TestKit probe = new TestKit(system);
    String clusterName = "testListJobsForCluster";
    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);
    final JobDefinition jobDefn1 = createJob(clusterName);
    String jobId = clusterName + "-1";
    JobTestHelper.submitJobAndVerifySuccess(probe, clusterName, jobClusterActor, jobDefn1, jobId);
    String jobId2 = clusterName + "-2";
    JobTestHelper.submitJobAndVerifySuccess(probe, clusterName, jobClusterActor, jobDefn1, jobId2);
    jobClusterActor.tell(new ListJobIdsRequest(), probe.getRef());
    ListJobIdsResponse listResp = probe.expectMsgClass(ListJobIdsResponse.class);
    assertEquals(SUCCESS, listResp.responseCode);
    assertEquals(2, listResp.getJobIds().size());
    boolean foundJob1 = false;
    boolean foundJob2 = false;
    for (JobClusterProtoAdapter.JobIdInfo jobIdInfo : listResp.getJobIds()) {
        if (jobIdInfo.getJobId().equals(jobId)) {
            foundJob1 = true;
        } else if (jobIdInfo.getJobId().equals(jobId2)) {
            foundJob2 = true;
        }
    }
    assertTrue(foundJob1);
    assertTrue(foundJob2);
    JobTestHelper.killJobAndVerify(probe, clusterName, new JobId(clusterName, 1), jobClusterActor);
    jobClusterActor.tell(new ListJobIdsRequest(empty(), empty(), of(true), empty(), empty(), empty()), probe.getRef());
    ListJobIdsResponse listResp2 = probe.expectMsgClass(ListJobIdsResponse.class);
    assertEquals(SUCCESS, listResp2.responseCode);
    assertEquals(1, listResp2.getJobIds().size());
    // assertFalse(listResp2.getJobIds().contains(JobId.fromId(jobId).get()));
    // assertTrue(listResp2.getJobIds().contains(JobId.fromId(jobId2).get()));
    foundJob1 = false;
    foundJob2 = false;
    for (JobClusterProtoAdapter.JobIdInfo jobIdInfo : listResp2.getJobIds()) {
        if (jobIdInfo.getJobId().equals(jobId)) {
            foundJob1 = true;
        } else if (jobIdInfo.getJobId().equals(jobId2)) {
            foundJob2 = true;
        }
    }
    assertFalse(foundJob1);
    assertTrue(foundJob2);
    JobTestHelper.killJobAndVerify(probe, clusterName, new JobId(clusterName, 2), jobClusterActor);
    jobClusterActor.tell(new ListJobIdsRequest(), probe.getRef());
    ListJobIdsResponse listResp3 = probe.expectMsgClass(ListJobIdsResponse.class);
    assertEquals(SUCCESS, listResp3.responseCode);
    assertEquals(0, listResp3.getJobIds().size());
    // assertFalse(listResp3.getJobIds().contains(JobId.fromId(jobId).get()));
    // assertFalse(listResp3.getJobIds().contains(JobId.fromId(jobId2).get()));
    foundJob1 = false;
    foundJob2 = false;
    for (JobClusterProtoAdapter.JobIdInfo jobIdInfo : listResp3.getJobIds()) {
        if (jobIdInfo.getJobId().equals(jobId)) {
            foundJob1 = true;
        } else if (jobIdInfo.getJobId().equals(jobId2)) {
            foundJob2 = true;
        }
    }
    assertFalse(foundJob1);
    assertFalse(foundJob2);
}
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) ListJobIdsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobIdsResponse) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) ListJobIdsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobIdsRequest) JobClusterProtoAdapter(io.mantisrx.master.api.akka.route.proto.JobClusterProtoAdapter) Test(org.junit.Test)

Example 25 with MantisJobStore

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

the class JobClusterTest method testJobSubmitTriggersSLAToKillOld.

// TODO
// TODO    @Test
public void testJobSubmitTriggersSLAToKillOld() {
    TestKit probe = new TestKit(system);
    String clusterName = "testJobSubmitTriggersSLAToKillOld";
    MantisScheduler schedulerMock = mock(MantisScheduler.class);
    MantisJobStore jobStoreMock = mock(MantisJobStore.class);
    SLA sla = new SLA(1, 1, null, null);
    final JobClusterDefinitionImpl fakeJobCluster = createFakeJobClusterDefn(clusterName, Lists.newArrayList(), sla);
    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);
    String jobId = clusterName + "-1";
    WorkerId workerId1 = new WorkerId(clusterName, jobId, 0, 1);
    doAnswer(invocation -> {
        WorkerEvent terminate = new WorkerTerminate(workerId1, WorkerState.Completed, JobCompletedReason.Killed, System.currentTimeMillis());
        jobClusterActor.tell(terminate, probe.getRef());
        return null;
    }).when(schedulerMock).unscheduleWorker(any(), any());
    try {
        final JobDefinition jobDefn = createJob(clusterName, 1, MantisJobDurationType.Transient);
        JobTestHelper.submitJobAndVerifySuccess(probe, clusterName, jobClusterActor, jobDefn, jobId);
        JobTestHelper.getJobDetailsAndVerify(probe, jobClusterActor, jobId, SUCCESS, JobState.Accepted);
        JobTestHelper.sendLaunchedInitiatedStartedEventsToWorker(probe, jobClusterActor, jobId, 1, new WorkerId(clusterName, jobId, 0, 1));
        JobTestHelper.getJobDetailsAndVerify(probe, jobClusterActor, jobId, SUCCESS, JobState.Launched);
        // submit 2nd job
        String jobId2 = clusterName + "-2";
        JobTestHelper.submitJobAndVerifySuccess(probe, clusterName, jobClusterActor, jobDefn, jobId2);
        JobTestHelper.getJobDetailsAndVerify(probe, jobClusterActor, jobId2, SUCCESS, JobState.Accepted);
        JobTestHelper.sendLaunchedInitiatedStartedEventsToWorker(probe, jobClusterActor, jobId2, 1, new WorkerId(clusterName, jobId2, 0, 1));
        JobTestHelper.getJobDetailsAndVerify(probe, jobClusterActor, jobId2, SUCCESS, JobState.Launched);
        boolean completed = false;
        assertTrue(JobTestHelper.verifyJobStatusWithPolling(probe, jobClusterActor, jobId, JobState.Completed));
        // jobClusterActor.tell(new ListJobIdsRequest(), probe.getRef());
        // ListJobIdsResponse listJobIdsResponse = probe.expectMsgClass(ListJobIdsResponse.class);
        // assertEquals(SUCCESS, listJobIdsResponse.responseCode);
        // assertEquals(1,listJobIdsResponse.getJobIds().size());
        // assertEquals(jobId2, listJobIdsResponse.getJobIds().get(0).getId());
        // // try a few times for timing issue
        // for(int i=0; i<10; i++) {
        // jobClusterActor.tell(new GetJobDetailsRequest("nj", JobId.fromId(jobId).get()), probe.getRef());
        // GetJobDetailsResponse detailsResp = probe.expectMsgClass(GetJobDetailsResponse.class);
        // if(JobState.Completed.equals(detailsResp.getJobMetadata().get().getState())) {
        // completed = true;
        // break;
        // }
        // }
        // assertTrue(completed);
        // JobTestHelper.getJobDetailsAndVerify(probe, jobClusterActor, jobId, SUCCESS, JobState.Completed);
        JobTestHelper.killJobAndVerify(probe, clusterName, new JobId(clusterName, 2), jobClusterActor);
    // verify(jobStoreMock, times(1)).createJobCluster(any());
    // verify(jobStoreMock, times(1)).updateJobCluster(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) WorkerTerminate(io.mantisrx.master.jobcluster.job.worker.WorkerTerminate) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) WorkerEvent(io.mantisrx.server.master.scheduler.WorkerEvent)

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