Search in sources :

Example 11 with Http

use of akka.http.javadsl.Http in project mantis by Netflix.

the class JobRouteTest method testJobStatus.

@Test(dependsOnMethods = { "testJobClusterScaleStage" })
public void testJobStatus() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    final CompletionStage<HttpResponse> responseFuture = http.singleRequest(HttpRequest.POST(String.format("http://127.0.0.1:%d/api/postjobstatus", targetEndpointPort)).withMethod(HttpMethods.POST).withEntity(ContentTypes.create(MediaTypes.TEXT_PLAIN, HttpCharsets.ISO_8859_1), JobPayloads.JOB_STATUS));
    responseFuture.thenCompose(r -> processRespFutWithoutHeadersCheck(r, Optional.of(200))).whenComplete((r, t) -> {
        String responseMessage = getResponseMessage(r, t);
        logger.info("got response '{}'", responseMessage);
        assertEquals("forwarded worker status", 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 12 with Http

use of akka.http.javadsl.Http in project mantis by Netflix.

the class JobDiscoveryStreamRouteTest method setup.

@BeforeClass
public void setup() throws Exception {
    JobTestHelper.deleteAllFiles();
    JobTestHelper.createDirsIfRequired();
    final CountDownLatch latch = new CountDownLatch(1);
    t = new Thread(() -> {
        try {
            // boot up server using the route as defined below
            final Http http = Http.get(system);
            final ActorMaterializer materializer = ActorMaterializer.create(system);
            final LifecycleEventPublisher lifecycleEventPublisher = new LifecycleEventPublisherImpl(new AuditEventSubscriberLoggingImpl(), new StatusEventSubscriberLoggingImpl(), new WorkerEventSubscriberLoggingImpl());
            TestHelpers.setupMasterConfig();
            ActorRef jobClustersManagerActor = system.actorOf(JobClustersManagerActor.props(new MantisJobStore(new io.mantisrx.server.master.persistence.SimpleCachedFileStorageProvider(true)), lifecycleEventPublisher), "jobClustersManager");
            MantisScheduler fakeScheduler = new FakeMantisScheduler(jobClustersManagerActor);
            jobClustersManagerActor.tell(new JobClusterManagerProto.JobClustersManagerInitialize(fakeScheduler, false), ActorRef.noSender());
            agentsErrorMonitorActor.tell(new AgentsErrorMonitorActor.InitializeAgentsErrorMonitor(fakeScheduler), ActorRef.noSender());
            Duration idleTimeout = system.settings().config().getDuration("akka.http.server.idle-timeout");
            logger.info("idle timeout {} sec ", idleTimeout.getSeconds());
            final JobDiscoveryRouteHandler jobDiscoveryRouteHandler = new JobDiscoveryRouteHandlerAkkaImpl(jobClustersManagerActor, idleTimeout);
            final JobDiscoveryStreamRoute jobDiscoveryRoute = new JobDiscoveryStreamRoute(jobDiscoveryRouteHandler);
            final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = jobDiscoveryRoute.createRoute(Function.identity()).flow(system, materializer);
            logger.info("starting test server on port {}", SERVER_PORT);
            binding = http.bindAndHandle(routeFlow, ConnectHttp.toHost("localhost", SERVER_PORT), materializer);
            latch.countDown();
        } catch (Exception e) {
            logger.info("caught exception", e);
            latch.countDown();
            e.printStackTrace();
        }
    });
    t.setDaemon(true);
    t.start();
    latch.await();
}
Also used : FakeMantisScheduler(io.mantisrx.master.scheduler.FakeMantisScheduler) StatusEventSubscriberLoggingImpl(io.mantisrx.master.events.StatusEventSubscriberLoggingImpl) ActorRef(akka.actor.ActorRef) Http(akka.http.javadsl.Http) ConnectHttp(akka.http.javadsl.ConnectHttp) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) FakeMantisScheduler(io.mantisrx.master.scheduler.FakeMantisScheduler) Duration(java.time.Duration) LifecycleEventPublisher(io.mantisrx.master.events.LifecycleEventPublisher) CountDownLatch(java.util.concurrent.CountDownLatch) JobDiscoveryRouteHandlerAkkaImpl(io.mantisrx.master.api.akka.route.handlers.JobDiscoveryRouteHandlerAkkaImpl) ActorMaterializer(akka.stream.ActorMaterializer) Flow(akka.stream.javadsl.Flow) AuditEventSubscriberLoggingImpl(io.mantisrx.master.events.AuditEventSubscriberLoggingImpl) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) LifecycleEventPublisherImpl(io.mantisrx.master.events.LifecycleEventPublisherImpl) JobDiscoveryRouteHandler(io.mantisrx.master.api.akka.route.handlers.JobDiscoveryRouteHandler) WorkerEventSubscriberLoggingImpl(io.mantisrx.master.events.WorkerEventSubscriberLoggingImpl) BeforeClass(org.testng.annotations.BeforeClass)

Example 13 with Http

use of akka.http.javadsl.Http in project mantis by Netflix.

the class LeaderRedirectionRouteTest method setup.

@BeforeClass
public static void setup() throws Exception {
    JobTestHelper.deleteAllFiles();
    JobTestHelper.createDirsIfRequired();
    final CountDownLatch latch = new CountDownLatch(1);
    t = new Thread(() -> {
        try {
            // boot up server using the route as defined below
            final Http http = Http.get(system);
            final ActorMaterializer materializer = ActorMaterializer.create(system);
            TestHelpers.setupMasterConfig();
            final MasterDescriptionRoute app = new MasterDescriptionRoute(fakeMasterDesc);
            final LeaderRedirectionFilter leaderRedirectionFilter = new LeaderRedirectionFilter(masterMonitor, leadershipMgr);
            final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = app.createRoute(leaderRedirectionFilter::redirectIfNotLeader).flow(system, materializer);
            logger.info("starting test server on port {}", serverPort);
            latch.countDown();
            binding = http.bindAndHandle(routeFlow, ConnectHttp.toHost("localhost", serverPort), materializer);
        } catch (Exception e) {
            logger.info("caught exception", e);
            latch.countDown();
            e.printStackTrace();
        }
    });
    t.setDaemon(true);
    t.start();
    latch.await();
}
Also used : MasterDescriptionRoute(io.mantisrx.master.api.akka.route.v0.MasterDescriptionRoute) Http(akka.http.javadsl.Http) ConnectHttp(akka.http.javadsl.ConnectHttp) LeaderRedirectionFilter(io.mantisrx.server.master.LeaderRedirectionFilter) CountDownLatch(java.util.concurrent.CountDownLatch) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) ActorMaterializer(akka.stream.ActorMaterializer) Flow(akka.stream.javadsl.Flow) BeforeClass(org.testng.annotations.BeforeClass)

