Skip to content

Commit a1e6c71

Browse files
committed
Tribe node: system properties and configuration settings must not be forwarded to tribe clients
The tribe node, at startup, sets up the tribe clients that will join their corresponding tribes. All of the tribe.* settings are properly forwarded to the corresponding tribe client. System properties and global configuration settings must not be forwarded to the tribe client though or they will end up overriding per tribe settings with same name causing issues. For instance if you set the transport.tcp.port to some defined value for the tribe node, via system property or configuration file, that same value must not be forwarded to the tribe clients, otherwise they will try and use the same port, which will be already occupied by the tribe node itself, resulting in startup failed. Same for cluster.name, which will cause the tribe clients not to join their tribes. Closes #9576 Closes #9721
1 parent 0d17845 commit a1e6c71

File tree

3 files changed

+120
-1
lines changed

3 files changed

+120
-1
lines changed

src/main/java/org/elasticsearch/tribe/TribeService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,11 @@ public TribeService(Settings settings, ClusterService clusterService, DiscoveryS
129129
ImmutableSettings.Builder sb = ImmutableSettings.builder().put(entry.getValue());
130130
sb.put("node.name", settings.get("name") + "/" + entry.getKey());
131131
sb.put(TRIBE_NAME, entry.getKey());
132+
sb.put("config.ignore_system_properties", true);
132133
if (sb.get("http.enabled") == null) {
133134
sb.put("http.enabled", false);
134135
}
135-
nodes.add((InternalNode) NodeBuilder.nodeBuilder().settings(sb).client(true).build());
136+
nodes.add((InternalNode) NodeBuilder.nodeBuilder().settings(sb).client(true).loadConfigSettings(false).build());
136137
}
137138

138139
String[] blockIndicesWrite = Strings.EMPTY_ARRAY;
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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.tribe;
21+
22+
import org.elasticsearch.client.Client;
23+
import org.elasticsearch.cluster.ClusterState;
24+
import org.elasticsearch.cluster.node.DiscoveryNode;
25+
import org.elasticsearch.common.settings.ImmutableSettings;
26+
import org.elasticsearch.common.settings.Settings;
27+
import org.elasticsearch.node.Node;
28+
import org.elasticsearch.node.NodeBuilder;
29+
import org.elasticsearch.test.ElasticsearchTestCase;
30+
import org.elasticsearch.test.InternalTestCluster;
31+
import org.junit.AfterClass;
32+
import org.junit.BeforeClass;
33+
import org.junit.Test;
34+
35+
import java.nio.file.Path;
36+
import java.nio.file.Paths;
37+
38+
import static org.hamcrest.CoreMatchers.either;
39+
import static org.hamcrest.CoreMatchers.equalTo;
40+
41+
/**
42+
* This test doesn't extend {@link org.elasticsearch.test.ElasticsearchIntegrationTest} as the internal cluster ignores system properties
43+
* all the time, while we need to make the tribe node accept them in this case, so that we can verify that they are not read again as part
44+
* of the tribe client nodes initialization. Note that the started nodes will obey to the 'node.mode' settings as the internal cluster does.
45+
*/
46+
public class TribeUnitTests extends ElasticsearchTestCase {
47+
48+
private static Node tribe1;
49+
private static Node tribe2;
50+
51+
private static final String NODE_MODE = InternalTestCluster.nodeMode();
52+
53+
@BeforeClass
54+
public static void createTribes() {
55+
tribe1 = NodeBuilder.nodeBuilder().settings(ImmutableSettings.builder().put("config.ignore_system_properties", true).put("http.enabled", false)
56+
.put("node.mode", NODE_MODE).put("cluster.name", "tribe1").put("node.name", "tribe1_node")).node();
57+
tribe2 = NodeBuilder.nodeBuilder().settings(ImmutableSettings.builder().put("config.ignore_system_properties", true).put("http.enabled", false)
58+
.put("node.mode", NODE_MODE).put("cluster.name", "tribe2").put("node.name", "tribe2_node")).node();
59+
60+
}
61+
62+
@AfterClass
63+
public static void closeTribes() {
64+
tribe1.close();
65+
tribe1 = null;
66+
tribe2.close();
67+
tribe2 = null;
68+
}
69+
70+
@Test
71+
public void testThatTribeClientsIgnoreGlobalSysProps() throws Exception {
72+
System.setProperty("es.cluster.name", "tribe_node_cluster");
73+
System.setProperty("es.tribe.t1.cluster.name", "tribe1");
74+
System.setProperty("es.tribe.t2.cluster.name", "tribe2");
75+
76+
try {
77+
assertTribeNodeSuccesfullyCreated(ImmutableSettings.EMPTY);
78+
} finally {
79+
System.clearProperty("es.cluster.name");
80+
System.clearProperty("es.tribe.t1.cluster.name");
81+
System.clearProperty("es.tribe.t2.cluster.name");
82+
}
83+
}
84+
85+
@Test
86+
public void testThatTribeClientsIgnoreGlobalConfig() throws Exception {
87+
Path pathConf = Paths.get(TribeUnitTests.class.getResource("elasticsearch.yml").toURI()).getParent();
88+
Settings settings = ImmutableSettings.builder().put("config.ignore_system_properties", true).put("path.conf", pathConf).build();
89+
assertTribeNodeSuccesfullyCreated(settings);
90+
}
91+
92+
private static void assertTribeNodeSuccesfullyCreated(Settings extraSettings) throws Exception {
93+
//tribe node doesn't need the node.mode setting, as it's forced local internally anyways. The tribe clients do need it to make sure
94+
//they can find their corresponding tribes using the proper transport
95+
Settings settings = ImmutableSettings.builder().put("http.enabled", false).put("node.name", "tribe_node")
96+
.put("tribe.t1.node.mode", NODE_MODE).put("tribe.t2.node.mode", NODE_MODE).put(extraSettings).build();
97+
98+
try (Node node = NodeBuilder.nodeBuilder().settings(settings).node()) {
99+
try (Client client = node.client()) {
100+
assertBusy(new Runnable() {
101+
@Override
102+
public void run() {
103+
ClusterState state = client.admin().cluster().prepareState().clear().setNodes(true).get().getState();
104+
assertThat(state.getClusterName().value(), equalTo("tribe_node_cluster"));
105+
assertThat(state.getNodes().getSize(), equalTo(5));
106+
for (DiscoveryNode discoveryNode : state.getNodes()) {
107+
assertThat(discoveryNode.getName(), either(equalTo("tribe1_node")).or(equalTo("tribe2_node")).or(equalTo("tribe_node"))
108+
.or(equalTo("tribe_node/t1")).or(equalTo("tribe_node/t2")));
109+
}
110+
}
111+
});
112+
}
113+
}
114+
}
115+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cluster.name: tribe_node_cluster
2+
tribe.t1.cluster.name: tribe1
3+
tribe.t2.cluster.name: tribe2

0 commit comments

Comments
 (0)