Search in sources :

Example 1 with JobSchedulingInfo

use of io.mantisrx.server.core.JobSchedulingInfo in project mantis by Netflix.

the class JobDiscoveryStreamRouteTest method testJobDiscoveryStreamForNonExistentJob.

@Test
public void testJobDiscoveryStreamForNonExistentJob() throws InterruptedException {
    // The current behavior of Mantis client is to retry non-200 responses
    // This test overrides the default retry/repeat behavior to test a Sched info observable would complete if the job id requested is non-existent
    final CountDownLatch latch = new CountDownLatch(1);
    Observable<JobSchedulingInfo> jobSchedulingInfoObservable = mantisClient.discoveryStream("testJobCluster-1", obs -> Observable.just(1), obs -> Observable.empty());
    jobSchedulingInfoObservable.doOnNext(x -> logger.info("onNext {}", x)).doOnError(t -> logger.warn("onError", t)).doOnCompleted(() -> {
        logger.info("onCompleted");
        latch.countDown();
    }).subscribe();
    latch.await();
}
Also used : AgentsErrorMonitorActor(io.mantisrx.master.scheduler.AgentsErrorMonitorActor) TestHelpers(com.netflix.mantis.master.scheduler.TestHelpers) Flow(akka.stream.javadsl.Flow) LoggerFactory(org.slf4j.LoggerFactory) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) Test(org.testng.annotations.Test) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) Function(java.util.function.Function) AuditEventSubscriberLoggingImpl(io.mantisrx.master.events.AuditEventSubscriberLoggingImpl) JobClustersManagerActor(io.mantisrx.master.JobClustersManagerActor) Observable(rx.Observable) ActorMaterializer(akka.stream.ActorMaterializer) LifecycleEventPublisherImpl(io.mantisrx.master.events.LifecycleEventPublisherImpl) JobTestHelper(io.mantisrx.master.jobcluster.job.JobTestHelper) ActorRef(akka.actor.ActorRef) Duration(java.time.Duration) StatusEventSubscriberLoggingImpl(io.mantisrx.master.events.StatusEventSubscriberLoggingImpl) NamedJobInfo(io.mantisrx.server.core.NamedJobInfo) ServerBinding(akka.http.javadsl.ServerBinding) JobSchedulingInfo(io.mantisrx.server.core.JobSchedulingInfo) AfterClass(org.testng.annotations.AfterClass) Logger(org.slf4j.Logger) WorkerEventSubscriberLoggingImpl(io.mantisrx.master.events.WorkerEventSubscriberLoggingImpl) Http(akka.http.javadsl.Http) HttpRequest(akka.http.javadsl.model.HttpRequest) BeforeClass(org.testng.annotations.BeforeClass) JobDiscoveryRouteHandler(io.mantisrx.master.api.akka.route.handlers.JobDiscoveryRouteHandler) HttpResponse(akka.http.javadsl.model.HttpResponse) FakeMantisScheduler(io.mantisrx.master.scheduler.FakeMantisScheduler) JobClusterManagerProto(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto) CountDownLatch(java.util.concurrent.CountDownLatch) ConnectHttp(akka.http.javadsl.ConnectHttp) CompletionStage(java.util.concurrent.CompletionStage) NotUsed(akka.NotUsed) JobDiscoveryRouteHandlerAkkaImpl(io.mantisrx.master.api.akka.route.handlers.JobDiscoveryRouteHandlerAkkaImpl) LifecycleEventPublisher(io.mantisrx.master.events.LifecycleEventPublisher) JobSchedulingInfo(io.mantisrx.server.core.JobSchedulingInfo) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.testng.annotations.Test)

Example 2 with JobSchedulingInfo

use of io.mantisrx.server.core.JobSchedulingInfo in project mantis by Netflix.

the class JobRouteTest method testSchedulingInfo.

