Search in sources :

Example 1 with ListJobsRequest

use of io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobsRequest in project mantis by Netflix.

the class JobClusterActor method onJobList.

@Override
public void onJobList(final ListJobsRequest request) {
    if (logger.isDebugEnabled()) {
        logger.info("Entering JCA:onJobList");
    }
    final ActorRef sender = getSender();
    final ActorRef self = getSelf();
    Set<JobId> jobIdsFilteredByLabelsSet = new HashSet<>();
    // If labels criterion is given prefilter by labels
    if (!request.getCriteria().getMatchingLabels().isEmpty()) {
        jobIdsFilteredByLabelsSet = jobManager.getJobsMatchingLabels(request.getCriteria().getMatchingLabels(), request.getCriteria().getLabelsOperand());
        // Found no jobs matching labels exit
        if (jobIdsFilteredByLabelsSet.isEmpty()) {
            if (logger.isTraceEnabled()) {
                logger.trace("Exit JCA:onJobList {}", jobIdsFilteredByLabelsSet.size());
            }
            sender.tell(new ListJobsResponse(request.requestId, SUCCESS, "", new ArrayList<>()), self);
            return;
        }
    }
    // Found jobs matching labels or no labels criterion given.
    // Apply additional criterion to both active and completed jobs
    getFilteredNonTerminalJobList(request.getCriteria(), jobIdsFilteredByLabelsSet).mergeWith(getFilteredTerminalJobList(request.getCriteria(), jobIdsFilteredByLabelsSet)).collect(() -> Lists.<MantisJobMetadataView>newArrayList(), List::add).doOnNext(resultList -> {
        if (logger.isTraceEnabled()) {
            logger.trace("Exit JCA:onJobList {}", resultList.size());
        }
        sender.tell(new ListJobsResponse(request.requestId, SUCCESS, "", resultList), self);
    }).subscribe();
}
Also used : JobId(io.mantisrx.server.master.domain.JobId) Terminated(akka.actor.Terminated) Optional.of(java.util.Optional.of) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) Action1(rx.functions.Action1) TriggerOperator(com.netflix.fenzo.triggers.TriggerOperator) GetLastSubmittedJobIdStreamResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLastSubmittedJobIdStreamResponse) JobActor(io.mantisrx.master.jobcluster.job.JobActor) ListArchivedWorkersRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListArchivedWorkersRequest) ActorRef(akka.actor.ActorRef) UpdateJobClusterLabelsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterLabelsResponse) UpdateJobClusterArtifactResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterArtifactResponse) Duration(java.time.Duration) Map(java.util.Map) CronPolicy(io.mantisrx.server.master.domain.IJobClusterDefinition.CronPolicy) Schedulers(rx.schedulers.Schedulers) Metrics(io.mantisrx.common.metrics.Metrics) Preconditions(com.netflix.spectator.impl.Preconditions) DisableJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DisableJobClusterResponse) ListCompletedJobsInClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListCompletedJobsInClusterResponse) JobDefinition(io.mantisrx.server.master.domain.JobDefinition) Set(java.util.Set) ListCompletedJobsInClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListCompletedJobsInClusterRequest) ScaleStageRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ScaleStageRequest) JobStartedEvent(io.mantisrx.master.jobcluster.proto.JobClusterProto.JobStartedEvent) SubmitJobRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.SubmitJobRequest) CompletionStage(java.util.concurrent.CompletionStage) UpdateJobClusterWorkerMigrationStrategyRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterWorkerMigrationStrategyRequest) TriggerNotFoundException(com.netflix.fenzo.triggers.exceptions.TriggerNotFoundException) JobHelper(io.mantisrx.master.jobcluster.job.JobHelper) ListJobIdsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobIdsRequest) BehaviorSubject(rx.subjects.BehaviorSubject) ListWorkersRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListWorkersRequest) GetJobDefinitionUpdatedFromJobActorRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDefinitionUpdatedFromJobActorRequest) Optional.empty(java.util.Optional.empty) SERVER_ERROR(io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.SERVER_ERROR) CronTrigger(com.netflix.fenzo.triggers.CronTrigger) MetricsRegistry(io.mantisrx.common.metrics.MetricsRegistry) JobConstraints(io.mantisrx.runtime.JobConstraints) LabelUtils(com.mantisrx.common.utils.LabelUtils) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ListJobIdsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobIdsResponse) SupervisorStrategy(akka.actor.SupervisorStrategy) JobClusterDefinitionImpl(io.mantisrx.server.master.domain.JobClusterDefinitionImpl) WorkerEvent(io.mantisrx.server.master.scheduler.WorkerEvent) GetLastSubmittedJobIdStreamRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLastSubmittedJobIdStreamRequest) Label(io.mantisrx.common.Label) EnableJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.EnableJobClusterRequest) GetJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterRequest) UpdateJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterRequest) MANTIS_MASTER_USER(io.mantisrx.master.StringConstants.MANTIS_MASTER_USER) CLIENT_ERROR_NOT_FOUND(io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.CLIENT_ERROR_NOT_FOUND) UpdateJobClusterWorkerMigrationStrategyResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterWorkerMigrationStrategyResponse) CompletedJob(io.mantisrx.server.master.domain.JobClusterDefinitionImpl.CompletedJob) IMantisJobMetadata(io.mantisrx.master.jobcluster.job.IMantisJobMetadata) KillJobResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.KillJobResponse) SchedulerException(com.netflix.fenzo.triggers.exceptions.SchedulerException) IMantisWorkerMetadata(io.mantisrx.master.jobcluster.job.worker.IMantisWorkerMetadata) ListJobsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobsResponse) EnableJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.EnableJobClusterResponse) IJobClusterDefinition(io.mantisrx.server.master.domain.IJobClusterDefinition) JobState(io.mantisrx.master.jobcluster.job.JobState) GetJobSchedInfoRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobSchedInfoRequest) LoggerFactory(org.slf4j.LoggerFactory) GaugeCallback(io.mantisrx.common.metrics.spectator.GaugeCallback) StageSchedulingInfo(io.mantisrx.runtime.descriptor.StageSchedulingInfo) JobCompletedReason(io.mantisrx.server.core.JobCompletedReason) InvalidJobRequest(io.mantisrx.server.master.InvalidJobRequest) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) ListJobsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobsRequest) CLIENT_ERROR(io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.CLIENT_ERROR) GetJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterResponse) JobClusterProto(io.mantisrx.master.jobcluster.proto.JobClusterProto) GetLatestJobDiscoveryInfoResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLatestJobDiscoveryInfoResponse) GetJobDetailsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsResponse) BasicTag(com.netflix.spectator.api.BasicTag) JobProto(io.mantisrx.master.jobcluster.proto.JobProto) ResubmitWorkerResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ResubmitWorkerResponse) ConstraintsEvaluators(io.mantisrx.server.master.ConstraintsEvaluators) DisableJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DisableJobClusterRequest) ResubmitWorkerRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ResubmitWorkerRequest) GetJobDefinitionUpdatedFromJobActorResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDefinitionUpdatedFromJobActorResponse) UpdateJobClusterLabelsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterLabelsRequest) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SLA(io.mantisrx.server.master.domain.SLA) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) GetJobSchedInfoResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobSchedInfoResponse) Objects(java.util.Objects) List(java.util.List) PatternsCS.ask(akka.pattern.PatternsCS.ask) GetJobDetailsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsRequest) SubmitJobResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.SubmitJobResponse) ConfigurationProvider(io.mantisrx.server.master.config.ConfigurationProvider) Optional(java.util.Optional) Props(akka.actor.Props) UpdateJobClusterSLARequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterSLARequest) MantisJobMetadataView(io.mantisrx.master.jobcluster.job.MantisJobMetadataView) ScaleStageResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ScaleStageResponse) UpdateJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterResponse) JobIdInfo(io.mantisrx.master.api.akka.route.proto.JobClusterProtoAdapter.JobIdInfo) KillJobRequest(io.mantisrx.master.jobcluster.proto.JobClusterProto.KillJobRequest) ListArchivedWorkersResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListArchivedWorkersResponse) MantisJobMetadataImpl(io.mantisrx.master.jobcluster.job.MantisJobMetadataImpl) JobSla(io.mantisrx.runtime.JobSla) HashMap(java.util.HashMap) UpdateJobClusterSLAResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterSLAResponse) MantisActorSupervisorStrategy(io.mantisrx.master.akka.MantisActorSupervisorStrategy) ConcurrentMap(java.util.concurrent.ConcurrentMap) Observable(rx.Observable) HashSet(java.util.HashSet) LifecycleEventsProto(io.mantisrx.master.events.LifecycleEventsProto) DeleteJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DeleteJobClusterResponse) ListWorkersResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListWorkersResponse) AbstractActorWithTimers(akka.actor.AbstractActorWithTimers) JobClusterAlreadyExistsException(io.mantisrx.server.master.persistence.exceptions.JobClusterAlreadyExistsException) Counter(io.mantisrx.common.metrics.Counter) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Optional.ofNullable(java.util.Optional.ofNullable) ListJobCriteria(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobCriteria) GetLatestJobDiscoveryInfoRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLatestJobDiscoveryInfoRequest) JobClusterConfig(io.mantisrx.server.master.domain.JobClusterConfig) SUCCESS(io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.SUCCESS) JobClusterManagerProto(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto) Lists(io.mantisrx.shaded.com.google.common.collect.Lists) UpdateJobClusterArtifactRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterArtifactRequest) Collections(java.util.Collections) LifecycleEventPublisher(io.mantisrx.master.events.LifecycleEventPublisher) JobClustersManagerInitializeResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.JobClustersManagerInitializeResponse) MetricGroupId(io.mantisrx.common.metrics.spectator.MetricGroupId) ActorRef(akka.actor.ActorRef) ArrayList(java.util.ArrayList) ListJobsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobsResponse) ArrayList(java.util.ArrayList) List(java.util.List) JobId(io.mantisrx.server.master.domain.JobId) HashSet(java.util.HashSet)

