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));
}
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));
}
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)));
}
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();
}
}
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())));
}
Aggregations