Search in sources :

Example 11 with Configuration

use of com.hotels.styx.api.configuration.Configuration in project styx by ExpediaGroup.

the class StyxServerTest method styxConfig.

private static StyxConfig styxConfig() {
    ProxyServerConfig proxyConfig = new ProxyServerConfig.Builder().setHttpConnector(new HttpConnectorConfig(0)).build();
    AdminServerConfig adminConfig = new AdminServerConfig.Builder().setHttpConnector(new HttpConnectorConfig(0)).build();
    Configuration config = new MapBackedConfiguration(EMPTY_CONFIGURATION).set("admin", adminConfig).set("proxy", proxyConfig);
    return new StyxConfig(config);
}
Also used : AdminServerConfig(com.hotels.styx.admin.AdminServerConfig) Configuration(com.hotels.styx.api.configuration.Configuration) MapBackedConfiguration(com.hotels.styx.api.configuration.Configuration.MapBackedConfiguration) ProxyServerConfig(com.hotels.styx.proxy.ProxyServerConfig) MapBackedConfiguration(com.hotels.styx.api.configuration.Configuration.MapBackedConfiguration) HttpConnectorConfig(com.hotels.styx.server.HttpConnectorConfig)

Example 12 with Configuration

use of com.hotels.styx.api.configuration.Configuration in project styx by ExpediaGroup.

the class ServiceProvision method servicesMap.

private static <U> Map<String, U> servicesMap(JsonNode jsonNode, Environment environment, Class<? extends U> serviceClass) {
    JsonNode factories = jsonNode.get("factories");
    JsonNodeConfig jsonNodeConfig = new JsonNodeConfig(factories);
    return iteratorToList(factories.fieldNames()).stream().flatMap(name -> {
        if (isType(name, jsonNodeConfig, SpiExtension.class)) {
            return namedExtensionFromSpiExtension(environment, serviceClass, jsonNodeConfig, name);
        } else if (isType(name, jsonNodeConfig, ServiceFactoryConfig.class)) {
            return namedExtensionFromServiceFactoryConfig(environment, serviceClass, jsonNodeConfig, name);
        } else {
            String content = factories.get(name).toString();
            String message = format("Unexpected configuration object 'services.factories.%s', Configuration='%s'", name, content);
            throw new ConfigurationException(message);
        }
    }).collect(toMap(Pair::key, Pair::value));
}
Also used : RetryPolicy(com.hotels.styx.api.extension.retrypolicy.spi.RetryPolicy) LoggerFactory(org.slf4j.LoggerFactory) ActiveOrigins(com.hotels.styx.api.extension.ActiveOrigins) RetryPolicyFactory(com.hotels.styx.api.extension.retrypolicy.spi.RetryPolicyFactory) Collectors.toMap(java.util.stream.Collectors.toMap) ServiceFactoryConfig(com.hotels.styx.spi.config.ServiceFactoryConfig) Map(java.util.Map) Pair(com.hotels.styx.common.Pair) JsonNode(com.fasterxml.jackson.databind.JsonNode) Configuration(com.hotels.styx.api.configuration.Configuration) EXTENSION_OBJECT_FACTORY(com.hotels.styx.spi.ExtensionObjectFactory.EXTENSION_OBJECT_FACTORY) ServiceFactory(com.hotels.styx.api.configuration.ServiceFactory) Collections.emptyMap(java.util.Collections.emptyMap) Logger(org.slf4j.Logger) LoadBalancer(com.hotels.styx.api.extension.loadbalancing.spi.LoadBalancer) ClassFactories.newInstance(com.hotels.styx.proxy.ClassFactories.newInstance) String.format(java.lang.String.format) JsonNodeConfig(com.hotels.styx.infrastructure.configuration.yaml.JsonNodeConfig) SpiExtension(com.hotels.styx.spi.config.SpiExtension) List(java.util.List) Stream(java.util.stream.Stream) UtilKt.iteratorToList(com.hotels.styx.javaconvenience.UtilKt.iteratorToList) Optional(java.util.Optional) Pair.pair(com.hotels.styx.common.Pair.pair) LoadBalancerFactory(com.hotels.styx.api.extension.loadbalancing.spi.LoadBalancerFactory) Environment(com.hotels.styx.api.Environment) ConfigurationException(com.hotels.styx.api.configuration.ConfigurationException) JsonNodeConfig(com.hotels.styx.infrastructure.configuration.yaml.JsonNodeConfig) ConfigurationException(com.hotels.styx.api.configuration.ConfigurationException) SpiExtension(com.hotels.styx.spi.config.SpiExtension) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 13 with Configuration

use of com.hotels.styx.api.configuration.Configuration in project styx by ExpediaGroup.

the class StyxServerComponentsTest method createsEnvironment.

@Test
public void createsEnvironment() {
    Configuration config = new Configuration.MapBackedConfiguration().set("foo", "abc").set("bar", "def");
    StyxServerComponents components = new StyxServerComponents.Builder().registry(new MicrometerRegistry(new CompositeMeterRegistry())).styxConfig(new StyxConfig(config)).build();
    Environment environment = components.environment();
    assertThat(environment.configuration().get("foo", String.class), isValue("abc"));
    assertThat(environment.configuration().get("bar", String.class), isValue("def"));
    assertThat(environment.eventBus(), is(notNullValue()));
    assertThat(environment.metricRegistry(), is(notNullValue()));
}
Also used : CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) StyxConfig(com.hotels.styx.StyxConfig) Configuration(com.hotels.styx.api.configuration.Configuration) Environment(com.hotels.styx.Environment) Test(org.junit.jupiter.api.Test)

Aggregations

Configuration (com.hotels.styx.api.configuration.Configuration)13 Test (org.junit.jupiter.api.Test)9 ConfigurationException (com.hotels.styx.api.configuration.ConfigurationException)3 YamlConfig (com.hotels.styx.infrastructure.configuration.yaml.YamlConfig)3 MapBackedConfiguration (com.hotels.styx.api.configuration.Configuration.MapBackedConfiguration)2 RetryPolicy (com.hotels.styx.api.extension.retrypolicy.spi.RetryPolicy)2 FileMonitorSettings (com.hotels.styx.proxy.backends.file.FileChangeMonitor.FileMonitorSettings)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Environment (com.hotels.styx.Environment)1 StyxConfig (com.hotels.styx.StyxConfig)1 AdminServerConfig (com.hotels.styx.admin.AdminServerConfig)1 Environment (com.hotels.styx.api.Environment)1 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)1 ServiceFactory (com.hotels.styx.api.configuration.ServiceFactory)1 ActiveOrigins (com.hotels.styx.api.extension.ActiveOrigins)1 LoadBalancer (com.hotels.styx.api.extension.loadbalancing.spi.LoadBalancer)1 LoadBalancerFactory (com.hotels.styx.api.extension.loadbalancing.spi.LoadBalancerFactory)1 RetryPolicyFactory (com.hotels.styx.api.extension.retrypolicy.spi.RetryPolicyFactory)1 Pair (com.hotels.styx.common.Pair)1 Pair.pair (com.hotels.styx.common.Pair.pair)1