private static String pluginPath(NamedPlugin namedPlugin) { return "/admin/plugins/" + namedPlugin.name(); }
@JsonProperty("name") public String name() { return plugin.name(); }
/** * Construct an instance given the plugins that you want to be able to enable and disable. * * @param namedPlugins the plugins */ public PluginToggleHandler(Iterable<NamedPlugin> namedPlugins) { this.plugins = new HashMap<>(); namedPlugins.forEach(namedPlugin -> this.plugins.put(namedPlugin.name(), namedPlugin)); }
@Override public void stopping(Service.State from) { for (NamedPlugin plugin : plugins) { try { plugin.styxStopping(); } catch (Exception e) { LOG.error("Error stopping plugin '{}'", plugin.name(), e); } } } }
private static void initialisePlugins(Iterable<NamedPlugin> plugins) { int exceptions = 0; for (NamedPlugin plugin : plugins) { try { plugin.styxStarting(); } catch (Exception e) { exceptions++; LOG.error("Error starting plugin '{}'", plugin.name(), e); } } if (exceptions > 0) { throw new RuntimeException(format("%s plugins failed to start", exceptions)); } }
String linkLabel() { String relativePath = path().substring(pluginPath(namedPlugin).length() + 1); return namedPlugin.name() + ": " + dropFirstForwardSlash(relativePath); }
private String wasNotChangedMessage(RequestedUpdate requestedUpdate) { return format("State of '%s' was already '%s'", requestedUpdate.plugin().name(), requestedUpdate.newState()); }
public InstrumentedPlugin(NamedPlugin plugin, Environment environment) { this.plugin = requireNonNull(plugin); requireNonNull(environment); this.errorStatusMetrics = new SimpleCache<>(statusCode -> environment.metricRegistry().meter("plugins." + plugin.name() + ".response.status." + statusCode.code())); this.exceptionMetrics = new SimpleCache<>(type -> environment.metricRegistry().meter("plugins." + plugin.name() + ".exception." + formattedExceptionName(type))); this.errors = environment.metricRegistry().meter("plugins." + plugin.name() + ".errors"); LOGGER.info("Plugin {} instrumented", plugin.name()); }
private String wasChangedMessage(RequestedUpdate requestedUpdate) { return format("State of '%s' changed to '%s'", requestedUpdate.plugin().name(), requestedUpdate.newState()); }
private Throwable recordAndWrapError(StatusRecordingChain chain, Throwable error) { if (chain.upstreamException) { return error; } recordException(error); return new PluginException(error, plugin.name()); }
private static List<Route> routesForPlugin(NamedPlugin namedPlugin) { List<PluginAdminEndpointRoute> routes = pluginAdminEndpointRoutes(namedPlugin); List<IndexHandler.Link> endpointLinks = routes.stream() .map(PluginAdminEndpointRoute::link) .collect(toList()); HttpHandler handler = endpointLinks.isEmpty() ? new StaticBodyHttpHandler(HTML_UTF_8, format("This plugin (%s) does not expose any admin interfaces", namedPlugin.name())) : new IndexHandler(endpointLinks); Route indexRoute = new Route(pluginPath(namedPlugin), handler); return concatenate(indexRoute, routes); }
@Override public Eventual<LiveHttpResponse> intercept(LiveHttpRequest request, Chain originalChain) { StatusRecordingChain chain = new StatusRecordingChain(originalChain); try { return new Eventual<>(toPublisher( toObservable(plugin.intercept(request, chain)) .doOnNext(response -> recordStatusCode(chain, response)) .onErrorResumeNext(error -> error(recordAndWrapError(chain, error))))); } catch (Throwable e) { recordException(e); return Eventual.error(new PluginException(e, plugin.name())); } }