@Test(dependsOnMethods = { "testNamedJobInfoStream" })
public void testSchedulingInfo() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    final String jobId = "sine-function-1";
    // final AtomicBoolean flag = new AtomicBoolean(false);
    Observable<JobSchedulingInfo> jobSchedulingInfoObservable = mantisClient.schedulingChanges(jobId);
    jobSchedulingInfoObservable.map(schedInfo -> {
        logger.info("schedInfo {}", schedInfo);
        try {
            assertEquals(jobId, schedInfo.getJobId());
            Map<Integer, WorkerAssignments> wa = schedInfo.getWorkerAssignments();
            assertEquals(2, wa.size());
            // 1 worker in stage 0
            assertEquals(1, wa.get(0).getHosts().size());
            assertEquals(0, wa.get(0).getHosts().get(1).getWorkerIndex());
            assertEquals(1, wa.get(0).getHosts().get(1).getWorkerNumber());
            assertEquals(MantisJobState.Started, wa.get(0).getHosts().get(1).getState());
            // 1 worker in stage 1
            assertEquals(1, wa.get(1).getHosts().size());
            assertEquals(0, wa.get(1).getHosts().get(2).getWorkerIndex());
            assertEquals(2, wa.get(1).getHosts().get(2).getWorkerNumber());
            assertEquals(MantisJobState.Started, wa.get(1).getHosts().get(2).getState());
        // if (flag.compareAndSet(false, true)) {
        // testJobResubmitWorker();
        // }
        } catch (Exception e) {
            logger.error("caught exception", e);
            org.testng.Assert.fail("testSchedulingInfo test failed with exception " + e.getMessage(), e);
        }
        latch.countDown();
        return schedInfo;
    }).take(1).doOnError(t -> logger.warn("onError", t)).doOnCompleted(() -> logger.info("onCompleted")).doAfterTerminate(() -> latch.countDown()).subscribe();
    latch.await();
}
Also used : JobStatusStreamRoute(io.mantisrx.master.api.akka.route.v1.JobStatusStreamRoute) TestHelpers(com.netflix.mantis.master.scheduler.TestHelpers) MantisJobDurationType(io.mantisrx.runtime.MantisJobDurationType) MantisJobState(io.mantisrx.runtime.MantisJobState) MasterDescription(io.mantisrx.server.core.master.MasterDescription) JobRouteHandler(io.mantisrx.master.api.akka.route.handlers.JobRouteHandler) TypeReference(io.mantisrx.shaded.com.fasterxml.jackson.core.type.TypeReference) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) Test(org.testng.annotations.Test) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) JobsRoute(io.mantisrx.master.api.akka.route.v1.JobsRoute) MantisStageMetadataWritable(io.mantisrx.server.master.store.MantisStageMetadataWritable) JobClustersManagerActor(io.mantisrx.master.JobClustersManagerActor) JobPayloads(io.mantisrx.master.api.akka.payloads.JobPayloads) ActorMaterializer(akka.stream.ActorMaterializer) ActorRef(akka.actor.ActorRef) MantisMasterRoute(io.mantisrx.master.api.akka.route.MantisMasterRoute) Duration(java.time.Duration) Map(java.util.Map) JobClusterProtoAdapter(io.mantisrx.master.api.akka.route.proto.JobClusterProtoAdapter) Assert.fail(org.junit.Assert.fail) LastSubmittedJobIdStreamRoute(io.mantisrx.master.api.akka.route.v1.LastSubmittedJobIdStreamRoute) StatusEventSubscriberLoggingImpl(io.mantisrx.master.events.StatusEventSubscriberLoggingImpl) ServerBinding(akka.http.javadsl.ServerBinding) HttpCharsets(akka.http.javadsl.model.HttpCharsets) JobStatusRouteHandler(io.mantisrx.master.api.akka.route.handlers.JobStatusRouteHandler) WorkerEventSubscriberLoggingImpl(io.mantisrx.master.events.WorkerEventSubscriberLoggingImpl) Jackson(io.mantisrx.master.api.akka.route.Jackson) BeforeClass(org.testng.annotations.BeforeClass) AdminMasterRoute(io.mantisrx.master.api.akka.route.v1.AdminMasterRoute) JobDiscoveryRouteHandler(io.mantisrx.master.api.akka.route.handlers.JobDiscoveryRouteHandler) HttpMethods(akka.http.javadsl.model.HttpMethods) WorkerAssignments(io.mantisrx.server.core.WorkerAssignments) JobClusterRouteHandler(io.mantisrx.master.api.akka.route.handlers.JobClusterRouteHandler) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) AgentClusterOperations(io.mantisrx.master.vm.AgentClusterOperations) CompletionStage(java.util.concurrent.CompletionStage) NotUsed(akka.NotUsed) AgentClustersRoute(io.mantisrx.master.api.akka.route.v1.AgentClustersRoute) ActorSystem(akka.actor.ActorSystem) JobDiscoveryStreamRoute(io.mantisrx.master.api.akka.route.v1.JobDiscoveryStreamRoute) JobDiscoveryRouteHandlerAkkaImpl(io.mantisrx.master.api.akka.route.handlers.JobDiscoveryRouteHandlerAkkaImpl) Optional(java.util.Optional) Mockito.mock(org.mockito.Mockito.mock) MantisJobMetadataView(io.mantisrx.master.jobcluster.job.MantisJobMetadataView) MantisWorkerMetadataWritable(io.mantisrx.server.master.store.MantisWorkerMetadataWritable) Flow(akka.stream.javadsl.Flow) JobRouteHandlerAkkaImpl(io.mantisrx.master.api.akka.route.handlers.JobRouteHandlerAkkaImpl) LeaderRedirectionFilter(io.mantisrx.server.master.LeaderRedirectionFilter) Matchers.anyString(org.mockito.Matchers.anyString) AuditEventSubscriberLoggingImpl(io.mantisrx.master.events.AuditEventSubscriberLoggingImpl) Observable(rx.Observable) JobClusterPayloads(io.mantisrx.master.api.akka.payloads.JobClusterPayloads) CompactJobInfo(io.mantisrx.server.master.http.api.CompactJobInfo) LifecycleEventPublisherImpl(io.mantisrx.master.events.LifecycleEventPublisherImpl) JobTestHelper(io.mantisrx.master.jobcluster.job.JobTestHelper) ByteString(akka.util.ByteString) HttpEntity(akka.http.javadsl.model.HttpEntity) NamedJobInfo(io.mantisrx.server.core.NamedJobInfo) LocalMasterMonitor(io.mantisrx.server.core.master.LocalMasterMonitor) LeadershipManagerLocalImpl(io.mantisrx.server.master.LeadershipManagerLocalImpl) JobClusterRouteHandlerAkkaImpl(io.mantisrx.master.api.akka.route.handlers.JobClusterRouteHandlerAkkaImpl) JobSchedulingInfo(io.mantisrx.server.core.JobSchedulingInfo) AfterClass(org.testng.annotations.AfterClass) Logger(org.slf4j.Logger) Assert.assertNotNull(org.junit.Assert.assertNotNull) Http(akka.http.javadsl.Http) HttpRequest(akka.http.javadsl.model.HttpRequest) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) ContentTypes(akka.http.javadsl.model.ContentTypes) HttpEntities(akka.http.javadsl.model.HttpEntities) HttpResponse(akka.http.javadsl.model.HttpResponse) FakeMantisScheduler(io.mantisrx.master.scheduler.FakeMantisScheduler) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) JobClusterManagerProto(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto) ConnectHttp(akka.http.javadsl.ConnectHttp) MediaTypes(akka.http.javadsl.model.MediaTypes) JobClustersRoute(io.mantisrx.master.api.akka.route.v1.JobClustersRoute) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) LifecycleEventPublisher(io.mantisrx.master.events.LifecycleEventPublisher) JobSchedulingInfo(io.mantisrx.server.core.JobSchedulingInfo) Matchers.anyString(org.mockito.Matchers.anyString) ByteString(akka.util.ByteString) CountDownLatch(java.util.concurrent.CountDownLatch) Map(java.util.Map) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.testng.annotations.Test)

