Search in sources :

Example 1 with WebSocketSettings

use of akka.http.javadsl.settings.WebSocketSettings in project mantis by Netflix.

the class JobStatusRouteTest method testJobStatus.

// @Test
// @Ignore
public void testJobStatus() throws InterruptedException {
    Flow<Message, Message, NotUsed> clientFlow = Flow.fromSinkAndSource(Sink.foreach(x -> System.out.println("client got " + x.asTextMessage().getStrictText())), Source.empty());
    ClientConnectionSettings defaultSettings = ClientConnectionSettings.create(system);
    AtomicInteger pingCounter = new AtomicInteger();
    WebSocketSettings customWebsocketSettings = defaultSettings.getWebsocketSettings().withPeriodicKeepAliveData(() -> ByteString.fromString(String.format("debug-%d", pingCounter.incrementAndGet())));
    ClientConnectionSettings customSettings = defaultSettings.withWebsocketSettings(customWebsocketSettings);
    http.singleWebSocketRequest(WebSocketRequest.create("ws://127.0.0.1:8207/job/status/sine-function-1"), clientFlow, ConnectionContext.noEncryption(), Optional.empty(), customSettings, system.log(), materializer);
    while (pingCounter.get() != 2) {
        statusEventBrokerActor.tell(new LifecycleEventsProto.WorkerStatusEvent(LifecycleEventsProto.StatusEvent.StatusEventType.INFO, "test message", 1, WorkerId.fromId("sine-function-1-worker-0-2").get(), WorkerState.Started), ActorRef.noSender());
        Thread.sleep(2000);
    }
}
Also used : ClientConnectionSettings(akka.http.javadsl.settings.ClientConnectionSettings) AgentsErrorMonitorActor(io.mantisrx.master.scheduler.AgentsErrorMonitorActor) WebSocketSettings(akka.http.javadsl.settings.WebSocketSettings) Flow(akka.stream.javadsl.Flow) Source(akka.stream.javadsl.Source) LoggerFactory(org.slf4j.LoggerFactory) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) JobStatusRouteHandlerAkkaImpl(io.mantisrx.master.api.akka.route.handlers.JobStatusRouteHandlerAkkaImpl) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) WebSocketRequest(akka.http.javadsl.model.ws.WebSocketRequest) Function(java.util.function.Function) JobClustersManagerActor(io.mantisrx.master.JobClustersManagerActor) ActorMaterializer(akka.stream.ActorMaterializer) JobTestHelper(io.mantisrx.master.jobcluster.job.JobTestHelper) ByteString(akka.util.ByteString) ActorRef(akka.actor.ActorRef) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Message(akka.http.javadsl.model.ws.Message) ServerBinding(akka.http.javadsl.ServerBinding) AfterClass(org.testng.annotations.AfterClass) Logger(org.slf4j.Logger) JobStatusRouteHandler(io.mantisrx.master.api.akka.route.handlers.JobStatusRouteHandler) Http(akka.http.javadsl.Http) HttpRequest(akka.http.javadsl.model.HttpRequest) BeforeClass(org.testng.annotations.BeforeClass) Sink(akka.stream.javadsl.Sink) io.mantisrx.master.events(io.mantisrx.master.events) HttpResponse(akka.http.javadsl.model.HttpResponse) FakeMantisScheduler(io.mantisrx.master.scheduler.FakeMantisScheduler) JobClusterManagerProto(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto) CountDownLatch(java.util.concurrent.CountDownLatch) WorkerId(io.mantisrx.server.core.domain.WorkerId) ConnectHttp(akka.http.javadsl.ConnectHttp) CompletionStage(java.util.concurrent.CompletionStage) NotUsed(akka.NotUsed) WorkerState(io.mantisrx.master.jobcluster.job.worker.WorkerState) ActorSystem(akka.actor.ActorSystem) Optional(java.util.Optional) ConnectionContext(akka.http.javadsl.ConnectionContext) Message(akka.http.javadsl.model.ws.Message) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientConnectionSettings(akka.http.javadsl.settings.ClientConnectionSettings) WebSocketSettings(akka.http.javadsl.settings.WebSocketSettings) NotUsed(akka.NotUsed)

