Search in sources :

Example 6 with JsonNodeConfig

use of com.hotels.styx.infrastructure.configuration.yaml.JsonNodeConfig 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)

Aggregations

JsonNodeConfig (com.hotels.styx.infrastructure.configuration.yaml.JsonNodeConfig)6 ServiceFactory (com.hotels.styx.api.configuration.ServiceFactory)3 RetryPolicyFactory (com.hotels.styx.api.extension.retrypolicy.spi.RetryPolicyFactory)2 ServiceFactoryConfig (com.hotels.styx.spi.config.ServiceFactoryConfig)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Environment (com.hotels.styx.api.Environment)1 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)1 Configuration (com.hotels.styx.api.configuration.Configuration)1 ConfigurationException (com.hotels.styx.api.configuration.ConfigurationException)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 Registry (com.hotels.styx.api.extension.service.spi.Registry)1 Pair (com.hotels.styx.common.Pair)1 Pair.pair (com.hotels.styx.common.Pair.pair)1 UtilKt.iteratorToList (com.hotels.styx.javaconvenience.UtilKt.iteratorToList)1 ClassFactories.newInstance (com.hotels.styx.proxy.ClassFactories.newInstance)1 StyxObjectDefinition (com.hotels.styx.routing.config.StyxObjectDefinition)1 EXTENSION_OBJECT_FACTORY (com.hotels.styx.spi.ExtensionObjectFactory.EXTENSION_OBJECT_FACTORY)1