Example 3 with JobSchedulingInfo

use of io.mantisrx.server.core.JobSchedulingInfo in project mantis by Netflix.

the class JobDiscoveryRouteTest method testSchedulingInfoStreamForNonExistentJob.

@Test
public void testSchedulingInfoStreamForNonExistentJob() throws InterruptedException {
    // The current behavior of Mantis client is to retry non-200 responses
    // This test overrides the default retry/repeat behavior to test a Sched info observable would complete if the job id requested is non-existent
    final CountDownLatch latch = new CountDownLatch(1);
    Observable<JobSchedulingInfo> jobSchedulingInfoObservable = mantisClient.schedulingChanges("testJobCluster-1", obs -> Observable.just(1), obs -> Observable.empty());
    jobSchedulingInfoObservable.doOnNext(x -> logger.info("onNext {}", x)).doOnError(t -> logger.warn("onError", t)).doOnCompleted(() -> {
        logger.info("onCompleted");
        latch.countDown();
    }).subscribe();
    latch.await();
}
Also used : AgentsErrorMonitorActor(io.mantisrx.master.scheduler.AgentsErrorMonitorActor) TestHelpers(com.netflix.mantis.master.scheduler.TestHelpers) Flow(akka.stream.javadsl.Flow) LoggerFactory(org.slf4j.LoggerFactory) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) Test(org.testng.annotations.Test) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) Function(java.util.function.Function) AuditEventSubscriberLoggingImpl(io.mantisrx.master.events.AuditEventSubscriberLoggingImpl) JobClustersManagerActor(io.mantisrx.master.JobClustersManagerActor) Observable(rx.Observable) ActorMaterializer(akka.stream.ActorMaterializer) LifecycleEventPublisherImpl(io.mantisrx.master.events.LifecycleEventPublisherImpl) JobTestHelper(io.mantisrx.master.jobcluster.job.JobTestHelper) ActorRef(akka.actor.ActorRef) Duration(java.time.Duration) StatusEventSubscriberLoggingImpl(io.mantisrx.master.events.StatusEventSubscriberLoggingImpl) NamedJobInfo(io.mantisrx.server.core.NamedJobInfo) ServerBinding(akka.http.javadsl.ServerBinding) JobSchedulingInfo(io.mantisrx.server.core.JobSchedulingInfo) AfterClass(org.testng.annotations.AfterClass) Logger(org.slf4j.Logger) WorkerEventSubscriberLoggingImpl(io.mantisrx.master.events.WorkerEventSubscriberLoggingImpl) Http(akka.http.javadsl.Http) HttpRequest(akka.http.javadsl.model.HttpRequest) BeforeClass(org.testng.annotations.BeforeClass) JobDiscoveryRouteHandler(io.mantisrx.master.api.akka.route.handlers.JobDiscoveryRouteHandler) HttpResponse(akka.http.javadsl.model.HttpResponse) FakeMantisScheduler(io.mantisrx.master.scheduler.FakeMantisScheduler) JobClusterManagerProto(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto) CountDownLatch(java.util.concurrent.CountDownLatch) ConnectHttp(akka.http.javadsl.ConnectHttp) CompletionStage(java.util.concurrent.CompletionStage) NotUsed(akka.NotUsed) ActorSystem(akka.actor.ActorSystem) JobDiscoveryRouteHandlerAkkaImpl(io.mantisrx.master.api.akka.route.handlers.JobDiscoveryRouteHandlerAkkaImpl) LifecycleEventPublisher(io.mantisrx.master.events.LifecycleEventPublisher) JobSchedulingInfo(io.mantisrx.server.core.JobSchedulingInfo) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.testng.annotations.Test)

