Search in sources :

Example 1 with HttpResponse

use of akka.http.javadsl.model.HttpResponse in project mantis by Netflix.

the class JobRouteTest method setupJobCluster.

@Test(dependsOnMethods = { "cleanupExistingJobs" })
public void setupJobCluster() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    final CompletionStage<HttpResponse> responseFuture = http.singleRequest(HttpRequest.POST(jobClusterAPIEndpoint("create")).withMethod(HttpMethods.POST).withEntity(HttpEntities.create(ContentTypes.APPLICATION_JSON, JobClusterPayloads.JOB_CLUSTER_CREATE)));
    responseFuture.thenCompose(r -> processRespFut(r, Optional.of(200))).whenComplete((r, t) -> {
        String responseMessage = getResponseMessage(r, t);
        logger.info("got response {}", responseMessage);
        assertEquals("sine-function created", responseMessage);
        latch.countDown();
    });
    assertTrue(latch.await(2, TimeUnit.SECONDS));
}
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) HttpResponse(akka.http.javadsl.model.HttpResponse) Matchers.anyString(org.mockito.Matchers.anyString) ByteString(akka.util.ByteString) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.testng.annotations.Test)

Example 2 with HttpResponse

use of akka.http.javadsl.model.HttpResponse in project mantis by Netflix.

the class AgentClustersRouteTest method testGetActiveAgentClusters.

@Test(dependsOnMethods = { "testGetAutoScalePolicy" })
public void testGetActiveAgentClusters() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    final CompletionStage<HttpResponse> responseFuture = http.singleRequest(HttpRequest.GET(SERVER_ENDPOINT));
    responseFuture.thenCompose(r -> processRespFut(r, 200)).whenComplete((msg, t) -> {
        String responseMessage = getResponseMessage(msg, t);
        logger.info("got response {}", responseMessage);
        assertEquals(AgentClusterPayloads.SET_ACTIVE, responseMessage);
        latch.countDown();
    });
    assertTrue(latch.await(1, TimeUnit.SECONDS));
}
Also used : TestHelpers(com.netflix.mantis.master.scheduler.TestHelpers) ObjectMapper(io.mantisrx.shaded.com.fasterxml.jackson.databind.ObjectMapper) TypeReference(io.mantisrx.shaded.com.fasterxml.jackson.core.type.TypeReference) LoggerFactory(org.slf4j.LoggerFactory) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) Test(org.testng.annotations.Test) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) JobClustersManagerActor(io.mantisrx.master.JobClustersManagerActor) AgentClustersAutoScaler(io.mantisrx.server.master.AgentClustersAutoScaler) ActorMaterializer(akka.stream.ActorMaterializer) ActorRef(akka.actor.ActorRef) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) SimpleCachedFileStorageProvider(io.mantisrx.server.master.persistence.SimpleCachedFileStorageProvider) StatusEventSubscriberLoggingImpl(io.mantisrx.master.events.StatusEventSubscriberLoggingImpl) ServerBinding(akka.http.javadsl.ServerBinding) JobMessageRouterImpl(io.mantisrx.master.scheduler.JobMessageRouterImpl) VirtualMachineLease(com.netflix.fenzo.VirtualMachineLease) WorkerEventSubscriberLoggingImpl(io.mantisrx.master.events.WorkerEventSubscriberLoggingImpl) BeforeClass(org.testng.annotations.BeforeClass) Observer(rx.Observer) DeserializationFeature(io.mantisrx.shaded.com.fasterxml.jackson.databind.DeserializationFeature) CountDownLatch(java.util.concurrent.CountDownLatch) AgentClusterOperations(io.mantisrx.master.vm.AgentClusterOperations) CompletionStage(java.util.concurrent.CompletionStage) NotUsed(akka.NotUsed) AgentClusterPayloads(io.mantisrx.master.api.akka.payloads.AgentClusterPayloads) IMantisStorageProvider(io.mantisrx.server.master.persistence.IMantisStorageProvider) Flow(akka.stream.javadsl.Flow) Function(java.util.function.Function) AuditEventSubscriberLoggingImpl(io.mantisrx.master.events.AuditEventSubscriberLoggingImpl) HashSet(java.util.HashSet) LifecycleEventPublisherImpl(io.mantisrx.master.events.LifecycleEventPublisherImpl) AutoScaleRule(com.netflix.fenzo.AutoScaleRule) AgentClusterOperationsImpl(io.mantisrx.master.vm.AgentClusterOperationsImpl) AfterClass(org.testng.annotations.AfterClass) Logger(org.slf4j.Logger) Http(akka.http.javadsl.Http) HttpRequest(akka.http.javadsl.model.HttpRequest) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) ContentTypes(akka.http.javadsl.model.ContentTypes) HttpEntities(akka.http.javadsl.model.HttpEntities) HttpResponse(akka.http.javadsl.model.HttpResponse) FakeMantisScheduler(io.mantisrx.master.scheduler.FakeMantisScheduler) TimeUnit(java.util.concurrent.TimeUnit) JobClusterManagerProto(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto) ConnectHttp(akka.http.javadsl.ConnectHttp) AutoScaleAction(com.netflix.fenzo.AutoScaleAction) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) LifecycleEventPublisher(io.mantisrx.master.events.LifecycleEventPublisher) HttpResponse(akka.http.javadsl.model.HttpResponse) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.testng.annotations.Test)

