Skip to content

Commit 8777a1e

Browse files
authored
Add stable indicator for plugin descriptor (#88823)
A forgotten piece of #88731 is whether a plugin descriptor in memory came from a stable or internal descriptor. This commit adds a flag for that. Note that this is implied by the file that was loaded, so no new property is needed.
1 parent e3f1de2 commit 8777a1e

File tree

7 files changed

+35
-9
lines changed

7 files changed

+35
-9
lines changed

server/src/main/java/org/elasticsearch/plugins/PluginDescriptor.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public class PluginDescriptor implements Writeable, ToXContentObject {
5858
private final boolean hasNativeController;
5959
private final boolean isLicensed;
6060
private final boolean isModular;
61+
private final boolean isStable;
6162

6263
/**
6364
* Construct plugin info.
@@ -85,7 +86,8 @@ public PluginDescriptor(
8586
List<String> extendedPlugins,
8687
boolean hasNativeController,
8788
boolean isLicensed,
88-
boolean isModular
89+
boolean isModular,
90+
boolean isStable
8991
) {
9092
this.name = name;
9193
this.description = description;
@@ -98,6 +100,7 @@ public PluginDescriptor(
98100
this.hasNativeController = hasNativeController;
99101
this.isLicensed = isLicensed;
100102
this.isModular = isModular;
103+
this.isStable = isStable;
101104
}
102105

103106
/**
@@ -133,8 +136,10 @@ public PluginDescriptor(final StreamInput in) throws IOException {
133136

134137
if (in.getVersion().onOrAfter(Version.V_8_4_0)) {
135138
isModular = in.readBoolean();
139+
isStable = in.readBoolean();
136140
} else {
137141
isModular = moduleName != null;
142+
isStable = false;
138143
}
139144
}
140145

@@ -161,6 +166,7 @@ public void writeTo(final StreamOutput out) throws IOException {
161166
}
162167
if (out.getVersion().onOrAfter(Version.V_8_4_0)) {
163168
out.writeBoolean(isModular);
169+
out.writeBoolean(isStable);
164170
}
165171
}
166172

@@ -236,8 +242,9 @@ private static PluginDescriptor readerInternalDescriptor(Map<String, String> pro
236242
}
237243

238244
boolean isLicensed = readBoolean(propsMap, name, "licensed");
245+
boolean modular = module != null;
239246

240-
return new PluginDescriptor(name, desc, ver, esVer, javaVer, classname, module, extended, nativeCont, isLicensed, module != null);
247+
return new PluginDescriptor(name, desc, ver, esVer, javaVer, classname, module, extended, nativeCont, isLicensed, modular, false);
241248
}
242249

243250
private static PluginDescriptor readerStableDescriptor(Map<String, String> propsMap, String filename) {
@@ -248,7 +255,7 @@ private static PluginDescriptor readerStableDescriptor(Map<String, String> props
248255
String javaVer = readJavaVersion(propsMap, name);
249256
boolean isModular = readBoolean(propsMap, name, "modular");
250257

251-
return new PluginDescriptor(name, desc, ver, esVer, javaVer, null, null, List.of(), false, false, isModular);
258+
return new PluginDescriptor(name, desc, ver, esVer, javaVer, null, null, List.of(), false, false, isModular, true);
252259
}
253260

254261
private static String readNonEmptyString(Map<String, String> propsMap, String pluginId, String name) {
@@ -389,6 +396,13 @@ public boolean isModular() {
389396
return isModular;
390397
}
391398

399+
/**
400+
* Whether this plugin uses only stable APIs.
401+
*/
402+
public boolean isStable() {
403+
return isStable;
404+
}
405+
392406
@Override
393407
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
394408
builder.startObject();

server/src/test/java/org/elasticsearch/nodesinfo/NodeInfoStreamingTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ private static NodeInfo createNodeInfo() {
157157
Collections.emptyList(),
158158
randomBoolean(),
159159
randomBoolean(),
160+
randomBoolean(),
160161
randomBoolean()
161162
)
162163
);
@@ -176,6 +177,7 @@ private static NodeInfo createNodeInfo() {
176177
Collections.emptyList(),
177178
randomBoolean(),
178179
randomBoolean(),
180+
randomBoolean(),
179181
randomBoolean()
180182
)
181183
);

