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));
}
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));
}
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));
});
}
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));
}
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;
}
Aggregations