Example 2 with ListJobsRequest

use of io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobsRequest in project mantis by Netflix.

the class JobClusterTest method testLostWorkerGetsReplaced.

@Test
public void testLostWorkerGetsReplaced() {
    TestKit probe = new TestKit(system);
    String clusterName = "testLostWorkerGetsReplaced";
    MantisScheduler schedulerMock = mock(MantisScheduler.class);
    // MantisJobStore jobStoreMock = mock(MantisJobStore.class);
    MantisJobStore jobStoreSpied = Mockito.spy(jobStore);
    final JobClusterDefinitionImpl fakeJobCluster = createFakeJobClusterDefn(clusterName);
    ActorRef jobClusterActor = system.actorOf(props(clusterName, jobStoreSpied, 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.killJobAndVerify(probe, clusterName, new JobId(clusterName, 1), jobClusterActor);
        verify(jobStoreSpied, times(1)).createJobCluster(any());
        verify(jobStoreSpied, times(1)).updateJobCluster(any());
        int stageNo = 1;
        // send launched event
        WorkerId workerId = new WorkerId(jobId, 0, 1);
        // send heartbeat
        JobTestHelper.sendLaunchedInitiatedStartedEventsToWorker(probe, jobClusterActor, jobId, stageNo, workerId);
        // check job status again
        jobClusterActor.tell(new GetJobDetailsRequest("nj", jobId), probe.getRef());
        // jobActor.tell(new JobProto.InitJob(probe.getRef()), probe.getRef());
        GetJobDetailsResponse resp2 = probe.expectMsgClass(GetJobDetailsResponse.class);
        System.out.println("resp " + resp2 + " msg " + resp2.message);
        assertEquals(SUCCESS, resp2.responseCode);
        // Job started
        assertEquals(JobState.Launched, resp2.getJobMetadata().get().getState());
        // send launched event
        // worker 2 gets terminated abnormally
        JobTestHelper.sendWorkerTerminatedEvent(probe, jobClusterActor, jobId, workerId);
        // replaced worker comes up and sends events
        WorkerId workerId2_replaced = new WorkerId(jobId, 0, 2);
        JobTestHelper.sendLaunchedInitiatedStartedEventsToWorker(probe, jobClusterActor, jobId, stageNo, workerId2_replaced);
        jobClusterActor.tell(new GetJobDetailsRequest("nj", jobId), probe.getRef());
        GetJobDetailsResponse resp4 = probe.expectMsgClass(GetJobDetailsResponse.class);
        IMantisJobMetadata jobMeta = resp4.getJobMetadata().get();
        Map<Integer, ? extends IMantisStageMetadata> stageMetadata = jobMeta.getStageMetadata();
        IMantisStageMetadata stage = stageMetadata.get(1);
        for (JobWorker worker : stage.getAllWorkers()) {
            System.out.println("worker -> " + worker.getMetadata());
        }
        // 2 initial schedules and 1 replacement
        verify(schedulerMock, timeout(1_000).times(2)).scheduleWorker(any());
        // archive worker should get called once for the dead worker
        // verify(jobStoreMock, timeout(1_000).times(1)).archiveWorker(any());
        Mockito.verify(jobStoreSpied).archiveWorker(any());
        jobClusterActor.tell(new ListJobsRequest(), probe.getRef());
        ListJobsResponse listResp2 = probe.expectMsgClass(ListJobsResponse.class);
        assertEquals(SUCCESS, listResp2.responseCode);
        assertEquals(1, listResp2.getJobList().size());
        for (MantisJobMetadataView jb : listResp2.getJobList()) {
            System.out.println("Jb -> " + jb);
        }
    // assertEquals(jobActor, probe.getLastSender());
    } catch (InvalidJobException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        fail();
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    } finally {
        system.stop(jobClusterActor);
    }
}
Also used : JobClusterProto(io.mantisrx.master.jobcluster.proto.JobClusterProto) ActorRef(akka.actor.ActorRef) GetJobDetailsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsRequest) IMantisJobMetadata(io.mantisrx.master.jobcluster.job.IMantisJobMetadata) ListJobsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobsResponse) 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) GetJobDetailsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsResponse) JobWorker(io.mantisrx.master.jobcluster.job.worker.JobWorker) ListJobsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobsRequest) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) MantisJobMetadataView(io.mantisrx.master.jobcluster.job.MantisJobMetadataView) IMantisStageMetadata(io.mantisrx.master.jobcluster.job.IMantisStageMetadata) InvalidJobException(io.mantisrx.runtime.command.InvalidJobException) Test(org.junit.Test)

