Search in sources :

Example 1 with JsonNodeConfig

use of com.hotels.styx.infrastructure.configuration.yaml.JsonNodeConfig in project styx by ExpediaGroup.

the class ServiceProvision method loadSpiExtension.

private static <T> T loadSpiExtension(SpiExtension factoryConfig, Environment environment, Class<T> serviceSuperclass) {
    ServiceFactory factory = newServiceFactory(factoryConfig);
    JsonNodeConfig config = new JsonNodeConfig(factoryConfig.config());
    return serviceSuperclass.cast(factory.create(environment, config));
}
Also used : JsonNodeConfig(com.hotels.styx.infrastructure.configuration.yaml.JsonNodeConfig) ServiceFactory(com.hotels.styx.api.configuration.ServiceFactory)

Example 2 with JsonNodeConfig

use of com.hotels.styx.infrastructure.configuration.yaml.JsonNodeConfig in project styx by ExpediaGroup.

the class ServiceProvision method loadServiceFactory.

private static <T> T loadServiceFactory(ServiceFactoryConfig serviceFactoryConfig, Environment environment, Class<T> serviceSuperclass) {
    ServiceFactory factory = newInstance(serviceFactoryConfig.factory(), ServiceFactory.class);
    JsonNodeConfig config = serviceFactoryConfig.config();
    return serviceSuperclass.cast(factory.create(environment, config));
}
Also used : JsonNodeConfig(com.hotels.styx.infrastructure.configuration.yaml.JsonNodeConfig) ServiceFactory(com.hotels.styx.api.configuration.ServiceFactory)

Example 3 with JsonNodeConfig

use of com.hotels.styx.infrastructure.configuration.yaml.JsonNodeConfig in project styx by ExpediaGroup.

the class ServiceProvision method loadRetryPolicy.

/**
 * Create factory configured with a particular key, then uses the factory's create method
 * to create its product.
 *
 * @param <E>           service type
 * @param configuration Styx configuration
 * @param key           Factory configuration attribute
 * @param serviceClass  Service class
 * @return service, if such a configuration key exists
 */
public static <E extends RetryPolicy> Optional<E> loadRetryPolicy(Configuration configuration, Environment environment, String key, Class<? extends E> serviceClass) {
    return configuration.get(key, ServiceFactoryConfig.class).map(factoryConfig -> {
        RetryPolicyFactory factory = newInstance(factoryConfig.factory(), RetryPolicyFactory.class);
        JsonNodeConfig config = factoryConfig.config();
        return serviceClass.cast(factory.create(environment, config));
    });
}
Also used : ServiceFactoryConfig(com.hotels.styx.spi.config.ServiceFactoryConfig) JsonNodeConfig(com.hotels.styx.infrastructure.configuration.yaml.JsonNodeConfig) RetryPolicyFactory(com.hotels.styx.api.extension.retrypolicy.spi.RetryPolicyFactory)

Example 4 with JsonNodeConfig

use of com.hotels.styx.infrastructure.configuration.yaml.JsonNodeConfig in project styx by ExpediaGroup.

the class FileBackedBackendServicesRegistryFactoryTest method instantiatesFromYaml.

@Test
public void instantiatesFromYaml() {
    environment = new com.hotels.styx.Environment.Builder().registry(new MicrometerRegistry(new SimpleMeterRegistry())).configuration(StyxConfig.fromYaml("config: {originsFile: '${CONFIG_LOCATION:classpath:}/conf/origins/backend-factory-origins.yml'}", false)).build();
    JsonNodeConfig factoryConfig = new JsonNodeConfig(environment.configuration().get("config", JsonNode.class).get());
    Registry registry = new FileBackedBackendServicesRegistry.Factory().create(environment, factoryConfig);
    assertThat(registry != null, is(true));
}
Also used : MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) JsonNodeConfig(com.hotels.styx.infrastructure.configuration.yaml.JsonNodeConfig) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Registry(com.hotels.styx.api.extension.service.spi.Registry) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) Test(org.junit.jupiter.api.Test)

Example 5 with JsonNodeConfig

use of com.hotels.styx.infrastructure.configuration.yaml.JsonNodeConfig in project styx by ExpediaGroup.

the class StyxServerComponents method readComponents.

// CHECKSTYLE:ON
private static Map<String, StyxObjectDefinition> readComponents(JsonNode root) {
    Map<String, StyxObjectDefinition> handlers = new HashMap<>();
    root.fields().forEachRemaining(entry -> {
        String name = entry.getKey();
        StyxObjectDefinition handlerDef = new JsonNodeConfig(entry.getValue()).as(StyxObjectDefinition.class);
        handlers.put(name, handlerDef);
    });
    return handlers;
}
Also used : JsonNodeConfig(com.hotels.styx.infrastructure.configuration.yaml.JsonNodeConfig) HashMap(java.util.HashMap) StyxObjectDefinition(com.hotels.styx.routing.config.StyxObjectDefinition)

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