From 25d60e152fa4dfe57555388916e8125e8283653f Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Mon, 7 Dec 2015 15:58:42 -0800 Subject: [PATCH] Tribe: Fix tribe node to load config file for internal client nodes The tribe node creates one local client node for each cluster it connects to. Refactorings in #13383 broke this so that each local client node now tries to load the full elasticsearch.yml that the real tribe node uses. This change fixes the problem by adding a TribeClientNode which is a subclass of Node. The Environment the node uses is now passed in (in place of Settings), and the TribeClientNode simply does not use InternalSettingsPreparer.prepareEnvironment. The tests around tribe nodes are not great. The existing tests pass, but I also manually tested by creating 2 local clusters, and configuring and starting a tribe node. With this I was able to see in the logs the tribe node connecting to each cluster. closes #13383 --- .../java/org/elasticsearch/node/Node.java | 11 +++--- .../elasticsearch/tribe/TribeClientNode.java | 37 +++++++++++++++++++ .../org/elasticsearch/tribe/TribeService.java | 5 ++- .../elasticsearch/tribe/TribeUnitTests.java | 5 +-- .../java/org/elasticsearch/node/MockNode.java | 3 +- 5 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 core/src/main/java/org/elasticsearch/tribe/TribeClientNode.java diff --git a/core/src/main/java/org/elasticsearch/node/Node.java b/core/src/main/java/org/elasticsearch/node/Node.java index 04fc7e95565..3caff627530 100644 --- a/core/src/main/java/org/elasticsearch/node/Node.java +++ b/core/src/main/java/org/elasticsearch/node/Node.java @@ -128,14 +128,13 @@ public class Node implements Releasable { * @param preparedSettings Base settings to configure the node with */ public Node(Settings preparedSettings) { - this(preparedSettings, Version.CURRENT, Collections.>emptyList()); + this(InternalSettingsPreparer.prepareEnvironment(preparedSettings, null), Version.CURRENT, Collections.>emptyList()); } - Node(Settings preparedSettings, Version version, Collection> classpathPlugins) { - final Settings pSettings = settingsBuilder().put(preparedSettings) - .put(Client.CLIENT_TYPE_SETTING, CLIENT_TYPE).build(); - Environment tmpEnv = InternalSettingsPreparer.prepareEnvironment(pSettings, null); - Settings tmpSettings = TribeService.processSettings(tmpEnv.settings()); + protected Node(Environment tmpEnv, Version version, Collection> classpathPlugins) { + Settings tmpSettings = settingsBuilder().put(tmpEnv.settings()) + .put(Client.CLIENT_TYPE_SETTING, CLIENT_TYPE).build(); + tmpSettings = TribeService.processSettings(tmpSettings); ESLogger logger = Loggers.getLogger(Node.class, tmpSettings.get("name")); logger.info("version[{}], pid[{}], build[{}/{}]", version, JvmInfo.jvmInfo().pid(), Build.CURRENT.shortHash(), Build.CURRENT.date()); diff --git a/core/src/main/java/org/elasticsearch/tribe/TribeClientNode.java b/core/src/main/java/org/elasticsearch/tribe/TribeClientNode.java new file mode 100644 index 00000000000..688dfe5a92d --- /dev/null +++ b/core/src/main/java/org/elasticsearch/tribe/TribeClientNode.java @@ -0,0 +1,37 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.tribe; + +import org.elasticsearch.Version; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.env.Environment; +import org.elasticsearch.node.Node; +import org.elasticsearch.plugins.Plugin; + +import java.util.Collections; + +/** + * An internal node that connects to a remove cluster, as part of a tribe node. + */ +class TribeClientNode extends Node { + TribeClientNode(Settings settings) { + super(new Environment(settings), Version.CURRENT, Collections.>emptyList()); + } +} diff --git a/core/src/main/java/org/elasticsearch/tribe/TribeService.java b/core/src/main/java/org/elasticsearch/tribe/TribeService.java index 87da13fad4a..343606e7805 100644 --- a/core/src/main/java/org/elasticsearch/tribe/TribeService.java +++ b/core/src/main/java/org/elasticsearch/tribe/TribeService.java @@ -132,14 +132,15 @@ public class TribeService extends AbstractLifecycleComponent { nodesSettings.remove("on_conflict"); // remove prefix settings that don't indicate a client for (Map.Entry entry : nodesSettings.entrySet()) { Settings.Builder sb = Settings.builder().put(entry.getValue()); - sb.put("node.name", settings.get("name") + "/" + entry.getKey()); + sb.put("name", settings.get("name") + "/" + entry.getKey()); sb.put("path.home", settings.get("path.home")); // pass through ES home dir sb.put(TRIBE_NAME, entry.getKey()); sb.put(InternalSettingsPreparer.IGNORE_SYSTEM_PROPERTIES_SETTING, true); if (sb.get("http.enabled") == null) { sb.put("http.enabled", false); } - nodes.add(NodeBuilder.nodeBuilder().settings(sb).client(true).build()); + sb.put("node.client", true); + nodes.add(new TribeClientNode(sb.build())); } String[] blockIndicesWrite = Strings.EMPTY_ARRAY; diff --git a/qa/evil-tests/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java b/qa/evil-tests/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java index c13b91b159a..f25bd87db19 100644 --- a/qa/evil-tests/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java +++ b/qa/evil-tests/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java @@ -54,13 +54,12 @@ public class TribeUnitTests extends ESTestCase { @BeforeClass public static void createTribes() { Settings baseSettings = Settings.builder() - .put(InternalSettingsPreparer.IGNORE_SYSTEM_PROPERTIES_SETTING, true) .put("http.enabled", false) .put("node.mode", NODE_MODE) .put("path.home", createTempDir()).build(); - tribe1 = NodeBuilder.nodeBuilder().settings(Settings.builder().put(baseSettings).put("cluster.name", "tribe1").put("node.name", "tribe1_node")).node(); - tribe2 = NodeBuilder.nodeBuilder().settings(Settings.builder().put(baseSettings).put("cluster.name", "tribe2").put("node.name", "tribe2_node")).node(); + tribe1 = new TribeClientNode(Settings.builder().put(baseSettings).put("cluster.name", "tribe1").put("name", "tribe1_node").build()).start(); + tribe2 = new TribeClientNode(Settings.builder().put(baseSettings).put("cluster.name", "tribe2").put("name", "tribe2_node").build()).start(); } @AfterClass diff --git a/test-framework/src/main/java/org/elasticsearch/node/MockNode.java b/test-framework/src/main/java/org/elasticsearch/node/MockNode.java index c5592fef48d..57dcc08f4fe 100644 --- a/test-framework/src/main/java/org/elasticsearch/node/MockNode.java +++ b/test-framework/src/main/java/org/elasticsearch/node/MockNode.java @@ -21,6 +21,7 @@ package org.elasticsearch.node; import org.elasticsearch.Version; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.node.internal.InternalSettingsPreparer; import org.elasticsearch.plugins.Plugin; import java.util.Collection; @@ -39,7 +40,7 @@ public class MockNode extends Node { private Collection> plugins; public MockNode(Settings settings, Version version, Collection> classpathPlugins) { - super(settings, version, classpathPlugins); + super(InternalSettingsPreparer.prepareEnvironment(settings, null), version, classpathPlugins); this.version = version; this.plugins = classpathPlugins; }