Example 3 with ListJobsRequest

use of io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobsRequest in project mantis by Netflix.

the class JobClusterTest method testListJobWithLabelMatch.

@Test
public void testListJobWithLabelMatch() {
    TestKit probe = new TestKit(system);
    String clusterName = "testListJobWithLabelMatch";
    try {
        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;
        List<Label> labelList1 = new ArrayList<>();
        labelList1.add(new Label("l1", "l1v1"));
        jobDefn1 = createJob(clusterName, labelList1);
        String jobId = clusterName + "-1";
        JobTestHelper.submitJobAndVerifySuccess(probe, clusterName, jobClusterActor, jobDefn1, jobId);
        List<Label> labelList2 = new ArrayList<>();
        labelList2.add(new Label("l2", "l2v2"));
        String jobId2 = clusterName + "-2";
        JobDefinition jobDefn2 = createJob(clusterName, labelList2);
        JobTestHelper.submitJobAndVerifySuccess(probe, clusterName, jobClusterActor, jobDefn2, jobId2);
        // Query for Label1
        List<Integer> emptyIntList = Lists.newArrayList();
        List<WorkerState.MetaState> workerState = Lists.newArrayList();
        ListJobCriteria criteria1 = new ListJobCriteria(Optional.empty(), Optional.empty(), emptyIntList, emptyIntList, emptyIntList, workerState, Optional.empty(), Optional.empty(), of("l1=l1v1"), Optional.empty());
        jobClusterActor.tell(new ListJobsRequest(criteria1), probe.getRef());
        ListJobsResponse listResp = probe.expectMsgClass(ListJobsResponse.class);
        assertEquals(SUCCESS, listResp.responseCode);
        // Only job1 should be returned
        assertEquals(1, listResp.getJobList().size());
        assertEquals(jobId, listResp.getJobList().get(0).getJobMetadata().getJobId());
        assertTrue(listResp.getJobList().get(0).getStageMetadataList().size() == 1);
        System.out.println("Workers returned : " + listResp.getJobList().get(0).getWorkerMetadataList());
        assertTrue(listResp.getJobList().get(0).getWorkerMetadataList().size() == 1);
        // Query with an OR query for both labels
        ListJobCriteria criteria2 = new ListJobCriteria(Optional.empty(), Optional.empty(), emptyIntList, emptyIntList, emptyIntList, workerState, Optional.empty(), Optional.empty(), of("l1=l1v1,l2=l2v2"), Optional.empty());
        jobClusterActor.tell(new ListJobsRequest(criteria2), probe.getRef());
        ListJobsResponse listRes2 = probe.expectMsgClass(ListJobsResponse.class);
        assertEquals(SUCCESS, listRes2.responseCode);
        // Both jobs should be returned
        assertEquals(2, listRes2.getJobList().size());
        assertTrue(jobId.equals(listRes2.getJobList().get(0).getJobMetadata().getJobId()) || jobId.equals(listRes2.getJobList().get(1).getJobMetadata().getJobId()));
        assertTrue(jobId2.equals(listRes2.getJobList().get(0).getJobMetadata().getJobId()) || jobId2.equals(listRes2.getJobList().get(1).getJobMetadata().getJobId()));
        // Query with an AND query for both labels
        ListJobCriteria criteria3 = new ListJobCriteria(Optional.empty(), Optional.empty(), emptyIntList, emptyIntList, emptyIntList, workerState, Optional.empty(), Optional.empty(), of("l1=l1v1,l2=l2v2"), of("and"));
        jobClusterActor.tell(new ListJobsRequest(criteria3), probe.getRef());
        ListJobsResponse listRes3 = probe.expectMsgClass(ListJobsResponse.class);
        assertEquals(SUCCESS, listRes3.responseCode);
        // No jobs should be returned
        assertEquals(0, listRes3.getJobList().size());
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : JobClusterProto(io.mantisrx.master.jobcluster.proto.JobClusterProto) ActorRef(akka.actor.ActorRef) Label(io.mantisrx.common.Label) ArrayList(java.util.ArrayList) ListJobsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobsResponse) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) TestKit(akka.testkit.javadsl.TestKit) Matchers.anyString(org.mockito.Matchers.anyString) ListJobCriteria(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobCriteria) InvalidJobException(io.mantisrx.runtime.command.InvalidJobException) ListJobsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobsRequest) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) Test(org.junit.Test)

