use of com.hotels.styx.proxy.plugin.NamedPlugin in project styx by ExpediaGroup.
the class PluginLoadingForStartup method loadPluginsFromFactories.
private static List<NamedPlugin> loadPluginsFromFactories(Environment environment, List<ConfiguredPluginFactory> factories) {
return PLUGIN_STARTUP_FAILURE_HANDLING_STRATEGY.process(factories, factory -> {
LOGGER.info("Instantiating Plugin, pluginName={}...", factory.name());
NamedPlugin plugin = loadPlugin(environment, factory);
LOGGER.info("Instantiated Plugin, pluginName={}", factory.name());
return plugin;
});
}
use of com.hotels.styx.proxy.plugin.NamedPlugin in project styx by ExpediaGroup.
the class PluginLoadingForStartup method loadPlugin.
private static NamedPlugin loadPlugin(Environment environment, ConfiguredPluginFactory factory) {
PluginFactory.Environment pluginEnvironment = new PluginFactory.Environment() {
@Override
public <T> T pluginConfig(Class<T> clazz) {
return factory.pluginConfig(clazz);
}
@Override
public Configuration configuration() {
return environment.configuration();
}
@Override
public MeterRegistry pluginMeterRegistry() {
return environment.meterRegistry().scope("plugin.internal." + factory.name().toLowerCase());
}
@Override
@Deprecated
public MetricRegistry metricRegistry() {
return environment.metricRegistry().scope("plugin.internal." + factory.name());
}
};
Plugin plugin = factory.pluginFactory().create(pluginEnvironment);
return namedPlugin(factory.name(), plugin);
}
use of com.hotels.styx.proxy.plugin.NamedPlugin in project styx by ExpediaGroup.
the class PluginListHandlerTest method showsLoadedPlugins.
@Test
public void showsLoadedPlugins() {
NamedPlugin one = namedPlugin("one", PASS_THROUGH);
NamedPlugin two = namedPlugin("two", PASS_THROUGH);
List<NamedPlugin> plugins = asList(one, two);
PluginListHandler handler = new PluginListHandler(plugins);
HttpResponse response = Mono.from(handler.handle(get("/").build(), requestContext())).block();
assertThat(response.status(), is(OK));
assertThat(response.bodyAs(UTF_8), is("" + "<h3>Loaded</h3>" + "<a href='/admin/plugins/one'>one</a><br />" + "<a href='/admin/plugins/two'>two</a><br />"));
}
use of com.hotels.styx.proxy.plugin.NamedPlugin in project styx by ExpediaGroup.
the class PluginListHandlerTest method showsEnabledAndDisabledPlugins.
@Test
public void showsEnabledAndDisabledPlugins() {
NamedPlugin one = namedPlugin("one", PASS_THROUGH);
NamedPlugin two = namedPlugin("two", PASS_THROUGH);
NamedPlugin three = namedPlugin("three", PASS_THROUGH);
NamedPlugin four = namedPlugin("four", PASS_THROUGH);
two.setEnabled(false);
three.setEnabled(false);
List<NamedPlugin> plugins = asList(one, two, three, four);
PluginListHandler handler = new PluginListHandler(plugins);
HttpResponse response = Mono.from(handler.handle(get("/").build(), requestContext())).block();
assertThat(response.status(), is(OK));
assertThat(response.bodyAs(UTF_8), is("" + "<h3>Enabled</h3>" + "<a href='/admin/plugins/one'>one</a><br />" + "<a href='/admin/plugins/four'>four</a><br />" + "<h3>Disabled</h3>" + "<a href='/admin/plugins/two'>two</a><br />" + "<a href='/admin/plugins/three'>three</a><br />"));
}
use of com.hotels.styx.proxy.plugin.NamedPlugin in project styx by ExpediaGroup.
the class InterceptorPipelineBuilderTest method setUp.
@BeforeEach
public void setUp() {
environment = new Environment.Builder().registry(new MicrometerRegistry(new SimpleMeterRegistry())).configuration(StyxConfig.defaultConfig()).build();
plugins = List.of(namedPlugin("plug1", (request, chain) -> chain.proceed(request).map(response -> response.newBuilder().header("plug1", "1").build())), namedPlugin("plug2", (request, chain) -> chain.proceed(request).map(response -> response.newBuilder().header("plug2", "1").build())));
handler = mock(RoutingObject.class);
when(handler.handle(any(LiveHttpRequest.class), any(HttpInterceptor.Context.class))).thenReturn(Eventual.of(response(OK).build()));
}
Aggregations