Search in sources :

Example 16 with Http

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

the class AdminMasterRouteTest 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 Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = masterDescRoute.createRoute(Function.identity()).flow(system, materializer);
            logger.info("starting test server on port {}", ADMIN_MASTER_PORT);
            latch.countDown();
            binding = http.bindAndHandle(routeFlow, ConnectHttp.toHost("localhost", ADMIN_MASTER_PORT), 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)

Example 17 with Http

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

the class JobClustersRouteTest method setup.

@BeforeClass
public void setup() throws Exception {
    TestHelpers.setupMasterConfig();
    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());
            ActorRef jobClustersManagerActor = system.actorOf(JobClustersManagerActor.props(new MantisJobStore(new SimpleCachedFileStorageProvider(true)), lifecycleEventPublisher), "jobClustersManager");
            MantisScheduler fakeScheduler = new FakeMantisScheduler(jobClustersManagerActor);
            jobClustersManagerActor.tell(new JobClusterManagerProto.JobClustersManagerInitialize(fakeScheduler, false), ActorRef.noSender());
            final JobClusterRouteHandler jobClusterRouteHandler = new JobClusterRouteHandlerAkkaImpl(jobClustersManagerActor);
            final JobClustersRoute app = new JobClustersRoute(jobClusterRouteHandler, system);
            final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = app.createRoute(Function.identity()).flow(system, materializer);
            logger.info("starting test server on port {}", SERVER_PORT);
            latch.countDown();
            binding = http.bindAndHandle(routeFlow, ConnectHttp.toHost("localhost", SERVER_PORT), materializer);
        } catch (Exception e) {
            logger.info("caught exception", e);
            latch.countDown();
            e.printStackTrace();
        }
    });
    t.setDaemon(true);
    t.start();
    latch.await();
}
Also used : JobClusterRouteHandler(io.mantisrx.master.api.akka.route.handlers.JobClusterRouteHandler) FakeMantisScheduler(io.mantisrx.master.scheduler.FakeMantisScheduler) ActorRef(akka.actor.ActorRef) JobClusterRouteHandlerAkkaImpl(io.mantisrx.master.api.akka.route.handlers.JobClusterRouteHandlerAkkaImpl) Http(akka.http.javadsl.Http) ConnectHttp(akka.http.javadsl.ConnectHttp) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) FakeMantisScheduler(io.mantisrx.master.scheduler.FakeMantisScheduler) CountDownLatch(java.util.concurrent.CountDownLatch) IOException(java.io.IOException) ActorMaterializer(akka.stream.ActorMaterializer) Flow(akka.stream.javadsl.Flow) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) SimpleCachedFileStorageProvider(io.mantisrx.server.master.persistence.SimpleCachedFileStorageProvider) BeforeClass(org.testng.annotations.BeforeClass)

Example 18 with Http

use of akka.http.javadsl.Http in project ditto by eclipse.

the class DefaultHttpPushFactory method createFlow.