Example 4 with ListJobsRequest

use of io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobsRequest in project mantis by Netflix.

the class JobClusterTest method testListJobsForCluster.

@Test
public void testListJobsForCluster() throws InvalidJobException, InterruptedException {
    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);
    JobTestHelper.sendLaunchedInitiatedStartedEventsToWorker(probe, jobClusterActor, jobId, 1, new WorkerId(clusterName, jobId, 0, 1));
    String jobId2 = clusterName + "-2";
    JobTestHelper.submitJobAndVerifySuccess(probe, clusterName, jobClusterActor, jobDefn1, jobId2);
    JobTestHelper.sendLaunchedInitiatedStartedEventsToWorker(probe, jobClusterActor, jobId2, 1, new WorkerId(clusterName, jobId2, 0, 1));
    jobClusterActor.tell(new ListJobsRequest(), probe.getRef());
    // Thread.sleep(1000);
    ListJobsResponse listResp = probe.expectMsgClass(ListJobsResponse.class);
    assertEquals(SUCCESS, listResp.responseCode);
    assertEquals(2, listResp.getJobList().size());
    // assertTrue(listResp.getJobIds().contains(JobId.fromId(jobId).get()));
    // assertTrue(listResp.getJobIds().contains(JobId.fromId(jobId2).get()));
    JobTestHelper.killJobAndVerify(probe, clusterName, new JobId(clusterName, 1), jobClusterActor);
    jobClusterActor.tell(new ListJobsRequest(new ListJobCriteria(empty(), empty(), Lists.newArrayList(), Lists.newArrayList(), Lists.newArrayList(), Lists.newArrayList(), of(true), empty(), empty(), empty())), probe.getRef());
    ListJobsResponse listResp2 = probe.expectMsgClass(ListJobsResponse.class);
    assertEquals(SUCCESS, listResp2.responseCode);
    assertEquals(1, listResp2.getJobList().size());
    // assertFalse(listResp2.getJobIds().contains(JobId.fromId(jobId).get()));
    // assertTrue(listResp2.getJobIds().contains(JobId.fromId(jobId2).get()));
    JobTestHelper.killJobAndVerify(probe, clusterName, new JobId(clusterName, 2), jobClusterActor);
    jobClusterActor.tell(new ListJobsRequest(new ListJobCriteria(empty(), empty(), Lists.newArrayList(), Lists.newArrayList(), Lists.newArrayList(), Lists.newArrayList(), of(true), empty(), empty(), empty())), probe.getRef());
    ListJobsResponse listResp3 = probe.expectMsgClass(ListJobsResponse.class);
    assertEquals(SUCCESS, listResp3.responseCode);
    assertEquals(0, listResp3.getJobList().size());