server/src/test/java/org/elasticsearch/plugins/PluginDescriptorTests.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ public void testSerialize() throws Exception {
234234
Collections.singletonList("foo"),
235235
randomBoolean(),
236236
randomBoolean(),
237+
randomBoolean(),
237238
randomBoolean()
238239
);
239240
BytesStreamOutput output = new BytesStreamOutput();
@@ -256,6 +257,7 @@ public void testSerializeWithModuleName() throws Exception {
256257
Collections.singletonList("foo"),
257258
randomBoolean(),
258259
randomBoolean(),
260+
randomBoolean(),
259261
randomBoolean()
260262
);
261263
BytesStreamOutput output = new BytesStreamOutput();
@@ -278,6 +280,7 @@ PluginDescriptor newMockDescriptor(String name) {
278280
List.of(),
279281
randomBoolean(),
280282
randomBoolean(),
283+
randomBoolean(),
281284
randomBoolean()
282285
);
283286
}
@@ -319,6 +322,7 @@ public void testPluginEqualityAndHash() {
319322
Collections.singletonList("foo"),
320323
randomBoolean(),
321324
randomBoolean(),
325+
randomBoolean(),
322326
randomBoolean()
323327
);
324328
// everything but name is different from descriptor1
@@ -335,7 +339,8 @@ public void testPluginEqualityAndHash() {
335339
),
336340
descriptor1.hasNativeController() == false,
337341
descriptor1.isLicensed() == false,
338-
descriptor1.isModular() == false
342+
descriptor1.isModular() == false,
343+
descriptor1.isStable() == false
339344
);
340345
// only name is different from descriptor1
341346
PluginDescriptor descriptor3 = new PluginDescriptor(
@@ -349,7 +354,8 @@ public void testPluginEqualityAndHash() {
349354
descriptor1.getExtendedPlugins(),
350355
descriptor1.hasNativeController(),
351356
descriptor1.isLicensed(),
352-
descriptor1.isModular()
357+
descriptor1.isModular(),
358+
descriptor1.isStable()
353359
);
354360

355361
assertThat(descriptor1, equalTo(descriptor2));

server/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ public void testExtensiblePlugin() {
456456
PluginsService.loadExtensions(
457457
List.of(
458458
new PluginsService.LoadedPlugin(
459-
new PluginDescriptor("extensible", null, null, null, null, null, null, List.of(), false, false, false),
459+
new PluginDescriptor("extensible", null, null, null, null, null, null, List.of(), false, false, false, false),
460460
extensiblePlugin
461461
)
462462
)
@@ -470,11 +470,11 @@ public void testExtensiblePlugin() {
470470
PluginsService.loadExtensions(
471471
List.of(
472472
new PluginsService.LoadedPlugin(
473-
new PluginDescriptor("extensible", null, null, null, null, null, null, List.of(), false, false, false),
473+
new PluginDescriptor("extensible", null, null, null, null, null, null, List.of(), false, false, false, false),
474474
extensiblePlugin
475475
),
476476
new PluginsService.LoadedPlugin(
477-
new PluginDescriptor("test", null, null, null, null, null, null, List.of("extensible"), false, false, false),
477+
new PluginDescriptor("test", null, null, null, null, null, null, List.of("extensible"), false, false, false, false),
478478
testPlugin
479479
)
480480
)

server/src/test/java/org/elasticsearch/plugins/PluginsUtilsTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class PluginsUtilsTests extends ESTestCase {
3939

4040
PluginDescriptor newTestDescriptor(String name, List<String> deps) {
4141
String javaVersion = Runtime.version().toString();
42-
return new PluginDescriptor(name, "desc", "1.0", Version.CURRENT, javaVersion, "MyPlugin", null, deps, false, false, false);
42+
return new PluginDescriptor(name, "desc", "1.0", Version.CURRENT, javaVersion, "MyPlugin", null, deps, false, false, false, false);
4343
}
4444

4545
public void testExistingPluginMissingDescriptor() throws Exception {
@@ -380,6 +380,7 @@ public void testIncompatibleElasticsearchVersion() throws Exception {
380380
Collections.emptyList(),
381381
false,
382382
false,
383+
false,
383384
false
384385
);
385386
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> PluginsUtils.verifyCompatibility(info));
@@ -398,6 +399,7 @@ public void testIncompatibleJavaVersion() throws Exception {
398399
Collections.emptyList(),
399400
false,
400401
false,
402+
false,
401403
false
402404
);
403405
IllegalStateException e = expectThrows(IllegalStateException.class, () -> PluginsUtils.verifyCompatibility(info));

test/framework/src/main/java/org/elasticsearch/plugins/MockPluginsService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public MockPluginsService(Settings settings, Environment environment, Collection
5858
Collections.emptyList(),
5959
false,
6060
false,
61+
false,
6162
false
6263
);
6364
if (logger.isTraceEnabled()) {

x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ public void testToXContent() throws IOException {
336336
Collections.emptyList(),
337337
false,
338338
false,
339+
false,
339340
false
340341
);
341342
final PluginRuntimeInfo pluginRuntimeInfo = new PluginRuntimeInfo(pluginDescriptor);

0 commit comments

Comments
 (0)