Search in sources :

Example 1 with NamedPlugin

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;
    });
}
Also used : NamedPlugin(com.hotels.styx.proxy.plugin.NamedPlugin)

Example 2 with NamedPlugin

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);
}
Also used : Environment(com.hotels.styx.Environment) PluginFactory(com.hotels.styx.api.plugins.spi.PluginFactory) Plugin(com.hotels.styx.api.plugins.spi.Plugin) NamedPlugin(com.hotels.styx.proxy.plugin.NamedPlugin) NamedPlugin.namedPlugin(com.hotels.styx.proxy.plugin.NamedPlugin.namedPlugin)

Example 3 with NamedPlugin

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 />"));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) NamedPlugin(com.hotels.styx.proxy.plugin.NamedPlugin) Test(org.junit.jupiter.api.Test)

Example 4 with NamedPlugin

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 />"));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) NamedPlugin(com.hotels.styx.proxy.plugin.NamedPlugin) Test(org.junit.jupiter.api.Test)

Example 5 with NamedPlugin

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()));
}
Also used : RoutingObject(com.hotels.styx.routing.RoutingObject) BeforeEach(org.junit.jupiter.api.BeforeEach) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) LiveHttpResponse.response(com.hotels.styx.api.LiveHttpResponse.response) StyxConfig(com.hotels.styx.StyxConfig) NamedPlugin(com.hotels.styx.proxy.plugin.NamedPlugin) Support.requestContext(com.hotels.styx.support.Support.requestContext) LiveHttpRequest.get(com.hotels.styx.api.LiveHttpRequest.get) NamedPlugin.namedPlugin(com.hotels.styx.proxy.plugin.NamedPlugin.namedPlugin) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Eventual(com.hotels.styx.api.Eventual) HttpHandler(com.hotels.styx.api.HttpHandler) Mono(reactor.core.publisher.Mono) Mockito.when(org.mockito.Mockito.when) HttpInterceptor(com.hotels.styx.api.HttpInterceptor) Test(org.junit.jupiter.api.Test) Matchers.any(org.mockito.Matchers.any) List(java.util.List) IsOptional.isValue(com.hotels.styx.support.matchers.IsOptional.isValue) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Environment(com.hotels.styx.Environment) OK(com.hotels.styx.api.HttpResponseStatus.OK) Matchers.is(org.hamcrest.Matchers.is) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Mockito.mock(org.mockito.Mockito.mock) RoutingObject(com.hotels.styx.routing.RoutingObject) Support.requestContext(com.hotels.styx.support.Support.requestContext) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

NamedPlugin (com.hotels.styx.proxy.plugin.NamedPlugin)8 Test (org.junit.jupiter.api.Test)6 Environment (com.hotels.styx.Environment)2 StyxConfig (com.hotels.styx.StyxConfig)2 HttpHandler (com.hotels.styx.api.HttpHandler)2 HttpResponse (com.hotels.styx.api.HttpResponse)2 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)2 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)2 NamedPlugin.namedPlugin (com.hotels.styx.proxy.plugin.NamedPlugin.namedPlugin)2 Eventual (com.hotels.styx.api.Eventual)1 HttpInterceptor (com.hotels.styx.api.HttpInterceptor)1 OK (com.hotels.styx.api.HttpResponseStatus.OK)1 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)1 LiveHttpRequest.get (com.hotels.styx.api.LiveHttpRequest.get)1 LiveHttpResponse.response (com.hotels.styx.api.LiveHttpResponse.response)1 Plugin (com.hotels.styx.api.plugins.spi.Plugin)1 PluginFactory (com.hotels.styx.api.plugins.spi.PluginFactory)1 RoutingObject (com.hotels.styx.routing.RoutingObject)1 ConfiguredPluginFactory (com.hotels.styx.startup.extensions.ConfiguredPluginFactory)1 Support.requestContext (com.hotels.styx.support.Support.requestContext)1