// assertFalse(listResp3.getJobIds().contains(JobId.fromId(jobId).get()));
// assertFalse(listResp3.getJobIds().contains(JobId.fromId(jobId2).get()));
}
Also used : JobClusterProto(io.mantisrx.master.jobcluster.proto.JobClusterProto) ActorRef(akka.actor.ActorRef) ListJobsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobsResponse) 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) ListJobCriteria(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobCriteria) ListJobsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobsRequest) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) Test(org.junit.Test)

Aggregations

ActorRef (akka.actor.ActorRef)4 ListJobsRequest (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobsRequest)4 ListJobsResponse (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobsResponse)4 JobClusterProto (io.mantisrx.master.jobcluster.proto.JobClusterProto)4 MantisJobStore (io.mantisrx.server.master.persistence.MantisJobStore)4 MantisScheduler (io.mantisrx.server.master.scheduler.MantisScheduler)4 TestKit (akka.testkit.javadsl.TestKit)3 Label (io.mantisrx.common.Label)2 IMantisJobMetadata (io.mantisrx.master.jobcluster.job.IMantisJobMetadata)2 MantisJobMetadataView (io.mantisrx.master.jobcluster.job.MantisJobMetadataView)2 GetJobDetailsRequest (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsRequest)2 GetJobDetailsResponse (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsResponse)2 ListJobCriteria (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobCriteria)2 Test (org.junit.Test)2 Matchers.anyString (org.mockito.Matchers.anyString)2 AbstractActorWithTimers (akka.actor.AbstractActorWithTimers)1 Props (akka.actor.Props)1 SupervisorStrategy (akka.actor.SupervisorStrategy)1 Terminated (akka.actor.Terminated)1 PatternsCS.ask (akka.pattern.PatternsCS.ask)1