Example 3 with HttpResponse

use of akka.http.javadsl.model.HttpResponse in project mantis by Netflix.

the class AgentClustersRouteTest method testGetAutoScalePolicy.

@Test(dependsOnMethods = { "testGetJobsOnAgentClusters" })
public void testGetAutoScalePolicy() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    final CompletionStage<HttpResponse> responseFuture = http.singleRequest(HttpRequest.GET(SERVER_ENDPOINT + "/autoScalePolicy"));
    responseFuture.thenCompose(r -> processRespFut(r, 200)).whenComplete((msg, t) -> {
        String responseMessage = getResponseMessage(msg, t);
        logger.info("got response {}", responseMessage);
        try {
            Map<String, AgentClusterOperations.AgentClusterAutoScaleRule> agentClusterAutoScaleRule = mapper.readValue(responseMessage, new TypeReference<Map<String, AgentClusterOperations.AgentClusterAutoScaleRule>>() {
            });
            agentClusterAutoScaleRule.values().forEach(autoScaleRule -> {
                assertEquals("test", autoScaleRule.getName());
                assertEquals(300, autoScaleRule.getCooldownSecs());
                assertEquals(1, autoScaleRule.getMinIdle());
                assertEquals(10, autoScaleRule.getMaxIdle());
                assertEquals(1, autoScaleRule.getMinSize());
                assertEquals(100, autoScaleRule.getMaxSize());
            });
        } catch (IOException e) {
            logger.error("caught error", e);
            fail("failed to deserialize response");
        }
        latch.countDown();
    });
    assertTrue(latch.await(1, TimeUnit.SECONDS));
}
Also used : TestHelpers(com.netflix.mantis.master.scheduler.TestHelpers) ObjectMapper(io.mantisrx.shaded.com.fasterxml.jackson.databind.ObjectMapper) TypeReference(io.mantisrx.shaded.com.fasterxml.jackson.core.type.TypeReference) LoggerFactory(org.slf4j.LoggerFactory) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) Test(org.testng.annotations.Test) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) JobClustersManagerActor(io.mantisrx.master.JobClustersManagerActor) AgentClustersAutoScaler(io.mantisrx.server.master.AgentClustersAutoScaler) ActorMaterializer(akka.stream.ActorMaterializer) ActorRef(akka.actor.ActorRef) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) SimpleCachedFileStorageProvider(io.mantisrx.server.master.persistence.SimpleCachedFileStorageProvider) StatusEventSubscriberLoggingImpl(io.mantisrx.master.events.StatusEventSubscriberLoggingImpl) ServerBinding(akka.http.javadsl.ServerBinding) JobMessageRouterImpl(io.mantisrx.master.scheduler.JobMessageRouterImpl) VirtualMachineLease(com.netflix.fenzo.VirtualMachineLease) WorkerEventSubscriberLoggingImpl(io.mantisrx.master.events.WorkerEventSubscriberLoggingImpl) BeforeClass(org.testng.annotations.BeforeClass) Observer(rx.Observer) DeserializationFeature(io.mantisrx.shaded.com.fasterxml.jackson.databind.DeserializationFeature) CountDownLatch(java.util.concurrent.CountDownLatch) AgentClusterOperations(io.mantisrx.master.vm.AgentClusterOperations) CompletionStage(java.util.concurrent.CompletionStage) NotUsed(akka.NotUsed) AgentClusterPayloads(io.mantisrx.master.api.akka.payloads.AgentClusterPayloads) IMantisStorageProvider(io.mantisrx.server.master.persistence.IMantisStorageProvider) Flow(akka.stream.javadsl.Flow) Function(java.util.function.Function) AuditEventSubscriberLoggingImpl(io.mantisrx.master.events.AuditEventSubscriberLoggingImpl) HashSet(java.util.HashSet) LifecycleEventPublisherImpl(io.mantisrx.master.events.LifecycleEventPublisherImpl) AutoScaleRule(com.netflix.fenzo.AutoScaleRule) AgentClusterOperationsImpl(io.mantisrx.master.vm.AgentClusterOperationsImpl) AfterClass(org.testng.annotations.AfterClass) Logger(org.slf4j.Logger) Http(akka.http.javadsl.Http) HttpRequest(akka.http.javadsl.model.HttpRequest) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) ContentTypes(akka.http.javadsl.model.ContentTypes) HttpEntities(akka.http.javadsl.model.HttpEntities) HttpResponse(akka.http.javadsl.model.HttpResponse) FakeMantisScheduler(io.mantisrx.master.scheduler.FakeMantisScheduler) TimeUnit(java.util.concurrent.TimeUnit) JobClusterManagerProto(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto) ConnectHttp(akka.http.javadsl.ConnectHttp) AutoScaleAction(com.netflix.fenzo.AutoScaleAction) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) LifecycleEventPublisher(io.mantisrx.master.events.LifecycleEventPublisher) HttpResponse(akka.http.javadsl.model.HttpResponse) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) Map(java.util.Map) AgentClusterOperations(io.mantisrx.master.vm.AgentClusterOperations) Test(org.testng.annotations.Test)

