Skip to content

Commit 1b6ae1d

Browse files
committed
Simplify node attributes check
1 parent ed235a5 commit 1b6ae1d

File tree

2 files changed

+9
-25
lines changed

2 files changed

+9
-25
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -210,22 +210,13 @@ private static boolean alreadyContainsXPackCustomMetadata(ClusterState clusterSt
210210
public Settings additionalSettings() {
211211
final String xpackInstalledNodeAttrSetting = "node.attr." + XPACK_INSTALLED_NODE_ATTR;
212212

213-
if (transportClientMode) {
214-
if (settings.get(xpackInstalledNodeAttrSetting) != null) {
215-
throw new IllegalArgumentException("Directly setting [" + xpackInstalledNodeAttrSetting + "] is not permitted");
216-
}
213+
if (settings.get(xpackInstalledNodeAttrSetting) != null) {
214+
throw new IllegalArgumentException("Directly setting [" + xpackInstalledNodeAttrSetting + "] is not permitted");
215+
}
217216

217+
if (transportClientMode) {
218218
return super.additionalSettings();
219219
} else {
220-
// Unfortunately we cannot simply disallow any value for xpackInstalledNodeAttrSetting, because the
221-
// internal cluster integration test framework will restart nodes with settings copied from the node
222-
// immediately before it was stopped. The best we can do is reject inconsistencies.
223-
// TODO: fix the test framework not to copy derived node settings upon restart.
224-
if (settings.get(xpackInstalledNodeAttrSetting) != null &&
225-
settings.get(xpackInstalledNodeAttrSetting).equals("true") == false) {
226-
throw new IllegalArgumentException("Conflicting setting [" + xpackInstalledNodeAttrSetting + "]");
227-
}
228-
229220
return Settings.builder().put(super.additionalSettings()).put(xpackInstalledNodeAttrSetting, "true").build();
230221
}
231222
}

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/XPackPluginTests.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,18 @@
2525

2626
public class XPackPluginTests extends ESTestCase {
2727

28-
public void testXPackInstalledAttrClashOnTransport() throws Exception {
28+
public void testXPackInstalledAttrClash() throws Exception {
2929
Settings.Builder builder = Settings.builder();
30-
builder.put("node.attr." + XPackPlugin.XPACK_INSTALLED_NODE_ATTR, "true");
31-
builder.put(Client.CLIENT_TYPE_SETTING_S.getKey(), "transport");
30+
builder.put("node.attr." + XPackPlugin.XPACK_INSTALLED_NODE_ATTR, randomBoolean());
31+
if (randomBoolean()) {
32+
builder.put(Client.CLIENT_TYPE_SETTING_S.getKey(), "transport");
33+
}
3234
XPackPlugin xpackPlugin = createXPackPlugin(builder.put("path.home", createTempDir()).build());
3335
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, xpackPlugin::additionalSettings);
3436
assertThat(e.getMessage(),
3537
containsString("Directly setting [node.attr." + XPackPlugin.XPACK_INSTALLED_NODE_ATTR + "] is not permitted"));
3638
}
3739

38-
public void testXPackInstalledAttrClashOnNode() throws Exception {
39-
Settings.Builder builder = Settings.builder();
40-
builder.put("node.attr." + XPackPlugin.XPACK_INSTALLED_NODE_ATTR, "false");
41-
XPackPlugin xpackPlugin = createXPackPlugin(builder.put("path.home", createTempDir()).build());
42-
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, xpackPlugin::additionalSettings);
43-
assertThat(e.getMessage(),
44-
containsString("Conflicting setting [node.attr." + XPackPlugin.XPACK_INSTALLED_NODE_ATTR + "]"));
45-
}
46-
4740
public void testXPackInstalledAttrExists() throws Exception {
4841
XPackPlugin xpackPlugin = createXPackPlugin(Settings.builder().put("path.home", createTempDir()).build());
4942
assertEquals("true", xpackPlugin.additionalSettings().get("node.attr." + XPackPlugin.XPACK_INSTALLED_NODE_ATTR));

0 commit comments

Comments
 (0)