|
|
@@ -20,11 +20,13 @@
|
|
|
package org.elasticsearch.plugins;
|
|
|
|
|
|
import com.google.common.collect.*;
|
|
|
+import org.apache.lucene.util.IOUtils;
|
|
|
import org.elasticsearch.ElasticsearchException;
|
|
|
import org.elasticsearch.action.admin.cluster.node.info.PluginInfo;
|
|
|
import org.elasticsearch.action.admin.cluster.node.info.PluginsInfo;
|
|
|
import org.elasticsearch.common.Strings;
|
|
|
import org.elasticsearch.common.collect.MapBuilder;
|
|
|
+import org.elasticsearch.common.collect.Tuple;
|
|
|
import org.elasticsearch.common.component.AbstractComponent;
|
|
|
import org.elasticsearch.common.component.LifecycleComponent;
|
|
|
import org.elasticsearch.common.inject.Module;
|
|
|
@@ -42,8 +44,6 @@ import java.lang.reflect.Method;
|
|
|
import java.net.URL;
|
|
|
import java.util.*;
|
|
|
|
|
|
-import static com.google.common.collect.Maps.newHashMap;
|
|
|
-
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
@@ -52,7 +52,10 @@ public class PluginsService extends AbstractComponent {
|
|
|
|
|
|
private final Environment environment;
|
|
|
|
|
|
- private final ImmutableMap<String, Plugin> plugins;
|
|
|
+ /**
|
|
|
+ * We keep around a list of jvm plugins
|
|
|
+ */
|
|
|
+ private final ImmutableList<Tuple<PluginInfo, Plugin>> plugins;
|
|
|
|
|
|
private final ImmutableMap<Plugin, List<OnModuleReference>> onModuleReferences;
|
|
|
|
|
|
@@ -79,25 +82,47 @@ public class PluginsService extends AbstractComponent {
|
|
|
super(settings);
|
|
|
this.environment = environment;
|
|
|
|
|
|
- Map<String, Plugin> plugins = Maps.newHashMap();
|
|
|
+ ImmutableList.Builder<Tuple<PluginInfo, Plugin>> tupleBuilder = ImmutableList.builder();
|
|
|
|
|
|
- //first we load all the default plugins from the settings
|
|
|
+ // first we load all the default plugins from the settings
|
|
|
String[] defaultPluginsClasses = settings.getAsArray("plugin.types");
|
|
|
for (String pluginClass : defaultPluginsClasses) {
|
|
|
Plugin plugin = loadPlugin(pluginClass, settings);
|
|
|
- plugins.put(plugin.name(), plugin);
|
|
|
+ PluginInfo pluginInfo = new PluginInfo(plugin.name(), plugin.description(), hasSite(plugin.name()), true, PluginInfo.VERSION_NOT_AVAILABLE);
|
|
|
+ if (logger.isTraceEnabled()) {
|
|
|
+ logger.trace("plugin loaded from settings [{}]", pluginInfo);
|
|
|
+ }
|
|
|
+ tupleBuilder.add(new Tuple<PluginInfo, Plugin>(pluginInfo, plugin));
|
|
|
}
|
|
|
|
|
|
// now, find all the ones that are in the classpath
|
|
|
loadPluginsIntoClassLoader();
|
|
|
- plugins.putAll(loadPluginsFromClasspath(settings));
|
|
|
- Set<String> sitePlugins = PluginsHelper.sitePlugins(this.environment);
|
|
|
+ tupleBuilder.addAll(loadPluginsFromClasspath(settings));
|
|
|
+ this.plugins = tupleBuilder.build();
|
|
|
+
|
|
|
+ // We need to build a List of jvm and site plugins for checking mandatory plugins
|
|
|
+ Map<String, Plugin> jvmPlugins = Maps.newHashMap();
|
|
|
+ List<String> sitePlugins = Lists.newArrayList();
|
|
|
|
|
|
+ for (Tuple<PluginInfo, Plugin> tuple : this.plugins) {
|
|
|
+ jvmPlugins.put(tuple.v2().name(), tuple.v2());
|
|
|
+ if (tuple.v1().isSite()) {
|
|
|
+ sitePlugins.add(tuple.v1().getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // we load site plugins
|
|
|
+ ImmutableList<Tuple<PluginInfo, Plugin>> tuples = loadSitePlugins();
|
|
|
+ for (Tuple<PluginInfo, Plugin> tuple : tuples) {
|
|
|
+ sitePlugins.add(tuple.v1().getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ // Checking expected plugins
|
|
|
String[] mandatoryPlugins = settings.getAsArray("plugin.mandatory", null);
|
|
|
if (mandatoryPlugins != null) {
|
|
|
Set<String> missingPlugins = Sets.newHashSet();
|
|
|
for (String mandatoryPlugin : mandatoryPlugins) {
|
|
|
- if (!plugins.containsKey(mandatoryPlugin) && !sitePlugins.contains(mandatoryPlugin) && !missingPlugins.contains(mandatoryPlugin)) {
|
|
|
+ if (!jvmPlugins.containsKey(mandatoryPlugin) && !sitePlugins.contains(mandatoryPlugin) && !missingPlugins.contains(mandatoryPlugin)) {
|
|
|
missingPlugins.add(mandatoryPlugin);
|
|
|
}
|
|
|
}
|
|
|
@@ -106,12 +131,10 @@ public class PluginsService extends AbstractComponent {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- logger.info("loaded {}, sites {}", plugins.keySet(), sitePlugins);
|
|
|
-
|
|
|
- this.plugins = ImmutableMap.copyOf(plugins);
|
|
|
+ logger.info("loaded {}, sites {}", jvmPlugins.keySet(), sitePlugins);
|
|
|
|
|
|
MapBuilder<Plugin, List<OnModuleReference>> onModuleReferences = MapBuilder.newMapBuilder();
|
|
|
- for (Plugin plugin : plugins.values()) {
|
|
|
+ for (Plugin plugin : jvmPlugins.values()) {
|
|
|
List<OnModuleReference> list = Lists.newArrayList();
|
|
|
for (Method method : plugin.getClass().getDeclaredMethods()) {
|
|
|
if (!method.getName().equals("onModule")) {
|
|
|
@@ -139,7 +162,7 @@ public class PluginsService extends AbstractComponent {
|
|
|
|
|
|
}
|
|
|
|
|
|
- public ImmutableMap<String, Plugin> plugins() {
|
|
|
+ public ImmutableList<Tuple<PluginInfo, Plugin>> plugins() {
|
|
|
return plugins;
|
|
|
}
|
|
|
|
|
|
@@ -150,17 +173,17 @@ public class PluginsService extends AbstractComponent {
|
|
|
}
|
|
|
|
|
|
public void processModule(Module module) {
|
|
|
- for (Plugin plugin : plugins().values()) {
|
|
|
- plugin.processModule(module);
|
|
|
+ for (Tuple<PluginInfo, Plugin> plugin : plugins()) {
|
|
|
+ plugin.v2().processModule(module);
|
|
|
// see if there are onModule references
|
|
|
- List<OnModuleReference> references = onModuleReferences.get(plugin);
|
|
|
+ List<OnModuleReference> references = onModuleReferences.get(plugin.v2());
|
|
|
if (references != null) {
|
|
|
for (OnModuleReference reference : references) {
|
|
|
if (reference.moduleClass.isAssignableFrom(module.getClass())) {
|
|
|
try {
|
|
|
- reference.onModuleMethod.invoke(plugin, module);
|
|
|
+ reference.onModuleMethod.invoke(plugin.v2(), module);
|
|
|
} catch (Exception e) {
|
|
|
- logger.warn("plugin {}, failed to invoke custom onModule method", e, plugin.name());
|
|
|
+ logger.warn("plugin {}, failed to invoke custom onModule method", e, plugin.v2().name());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -171,80 +194,80 @@ public class PluginsService extends AbstractComponent {
|
|
|
public Settings updatedSettings() {
|
|
|
ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder()
|
|
|
.put(this.settings);
|
|
|
- for (Plugin plugin : plugins.values()) {
|
|
|
- builder.put(plugin.additionalSettings());
|
|
|
+ for (Tuple<PluginInfo, Plugin> plugin : plugins) {
|
|
|
+ builder.put(plugin.v2().additionalSettings());
|
|
|
}
|
|
|
return builder.build();
|
|
|
}
|
|
|
|
|
|
public Collection<Class<? extends Module>> modules() {
|
|
|
List<Class<? extends Module>> modules = Lists.newArrayList();
|
|
|
- for (Plugin plugin : plugins.values()) {
|
|
|
- modules.addAll(plugin.modules());
|
|
|
+ for (Tuple<PluginInfo, Plugin> plugin : plugins) {
|
|
|
+ modules.addAll(plugin.v2().modules());
|
|
|
}
|
|
|
return modules;
|
|
|
}
|
|
|
|
|
|
public Collection<Module> modules(Settings settings) {
|
|
|
List<Module> modules = Lists.newArrayList();
|
|
|
- for (Plugin plugin : plugins.values()) {
|
|
|
- modules.addAll(plugin.modules(settings));
|
|
|
+ for (Tuple<PluginInfo, Plugin> plugin : plugins) {
|
|
|
+ modules.addAll(plugin.v2().modules(settings));
|
|
|
}
|
|
|
return modules;
|
|
|
}
|
|
|
|
|
|
public Collection<Class<? extends LifecycleComponent>> services() {
|
|
|
List<Class<? extends LifecycleComponent>> services = Lists.newArrayList();
|
|
|
- for (Plugin plugin : plugins.values()) {
|
|
|
- services.addAll(plugin.services());
|
|
|
+ for (Tuple<PluginInfo, Plugin> plugin : plugins) {
|
|
|
+ services.addAll(plugin.v2().services());
|
|
|
}
|
|
|
return services;
|
|
|
}
|
|
|
|
|
|
public Collection<Class<? extends Module>> indexModules() {
|
|
|
List<Class<? extends Module>> modules = Lists.newArrayList();
|
|
|
- for (Plugin plugin : plugins.values()) {
|
|
|
- modules.addAll(plugin.indexModules());
|
|
|
+ for (Tuple<PluginInfo, Plugin> plugin : plugins) {
|
|
|
+ modules.addAll(plugin.v2().indexModules());
|
|
|
}
|
|
|
return modules;
|
|
|
}
|
|
|
|
|
|
public Collection<Module> indexModules(Settings settings) {
|
|
|
List<Module> modules = Lists.newArrayList();
|
|
|
- for (Plugin plugin : plugins.values()) {
|
|
|
- modules.addAll(plugin.indexModules(settings));
|
|
|
+ for (Tuple<PluginInfo, Plugin> plugin : plugins) {
|
|
|
+ modules.addAll(plugin.v2().indexModules(settings));
|
|
|
}
|
|
|
return modules;
|
|
|
}
|
|
|
|
|
|
public Collection<Class<? extends CloseableIndexComponent>> indexServices() {
|
|
|
List<Class<? extends CloseableIndexComponent>> services = Lists.newArrayList();
|
|
|
- for (Plugin plugin : plugins.values()) {
|
|
|
- services.addAll(plugin.indexServices());
|
|
|
+ for (Tuple<PluginInfo, Plugin> plugin : plugins) {
|
|
|
+ services.addAll(plugin.v2().indexServices());
|
|
|
}
|
|
|
return services;
|
|
|
}
|
|
|
|
|
|
public Collection<Class<? extends Module>> shardModules() {
|
|
|
List<Class<? extends Module>> modules = Lists.newArrayList();
|
|
|
- for (Plugin plugin : plugins.values()) {
|
|
|
- modules.addAll(plugin.shardModules());
|
|
|
+ for (Tuple<PluginInfo, Plugin> plugin : plugins) {
|
|
|
+ modules.addAll(plugin.v2().shardModules());
|
|
|
}
|
|
|
return modules;
|
|
|
}
|
|
|
|
|
|
public Collection<Module> shardModules(Settings settings) {
|
|
|
List<Module> modules = Lists.newArrayList();
|
|
|
- for (Plugin plugin : plugins.values()) {
|
|
|
- modules.addAll(plugin.shardModules(settings));
|
|
|
+ for (Tuple<PluginInfo, Plugin> plugin : plugins) {
|
|
|
+ modules.addAll(plugin.v2().shardModules(settings));
|
|
|
}
|
|
|
return modules;
|
|
|
}
|
|
|
|
|
|
public Collection<Class<? extends CloseableIndexComponent>> shardServices() {
|
|
|
List<Class<? extends CloseableIndexComponent>> services = Lists.newArrayList();
|
|
|
- for (Plugin plugin : plugins.values()) {
|
|
|
- services.addAll(plugin.shardServices());
|
|
|
+ for (Tuple<PluginInfo, Plugin> plugin : plugins) {
|
|
|
+ services.addAll(plugin.v2().shardServices());
|
|
|
}
|
|
|
return services;
|
|
|
}
|
|
|
@@ -260,79 +283,35 @@ public class PluginsService extends AbstractComponent {
|
|
|
if (refreshInterval.millis() != 0) {
|
|
|
if (cachedPluginsInfo != null &&
|
|
|
(refreshInterval.millis() < 0 || (System.currentTimeMillis() - lastRefresh) < refreshInterval.millis())) {
|
|
|
- if (logger.isTraceEnabled()) logger.trace("using cache to retrieve plugins info");
|
|
|
+ if (logger.isTraceEnabled()) {
|
|
|
+ logger.trace("using cache to retrieve plugins info");
|
|
|
+ }
|
|
|
return cachedPluginsInfo;
|
|
|
}
|
|
|
lastRefresh = System.currentTimeMillis();
|
|
|
}
|
|
|
|
|
|
- if (logger.isTraceEnabled()) logger.trace("starting to fetch info on plugins");
|
|
|
- cachedPluginsInfo = new PluginsInfo();
|
|
|
-
|
|
|
- // We create a map to have only unique values
|
|
|
- Set<String> plugins = new HashSet<String>();
|
|
|
-
|
|
|
- for (Plugin plugin : plugins().values()) {
|
|
|
- // We should detect if the plugin has also an embedded _site structure
|
|
|
- File siteFile = new File(new File(environment.pluginsFile(), plugin.name()), "_site");
|
|
|
- boolean isSite = siteFile.exists() && siteFile.isDirectory();
|
|
|
- if (logger.isTraceEnabled()) logger.trace("found a jvm plugin [{}], [{}]{}",
|
|
|
- plugin.name(), plugin.description(), isSite ? ": with _site structure" : "");
|
|
|
- cachedPluginsInfo.add(new PluginInfo(plugin.name(), plugin.description(), isSite, true));
|
|
|
- plugins.add(plugin.name());
|
|
|
+ if (logger.isTraceEnabled()) {
|
|
|
+ logger.trace("starting to fetch info on plugins");
|
|
|
}
|
|
|
+ cachedPluginsInfo = new PluginsInfo();
|
|
|
|
|
|
- File pluginsFile = environment.pluginsFile();
|
|
|
- if (!pluginsFile.exists()) {
|
|
|
- return cachedPluginsInfo;
|
|
|
- }
|
|
|
- if (!pluginsFile.isDirectory()) {
|
|
|
- return cachedPluginsInfo;
|
|
|
+ // We first add all JvmPlugins
|
|
|
+ for (Tuple<PluginInfo, Plugin> plugin : this.plugins) {
|
|
|
+ if (logger.isTraceEnabled()) {
|
|
|
+ logger.trace("adding jvm plugin [{}]", plugin.v1());
|
|
|
+ }
|
|
|
+ cachedPluginsInfo.add(plugin.v1());
|
|
|
}
|
|
|
|
|
|
- File[] pluginsFiles = pluginsFile.listFiles();
|
|
|
- if (pluginsFiles != null) {
|
|
|
- for (File plugin : pluginsFiles) {
|
|
|
- // We skip already known jvm plugins
|
|
|
- if (!plugins.contains(plugin.getName())) {
|
|
|
- File sitePluginDir = new File(plugin, "_site");
|
|
|
- if (sitePluginDir.exists()) {
|
|
|
- String name = plugin.getName();
|
|
|
- String description = "No description found for " + name + ".";
|
|
|
-
|
|
|
- // We check if es-plugin.properties exists in plugin/_site dir
|
|
|
- File pluginPropFile = new File(sitePluginDir, ES_PLUGIN_PROPERTIES);
|
|
|
- if (pluginPropFile.exists()) {
|
|
|
-
|
|
|
- Properties pluginProps = new Properties();
|
|
|
- InputStream is = null;
|
|
|
- try {
|
|
|
- is = new FileInputStream(pluginPropFile.getAbsolutePath());
|
|
|
- pluginProps.load(is);
|
|
|
- description = pluginProps.getProperty("description");
|
|
|
- } catch (Exception e) {
|
|
|
- logger.warn("failed to load plugin description from [" +
|
|
|
- pluginPropFile.getAbsolutePath() + "]", e);
|
|
|
- } finally {
|
|
|
- if (is != null) {
|
|
|
- try {
|
|
|
- is.close();
|
|
|
- } catch (IOException e) {
|
|
|
- // ignore
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (logger.isTraceEnabled()) logger.trace("found a site plugin [{}], [{}]",
|
|
|
- name, description);
|
|
|
- cachedPluginsInfo.add(new PluginInfo(name, description, true, false));
|
|
|
- }
|
|
|
- }
|
|
|
+ // We reload site plugins (in case of some changes)
|
|
|
+ for (Tuple<PluginInfo, Plugin> plugin : loadSitePlugins()) {
|
|
|
+ if (logger.isTraceEnabled()) {
|
|
|
+ logger.trace("adding site plugin [{}]", plugin.v1());
|
|
|
}
|
|
|
+ cachedPluginsInfo.add(plugin.v1());
|
|
|
}
|
|
|
|
|
|
-
|
|
|
return cachedPluginsInfo;
|
|
|
}
|
|
|
|
|
|
@@ -367,7 +346,9 @@ public class PluginsService extends AbstractComponent {
|
|
|
if (pluginsFile != null) {
|
|
|
for (File pluginFile : pluginsFiles) {
|
|
|
if (pluginFile.isDirectory()) {
|
|
|
- logger.trace("--- adding plugin [" + pluginFile.getAbsolutePath() + "]");
|
|
|
+ if (logger.isTraceEnabled()) {
|
|
|
+ logger.trace("--- adding plugin [" + pluginFile.getAbsolutePath() + "]");
|
|
|
+ }
|
|
|
try {
|
|
|
// add the root
|
|
|
addURL.invoke(classLoader, pluginFile.toURI().toURL());
|
|
|
@@ -388,7 +369,7 @@ public class PluginsService extends AbstractComponent {
|
|
|
}
|
|
|
addURL.invoke(classLoader, libFile.toURI().toURL());
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
+ } catch (Throwable e) {
|
|
|
logger.warn("failed to add plugin [" + pluginFile + "]", e);
|
|
|
}
|
|
|
}
|
|
|
@@ -398,48 +379,130 @@ public class PluginsService extends AbstractComponent {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private Map<String, Plugin> loadPluginsFromClasspath(Settings settings) {
|
|
|
- Map<String, Plugin> plugins = newHashMap();
|
|
|
- Enumeration<URL> pluginUrls = null;
|
|
|
+ private ImmutableList<Tuple<PluginInfo,Plugin>> loadPluginsFromClasspath(Settings settings) {
|
|
|
+ ImmutableList.Builder<Tuple<PluginInfo, Plugin>> plugins = ImmutableList.builder();
|
|
|
+
|
|
|
+ // Trying JVM plugins: looking for es-plugin.properties files
|
|
|
try {
|
|
|
- pluginUrls = settings.getClassLoader().getResources(ES_PLUGIN_PROPERTIES);
|
|
|
+ Enumeration<URL> pluginUrls = settings.getClassLoader().getResources(ES_PLUGIN_PROPERTIES);
|
|
|
+ while (pluginUrls.hasMoreElements()) {
|
|
|
+ URL pluginUrl = pluginUrls.nextElement();
|
|
|
+ Properties pluginProps = new Properties();
|
|
|
+ InputStream is = null;
|
|
|
+ try {
|
|
|
+ is = pluginUrl.openStream();
|
|
|
+ pluginProps.load(is);
|
|
|
+ String pluginClassName = pluginProps.getProperty("plugin");
|
|
|
+ String pluginVersion = pluginProps.getProperty("version", PluginInfo.VERSION_NOT_AVAILABLE);
|
|
|
+ Plugin plugin = loadPlugin(pluginClassName, settings);
|
|
|
+
|
|
|
+ // Is it a site plugin as well? Does it have also an embedded _site structure
|
|
|
+ File siteFile = new File(new File(environment.pluginsFile(), plugin.name()), "_site");
|
|
|
+ boolean isSite = siteFile.exists() && siteFile.isDirectory();
|
|
|
+ if (logger.isTraceEnabled()) {
|
|
|
+ logger.trace("found a jvm plugin [{}], [{}]{}",
|
|
|
+ plugin.name(), plugin.description(), isSite ? ": with _site structure" : "");
|
|
|
+ }
|
|
|
+
|
|
|
+ PluginInfo pluginInfo = new PluginInfo(plugin.name(), plugin.description(), isSite, true, pluginVersion);
|
|
|
+
|
|
|
+ plugins.add(new Tuple<PluginInfo, Plugin>(pluginInfo, plugin));
|
|
|
+ } catch (Throwable e) {
|
|
|
+ logger.warn("failed to load plugin from [" + pluginUrl + "]", e);
|
|
|
+ } finally {
|
|
|
+ IOUtils.closeWhileHandlingException(is);
|
|
|
+ }
|
|
|
+ }
|
|
|
} catch (IOException e) {
|
|
|
- logger.warn("failed to find plugins from classpath", e);
|
|
|
- return ImmutableMap.of();
|
|
|
+ logger.warn("failed to find jvm plugins from classpath", e);
|
|
|
}
|
|
|
- while (pluginUrls.hasMoreElements()) {
|
|
|
- URL pluginUrl = pluginUrls.nextElement();
|
|
|
- Properties pluginProps = new Properties();
|
|
|
- InputStream is = null;
|
|
|
- try {
|
|
|
- is = pluginUrl.openStream();
|
|
|
- pluginProps.load(is);
|
|
|
- String pluginClassName = pluginProps.getProperty("plugin");
|
|
|
- Plugin plugin = loadPlugin(pluginClassName, settings);
|
|
|
- plugins.put(plugin.name(), plugin);
|
|
|
- } catch (Exception e) {
|
|
|
- logger.warn("failed to load plugin from [" + pluginUrl + "]", e);
|
|
|
- } finally {
|
|
|
- if (is != null) {
|
|
|
- try {
|
|
|
- is.close();
|
|
|
- } catch (IOException e) {
|
|
|
- // ignore
|
|
|
+
|
|
|
+ return plugins.build();
|
|
|
+ }
|
|
|
+
|
|
|
+ private ImmutableList<Tuple<PluginInfo,Plugin>> loadSitePlugins() {
|
|
|
+ ImmutableList.Builder<Tuple<PluginInfo, Plugin>> sitePlugins = ImmutableList.builder();
|
|
|
+ List<String> loadedJvmPlugins = new ArrayList<String>();
|
|
|
+
|
|
|
+ // Already known jvm plugins are ignored
|
|
|
+ for(Tuple<PluginInfo, Plugin> tuple : plugins) {
|
|
|
+ if (tuple.v1().isSite()) {
|
|
|
+ loadedJvmPlugins.add(tuple.v1().getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Let's try to find all _site plugins we did not already found
|
|
|
+ File pluginsFile = environment.pluginsFile();
|
|
|
+
|
|
|
+ if (!pluginsFile.exists() || !pluginsFile.isDirectory()) {
|
|
|
+ return sitePlugins.build();
|
|
|
+ }
|
|
|
+
|
|
|
+ for (File pluginFile : pluginsFile.listFiles()) {
|
|
|
+ if (!loadedJvmPlugins.contains(pluginFile.getName())) {
|
|
|
+ File sitePluginDir = new File(pluginFile, "_site");
|
|
|
+ if (sitePluginDir.exists()) {
|
|
|
+ // We have a _site plugin. Let's try to get more information on it
|
|
|
+ String name = pluginFile.getName();
|
|
|
+ String version = PluginInfo.VERSION_NOT_AVAILABLE;
|
|
|
+ String description = PluginInfo.DESCRIPTION_NOT_AVAILABLE;
|
|
|
+
|
|
|
+ // We check if es-plugin.properties exists in plugin/_site dir
|
|
|
+ File pluginPropFile = new File(sitePluginDir, ES_PLUGIN_PROPERTIES);
|
|
|
+ if (pluginPropFile.exists()) {
|
|
|
+
|
|
|
+ Properties pluginProps = new Properties();
|
|
|
+ InputStream is = null;
|
|
|
+ try {
|
|
|
+ is = new FileInputStream(pluginPropFile.getAbsolutePath());
|
|
|
+ pluginProps.load(is);
|
|
|
+ description = pluginProps.getProperty("description", PluginInfo.DESCRIPTION_NOT_AVAILABLE);
|
|
|
+ version = pluginProps.getProperty("version", PluginInfo.VERSION_NOT_AVAILABLE);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // Can not load properties for this site plugin. Ignoring.
|
|
|
+ logger.debug("can not load {} file.", e, ES_PLUGIN_PROPERTIES);
|
|
|
+ } finally {
|
|
|
+ IOUtils.closeWhileHandlingException(is);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (logger.isTraceEnabled()) {
|
|
|
+ logger.trace("found a site plugin name [{}], version [{}], description [{}]",
|
|
|
+ name, version, description);
|
|
|
}
|
|
|
+ sitePlugins.add(new Tuple<PluginInfo, Plugin>(new PluginInfo(name, description, true, false, version), null));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return plugins;
|
|
|
+
|
|
|
+ return sitePlugins.build();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param name plugin name
|
|
|
+ * @return if this jvm plugin has also a _site structure
|
|
|
+ */
|
|
|
+ private boolean hasSite(String name) {
|
|
|
+ // Let's try to find all _site plugins we did not already found
|
|
|
+ File pluginsFile = environment.pluginsFile();
|
|
|
+
|
|
|
+ if (!pluginsFile.exists() || !pluginsFile.isDirectory()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ File sitePluginDir = new File(pluginsFile, name + "/_site");
|
|
|
+ return sitePluginDir.exists();
|
|
|
}
|
|
|
|
|
|
private Plugin loadPlugin(String className, Settings settings) {
|
|
|
try {
|
|
|
Class<? extends Plugin> pluginClass = (Class<? extends Plugin>) settings.getClassLoader().loadClass(className);
|
|
|
+ Plugin plugin;
|
|
|
try {
|
|
|
- return pluginClass.getConstructor(Settings.class).newInstance(settings);
|
|
|
+ plugin = pluginClass.getConstructor(Settings.class).newInstance(settings);
|
|
|
} catch (NoSuchMethodException e) {
|
|
|
try {
|
|
|
- return pluginClass.getConstructor().newInstance();
|
|
|
+ plugin = pluginClass.getConstructor().newInstance();
|
|
|
} catch (NoSuchMethodException e1) {
|
|
|
throw new ElasticsearchException("No constructor for [" + pluginClass + "]. A plugin class must " +
|
|
|
"have either an empty default constructor or a single argument constructor accepting a " +
|
|
|
@@ -447,9 +510,10 @@ public class PluginsService extends AbstractComponent {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- } catch (Exception e) {
|
|
|
+ return plugin;
|
|
|
+
|
|
|
+ } catch (Throwable e) {
|
|
|
throw new ElasticsearchException("Failed to load plugin class [" + className + "]", e);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|