Example 4 with HttpResponse

use of akka.http.javadsl.model.HttpResponse in project mantis by Netflix.

the class JobRouteTest method testJobClusterDelete.

@Test(dependsOnMethods = { "testJobClusterDisable" })
public void testJobClusterDelete() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    final CompletionStage<HttpResponse> responseFuture = http.singleRequest(HttpRequest.POST(jobClusterAPIEndpoint("delete")).withEntity(HttpEntities.create(ContentTypes.APPLICATION_JSON, JobClusterPayloads.JOB_CLUSTER_DELETE)));
    responseFuture.thenCompose(r -> processRespFut(r, Optional.of(200))).whenComplete((msg, t) -> {
        String responseMessage = getResponseMessage(msg, t);
        logger.info("got response {}", responseMessage);
        assertEquals("sine-function deleted", responseMessage);
        latch.countDown();
    });
    assertTrue(latch.await(1, TimeUnit.SECONDS));
}
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) HttpResponse(akka.http.javadsl.model.HttpResponse) Matchers.anyString(org.mockito.Matchers.anyString) ByteString(akka.util.ByteString) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.testng.annotations.Test)

Example 5 with HttpResponse

use of akka.http.javadsl.model.HttpResponse in project mantis by Netflix.

the class JobRouteTest method testJobClusterGetJobIds.

@Test(dependsOnMethods = { "testJobSubmit" })
public void testJobClusterGetJobIds() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    final CompletionStage<HttpResponse> responseFuture = http.singleRequest(HttpRequest.GET(jobClusterAPIEndpoint("listJobIds/sine-function?jobState=Active")));
    responseFuture.thenCompose(r -> processRespFut(r, Optional.of(200))).whenComplete((msg, t) -> {
        try {
            String responseMessage = getResponseMessage(msg, t);
            logger.info("got response {}", responseMessage);
            List<JobClusterProtoAdapter.JobIdInfo> jobIdInfos = Jackson.fromJSON(responseMessage, new TypeReference<List<JobClusterProtoAdapter.JobIdInfo>>() {
            });
            logger.info("jobInfos---> {}", jobIdInfos);
            assertEquals(1, jobIdInfos.size());
            JobClusterProtoAdapter.JobIdInfo jobIdInfo = jobIdInfos.get(0);
            assertEquals("sine-function-1", jobIdInfo.getJobId());
            // assertEquals("0.1.39 2018-03-13 09:40:53", jobIdInfo.getVersion());
            assertEquals("", jobIdInfo.getTerminatedAt());
            assertEquals("nmahilani", jobIdInfo.getUser());
            assertTrue(jobIdInfo.getState().equals(MantisJobState.Accepted) || jobIdInfo.getState().equals(MantisJobState.Launched));
        } catch (Exception e) {
            fail("unexpected error " + e.getMessage());
        }
        latch.countDown();
    });
    assertTrue(latch.await(2, TimeUnit.SECONDS));
}
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) HttpResponse(akka.http.javadsl.model.HttpResponse) JobClusterProtoAdapter(io.mantisrx.master.api.akka.route.proto.JobClusterProtoAdapter) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) ByteString(akka.util.ByteString) CountDownLatch(java.util.concurrent.CountDownLatch) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.testng.annotations.Test)

Aggregations

HttpResponse (akka.http.javadsl.model.HttpResponse)48 Http (akka.http.javadsl.Http)46 HttpRequest (akka.http.javadsl.model.HttpRequest)46 NotUsed (akka.NotUsed)45 ConnectHttp (akka.http.javadsl.ConnectHttp)45 ServerBinding (akka.http.javadsl.ServerBinding)45 ActorMaterializer (akka.stream.ActorMaterializer)45 CountDownLatch (java.util.concurrent.CountDownLatch)45 CompletionStage (java.util.concurrent.CompletionStage)44 TimeUnit (java.util.concurrent.TimeUnit)44 Assert.assertEquals (org.junit.Assert.assertEquals)44 Assert.assertTrue (org.junit.Assert.assertTrue)44 Assert.fail (org.junit.Assert.fail)44 Logger (org.slf4j.Logger)44 LoggerFactory (org.slf4j.LoggerFactory)44 Test (org.testng.annotations.Test)44 Flow (akka.stream.javadsl.Flow)43 AfterClass (org.testng.annotations.AfterClass)43 BeforeClass (org.testng.annotations.BeforeClass)43 TypeReference (io.mantisrx.shaded.com.fasterxml.jackson.core.type.TypeReference)41