Search in sources :

Example 41 with Origin

use of com.hotels.styx.api.extension.Origin in project styx by ExpediaGroup.

the class OriginTest method acceptsIfAllHostsAreDistinct.

@Test
public void acceptsIfAllHostsAreDistinct() {
    Origin origin1 = newOriginBuilder("localhost", 8080).applicationId("webapp").id("origin-01").build();
    Origin origin2 = newOriginBuilder("localhost", 8081).applicationId("webapp").id("origin-02").build();
    checkThatOriginsAreDistinct(List.of(origin1, origin2));
}
Also used : Origin(com.hotels.styx.api.extension.Origin) Test(org.junit.jupiter.api.Test)

Example 42 with Origin

use of com.hotels.styx.api.extension.Origin in project styx by ExpediaGroup.

the class OriginTest method acceptsIfAllIdsAreDistinct.

@Test
public void acceptsIfAllIdsAreDistinct() {
    Origin origin1 = newOriginBuilder("localhost", 8080).applicationId("webapp").id("origin-01").build();
    Origin origin2 = newOriginBuilder("localhost", 8081).applicationId("webapp").id("origin-02").build();
    checkThatOriginsAreDistinct(List.of(origin1, origin2));
}
Also used : Origin(com.hotels.styx.api.extension.Origin) Test(org.junit.jupiter.api.Test)

Example 43 with Origin

use of com.hotels.styx.api.extension.Origin in project styx by ExpediaGroup.

the class OriginTest method rejectsIfThereAreDuplicateIds.

@Test
public void rejectsIfThereAreDuplicateIds() {
    Origin origin1 = newOriginBuilder("localhost", 8080).applicationId("webapp").id("origin-01").build();
    Origin origin2 = newOriginBuilder("localhost", 8081).applicationId("webapp").id("origin-01").build();
    Origin origin3 = newOriginBuilder("localhost", 8082).applicationId("webapp").id("origin-03").build();
    assertThrows(IllegalArgumentException.class, () -> checkThatOriginsAreDistinct(List.of(origin1, origin2, origin3)));
}
Also used : Origin(com.hotels.styx.api.extension.Origin) Test(org.junit.jupiter.api.Test)

Example 44 with Origin

use of com.hotels.styx.api.extension.Origin in project styx by ExpediaGroup.

the class OriginsInventory method handleSetOriginsEvent.

private void handleSetOriginsEvent(SetOriginsEvent event) {
    Map<Id, Origin> newOriginsMap = event.newOrigins.stream().collect(toMap(Origin::id, o -> o));
    OriginChanges originChanges = new OriginChanges();
    concat(this.origins.keySet().stream(), newOriginsMap.keySet().stream()).collect(toSet()).forEach(originId -> {
        Origin origin = newOriginsMap.get(originId);
        if (isNewOrigin(originId, origin)) {
            MonitoredOrigin monitoredOrigin = addMonitoredEndpoint(origin);
            originChanges.addOrReplaceOrigin(originId, monitoredOrigin);
        } else if (isUpdatedOrigin(originId, origin)) {
            MonitoredOrigin monitoredOrigin = changeMonitoredEndpoint(origin);
            originChanges.addOrReplaceOrigin(originId, monitoredOrigin);
        } else if (isUnchangedOrigin(originId, origin)) {
            LOG.info("Existing origin has been left unchanged. Origin={}:{}", appId, origin);
            originChanges.keepExistingOrigin(originId, this.origins.get(originId));
        } else if (isRemovedOrigin(originId, origin)) {
            removeMonitoredEndpoint(originId);
            originChanges.noteRemovedOrigin();
        }
    });
    this.origins = originChanges.updatedOrigins();
    if (originChanges.changed()) {
        notifyStateChange();
    }
}
Also used : EnableOrigin(com.hotels.styx.client.origincommands.EnableOrigin) Origin(com.hotels.styx.api.extension.Origin) DisableOrigin(com.hotels.styx.client.origincommands.DisableOrigin) StyxFutures.await(com.hotels.styx.common.StyxFutures.await) QueueDrainingEventProcessor(com.hotels.styx.common.QueueDrainingEventProcessor) RemoteHost.remoteHost(com.hotels.styx.api.extension.RemoteHost.remoteHost) ActiveOrigins(com.hotels.styx.api.extension.ActiveOrigins) Collections.singleton(java.util.Collections.singleton) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) Objects.isNull(java.util.Objects.isNull) Collectors.toSet(java.util.stream.Collectors.toSet) HttpHandler(com.hotels.styx.api.HttpHandler) EventProcessor(com.hotels.styx.common.EventProcessor) ConnectionPools.simplePoolFactory(com.hotels.styx.client.connectionpool.ConnectionPools.simplePoolFactory) Collection(java.util.Collection) OriginsChangeListener(com.hotels.styx.api.extension.OriginsChangeListener) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) DISABLED(com.hotels.styx.client.OriginsInventory.OriginState.DISABLED) EnableOrigin(com.hotels.styx.client.origincommands.EnableOrigin) StateMachine(com.hotels.styx.common.StateMachine) List(java.util.List) Origin(com.hotels.styx.api.extension.Origin) Objects.nonNull(java.util.Objects.nonNull) INACTIVE(com.hotels.styx.client.OriginsInventory.OriginState.INACTIVE) DisableOrigin(com.hotels.styx.client.origincommands.DisableOrigin) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) NoOriginHealthStatusMonitor(com.hotels.styx.client.healthcheck.monitors.NoOriginHealthStatusMonitor) ConnectionPool(com.hotels.styx.client.connectionpool.ConnectionPool) OriginHealthStatusMonitor(com.hotels.styx.client.healthcheck.OriginHealthStatusMonitor) EventBus(com.google.common.eventbus.EventBus) Deleter(com.hotels.styx.metrics.Deleter) Objects.requireNonNull(java.util.Objects.requireNonNull) OriginsSnapshot(com.hotels.styx.api.extension.OriginsSnapshot) BackendService(com.hotels.styx.api.extension.service.BackendService) Subscribe(com.google.common.eventbus.Subscribe) Stream.concat(java.util.stream.Stream.concat) ACTIVE(com.hotels.styx.client.OriginsInventory.OriginState.ACTIVE) Collections.emptyMap(java.util.Collections.emptyMap) Eventual(com.hotels.styx.api.Eventual) Logger(org.slf4j.Logger) Collections.emptySet(java.util.Collections.emptySet) Preconditions.checkArgument(com.hotels.styx.common.Preconditions.checkArgument) GetOriginsInventorySnapshot(com.hotels.styx.client.origincommands.GetOriginsInventorySnapshot) RemoteHost(com.hotels.styx.api.extension.RemoteHost) Collectors.toList(java.util.stream.Collectors.toList) Closeable(java.io.Closeable) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) CentralisedMetrics(com.hotels.styx.metrics.CentralisedMetrics) Announcer(com.hotels.styx.api.extension.Announcer) Id(com.hotels.styx.api.Id) Id(com.hotels.styx.api.Id)

