Search in sources :

Example 21 with MantisScheduler

use of io.mantisrx.server.master.scheduler.MantisScheduler 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 22 with MantisScheduler

use of io.mantisrx.server.master.scheduler.MantisScheduler 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 23 with MantisScheduler

use of io.mantisrx.server.master.scheduler.MantisScheduler 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 24 with MantisScheduler

use of io.mantisrx.server.master.scheduler.MantisScheduler 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)

Example 25 with MantisScheduler

use of io.mantisrx.server.master.scheduler.MantisScheduler 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)

Aggregations

ActorRef (akka.actor.ActorRef)82 MantisScheduler (io.mantisrx.server.master.scheduler.MantisScheduler)82 MantisJobStore (io.mantisrx.server.master.persistence.MantisJobStore)77 Test (org.junit.Test)70 TestKit (akka.testkit.javadsl.TestKit)65 JobClusterProto (io.mantisrx.master.jobcluster.proto.JobClusterProto)49 Matchers.anyString (org.mockito.Matchers.anyString)45 InvalidJobException (io.mantisrx.runtime.command.InvalidJobException)41 WorkerId (io.mantisrx.server.core.domain.WorkerId)32 JobClusterManagerProto (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto)26 GetJobDetailsResponse (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsResponse)25 SchedulingInfo (io.mantisrx.runtime.descriptor.SchedulingInfo)21 IOException (java.io.IOException)20 JobId (io.mantisrx.server.master.domain.JobId)18 GetJobClusterRequest (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterRequest)16 GetJobClusterResponse (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterResponse)16 GetJobDetailsRequest (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsRequest)16 MachineDefinition (io.mantisrx.runtime.MachineDefinition)16 CountDownLatch (java.util.concurrent.CountDownLatch)13 IJobClusterDefinition (io.mantisrx.server.master.domain.IJobClusterDefinition)10