use of com.hotels.styx.StyxConfig in project styx by ExpediaGroup.
the class AdminServerBuilder method build.
public InetServer build() {
LOG.debug("event bus that will be used is {}", environment.eventBus());
StyxConfig styxConfig = environment.configuration();
AdminServerConfig adminServerConfig = styxConfig.adminServerConfig();
NettyExecutor bossExecutor = NettyExecutor.create("Admin-Boss", adminServerConfig.bossThreadsCount());
NettyExecutor workerExecutor = NettyExecutor.create("Admin-Worker", adminServerConfig.workerThreadsCount());
NettyServerBuilder builder = NettyServerBuilder.newBuilder().setMetricsRegistry(environment.metricRegistry()).bossExecutor(bossExecutor).workerExecutor(workerExecutor).handler(adminEndpoints(styxConfig, startupConfig)).shutdownAction(() -> {
bossExecutor.shut();
workerExecutor.shut();
});
// Currently admin server cannot be started over TLS protocol.
// This appears to be an existing issue that needs rectifying.
adminServerConfig.httpConnectorConfig().ifPresent(it -> builder.setProtocolConnector(new WebServerConnectorFactory().create(it)));
return builder.build();
}
use of com.hotels.styx.StyxConfig in project styx by ExpediaGroup.
the class StyxBackendServiceClientFactoryTest method usesTheOriginSpecifiedInTheOriginsRestrictionCookie.
@Test
public void usesTheOriginSpecifiedInTheOriginsRestrictionCookie() {
MapBackedConfiguration config = new MapBackedConfiguration();
config.set("originRestrictionCookie", ORIGINS_RESTRICTION_COOKIE);
environment = new Environment.Builder().registry(new MicrometerRegistry(new SimpleMeterRegistry())).configuration(new StyxConfig(config)).build();
BackendService backendService = newBackendServiceBuilder().origins(newOriginBuilder("localhost", 9091).id("x").build(), newOriginBuilder("localhost", 9092).id("y").build(), newOriginBuilder("localhost", 9093).id("z").build()).build();
BackendServiceClient styxBackendServiceClient = new StyxBackendServiceClientFactory(environment).createClient(backendService, newOriginsInventoryBuilder(environment.centralisedMetrics(), backendService).hostClientFactory((pool) -> {
if (pool.getOrigin().id().equals(id("x"))) {
return hostClient(response(OK).header("X-Origin-Id", "x").build());
} else if (pool.getOrigin().id().equals(id("y"))) {
return hostClient(response(OK).header("X-Origin-Id", "y").build());
} else {
return hostClient(response(OK).header("X-Origin-Id", "z").build());
}
}).build(), new CachingOriginStatsFactory(environment.centralisedMetrics()));
LiveHttpRequest requestz = get("/some-req").cookies(requestCookie(ORIGINS_RESTRICTION_COOKIE, id("z").toString())).build();
LiveHttpRequest requestx = get("/some-req").cookies(requestCookie(ORIGINS_RESTRICTION_COOKIE, id("x").toString())).build();
LiveHttpRequest requesty = get("/some-req").cookies(requestCookie(ORIGINS_RESTRICTION_COOKIE, id("y").toString())).build();
LiveHttpResponse responsez = Mono.from(styxBackendServiceClient.sendRequest(requestz, requestContext())).block();
LiveHttpResponse responsex = Mono.from(styxBackendServiceClient.sendRequest(requestx, requestContext())).block();
LiveHttpResponse responsey = Mono.from(styxBackendServiceClient.sendRequest(requesty, requestContext())).block();
assertThat(responsex.header("X-Origin-Id").get(), is("x"));
assertThat(responsey.header("X-Origin-Id").get(), is("y"));
assertThat(responsez.header("X-Origin-Id").get(), is("z"));
}
use of com.hotels.styx.StyxConfig in project styx by ExpediaGroup.
the class StyxServerComponentsTest method loadsPlugins.
@Test
public void loadsPlugins() {
ConfiguredPluginFactory f1 = new ConfiguredPluginFactory("plugin1", any -> stubPlugin("MyResponse1"));
ConfiguredPluginFactory f2 = new ConfiguredPluginFactory("plugin2", any -> stubPlugin("MyResponse2"));
StyxServerComponents components = new StyxServerComponents.Builder().registry(new MicrometerRegistry(new CompositeMeterRegistry())).styxConfig(new StyxConfig()).pluginFactories(List.of(f1, f2)).build();
List<NamedPlugin> plugins = components.plugins();
List<String> names = plugins.stream().map(NamedPlugin::name).collect(toList());
assertThat(names, contains("plugin1", "plugin2"));
}
use of com.hotels.styx.StyxConfig in project styx by ExpediaGroup.
the class StyxServerComponentsTest method loadsServices.
@Test
public void loadsServices() {
StyxServerComponents components = new StyxServerComponents.Builder().registry(new MicrometerRegistry(new CompositeMeterRegistry())).styxConfig(new StyxConfig()).services((env, routeDb) -> Map.of("service1", mock(StyxService.class), "service2", mock(StyxService.class))).build();
Map<String, StyxService> services = components.services();
assertThat(services.keySet(), containsInAnyOrder("service1", "service2"));
}
use of com.hotels.styx.StyxConfig in project styx by ExpediaGroup.
the class StyxServerComponentsTest method exposesAdditionalServices.
@Test
public void exposesAdditionalServices() {
StyxServerComponents components = new StyxServerComponents.Builder().registry(new MicrometerRegistry((new CompositeMeterRegistry()))).styxConfig(new StyxConfig()).additionalServices(Map.of("service1", mock(StyxService.class), "service2", mock(StyxService.class))).build();
Map<String, StyxService> services = components.services();
assertThat(services.keySet(), containsInAnyOrder("service1", "service2"));
}
Aggregations