Example 14 with Http

use of akka.http.javadsl.Http in project mantis by Netflix.

the class LeaderRedirectionRouteTest method testMasterInfoAPIWhenNotLeader.

@Test(dependsOnMethods = { "testMasterInfoAPIWhenLeader" })
public void testMasterInfoAPIWhenNotLeader() throws InterruptedException {
    leadershipMgr.stopBeingLeader();
    final CompletionStage<HttpResponse> responseFuture = http.singleRequest(HttpRequest.GET(masterEndpoint("masterinfo")));
    try {
        responseFuture.thenCompose(r -> {
            logger.info("headers {} {}", r.getHeaders(), r.status());
            assertEquals(302, r.status().intValue());
            assert (r.getHeader("Access-Control-Allow-Origin").isPresent());
            assertEquals("*", r.getHeader("Access-Control-Allow-Origin").get().value());
            assert (r.getHeader("Location").isPresent());
            assertEquals("http://example.com:" + targetEndpointPort + "/api/masterinfo", r.getHeader("Location").get().value());
            CompletionStage<HttpEntity.Strict> strictEntity = r.entity().toStrict(1000, materializer);
            return strictEntity.thenCompose(s -> s.getDataBytes().runFold(ByteString.emptyByteString(), (acc, b) -> acc.concat(b), materializer).thenApply(s2 -> s2.utf8String()));
        }).whenComplete((msg, t) -> {
            try {
                String responseMessage = getResponseMessage(msg, t);
                logger.info("got response {}", responseMessage);
            } catch (Exception e) {
                fail("unexpected error " + e.getMessage());
            }
        }).toCompletableFuture().get(2, TimeUnit.SECONDS);
    } catch (ExecutionException e) {
        throw new RuntimeException(e);
    } catch (TimeoutException e) {
        throw new RuntimeException(e);
    }
    leadershipMgr.becomeLeader();
    testMasterInfoAPIWhenLeader();
}
Also used : TestHelpers(com.netflix.mantis.master.scheduler.TestHelpers) MasterDescription(io.mantisrx.server.core.master.MasterDescription) Flow(akka.stream.javadsl.Flow) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) Test(org.testng.annotations.Test) LeaderRedirectionFilter(io.mantisrx.server.master.LeaderRedirectionFilter) MasterMonitor(io.mantisrx.server.core.master.MasterMonitor) ILeadershipManager(io.mantisrx.server.master.ILeadershipManager) ActorMaterializer(akka.stream.ActorMaterializer) JobTestHelper(io.mantisrx.master.jobcluster.job.JobTestHelper) ByteString(akka.util.ByteString) HttpEntity(akka.http.javadsl.model.HttpEntity) Assert.fail(org.junit.Assert.fail) MasterDescriptionRoute(io.mantisrx.master.api.akka.route.v0.MasterDescriptionRoute) LocalMasterMonitor(io.mantisrx.server.core.master.LocalMasterMonitor) LeadershipManagerLocalImpl(io.mantisrx.server.master.LeadershipManagerLocalImpl) ServerBinding(akka.http.javadsl.ServerBinding) AfterClass(org.testng.annotations.AfterClass) Logger(org.slf4j.Logger) Http(akka.http.javadsl.Http) HttpRequest(akka.http.javadsl.model.HttpRequest) BeforeClass(org.testng.annotations.BeforeClass) Assert.assertTrue(org.junit.Assert.assertTrue) HttpResponse(akka.http.javadsl.model.HttpResponse) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) ConnectHttp(akka.http.javadsl.ConnectHttp) CompletionStage(java.util.concurrent.CompletionStage) NotUsed(akka.NotUsed) ActorSystem(akka.actor.ActorSystem) Optional(java.util.Optional) Assert.assertEquals(org.junit.Assert.assertEquals) HttpEntity(akka.http.javadsl.model.HttpEntity) HttpResponse(akka.http.javadsl.model.HttpResponse) ByteString(akka.util.ByteString) ExecutionException(java.util.concurrent.ExecutionException) CompletionStage(java.util.concurrent.CompletionStage) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) Test(org.testng.annotations.Test)