@Override
public Flow<Pair<HttpRequest, HttpPushContext>, Pair<Try<HttpResponse>, HttpPushContext>, ?> createFlow(final ActorSystem system, final LoggingAdapter log, final Duration requestTimeout, @Nullable final PreparedTimer timer, @Nullable final BiConsumer<Duration, ConnectionMonitor.InfoProvider> durationConsumer) {
    final Http http = Http.get(system);
    final ConnectionPoolSettings poolSettings = getConnectionPoolSettings(system);
    final Flow<Pair<HttpRequest, HttpPushContext>, Pair<Try<HttpResponse>, HttpPushContext>, ?> flow;
    final Uri baseUri = getBaseUri();
    if (null != httpsConnectionContext) {
        final ConnectHttp connectHttpsWithCustomSSLContext = ConnectHttp.toHostHttps(baseUri).withCustomHttpsContext(httpsConnectionContext);
        // explicitly added <T> as in (some?) IntelliJ idea the line would show an error:
        flow = http.<HttpPushContext>cachedHostConnectionPoolHttps(connectHttpsWithCustomSSLContext, poolSettings, log);
    } else {
        // explicitly added <T> as in (some?) IntelliJ idea the line would show an error:
        // no SSL, hence no need for SSLContextCreator
        flow = http.<HttpPushContext>cachedHostConnectionPool(ConnectHttp.toHost(baseUri), poolSettings, log);
    }
    // make requests in parallel
    return Flow.<Pair<HttpRequest, HttpPushContext>>create().flatMapMerge(parallelism, request -> {
        final var startedTimer = timer != null ? timer.start() : null;
        return TimeoutFlow.single(request, flow, requestTimeout, DefaultHttpPushFactory::onRequestTimeout).map(pair -> {
            stopTimer(startedTimer, durationConsumer, pair.second().getInfoProvider(), log);
            return pair;
        }).async(DISPATCHER_NAME, parallelism);
    });
}
Also used : HttpRequest(akka.http.javadsl.model.HttpRequest) ClientConnectionSettings(akka.http.javadsl.settings.ClientConnectionSettings) SSLContext(javax.net.ssl.SSLContext) Uri(akka.http.javadsl.model.Uri) Flow(akka.stream.javadsl.Flow) TimeoutException(java.util.concurrent.TimeoutException) ConnectionMonitor(org.eclipse.ditto.connectivity.service.messaging.monitoring.ConnectionMonitor) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) SSLEngine(javax.net.ssl.SSLEngine) DittoHeaders(org.eclipse.ditto.base.model.headers.DittoHeaders) HttpPushConfig(org.eclipse.ditto.connectivity.service.config.HttpPushConfig) Duration(java.time.Duration) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) Nullable(javax.annotation.Nullable) Http(akka.http.javadsl.Http) LoggingAdapter(akka.event.LoggingAdapter) HttpRequest(akka.http.javadsl.model.HttpRequest) TimeoutFlow(org.eclipse.ditto.internal.utils.akka.controlflow.TimeoutFlow) HttpsConnectionContext(akka.http.javadsl.HttpsConnectionContext) ClientTransport(akka.http.javadsl.ClientTransport) Connection(org.eclipse.ditto.connectivity.model.Connection) HttpResponse(akka.http.javadsl.model.HttpResponse) Pair(akka.japi.Pair) ConnectHttp(akka.http.javadsl.ConnectHttp) HttpCredentials(akka.http.javadsl.model.headers.HttpCredentials) ConnectionLogger(org.eclipse.ditto.connectivity.service.messaging.monitoring.logs.ConnectionLogger) PreparedTimer(org.eclipse.ditto.internal.utils.metrics.instruments.timer.PreparedTimer) ActorSystem(akka.actor.ActorSystem) Failure(scala.util.Failure) SSLContextCreator(org.eclipse.ditto.connectivity.service.messaging.internal.ssl.SSLContextCreator) ParserSettings(akka.http.javadsl.settings.ParserSettings) SshTunnelState(org.eclipse.ditto.connectivity.service.messaging.tunnel.SshTunnelState) ConnectionId(org.eclipse.ditto.connectivity.model.ConnectionId) StartedTimer(org.eclipse.ditto.internal.utils.metrics.instruments.timer.StartedTimer) ConnectionPoolSettings(akka.http.javadsl.settings.ConnectionPoolSettings) Try(scala.util.Try) ConnectionContext(akka.http.javadsl.ConnectionContext) ConnectHttp(akka.http.javadsl.ConnectHttp) HttpResponse(akka.http.javadsl.model.HttpResponse) Http(akka.http.javadsl.Http) ConnectHttp(akka.http.javadsl.ConnectHttp) ConnectionPoolSettings(akka.http.javadsl.settings.ConnectionPoolSettings) Uri(akka.http.javadsl.model.Uri) Pair(akka.japi.Pair)

Example 19 with Http

use of akka.http.javadsl.Http in project ditto by eclipse.

the class DittoRootActor method bindHttpStatusRoute.