Example 4 with JobSchedulingInfo

use of io.mantisrx.server.core.JobSchedulingInfo in project mantis by Netflix.

the class JobActor method onGetLatestJobDiscoveryInfo.

@Override
public void onGetLatestJobDiscoveryInfo(GetLatestJobDiscoveryInfoRequest r) {
    LOGGER.trace("Entering onGetLatestJobDiscoveryInfo {}", r);
    ActorRef sender = getSender();
    if (r.getJobCluster().equals(this.jobId.getCluster())) {
        JobSchedulingInfo schedulingInfo = workerManager.getJobStatusSubject().getValue();
        if (schedulingInfo != null) {
            sender.tell(new GetLatestJobDiscoveryInfoResponse(r.requestId, SUCCESS, "", ofNullable(schedulingInfo)), getSelf());
        } else {
            LOGGER.info("discoveryInfo from BehaviorSubject is null {}", jobId);
            sender.tell(new GetLatestJobDiscoveryInfoResponse(r.requestId, SERVER_ERROR, "discoveryInfo from BehaviorSubject is null " + jobId, empty()), getSelf());
        }
    } else {
        String msg = "JobCluster in the request " + r.getJobCluster() + " does not match Job Actors job ID " + this.jobId;
        LOGGER.warn(msg);
        sender.tell(new GetLatestJobDiscoveryInfoResponse(r.requestId, SERVER_ERROR, msg, empty()), getSelf());
    }
}
Also used : ActorRef(akka.actor.ActorRef) JobSchedulingInfo(io.mantisrx.server.core.JobSchedulingInfo) GetLatestJobDiscoveryInfoResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLatestJobDiscoveryInfoResponse)

Example 5 with JobSchedulingInfo

use of io.mantisrx.server.core.JobSchedulingInfo in project mantis by Netflix.

the class ConnectToNamedJob method main2.

public static void main2(final String[] args) {
    List<String> remArgs = Collections.emptyList();
    try {
        remArgs = Args.parse(ConnectToNamedJob.class, args);
    } catch (IllegalArgumentException e) {
        Args.usage(SubmitEphemeralJob.class);
        System.exit(1);
    }
    if (remArgs.isEmpty()) {
        System.err.println("Must provide JobId as argument");
        System.exit(1);
    }
    final String jobId = remArgs.get(0);
    Properties properties = new Properties();
    System.out.println("propfile=" + propFile);
    try (InputStream inputStream = new FileInputStream(propFile)) {
        properties.load(inputStream);
    } catch (IOException e) {
        e.printStackTrace();
    }
    MasterClientWrapper clientWrapper = new MasterClientWrapper(properties);
    clientWrapper.getMasterClientApi().doOnNext(new Action1<MantisMasterClientApi>() {

        @Override
        public void call(MantisMasterClientApi clientApi) {
            logger.info("************** connecting to schedInfo for job " + jobId);
            clientApi.schedulingChanges(jobId).doOnNext(new Action1<JobSchedulingInfo>() {

                @Override
                public void call(JobSchedulingInfo schedulingInfo) {
                    final WorkerAssignments workerAssignments = schedulingInfo.getWorkerAssignments().get(1);
                    for (Map.Entry<Integer, WorkerHost> entry : workerAssignments.getHosts().entrySet()) {
                        System.out.println("Worker " + entry.getKey() + ": state=" + entry.getValue().getState() + ", host=" + entry.getValue().getHost() + ", port=" + entry.getValue().getPort());
                    }
                }
            }).subscribe();
            ;
        }
    }).subscribe();
    // .subscribe();
    try {
        Thread.sleep(10000000);
    } catch (InterruptedException ie) {
    }
}
Also used : MasterClientWrapper(io.mantisrx.server.master.client.MasterClientWrapper) WorkerHost(io.mantisrx.server.core.WorkerHost) Action1(rx.functions.Action1) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JobSchedulingInfo(io.mantisrx.server.core.JobSchedulingInfo) IOException(java.io.IOException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) MantisMasterClientApi(io.mantisrx.server.master.client.MantisMasterClientApi) WorkerAssignments(io.mantisrx.server.core.WorkerAssignments) Map(java.util.Map)

Aggregations

JobSchedulingInfo (io.mantisrx.server.core.JobSchedulingInfo)20 WorkerAssignments (io.mantisrx.server.core.WorkerAssignments)16 CountDownLatch (java.util.concurrent.CountDownLatch)13 HashMap (java.util.HashMap)12 WorkerHost (io.mantisrx.server.core.WorkerHost)11 MantisMasterClientApi (io.mantisrx.server.master.client.MantisMasterClientApi)10 Observable (rx.Observable)10 Logger (org.slf4j.Logger)9 LoggerFactory (org.slf4j.LoggerFactory)9 Map (java.util.Map)8 MantisJobDurationType (io.mantisrx.runtime.MantisJobDurationType)7 MantisJobState (io.mantisrx.runtime.MantisJobState)7 TimeUnit (java.util.concurrent.TimeUnit)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 WorkerMap (io.mantisrx.runtime.WorkerMap)6 ActorRef (akka.actor.ActorRef)5 Test (org.junit.Test)5 Duration (java.time.Duration)4 List (java.util.List)4 Optional (java.util.Optional)4