Example 15 with Http

use of akka.http.javadsl.Http in project mantis by Netflix.

the class MasterDescriptionRouteTest method setup.

@BeforeClass
public static void setup() throws Exception {
    JobTestHelper.deleteAllFiles();
    JobTestHelper.createDirsIfRequired();
    final CountDownLatch latch = new CountDownLatch(1);
    t = new Thread(() -> {
        try {
            // boot up server using the route as defined below
            final Http http = Http.get(system);
            final ActorMaterializer materializer = ActorMaterializer.create(system);
            final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = masterDescRoute.createRoute(Function.identity()).flow(system, materializer);
            logger.info("starting test server on port {}", serverPort);
            latch.countDown();
            binding = http.bindAndHandle(routeFlow, ConnectHttp.toHost("localhost", serverPort), materializer);
        } catch (Exception e) {
            logger.info("caught exception", e);
            latch.countDown();
            e.printStackTrace();
        }
    });
    t.setDaemon(true);
    t.start();
    latch.await();
}
Also used : Http(akka.http.javadsl.Http) ConnectHttp(akka.http.javadsl.ConnectHttp) CountDownLatch(java.util.concurrent.CountDownLatch) ActorMaterializer(akka.stream.ActorMaterializer) Flow(akka.stream.javadsl.Flow) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

Http (akka.http.javadsl.Http)17 ConnectHttp (akka.http.javadsl.ConnectHttp)16 ActorMaterializer (akka.stream.ActorMaterializer)15 Flow (akka.stream.javadsl.Flow)14 CountDownLatch (java.util.concurrent.CountDownLatch)14 BeforeClass (org.testng.annotations.BeforeClass)14 ActorRef (akka.actor.ActorRef)11 FakeMantisScheduler (io.mantisrx.master.scheduler.FakeMantisScheduler)11 MantisJobStore (io.mantisrx.server.master.persistence.MantisJobStore)11 MantisScheduler (io.mantisrx.server.master.scheduler.MantisScheduler)10 AuditEventSubscriberLoggingImpl (io.mantisrx.master.events.AuditEventSubscriberLoggingImpl)9 LifecycleEventPublisher (io.mantisrx.master.events.LifecycleEventPublisher)9 LifecycleEventPublisherImpl (io.mantisrx.master.events.LifecycleEventPublisherImpl)9 StatusEventSubscriberLoggingImpl (io.mantisrx.master.events.StatusEventSubscriberLoggingImpl)9 WorkerEventSubscriberLoggingImpl (io.mantisrx.master.events.WorkerEventSubscriberLoggingImpl)9 IOException (java.io.IOException)7 ServerBinding (akka.http.javadsl.ServerBinding)6 JobClusterRouteHandler (io.mantisrx.master.api.akka.route.handlers.JobClusterRouteHandler)6 JobClusterRouteHandlerAkkaImpl (io.mantisrx.master.api.akka.route.handlers.JobClusterRouteHandlerAkkaImpl)6 JobDiscoveryRouteHandler (io.mantisrx.master.api.akka.route.handlers.JobDiscoveryRouteHandler)6