Example 2 with WebSocketSettings

use of akka.http.javadsl.settings.WebSocketSettings in project mantis by Netflix.

the class MasterApiAkkaService method startAPIServer.

private void startAPIServer() {
    final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = this.mantisMasterRoute.createRoute().flow(system, materializer);
    final Http http = Http.get(system);
    ServerSettings defaultSettings = ServerSettings.create(system);
    java.time.Duration idleTimeout = system.settings().config().getDuration("akka.http.server.idle-timeout");
    logger.info("idle timeout {} sec ", idleTimeout.getSeconds());
    WebSocketSettings customWebsocketSettings = defaultSettings.getWebsocketSettings().withPeriodicKeepAliveMaxIdle(Duration.create(idleTimeout.getSeconds() - 1, TimeUnit.SECONDS)).withPeriodicKeepAliveMode("pong");
    ServerSettings customServerSettings = defaultSettings.withWebsocketSettings(customWebsocketSettings);
    final CompletionStage<ServerBinding> binding = http.bindAndHandle(routeFlow, ConnectHttp.toHost("0.0.0.0", port), customServerSettings, system.log(), materializer);
    binding.exceptionally(failure -> {
        System.err.println("API service exited, committing suicide !" + failure.getMessage());
        logger.info("Master API service exited in error, committing suicide !");
        system.terminate();
        System.exit(2);
        return null;
    });
    logger.info("Starting Mantis Master API on port {}", port);
    try {
        serviceLatch.await();
    } catch (InterruptedException e) {
        logger.error("Master API thread interrupted, committing suicide", e);
        System.exit(2);
    }
    binding.thenCompose(// trigger unbinding from the port
    ServerBinding::unbind).thenAccept(unbound -> {
        logger.error("Master API service unbind, committing suicide");
        system.terminate();
        System.exit(2);
    });
// and shutdown when done
}
Also used : HttpRequest(akka.http.javadsl.model.HttpRequest) ServerSettings(akka.http.javadsl.settings.ServerSettings) HttpResponse(akka.http.javadsl.model.HttpResponse) Http(akka.http.javadsl.Http) ConnectHttp(akka.http.javadsl.ConnectHttp) WebSocketSettings(akka.http.javadsl.settings.WebSocketSettings) NotUsed(akka.NotUsed) ServerBinding(akka.http.javadsl.ServerBinding)

Aggregations

NotUsed (akka.NotUsed)2 ConnectHttp (akka.http.javadsl.ConnectHttp)2 Http (akka.http.javadsl.Http)2 ServerBinding (akka.http.javadsl.ServerBinding)2 HttpRequest (akka.http.javadsl.model.HttpRequest)2 HttpResponse (akka.http.javadsl.model.HttpResponse)2 WebSocketSettings (akka.http.javadsl.settings.WebSocketSettings)2 ActorRef (akka.actor.ActorRef)1 ActorSystem (akka.actor.ActorSystem)1 ConnectionContext (akka.http.javadsl.ConnectionContext)1 Message (akka.http.javadsl.model.ws.Message)1 WebSocketRequest (akka.http.javadsl.model.ws.WebSocketRequest)1 ClientConnectionSettings (akka.http.javadsl.settings.ClientConnectionSettings)1 ServerSettings (akka.http.javadsl.settings.ServerSettings)1 ActorMaterializer (akka.stream.ActorMaterializer)1 Flow (akka.stream.javadsl.Flow)1 Sink (akka.stream.javadsl.Sink)1 Source (akka.stream.javadsl.Source)1 ByteString (akka.util.ByteString)1 JobClustersManagerActor (io.mantisrx.master.JobClustersManagerActor)1