Search in sources :

Example 1 with StyxConfig

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();
}
Also used : WebServerConnectorFactory(com.hotels.styx.server.netty.WebServerConnectorFactory) StyxConfig(com.hotels.styx.StyxConfig) NettyServerBuilder(com.hotels.styx.server.netty.NettyServerBuilder) NettyExecutor(com.hotels.styx.NettyExecutor)

Example 2 with StyxConfig

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"));
}
Also used : BackendService(com.hotels.styx.api.extension.service.BackendService) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) StyxConfig(com.hotels.styx.StyxConfig) StyxBackendServiceClient(com.hotels.styx.client.StyxBackendServiceClient) BackendServiceClient(com.hotels.styx.client.BackendServiceClient) CachingOriginStatsFactory(com.hotels.styx.client.OriginStatsFactory.CachingOriginStatsFactory) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) OriginsInventory.newOriginsInventoryBuilder(com.hotels.styx.client.OriginsInventory.newOriginsInventoryBuilder) Origin.newOriginBuilder(com.hotels.styx.api.extension.Origin.newOriginBuilder) BackendService.newBackendServiceBuilder(com.hotels.styx.api.extension.service.BackendService.newBackendServiceBuilder) StickySessionConfig.newStickySessionConfigBuilder(com.hotels.styx.api.extension.service.StickySessionConfig.newStickySessionConfigBuilder) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MapBackedConfiguration(com.hotels.styx.api.configuration.Configuration.MapBackedConfiguration) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test)

Example 3 with StyxConfig

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"));
}
Also used : CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) StyxConfig(com.hotels.styx.StyxConfig) NamedPlugin(com.hotels.styx.proxy.plugin.NamedPlugin) ConfiguredPluginFactory(com.hotels.styx.startup.extensions.ConfiguredPluginFactory) Test(org.junit.jupiter.api.Test)

Example 4 with StyxConfig

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"));
}
Also used : CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) StyxService(com.hotels.styx.api.extension.service.spi.StyxService) CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) StyxConfig(com.hotels.styx.StyxConfig) NamedPlugin(com.hotels.styx.proxy.plugin.NamedPlugin) LoggingSetUp(com.hotels.styx.startup.StyxServerComponents.LoggingSetUp) Map(java.util.Map) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) Configuration(com.hotels.styx.api.configuration.Configuration) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Eventual(com.hotels.styx.api.Eventual) Plugin(com.hotels.styx.api.plugins.spi.Plugin) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) UTF_8(java.nio.charset.StandardCharsets.UTF_8) HttpResponse.response(com.hotels.styx.api.HttpResponse.response) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Matchers.any(org.mockito.Matchers.any) List(java.util.List) IsOptional.isValue(com.hotels.styx.support.matchers.IsOptional.isValue) Collectors.toList(java.util.stream.Collectors.toList) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Environment(com.hotels.styx.Environment) ConfiguredPluginFactory(com.hotels.styx.startup.extensions.ConfiguredPluginFactory) Matchers.is(org.hamcrest.Matchers.is) Mockito.mock(org.mockito.Mockito.mock) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) StyxConfig(com.hotels.styx.StyxConfig) StyxService(com.hotels.styx.api.extension.service.spi.StyxService) Test(org.junit.jupiter.api.Test)

Example 5 with StyxConfig

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"));
}
Also used : CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) StyxConfig(com.hotels.styx.StyxConfig) StyxService(com.hotels.styx.api.extension.service.spi.StyxService) Test(org.junit.jupiter.api.Test)

Aggregations

StyxConfig (com.hotels.styx.StyxConfig)7 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)6 Test (org.junit.jupiter.api.Test)6 CompositeMeterRegistry (io.micrometer.core.instrument.composite.CompositeMeterRegistry)5 Environment (com.hotels.styx.Environment)3 Configuration (com.hotels.styx.api.configuration.Configuration)2 StyxService (com.hotels.styx.api.extension.service.spi.StyxService)2 NamedPlugin (com.hotels.styx.proxy.plugin.NamedPlugin)2 LoggingSetUp (com.hotels.styx.startup.StyxServerComponents.LoggingSetUp)2 ConfiguredPluginFactory (com.hotels.styx.startup.extensions.ConfiguredPluginFactory)2 NettyExecutor (com.hotels.styx.NettyExecutor)1 Eventual (com.hotels.styx.api.Eventual)1 HttpResponse.response (com.hotels.styx.api.HttpResponse.response)1 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)1 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)1 MapBackedConfiguration (com.hotels.styx.api.configuration.Configuration.MapBackedConfiguration)1 Origin.newOriginBuilder (com.hotels.styx.api.extension.Origin.newOriginBuilder)1 BackendService (com.hotels.styx.api.extension.service.BackendService)1 BackendService.newBackendServiceBuilder (com.hotels.styx.api.extension.service.BackendService.newBackendServiceBuilder)1 StickySessionConfig.newStickySessionConfigBuilder (com.hotels.styx.api.extension.service.StickySessionConfig.newStickySessionConfigBuilder)1