this.pluginsService = new PluginsService(tmpSettings, environment.configFile(), environment.modulesFile(), environment.pluginsFile(), classpathPlugins); this.settings = pluginsService.updatedSettings(); localNodeFactory = new LocalNodeFactory(settings, nodeEnvironment.nodeId()); final List<ExecutorBuilder<?>> executorBuilders = pluginsService.getExecutorBuilders(settings); final List<Setting<?>> additionalSettings = new ArrayList<>(pluginsService.getPluginSettings()); final List<String> additionalSettingsFilter = new ArrayList<>(pluginsService.getPluginSettingsFilter()); for (final ExecutorBuilder<?> builder : threadPool.builders()) { additionalSettings.addAll(builder.getRegisteredSettings()); final ScriptModule scriptModule = new ScriptModule(settings, pluginsService.filterPlugins(ScriptPlugin.class)); AnalysisModule analysisModule = new AnalysisModule(this.environment, pluginsService.filterPlugins(AnalysisPlugin.class)); final Set<SettingUpgrader<?>> settingsUpgraders = pluginsService.filterPlugins(Plugin.class) .stream() .map(Plugin::getSettingUpgraders) resourcesToClose.add(resourceWatcherService); final NetworkService networkService = new NetworkService( getCustomNameResolvers(pluginsService.filterPlugins(DiscoveryPlugin.class))); List<ClusterPlugin> clusterPlugins = pluginsService.filterPlugins(ClusterPlugin.class); final ClusterService clusterService = new ClusterService(settings, settingsModule.getClusterSettings(), threadPool, ClusterModule.getClusterStateCustomSuppliers(clusterPlugins)); resourcesToClose.add(clusterService); final IngestService ingestService = new IngestService(clusterService, threadPool, this.environment, scriptModule.getScriptService(), analysisModule.getAnalysisRegistry(), pluginsService.filterPlugins(IngestPlugin.class));
Plugin plugin = loadPlugin(pluginClass, settings, configPath); PluginInfo pluginInfo = new PluginInfo(pluginClass.getName(), "classpath plugin", "NA", Version.CURRENT, "1.8", pluginClass.getName(), Collections.emptyList(), false); Set<Bundle> modules = getModuleBundles(modulesDirectory); for (Bundle bundle : modules) { modulesList.add(bundle.plugin); checkForFailedPluginRemovals(pluginsDirectory); Set<Bundle> plugins = getPluginBundles(pluginsDirectory); for (final Bundle bundle : plugins) { pluginsList.add(bundle.plugin); List<Tuple<PluginInfo, Plugin>> loaded = loadBundles(seenBundles); pluginsLoaded.addAll(loaded); logPluginInfo(info.getModuleInfos(), "module", logger); logPluginInfo(info.getPluginInfos(), "plugin", logger);
public NodeInfo info(boolean settings, boolean os, boolean process, boolean jvm, boolean threadPool, boolean transport, boolean http, boolean plugin, boolean ingest, boolean indices) { return new NodeInfo(Version.CURRENT, Build.CURRENT, transportService.getLocalNode(), settings ? settingsFilter.filter(this.settings) : null, os ? monitorService.osService().info() : null, process ? monitorService.processService().info() : null, jvm ? monitorService.jvmService().info() : null, threadPool ? this.threadPool.info() : null, transport ? transportService.info() : null, http ? (httpServerTransport == null ? null : httpServerTransport.info()) : null, plugin ? (pluginService == null ? null : pluginService.info()) : null, ingest ? (ingestService == null ? null : ingestService.info()) : null, indices ? indicesService.getTotalIndexingBufferBytes() : null ); }
private Plugin loadBundle(Bundle bundle, Map<String, Plugin> loaded) { String name = bundle.plugin.getName(); verifyCompatibility(bundle.plugin); // collect loaders of extended plugins List<ClassLoader> extendedLoaders = new ArrayList<>(); for (String extendedPluginName : bundle.plugin.getExtendedPlugins()) { Plugin extendedPlugin = loaded.get(extendedPluginName); assert extendedPlugin != null; if (ExtensiblePlugin.class.isInstance(extendedPlugin) == false) { throw new IllegalStateException("Plugin [" + name + "] cannot extend non-extensible plugin [" + extendedPluginName + "]"); } extendedLoaders.add(extendedPlugin.getClass().getClassLoader()); } // create a child to load the plugin in this bundle ClassLoader parentLoader = PluginLoaderIndirection.createLoader(getClass().getClassLoader(), extendedLoaders); ClassLoader loader = URLClassLoader.newInstance(bundle.urls.toArray(new URL[0]), parentLoader); // reload SPI with any new services from the plugin reloadLuceneSPI(loader); for (String extendedPluginName : bundle.plugin.getExtendedPlugins()) { // note: already asserted above that extended plugins are loaded and extensible ExtensiblePlugin.class.cast(loaded.get(extendedPluginName)).reloadSPI(loader); } Class<? extends Plugin> pluginClass = loadPluginClass(bundle.plugin.getClassname(), loader); Plugin plugin = loadPlugin(pluginClass, settings, configPath); loaded.put(name, plugin); return plugin; }
Settings.builder() .put(defaultSettings) .put(pluginsService.updatedSettings()) .put(TransportSettings.FEATURE_PREFIX + "." + TRANSPORT_CLIENT_FEATURE, true) .build(); final NetworkService networkService = new NetworkService(Collections.emptyList()); try { final List<Setting<?>> additionalSettings = new ArrayList<>(pluginsService.getPluginSettings()); final List<String> additionalSettingsFilter = new ArrayList<>(pluginsService.getPluginSettingsFilter()); for (final ExecutorBuilder<?> builder : threadPool.builders()) { additionalSettings.addAll(builder.getRegisteredSettings()); SearchModule searchModule = new SearchModule(settings, true, pluginsService.filterPlugins(SearchPlugin.class)); IndicesModule indicesModule = new IndicesModule(Collections.emptyList()); List<NamedWriteableRegistry.Entry> entries = new ArrayList<>(); entries.addAll(indicesModule.getNamedWriteables()); entries.addAll(ClusterModule.getNamedWriteables()); entries.addAll(pluginsService.filterPlugins(Plugin.class).stream() .flatMap(p -> p.getNamedWriteables().stream()) .collect(Collectors.toList())); NamedXContentRegistry xContentRegistry = new NamedXContentRegistry(Stream.of( searchModule.getNamedXContents().stream(), pluginsService.filterPlugins(Plugin.class).stream() .flatMap(p -> p.getNamedXContent().stream()) ).flatMap(Function.identity()).collect(toList()));
protected AbstractClient(Settings pSettings, boolean loadConfigSettings) { Tuple<Settings, Environment> tuple = InternalSettingsPreparer.prepareSettings(pSettings, loadConfigSettings); Settings settings = settingsBuilder().put(tuple.v1()) .put("network.server", false) .put("node.client", true) .build(); this.environment = tuple.v2(); this.pluginsService = new PluginsService(settings, tuple.v2()); this.settings = pluginsService.updatedSettings(); Version version = Version.CURRENT; CompressorFactory.configure(this.settings); ModulesBuilder modules = new ModulesBuilder(); modules.add(new SettingsModule(this.settings)); modules.add(new ThreadPoolModule(this.settings)); this.injector = modules.createInjector(); }
Environment env = InternalSettingsPreparer.prepareEnvironment(nodeSettings, null); PluginsService pluginsService; pluginsService = new PluginsService(nodeSettings, null, env.modulesFile(), env.pluginsFile(), plugins); new Class[]{Client.class}, clientInvocationHandler); ScriptModule scriptModule = createScriptModule(pluginsService.filterPlugins(ScriptPlugin.class)); List<Setting<?>> additionalSettings = pluginsService.getPluginSettings(); additionalSettings.add(InternalSettingsPlugin.VERSION_CREATED); SettingsModule settingsModule = new SettingsModule(nodeSettings, additionalSettings, pluginsService.getPluginSettingsFilter()); searchModule = new SearchModule(nodeSettings, false, pluginsService.filterPlugins(SearchPlugin.class)); IndicesModule indicesModule = new IndicesModule(pluginsService.filterPlugins(MapperPlugin.class)); List<NamedWriteableRegistry.Entry> entries = new ArrayList<>(); entries.addAll(indicesModule.getNamedWriteables());
.build(); PluginsService pluginsService = new PluginsService(settings, null, null, pluginClasses); this.settings = pluginsService.updatedSettings(); modules.add(new Version.Module(version)); for (Module pluginModule : pluginsService.nodeModules()) { modules.add(pluginModule); modules.add(new CircuitBreakerModule(this.settings)); pluginsService.processModules(modules);
getClass().getClassLoader()); reloadLuceneSPI(loader); final Class<? extends Plugin> pluginClass = loadPluginClass(bundle.plugin.getClassname(), loader); final Plugin plugin = loadPlugin(pluginClass, settings); plugins.add(new Tuple<>(bundle.plugin, plugin));
final List<Exception> exceptions = new ArrayList<>(); pluginsService.filterPlugins(ReloadablePlugin.class).stream().forEach(p -> { try { p.reload(settingsWithKeystore);
/** * Setup for the whole base test class. */ @Override public void setUp() throws Exception { super.setUp(); Settings settings = Settings.builder() .put("node.name", AbstractQueryTestCase.class.toString()) .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) .build(); IndicesModule indicesModule = new IndicesModule(Collections.emptyList()); PluginsService pluginsService = new PluginsService(settings, null, null, null, getPlugins()); SearchModule searchModule = new SearchModule(settings, false, pluginsService.filterPlugins(SearchPlugin.class)); List<NamedWriteableRegistry.Entry> entries = new ArrayList<>(); entries.addAll(indicesModule.getNamedWriteables()); entries.addAll(searchModule.getNamedWriteables()); namedWriteableRegistry = new NamedWriteableRegistry(entries); xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents()); //create some random type with some default field, those types will stick around for all of the subclasses currentTypes = new String[randomIntBetween(0, 5)]; for (int i = 0; i < currentTypes.length; i++) { String type = randomAlphaOfLengthBetween(1, 10); currentTypes[i] = type; } }
private static PluginsService newPluginService(final Settings settings, Collection<Class<? extends Plugin>> plugins) { final Settings.Builder settingsBuilder = Settings.builder() .put(TransportSettings.PING_SCHEDULE.getKey(), "5s") // enable by default the transport schedule ping interval .put(InternalSettingsPreparer.prepareSettings(settings)) .put(NetworkService.NETWORK_SERVER.getKey(), false) .put(CLIENT_TYPE_SETTING_S.getKey(), CLIENT_TYPE); return new PluginsService(settingsBuilder.build(), null, null, null, plugins); }
/** check a candidate plugin for jar hell before installing it */ private void jarHellCheck(Path candidate, boolean isolated) throws IOException { // create list of current jars in classpath final List<URL> jars = new ArrayList<>(); jars.addAll(Arrays.asList(JarHell.parseClassPath())); // read existing bundles. this does some checks on the installation too. List<Bundle> bundles = PluginsService.getPluginBundles(environment.pluginsFile()); // if we aren't isolated, we need to jarhellcheck against any other non-isolated plugins // thats always the first bundle if (isolated == false) { jars.addAll(bundles.get(0).urls); } // add plugin jars to the list Path pluginJars[] = FileSystemUtils.files(candidate, "*.jar"); for (Path jar : pluginJars) { jars.add(jar.toUri().toURL()); } // check combined (current classpath + new jars to-be-added) try { JarHell.checkJarHell(jars.toArray(new URL[jars.size()])); } catch (Exception ex) { throw new RuntimeException(ex); } }
Settings.builder() .put(defaultSettings) .put(pluginsService.updatedSettings()) .put(TcpTransport.FEATURE_PREFIX + "." + TRANSPORT_CLIENT_FEATURE, true) .build(); final NetworkService networkService = new NetworkService(Collections.emptyList()); try { final List<Setting<?>> additionalSettings = new ArrayList<>(pluginsService.getPluginSettings()); final List<String> additionalSettingsFilter = new ArrayList<>(pluginsService.getPluginSettingsFilter()); for (final ExecutorBuilder<?> builder : threadPool.builders()) { additionalSettings.addAll(builder.getRegisteredSettings()); SearchModule searchModule = new SearchModule(settings, true, pluginsService.filterPlugins(SearchPlugin.class)); IndicesModule indicesModule = new IndicesModule(Collections.emptyList()); List<NamedWriteableRegistry.Entry> entries = new ArrayList<>(); entries.addAll(indicesModule.getNamedWriteables()); entries.addAll(ClusterModule.getNamedWriteables()); entries.addAll(pluginsService.filterPlugins(Plugin.class).stream() .flatMap(p -> p.getNamedWriteables().stream()) .collect(Collectors.toList())); NamedXContentRegistry xContentRegistry = new NamedXContentRegistry(Stream.of( searchModule.getNamedXContents().stream(), pluginsService.filterPlugins(Plugin.class).stream() .flatMap(p -> p.getNamedXContent().stream()) ).flatMap(Function.identity()).collect(toList()));
logger.info("{{}}[{}]: initializing ...", Version.CURRENT, JvmInfo.jvmInfo().pid()); this.pluginsService = new PluginsService(tuple.v1(), tuple.v2()); this.settings = pluginsService.updatedSettings(); this.environment = tuple.v2();
private Plugin loadBundle(Bundle bundle, Map<String, Plugin> loaded) { String name = bundle.plugin.getName(); verifyCompatibility(bundle.plugin); // collect loaders of extended plugins List<ClassLoader> extendedLoaders = new ArrayList<>(); for (String extendedPluginName : bundle.plugin.getExtendedPlugins()) { Plugin extendedPlugin = loaded.get(extendedPluginName); assert extendedPlugin != null; if (ExtensiblePlugin.class.isInstance(extendedPlugin) == false) { throw new IllegalStateException("Plugin [" + name + "] cannot extend non-extensible plugin [" + extendedPluginName + "]"); } extendedLoaders.add(extendedPlugin.getClass().getClassLoader()); } // create a child to load the plugin in this bundle ClassLoader parentLoader = PluginLoaderIndirection.createLoader(getClass().getClassLoader(), extendedLoaders); ClassLoader loader = URLClassLoader.newInstance(bundle.urls.toArray(new URL[0]), parentLoader); // reload SPI with any new services from the plugin reloadLuceneSPI(loader); for (String extendedPluginName : bundle.plugin.getExtendedPlugins()) { // note: already asserted above that extended plugins are loaded and extensible ExtensiblePlugin.class.cast(loaded.get(extendedPluginName)).reloadSPI(loader); } Class<? extends Plugin> pluginClass = loadPluginClass(bundle.plugin.getClassname(), loader); Plugin plugin = loadPlugin(pluginClass, settings, configPath); loaded.put(name, plugin); return plugin; }
this.pluginsService = new PluginsService(tmpSettings, tmpEnv.modulesFile(), tmpEnv.pluginsFile(), classpathPlugins); this.settings = pluginsService.updatedSettings(); modules.add(new CircuitBreakerModule(settings)); for (Module pluginModule : pluginsService.nodeModules()) { modules.add(pluginModule); pluginsService.processModules(modules);
private List<Tuple<PluginInfo,Plugin>> loadBundles(List<Bundle> bundles) { List<Tuple<PluginInfo, Plugin>> plugins = new ArrayList<>(); for (Bundle bundle : bundles) { // jar-hell check the bundle against the parent classloader // pluginmanager does it, but we do it again, in case lusers mess with jar files manually try { final List<URL> jars = new ArrayList<>(); jars.addAll(Arrays.asList(JarHell.parseClassPath())); jars.addAll(bundle.urls); JarHell.checkJarHell(jars.toArray(new URL[0])); } catch (Exception e) { throw new IllegalStateException("failed to load bundle " + bundle.urls + " due to jar hell", e); } // create a child to load the plugins in this bundle ClassLoader loader = URLClassLoader.newInstance(bundle.urls.toArray(new URL[0]), getClass().getClassLoader()); for (PluginInfo pluginInfo : bundle.plugins) { final Plugin plugin; if (pluginInfo.isJvm()) { // reload lucene SPI with any new services from the plugin reloadLuceneSPI(loader); Class<? extends Plugin> pluginClass = loadPluginClass(pluginInfo.getClassname(), loader); plugin = loadPlugin(pluginClass, settings); } else { plugin = new SitePlugin(pluginInfo.getName(), pluginInfo.getDescription()); } plugins.add(new Tuple<>(pluginInfo, plugin)); } } return Collections.unmodifiableList(plugins); }
toClose.add(plugin); toClose.addAll(pluginsService.filterPlugins(Plugin.class));
private static PluginsService newPluginService(final Settings settings, Collection<Class<? extends Plugin>> plugins) { final Settings.Builder settingsBuilder = Settings.builder() .put(TcpTransport.PING_SCHEDULE.getKey(), "5s") // enable by default the transport schedule ping interval .put(InternalSettingsPreparer.prepareSettings(settings)) .put(NetworkService.NETWORK_SERVER.getKey(), false) .put(CLIENT_TYPE_SETTING_S.getKey(), CLIENT_TYPE); return new PluginsService(settingsBuilder.build(), null, null, null, plugins); }