Search in sources :

Example 6 with Environment

use of com.hotels.styx.api.Environment 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 7 with Environment

use of com.hotels.styx.api.Environment in project styx by ExpediaGroup.

the class ServiceProvisionTest method ignoresDisabledServices.

@Test
public void ignoresDisabledServices() {
    Environment env = environmentWithConfig(mixedDisabledServices);
    Map<String, StyxService> services = loadServices(env.configuration(), env, "multi", StyxService.class);
    assertThat(services.isEmpty(), is(true));
}
Also used : Environment(com.hotels.styx.api.Environment) StyxService(com.hotels.styx.api.extension.service.spi.StyxService) AbstractStyxService(com.hotels.styx.api.extension.service.spi.AbstractStyxService) Test(org.junit.jupiter.api.Test)

Example 8 with Environment

use of com.hotels.styx.api.Environment in project styx by ExpediaGroup.

the class ServiceProvisionTest method loadsFromMixedConfigFormat.

@Test
public void loadsFromMixedConfigFormat() {
    Environment env = environmentWithConfig(yamlForMixedServiceFactories);
    Map<String, StyxService> services = loadServices(env.configuration(), env, "multi", StyxService.class);
    assertThat(services.get("backendProvider"), instanceOf(BackendServiceProvider.class));
    assertThat(services.get("routingProvider"), instanceOf(RoutingObjectProvider.class));
}
Also used : Environment(com.hotels.styx.api.Environment) StyxService(com.hotels.styx.api.extension.service.spi.StyxService) AbstractStyxService(com.hotels.styx.api.extension.service.spi.AbstractStyxService) Test(org.junit.jupiter.api.Test)

Aggregations

Environment (com.hotels.styx.api.Environment)8 AbstractStyxService (com.hotels.styx.api.extension.service.spi.AbstractStyxService)6 StyxService (com.hotels.styx.api.extension.service.spi.StyxService)6 Test (org.junit.jupiter.api.Test)6 ConfigurationException (com.hotels.styx.api.configuration.ConfigurationException)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)1 Configuration (com.hotels.styx.api.configuration.Configuration)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 RetryPolicy (com.hotels.styx.api.extension.retrypolicy.spi.RetryPolicy)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 JsonNodeConfig (com.hotels.styx.infrastructure.configuration.yaml.JsonNodeConfig)1 UtilKt.iteratorToList (com.hotels.styx.javaconvenience.UtilKt.iteratorToList)1 ClassFactories.newInstance (com.hotels.styx.proxy.ClassFactories.newInstance)1 EXTENSION_OBJECT_FACTORY (com.hotels.styx.spi.ExtensionObjectFactory.EXTENSION_OBJECT_FACTORY)1