Search in sources :

Example 1 with CompactJobInfo

use of io.mantisrx.server.master.http.api.CompactJobInfo in project mantis by Netflix.

the class JobRouteTest method testJobClusterGetJobsCompact.

@Test(dependsOnMethods = { "testJobClusterGetJobDetail" })
public void testJobClusterGetJobsCompact() throws InterruptedException {
    final CompletionStage<HttpResponse> responseFuture = http.singleRequest(HttpRequest.GET(jobAPIEndpoint("list?compact=true")));
    try {
        responseFuture.thenCompose(r -> processRespFut(r, Optional.of(200))).whenComplete((msg, t) -> {
            String responseMessage = getResponseMessage(msg, t);
            logger.info("got response {}", responseMessage);
            List<CompactJobInfo> jobIdInfos = Collections.emptyList();
            try {
                jobIdInfos = Jackson.fromJSON(responseMessage, new TypeReference<List<CompactJobInfo>>() {
                });
            } catch (IOException e) {
                logger.error("failed to get CompactJobInfos from json response {}", responseMessage, e);
                fail("compactJobInfo deser failed");
            }
            logger.info("got jobIdInfos {}", jobIdInfos);
            assertEquals(1, jobIdInfos.size());
            CompactJobInfo jobInfo = jobIdInfos.get(0);
            assertEquals("sine-function-1", jobInfo.getJobId());
            assertEquals("nmahilani", jobInfo.getUser());
            assertEquals(7, jobInfo.getLabels().size());
            assertEquals(2, jobInfo.getNumStages());
            assertEquals(2, jobInfo.getNumWorkers());
            assertTrue(jobInfo.getState().equals(MantisJobState.Accepted) || jobInfo.getState().equals(MantisJobState.Launched));
            assertEquals(2.0, jobInfo.getTotCPUs(), 0.0);
            // TODO total memory is 400 for old master, 2048 for new master
            // assertEquals(400.0, jobInfo.getTotMemory(), 0.0);
            assertEquals(MantisJobDurationType.Perpetual, jobInfo.getType());
            assertTrue(Collections.singletonMap("Started", 2).equals(jobInfo.getStatesSummary()) || Collections.singletonMap("StartInitiated", 2).equals(jobInfo.getStatesSummary()) || Collections.singletonMap("Launched", 2).equals(jobInfo.getStatesSummary()) || Collections.singletonMap("Accepted", 2).equals(jobInfo.getStatesSummary()));
        }).toCompletableFuture().get(2, TimeUnit.SECONDS);
    } catch (ExecutionException e) {
        throw new RuntimeException(e);
    } catch (TimeoutException e) {
        throw new RuntimeException(e);
    }
}
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) CompactJobInfo(io.mantisrx.server.master.http.api.CompactJobInfo) HttpResponse(akka.http.javadsl.model.HttpResponse) Matchers.anyString(org.mockito.Matchers.anyString) ByteString(akka.util.ByteString) TypeReference(io.mantisrx.shaded.com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) Test(org.testng.annotations.Test)

Example 2 with CompactJobInfo

use of io.mantisrx.server.master.http.api.CompactJobInfo in project mantis by Netflix.

the class JobClusterProtoAdapter method toCompactJobInfo.

public static final CompactJobInfo toCompactJobInfo(final MantisJobMetadataView view) {
    MantisJobMetadata jm = view.getJobMetadata();
    int workers = 0;
    double totCPUs = 0.0;
    double totMem = 0.0;
    Map<String, Integer> stSmry = new HashMap<>();
    for (MantisStageMetadata s : view.getStageMetadataList()) {
        workers += s.getNumWorkers();
        totCPUs += s.getNumWorkers() * s.getMachineDefinition().getCpuCores();
        totMem += s.getNumWorkers() * s.getMachineDefinition().getMemoryMB();
    }
    for (MantisWorkerMetadata w : view.getWorkerMetadataList()) {
        final Integer prevVal = stSmry.get(w.getState() + "");
        if (prevVal == null) {
            stSmry.put(w.getState() + "", 1);
        } else {
            stSmry.put(w.getState() + "", prevVal + 1);
        }
    }
    return new CompactJobInfo(jm.getJobId(), (jm.getJarUrl() != null) ? jm.getJarUrl().toString() : "", jm.getSubmittedAt(), jm.getUser(), jm.getState(), jm.getSla() != null ? jm.getSla().getDurationType() : MantisJobDurationType.Transient, jm.getNumStages(), workers, totCPUs, totMem, stSmry, jm.getLabels());
}
Also used : MantisJobMetadata(io.mantisrx.server.master.store.MantisJobMetadata) MantisWorkerMetadata(io.mantisrx.server.master.store.MantisWorkerMetadata) HashMap(java.util.HashMap) CompactJobInfo(io.mantisrx.server.master.http.api.CompactJobInfo) MantisStageMetadata(io.mantisrx.server.master.store.MantisStageMetadata)

Aggregations

CompactJobInfo (io.mantisrx.server.master.http.api.CompactJobInfo)2 NotUsed (akka.NotUsed)1 ActorRef (akka.actor.ActorRef)1 ActorSystem (akka.actor.ActorSystem)1 ConnectHttp (akka.http.javadsl.ConnectHttp)1 Http (akka.http.javadsl.Http)1 ServerBinding (akka.http.javadsl.ServerBinding)1 ContentTypes (akka.http.javadsl.model.ContentTypes)1 HttpCharsets (akka.http.javadsl.model.HttpCharsets)1 HttpEntities (akka.http.javadsl.model.HttpEntities)1 HttpEntity (akka.http.javadsl.model.HttpEntity)1 HttpMethods (akka.http.javadsl.model.HttpMethods)1 HttpRequest (akka.http.javadsl.model.HttpRequest)1 HttpResponse (akka.http.javadsl.model.HttpResponse)1 MediaTypes (akka.http.javadsl.model.MediaTypes)1 ActorMaterializer (akka.stream.ActorMaterializer)1 Flow (akka.stream.javadsl.Flow)1 ByteString (akka.util.ByteString)1 TestHelpers (com.netflix.mantis.master.scheduler.TestHelpers)1 JobClustersManagerActor (io.mantisrx.master.JobClustersManagerActor)1