Skip to content

Commit 1c06386

Browse files
committed
Merge pull request #15303 from rmuir/strong_dose_of_xml
backport plugin bundling to 2.2
2 parents 7f27850 + 1ba7b4f commit 1c06386

File tree

150 files changed

+1428
-604
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+1428
-604
lines changed

core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ public class NodeInfo extends BaseNodeResponse {
7171
private HttpInfo http;
7272

7373
@Nullable
74-
private PluginsInfo plugins;
74+
private PluginsAndModules plugins;
7575

7676
NodeInfo() {
7777
}
7878

7979
public NodeInfo(Version version, Build build, DiscoveryNode node, @Nullable ImmutableMap<String, String> serviceAttributes, @Nullable Settings settings,
8080
@Nullable OsInfo os, @Nullable ProcessInfo process, @Nullable JvmInfo jvm, @Nullable ThreadPoolInfo threadPool,
81-
@Nullable TransportInfo transport, @Nullable HttpInfo http, @Nullable PluginsInfo plugins) {
81+
@Nullable TransportInfo transport, @Nullable HttpInfo http, @Nullable PluginsAndModules plugins) {
8282
super(node);
8383
this.version = version;
8484
this.build = build;
@@ -171,7 +171,7 @@ public HttpInfo getHttp() {
171171
}
172172

173173
@Nullable
174-
public PluginsInfo getPlugins() {
174+
public PluginsAndModules getPlugins() {
175175
return this.plugins;
176176
}
177177

@@ -216,7 +216,8 @@ public void readFrom(StreamInput in) throws IOException {
216216
http = HttpInfo.readHttpInfo(in);
217217
}
218218
if (in.readBoolean()) {
219-
plugins = PluginsInfo.readPluginsInfo(in);
219+
plugins = new PluginsAndModules();
220+
plugins.readFrom(in);
220221
}
221222
}
222223

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.action.admin.cluster.node.info;
21+
22+
import org.elasticsearch.common.io.stream.StreamInput;
23+
import org.elasticsearch.common.io.stream.StreamOutput;
24+
import org.elasticsearch.common.io.stream.Streamable;
25+
import org.elasticsearch.common.xcontent.ToXContent;
26+
import org.elasticsearch.common.xcontent.XContentBuilder;
27+
import org.elasticsearch.plugins.PluginInfo;
28+
29+
import java.io.IOException;
30+
import java.util.ArrayList;
31+
import java.util.Collections;
32+
import java.util.Comparator;
33+
import java.util.List;
34+
35+
/**
36+
* Information about plugins and modules
37+
*/
38+
public class PluginsAndModules implements Streamable, ToXContent {
39+
private List<PluginInfo> plugins;
40+
private List<PluginInfo> modules;
41+
42+
public PluginsAndModules() {
43+
plugins = new ArrayList<>();
44+
modules = new ArrayList<>();
45+
}
46+
47+
/**
48+
* Returns an ordered list based on plugins name
49+
*/
50+
public List<PluginInfo> getPluginInfos() {
51+
List<PluginInfo> plugins = new ArrayList<>(this.plugins);
52+
Collections.sort(plugins, new Comparator<PluginInfo>() {
53+
@Override
54+
public int compare(PluginInfo p1, PluginInfo p2) {
55+
return p1.getName().compareTo(p2.getName());
56+
}
57+
});
58+
return plugins;
59+
}
60+
61+
/**
62+
* Returns an ordered list based on modules name
63+
*/
64+
public List<PluginInfo> getModuleInfos() {
65+
List<PluginInfo> modules = new ArrayList<>(this.modules);
66+
Collections.sort(modules, new Comparator<PluginInfo>() {
67+
@Override
68+
public int compare(PluginInfo p1, PluginInfo p2) {
69+
return p1.getName().compareTo(p2.getName());
70+
}
71+
});
72+
return modules;
73+
}
74+
75+
public void addPlugin(PluginInfo info) {
76+
plugins.add(info);
77+
}
78+
79+
public void addModule(PluginInfo info) {
80+
modules.add(info);
81+
}
82+
83+
@Override
84+
public void readFrom(StreamInput in) throws IOException {
85+
if (plugins.isEmpty() == false || modules.isEmpty() == false) {
86+
throw new IllegalStateException("instance is already populated");
87+
}
88+
int plugins_size = in.readInt();
89+
for (int i = 0; i < plugins_size; i++) {
90+
plugins.add(PluginInfo.readFromStream(in));
91+
}
92+
int modules_size = in.readInt();
93+
for (int i = 0; i < modules_size; i++) {
94+
modules.add(PluginInfo.readFromStream(in));
95+
}
96+
}
97+
98+
@Override
99+
public void writeTo(StreamOutput out) throws IOException {
100+
out.writeInt(plugins.size());
101+
for (PluginInfo plugin : getPluginInfos()) {
102+
plugin.writeTo(out);
103+
}
104+
out.writeInt(modules.size());
105+
for (PluginInfo module : getModuleInfos()) {
106+
module.writeTo(out);
107+
}
108+
}
109+
110+
@Override
111+
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
112+
builder.startArray("plugins");
113+
for (PluginInfo pluginInfo : getPluginInfos()) {
114+
pluginInfo.toXContent(builder, params);
115+
}
116+
builder.endArray();
117+
// TODO: not ideal, make a better api for this (e.g. with jar metadata, and so on)
118+
builder.startArray("modules");
119+
for (PluginInfo moduleInfo : getModuleInfos()) {
120+
moduleInfo.toXContent(builder, params);
121+
}
122+
builder.endArray();
123+
124+
return builder;
125+
}
126+
}

core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/PluginsInfo.java

Lines changed: 0 additions & 101 deletions
This file was deleted.

core/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public ClusterStatsNodes(ClusterStatsNodeResponse[] nodeResponses) {
7474
versions.add(nodeResponse.nodeInfo().getVersion());
7575
process.addNodeStats(nodeResponse.nodeStats());
7676
jvm.addNodeInfoStats(nodeResponse.nodeInfo(), nodeResponse.nodeStats());
77-
plugins.addAll(nodeResponse.nodeInfo().getPlugins().getInfos());
77+
plugins.addAll(nodeResponse.nodeInfo().getPlugins().getPluginInfos());
7878

7979
// now do the stats that should be deduped by hardware (implemented by ip deduping)
8080
TransportAddress publishAddress = nodeResponse.nodeInfo().getTransport().address().publishAddress();

core/src/main/java/org/elasticsearch/bootstrap/Security.java

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -131,34 +131,48 @@ static void configure(Environment environment, boolean filterBadDefaults) throws
131131
@SuppressForbidden(reason = "proper use of URL")
132132
static Map<String,Policy> getPluginPermissions(Environment environment) throws IOException, NoSuchAlgorithmException {
133133
Map<String,Policy> map = new HashMap<>();
134+
// collect up lists of plugins and modules
135+
List<Path> pluginsAndModules = new ArrayList<>();
134136
if (Files.exists(environment.pluginsFile())) {
135137
try (DirectoryStream<Path> stream = Files.newDirectoryStream(environment.pluginsFile())) {
136138
for (Path plugin : stream) {
137-
Path policyFile = plugin.resolve(PluginInfo.ES_PLUGIN_POLICY);
138-
if (Files.exists(policyFile)) {
139-
// first get a list of URLs for the plugins' jars:
140-
// we resolve symlinks so map is keyed on the normalize codebase name
141-
List<URL> codebases = new ArrayList<>();
142-
try (DirectoryStream<Path> jarStream = Files.newDirectoryStream(plugin, "*.jar")) {
143-
for (Path jar : jarStream) {
144-
codebases.add(jar.toRealPath().toUri().toURL());
145-
}
146-
}
147-
148-
// parse the plugin's policy file into a set of permissions
149-
Policy policy = readPolicy(policyFile.toUri().toURL(), codebases.toArray(new URL[codebases.size()]));
150-
151-
// consult this policy for each of the plugin's jars:
152-
for (URL url : codebases) {
153-
if (map.put(url.getFile(), policy) != null) {
154-
// just be paranoid ok?
155-
throw new IllegalStateException("per-plugin permissions already granted for jar file: " + url);
156-
}
157-
}
139+
pluginsAndModules.add(plugin);
140+
}
141+
}
142+
}
143+
if (Files.exists(environment.modulesFile())) {
144+
try (DirectoryStream<Path> stream = Files.newDirectoryStream(environment.modulesFile())) {
145+
for (Path plugin : stream) {
146+
pluginsAndModules.add(plugin);
147+
}
148+
}
149+
}
150+
// now process each one
151+
for (Path plugin : pluginsAndModules) {
152+
Path policyFile = plugin.resolve(PluginInfo.ES_PLUGIN_POLICY);
153+
if (Files.exists(policyFile)) {
154+
// first get a list of URLs for the plugins' jars:
155+
// we resolve symlinks so map is keyed on the normalize codebase name
156+
List<URL> codebases = new ArrayList<>();
157+
try (DirectoryStream<Path> jarStream = Files.newDirectoryStream(plugin, "*.jar")) {
158+
for (Path jar : jarStream) {
159+
codebases.add(jar.toRealPath().toUri().toURL());
160+
}
161+
}
162+
163+
// parse the plugin's policy file into a set of permissions
164+
Policy policy = readPolicy(policyFile.toUri().toURL(), codebases.toArray(new URL[codebases.size()]));
165+
166+
// consult this policy for each of the plugin's jars:
167+
for (URL url : codebases) {
168+
if (map.put(url.getFile(), policy) != null) {
169+
// just be paranoid ok?
170+
throw new IllegalStateException("per-plugin permissions already granted for jar file: " + url);
158171
}
159172
}
160173
}
161174
}
175+
162176
return Collections.unmodifiableMap(map);
163177
}
164178

@@ -228,6 +242,7 @@ static void addFilePermissions(Permissions policy, Environment environment) {
228242
// read-only dirs
229243
addPath(policy, "path.home", environment.binFile(), "read,readlink");
230244
addPath(policy, "path.home", environment.libFile(), "read,readlink");
245+
addPath(policy, "path.home", environment.modulesFile(), "read,readlink");
231246
addPath(policy, "path.plugins", environment.pluginsFile(), "read,readlink");
232247
addPath(policy, "path.conf", environment.configFile(), "read,readlink");
233248
addPath(policy, "path.scripts", environment.scriptsFile(), "read,readlink");

core/src/main/java/org/elasticsearch/client/transport/TransportClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public TransportClient build() {
122122
.put(CLIENT_TYPE_SETTING, CLIENT_TYPE)
123123
.build();
124124

125-
PluginsService pluginsService = new PluginsService(settings, null, pluginClasses);
125+
PluginsService pluginsService = new PluginsService(settings, null, null, pluginClasses);
126126
this.settings = pluginsService.updatedSettings();
127127

128128
Version version = Version.CURRENT;

core/src/main/java/org/elasticsearch/env/Environment.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public class Environment {
5858

5959
private final Path pluginsFile;
6060

61+
private final Path modulesFile;
62+
6163
private final Path sharedDataFile;
6264

6365
/** location of bin/, used by plugin manager */
@@ -157,6 +159,7 @@ public Environment(Settings settings) {
157159

158160
binFile = homeFile.resolve("bin");
159161
libFile = homeFile.resolve("lib");
162+
modulesFile = homeFile.resolve("modules");
160163
}
161164

162165
/**
@@ -275,6 +278,10 @@ public Path libFile() {
275278
return libFile;
276279
}
277280

281+
public Path modulesFile() {
282+
return modulesFile;
283+
}
284+
278285
public Path logsFile() {
279286
return logsFile;
280287
}

core/src/main/java/org/elasticsearch/node/Node.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ protected Node(Environment tmpEnv, Version version, Collection<Class<? extends P
143143
tmpEnv.configFile(), Arrays.toString(tmpEnv.dataFiles()), tmpEnv.logsFile(), tmpEnv.pluginsFile());
144144
}
145145

146-
this.pluginsService = new PluginsService(tmpSettings, tmpEnv.pluginsFile(), classpathPlugins);
146+
this.pluginsService = new PluginsService(tmpSettings, tmpEnv.modulesFile(), tmpEnv.pluginsFile(), classpathPlugins);
147147
this.settings = pluginsService.updatedSettings();
148148
// create the environment based on the finalized (processed) view of the settings
149149
this.environment = new Environment(this.settings());

0 commit comments

Comments
 (0)