protected void bindHttpStatusRoute(final HttpConfig httpConfig, final ActorRef healthCheckingActor) {
    String hostname = httpConfig.getHostname();
    if (hostname.isEmpty()) {
        hostname = LocalHostAddressSupplier.getInstance().get();
        log.info("No explicit hostname configured, using HTTP hostname: {}", hostname);
    }
    final ActorSystem system = getContext().getSystem();
    Http.get(system).newServerAt(hostname, httpConfig.getPort()).bindFlow(createStatusRoute(system, healthCheckingActor).flow(system)).thenAccept(theBinding -> {
        theBinding.addToCoordinatedShutdown(httpConfig.getCoordinatedShutdownTimeout(), system);
        log.info("Created new server binding for the status route.");
    }).exceptionally(failure -> {
        log.error(failure, "Could not create the server binding for the status route because of: <{}>", failure.getMessage());
        log.error("Terminating the actor system");
        system.terminate();
        return null;
    });
}
Also used : ActorSystem(akka.actor.ActorSystem) Directives.logRequest(akka.http.javadsl.server.Directives.logRequest) StatusRoute(org.eclipse.ditto.internal.utils.health.routes.StatusRoute) Route(akka.http.javadsl.server.Route) ClusterStatusSupplier(org.eclipse.ditto.internal.utils.cluster.ClusterStatusSupplier) DittoRuntimeException(org.eclipse.ditto.base.model.exceptions.DittoRuntimeException) ActorRef(akka.actor.ActorRef) Cluster(akka.cluster.Cluster) HttpConfig(org.eclipse.ditto.base.service.config.http.HttpConfig) Directives.logResult(akka.http.javadsl.server.Directives.logResult) ConnectException(java.net.ConnectException) DeciderBuilder(akka.japi.pf.DeciderBuilder) SupervisorStrategy(akka.actor.SupervisorStrategy) NoSuchElementException(java.util.NoSuchElementException) ActorInitializationException(akka.actor.ActorInitializationException) AskTimeoutException(akka.pattern.AskTimeoutException) PrintWriter(java.io.PrintWriter) DittoDiagnosticLoggingAdapter(org.eclipse.ditto.internal.utils.akka.logging.DittoDiagnosticLoggingAdapter) ActorKilledException(akka.actor.ActorKilledException) PartialFunction(scala.PartialFunction) Http(akka.http.javadsl.Http) StringWriter(java.io.StringWriter) InvalidActorNameException(akka.actor.InvalidActorNameException) DittoLoggerFactory(org.eclipse.ditto.internal.utils.akka.logging.DittoLoggerFactory) Status(akka.actor.Status) OneForOneStrategy(akka.actor.OneForOneStrategy) LocalHostAddressSupplier(org.eclipse.ditto.internal.utils.config.LocalHostAddressSupplier) ActorSystem(akka.actor.ActorSystem) AbstractActor(akka.actor.AbstractActor) ReceiveBuilder(akka.japi.pf.ReceiveBuilder) Props(akka.actor.Props)

Example 20 with Http

use of akka.http.javadsl.Http in project mutual-tls-ssl by Hakky54.

the class ClientConfigShould method createAkkaHttpClient.

@Test
void createAkkaHttpClient() {
    SSLFactory sslFactory = createSSLFactory(false, true);
    Http http = victim.akkaHttpClient(sslFactory, ActorSystem.create());
    assertThat(http).isNotNull();
    verify(sslFactory, times(1)).getSslContext();
}
Also used : SSLFactory(nl.altindag.ssl.SSLFactory) SSLFactoryTestHelper.createSSLFactory(nl.altindag.client.util.SSLFactoryTestHelper.createSSLFactory) Http(akka.http.javadsl.Http) Test(org.junit.jupiter.api.Test)

Aggregations

Http (akka.http.javadsl.Http)20 ConnectHttp (akka.http.javadsl.ConnectHttp)17 ActorMaterializer (akka.stream.ActorMaterializer)15 Flow (akka.stream.javadsl.Flow)15 CountDownLatch (java.util.concurrent.CountDownLatch)14 BeforeClass (org.testng.annotations.BeforeClass)14 ActorRef (akka.actor.ActorRef)12 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 ActorSystem (akka.actor.ActorSystem)7 IOException (java.io.IOException)7 ServerBinding (akka.http.javadsl.ServerBinding)6 HttpRequest (akka.http.javadsl.model.HttpRequest)6 HttpResponse (akka.http.javadsl.model.HttpResponse)6