list modules separately in pluginservice
This commit is contained in:
parent
afedd24877
commit
7160c5ec15
|
@ -217,7 +217,8 @@ public class NodeInfo extends BaseNodeResponse {
|
|||
http = HttpInfo.readHttpInfo(in);
|
||||
}
|
||||
if (in.readBoolean()) {
|
||||
plugins = PluginsInfo.readPluginsInfo(in);
|
||||
plugins = new PluginsInfo();
|
||||
plugins.readFrom(in);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,77 +24,91 @@ import org.elasticsearch.common.io.stream.StreamOutput;
|
|||
import org.elasticsearch.common.io.stream.Streamable;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
||||
import org.elasticsearch.plugins.PluginInfo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Information about plugins and modules
|
||||
*/
|
||||
public class PluginsInfo implements Streamable, ToXContent {
|
||||
static final class Fields {
|
||||
static final XContentBuilderString PLUGINS = new XContentBuilderString("plugins");
|
||||
}
|
||||
|
||||
private List<PluginInfo> infos;
|
||||
private List<PluginInfo> plugins;
|
||||
private List<PluginInfo> modules;
|
||||
|
||||
public PluginsInfo() {
|
||||
infos = new ArrayList<>();
|
||||
}
|
||||
|
||||
public PluginsInfo(int size) {
|
||||
infos = new ArrayList<>(size);
|
||||
plugins = new ArrayList<>();
|
||||
modules = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an ordered list based on plugins name
|
||||
* Returns an ordered list based on plugins name
|
||||
*/
|
||||
public List<PluginInfo> getInfos() {
|
||||
Collections.sort(infos, new Comparator<PluginInfo>() {
|
||||
@Override
|
||||
public int compare(final PluginInfo o1, final PluginInfo o2) {
|
||||
return o1.getName().compareTo(o2.getName());
|
||||
}
|
||||
});
|
||||
|
||||
return infos;
|
||||
public List<PluginInfo> getPluginInfos() {
|
||||
List<PluginInfo> plugins = new ArrayList<>(this.plugins);
|
||||
Collections.sort(plugins, (p1, p2) -> p1.getName().compareTo(p2.getName()));
|
||||
return plugins;
|
||||
}
|
||||
|
||||
public void add(PluginInfo info) {
|
||||
infos.add(info);
|
||||
/**
|
||||
* Returns an ordered list based on modules name
|
||||
*/
|
||||
public List<PluginInfo> getModuleInfos() {
|
||||
List<PluginInfo> modules = new ArrayList<>(this.modules);
|
||||
Collections.sort(modules, (p1, p2) -> p1.getName().compareTo(p2.getName()));
|
||||
return modules;
|
||||
}
|
||||
|
||||
public static PluginsInfo readPluginsInfo(StreamInput in) throws IOException {
|
||||
PluginsInfo infos = new PluginsInfo();
|
||||
infos.readFrom(in);
|
||||
return infos;
|
||||
public void addPlugin(PluginInfo info) {
|
||||
plugins.add(info);
|
||||
}
|
||||
|
||||
public void addModule(PluginInfo info) {
|
||||
modules.add(info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
if (plugins.isEmpty() == false || modules.isEmpty() == false) {
|
||||
throw new IllegalStateException("instance is already populated");
|
||||
}
|
||||
int plugins_size = in.readInt();
|
||||
for (int i = 0; i < plugins_size; i++) {
|
||||
infos.add(PluginInfo.readFromStream(in));
|
||||
plugins.add(PluginInfo.readFromStream(in));
|
||||
}
|
||||
int modules_size = in.readInt();
|
||||
for (int i = 0; i < modules_size; i++) {
|
||||
modules.add(PluginInfo.readFromStream(in));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeInt(infos.size());
|
||||
for (PluginInfo plugin : getInfos()) {
|
||||
out.writeInt(plugins.size());
|
||||
for (PluginInfo plugin : getPluginInfos()) {
|
||||
plugin.writeTo(out);
|
||||
}
|
||||
out.writeInt(modules.size());
|
||||
for (PluginInfo module : getModuleInfos()) {
|
||||
module.writeTo(out);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startArray(Fields.PLUGINS);
|
||||
for (PluginInfo pluginInfo : getInfos()) {
|
||||
builder.startArray("plugins");
|
||||
for (PluginInfo pluginInfo : getPluginInfos()) {
|
||||
pluginInfo.toXContent(builder, params);
|
||||
}
|
||||
builder.endArray();
|
||||
// TODO: not ideal, make a better api for this (e.g. with jar metadata, and so on)
|
||||
builder.startArray("modules");
|
||||
for (PluginInfo moduleInfo : getModuleInfos()) {
|
||||
moduleInfo.toXContent(builder, params);
|
||||
}
|
||||
builder.endArray();
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ public class ClusterStatsNodes implements ToXContent, Streamable {
|
|||
versions.add(nodeResponse.nodeInfo().getVersion());
|
||||
process.addNodeStats(nodeResponse.nodeStats());
|
||||
jvm.addNodeInfoStats(nodeResponse.nodeInfo(), nodeResponse.nodeStats());
|
||||
plugins.addAll(nodeResponse.nodeInfo().getPlugins().getInfos());
|
||||
plugins.addAll(nodeResponse.nodeInfo().getPlugins().getPluginInfos());
|
||||
|
||||
// now do the stats that should be deduped by hardware (implemented by ip deduping)
|
||||
TransportAddress publishAddress = nodeResponse.nodeInfo().getTransport().address().publishAddress();
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.apache.lucene.analysis.util.TokenizerFactory;
|
|||
import org.apache.lucene.codecs.Codec;
|
||||
import org.apache.lucene.codecs.DocValuesFormat;
|
||||
import org.apache.lucene.codecs.PostingsFormat;
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.action.admin.cluster.node.info.PluginsInfo;
|
||||
import org.elasticsearch.bootstrap.JarHell;
|
||||
|
@ -39,10 +38,7 @@ import org.elasticsearch.common.logging.ESLogger;
|
|||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.IndexModule;
|
||||
import org.elasticsearch.index.IndexService;
|
||||
import org.elasticsearch.index.shard.IndexEventListener;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
@ -69,7 +65,7 @@ import static org.elasticsearch.common.io.FileSystemUtils.isAccessibleDirectory;
|
|||
public class PluginsService extends AbstractComponent {
|
||||
|
||||
/**
|
||||
* We keep around a list of plugins
|
||||
* We keep around a list of plugins and modules
|
||||
*/
|
||||
private final List<Tuple<PluginInfo, Plugin>> plugins;
|
||||
private final PluginsInfo info;
|
||||
|
@ -95,8 +91,9 @@ public class PluginsService extends AbstractComponent {
|
|||
*/
|
||||
public PluginsService(Settings settings, Path modulesDirectory, Path pluginsDirectory, Collection<Class<? extends Plugin>> classpathPlugins) {
|
||||
super(settings);
|
||||
info = new PluginsInfo();
|
||||
|
||||
List<Tuple<PluginInfo, Plugin>> tupleBuilder = new ArrayList<>();
|
||||
List<Tuple<PluginInfo, Plugin>> pluginsLoaded = new ArrayList<>();
|
||||
|
||||
// first we load plugins that are on the classpath. this is for tests and transport clients
|
||||
for (Class<? extends Plugin> pluginClass : classpathPlugins) {
|
||||
|
@ -105,14 +102,19 @@ public class PluginsService extends AbstractComponent {
|
|||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("plugin loaded from classpath [{}]", pluginInfo);
|
||||
}
|
||||
tupleBuilder.add(new Tuple<>(pluginInfo, plugin));
|
||||
pluginsLoaded.add(new Tuple<>(pluginInfo, plugin));
|
||||
info.addPlugin(pluginInfo);
|
||||
}
|
||||
|
||||
// load modules
|
||||
if (modulesDirectory != null) {
|
||||
try {
|
||||
List<Bundle> bundles = getModuleBundles(modulesDirectory);
|
||||
tupleBuilder.addAll(loadBundles(bundles));
|
||||
List<Tuple<PluginInfo, Plugin>> loaded = loadBundles(bundles);
|
||||
pluginsLoaded.addAll(loaded);
|
||||
for (Tuple<PluginInfo, Plugin> module : loaded) {
|
||||
info.addModule(module.v1());
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw new IllegalStateException("Unable to initialize modules", ex);
|
||||
}
|
||||
|
@ -122,17 +124,17 @@ public class PluginsService extends AbstractComponent {
|
|||
if (pluginsDirectory != null) {
|
||||
try {
|
||||
List<Bundle> bundles = getPluginBundles(pluginsDirectory);
|
||||
tupleBuilder.addAll(loadBundles(bundles));
|
||||
List<Tuple<PluginInfo, Plugin>> loaded = loadBundles(bundles);
|
||||
pluginsLoaded.addAll(loaded);
|
||||
for (Tuple<PluginInfo, Plugin> plugin : loaded) {
|
||||
info.addPlugin(plugin.v1());
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw new IllegalStateException("Unable to initialize plugins", ex);
|
||||
}
|
||||
}
|
||||
|
||||
plugins = Collections.unmodifiableList(tupleBuilder);
|
||||
info = new PluginsInfo();
|
||||
for (Tuple<PluginInfo, Plugin> tuple : plugins) {
|
||||
info.add(tuple.v1());
|
||||
}
|
||||
plugins = Collections.unmodifiableList(pluginsLoaded);
|
||||
|
||||
// We need to build a List of jvm and site plugins for checking mandatory plugins
|
||||
Map<String, Plugin> jvmPlugins = new HashMap<>();
|
||||
|
|
|
@ -95,7 +95,7 @@ public class RestPluginsAction extends AbstractCatAction {
|
|||
for (DiscoveryNode node : nodes) {
|
||||
NodeInfo info = nodesInfo.getNodesMap().get(node.id());
|
||||
|
||||
for (PluginInfo pluginInfo : info.getPlugins().getInfos()) {
|
||||
for (PluginInfo pluginInfo : info.getPlugins().getPluginInfos()) {
|
||||
table.startRow();
|
||||
table.addCell(node.id());
|
||||
table.addCell(node.name());
|
||||
|
|
|
@ -259,14 +259,14 @@ public class PluginInfoTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testPluginListSorted() {
|
||||
PluginsInfo pluginsInfo = new PluginsInfo(5);
|
||||
pluginsInfo.add(new PluginInfo("c", "foo", true, "dummy", true, "dummyclass", true));
|
||||
pluginsInfo.add(new PluginInfo("b", "foo", true, "dummy", true, "dummyclass", true));
|
||||
pluginsInfo.add(new PluginInfo("e", "foo", true, "dummy", true, "dummyclass", true));
|
||||
pluginsInfo.add(new PluginInfo("a", "foo", true, "dummy", true, "dummyclass", true));
|
||||
pluginsInfo.add(new PluginInfo("d", "foo", true, "dummy", true, "dummyclass", true));
|
||||
PluginsInfo pluginsInfo = new PluginsInfo();
|
||||
pluginsInfo.addPlugin(new PluginInfo("c", "foo", true, "dummy", true, "dummyclass", true));
|
||||
pluginsInfo.addPlugin(new PluginInfo("b", "foo", true, "dummy", true, "dummyclass", true));
|
||||
pluginsInfo.addPlugin(new PluginInfo("e", "foo", true, "dummy", true, "dummyclass", true));
|
||||
pluginsInfo.addPlugin(new PluginInfo("a", "foo", true, "dummy", true, "dummyclass", true));
|
||||
pluginsInfo.addPlugin(new PluginInfo("d", "foo", true, "dummy", true, "dummyclass", true));
|
||||
|
||||
final List<PluginInfo> infos = pluginsInfo.getInfos();
|
||||
final List<PluginInfo> infos = pluginsInfo.getPluginInfos();
|
||||
List<String> names = infos.stream().map((input) -> input.getName()).collect(Collectors.toList());
|
||||
assertThat(names, contains("a", "b", "c", "d", "e"));
|
||||
}
|
||||
|
|
|
@ -10,5 +10,5 @@
|
|||
- do:
|
||||
nodes.info: {}
|
||||
|
||||
- match: { nodes.$master.plugins.0.name: lang-expression }
|
||||
- match: { nodes.$master.plugins.0.jvm: true }
|
||||
- match: { nodes.$master.modules.0.name: lang-expression }
|
||||
- match: { nodes.$master.modules.0.jvm: true }
|
||||
|
|
|
@ -10,5 +10,5 @@
|
|||
- do:
|
||||
nodes.info: {}
|
||||
|
||||
- match: { nodes.$master.plugins.0.name: lang-groovy }
|
||||
- match: { nodes.$master.plugins.0.jvm: true }
|
||||
- match: { nodes.$master.modules.0.name: lang-groovy }
|
||||
- match: { nodes.$master.modules.0.jvm: true }
|
||||
|
|
|
@ -761,7 +761,7 @@ public class ElasticsearchAssertions {
|
|||
|
||||
boolean anyHaveUrls =
|
||||
plugins
|
||||
.getInfos()
|
||||
.getPluginInfos()
|
||||
.stream()
|
||||
.filter(jvmPluginPredicate.and(sitePluginPredicate.negate()))
|
||||
.map(urlFunction)
|
||||
|
@ -792,7 +792,7 @@ public class ElasticsearchAssertions {
|
|||
}
|
||||
|
||||
private static List<String> filterAndMap(PluginsInfo pluginsInfo, Predicate<PluginInfo> predicate, Function<PluginInfo, String> function) {
|
||||
return pluginsInfo.getInfos().stream().filter(predicate).map(function).collect(Collectors.toList());
|
||||
return pluginsInfo.getPluginInfos().stream().filter(predicate).map(function).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static Predicate<PluginInfo> jvmPluginPredicate = p -> p.isJvm();
|
||||
|
|
Loading…
Reference in New Issue