Example 45 with Origin

use of com.hotels.styx.api.extension.Origin in project styx by ExpediaGroup.

the class StyxHttpClient method sendRequestInternal.

// Visible for testing
static Mono<LiveHttpResponse> sendRequestInternal(NettyConnectionFactory connectionFactory, LiveHttpRequest request, Builder params) {
    LiveHttpRequest networkRequest = addUserAgent(params.userAgent(), request);
    Origin origin = originFromRequest(networkRequest, params.https());
    SslContext sslContext = getSslContext(params.https(), params.tlsSettings());
    return connectionFactory.createConnection(origin, new ConnectionSettings(params.connectTimeoutMillis()), sslContext).flatMap(connection -> Mono.from(connection.write(networkRequest).doOnComplete(connection::close).doOnError(e -> connection.close()).map(response -> response.newBuilder().body(it -> it.doOnEnd(x -> connection.close()).doOnCancel(() -> connection.close())).build())));
}
Also used : Origin(com.hotels.styx.api.extension.Origin) HttpResponse(com.hotels.styx.api.HttpResponse) SslContext(io.netty.handler.ssl.SslContext) Origin.newOriginBuilder(com.hotels.styx.api.extension.Origin.newOriginBuilder) Preconditions.checkArgument(com.hotels.styx.common.Preconditions.checkArgument) NettyExecutor(com.hotels.styx.NettyExecutor) Mono(reactor.core.publisher.Mono) CompletableFuture(java.util.concurrent.CompletableFuture) HostAndPort(com.google.common.net.HostAndPort) HttpRequest(com.hotels.styx.api.HttpRequest) Url(com.hotels.styx.api.Url) TlsSettings(com.hotels.styx.api.extension.service.TlsSettings) TimeUnit(java.util.concurrent.TimeUnit) HttpConfig.newHttpConfigBuilder(com.hotels.styx.client.HttpConfig.newHttpConfigBuilder) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) SslContextFactory(com.hotels.styx.client.ssl.SslContextFactory) Origin(com.hotels.styx.api.extension.Origin) Objects.requireNonNull(java.util.Objects.requireNonNull) USER_AGENT(com.hotels.styx.api.HttpHeaderNames.USER_AGENT) Optional(java.util.Optional) HOST(com.hotels.styx.api.HttpHeaderNames.HOST) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) NettyConnectionFactory(com.hotels.styx.client.netty.connectionpool.NettyConnectionFactory) Builder.httpRequestOperationFactoryBuilder(com.hotels.styx.client.HttpRequestOperationFactory.Builder.httpRequestOperationFactoryBuilder) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) SslContext(io.netty.handler.ssl.SslContext)

Aggregations

Origin (com.hotels.styx.api.extension.Origin)49 Test (org.junit.jupiter.api.Test)40 RemoteHost (com.hotels.styx.api.extension.RemoteHost)15 ActiveOrigins (com.hotels.styx.api.extension.ActiveOrigins)11 Origin.newOriginBuilder (com.hotels.styx.api.extension.Origin.newOriginBuilder)11 Random (java.util.Random)9 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)8 LoadBalancer (com.hotels.styx.api.extension.loadbalancing.spi.LoadBalancer)8 HttpHandler (com.hotels.styx.api.HttpHandler)6 BackendService (com.hotels.styx.api.extension.service.BackendService)6 ConnectionSettings (com.hotels.styx.client.ConnectionSettings)6 Id (com.hotels.styx.api.Id)5 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)5 OriginUnreachableException (com.hotels.styx.api.exceptions.OriginUnreachableException)5 DisableOrigin (com.hotels.styx.client.origincommands.DisableOrigin)5 EnableOrigin (com.hotels.styx.client.origincommands.EnableOrigin)5 CentralisedMetrics (com.hotels.styx.metrics.CentralisedMetrics)5 EventBus (com.google.common.eventbus.EventBus)4 HttpInterceptor (com.hotels.styx.api.HttpInterceptor)4 Context (com.hotels.styx.api.HttpInterceptor.Context)4