Tribe: Passthrough environment and network settings to tribe client nodes

In 2.2, the client nodes created internally by a tribe node were changed
to be explicit about which settings the client nodes use, no longer
loading all settings from elasticsearch.yml. However, some settings were
missed, notably network bind settings. This change adds those settings
to be passed through, as well as adds unit tests for building the tribe
client node settings.
This commit is contained in:
Ryan Ernst 2016-03-01 14:42:28 -08:00
parent 72ed01c304
commit 6ca7666646
2 changed files with 107 additions and 12 deletions

View File

@ -41,6 +41,7 @@ import org.elasticsearch.common.Priority;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.network.NetworkService;
import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
@ -53,6 +54,7 @@ import org.elasticsearch.gateway.GatewayService;
import org.elasticsearch.node.Node;
import org.elasticsearch.rest.RestStatus;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
@ -154,6 +156,12 @@ public class TribeService extends AbstractLifecycleComponent<TribeService> {
public static final Set<String> TRIBE_SETTING_KEYS = Sets.newHashSet(TRIBE_NAME_SETTING.getKey(), ON_CONFLICT_SETTING.getKey(),
BLOCKS_METADATA_INDICES_SETTING.getKey(), BLOCKS_METADATA_SETTING.getKey(), BLOCKS_READ_INDICES_SETTING.getKey(), BLOCKS_WRITE_INDICES_SETTING.getKey(), BLOCKS_WRITE_SETTING.getKey());
// these settings should be passed through to each tribe client, if they are not set explicitly
private static final List<String> PASS_THROUGH_SETTINGS = Arrays.asList(
NetworkService.GLOBAL_NETWORK_HOST_SETTING.getKey(),
NetworkService.GLOBAL_NETWORK_BINDHOST_SETTING.getKey(),
NetworkService.GLOBAL_NETWORK_PUBLISHHOST_SETTING.getKey()
);
private final String onConflict;
private final Set<String> droppedIndices = ConcurrentCollections.newConcurrentSet();
@ -167,18 +175,8 @@ public class TribeService extends AbstractLifecycleComponent<TribeService> {
nodesSettings.remove("blocks"); // remove prefix settings that don't indicate a client
nodesSettings.remove("on_conflict"); // remove prefix settings that don't indicate a client
for (Map.Entry<String, Settings> entry : nodesSettings.entrySet()) {
Settings.Builder sb = Settings.builder().put(entry.getValue());
sb.put("node.name", settings.get("node.name") + "/" + entry.getKey());
sb.put(Environment.PATH_HOME_SETTING.getKey(), Environment.PATH_HOME_SETTING.get(settings)); // pass through ES home dir
if (Environment.PATH_CONF_SETTING.exists(settings)) {
sb.put(Environment.PATH_CONF_SETTING.getKey(), Environment.PATH_CONF_SETTING.get(settings));
}
sb.put(TRIBE_NAME_SETTING.getKey(), entry.getKey());
if (sb.get("http.enabled") == null) {
sb.put("http.enabled", false);
}
sb.put(Node.NODE_CLIENT_SETTING.getKey(), true);
nodes.add(new TribeClientNode(sb.build()));
Settings clientSettings = buildClientSettings(entry.getKey(), settings, entry.getValue());
nodes.add(new TribeClientNode(clientSettings));
}
this.blockIndicesMetadata = BLOCKS_METADATA_INDICES_SETTING.get(settings).toArray(Strings.EMPTY_ARRAY);
@ -197,6 +195,38 @@ public class TribeService extends AbstractLifecycleComponent<TribeService> {
this.onConflict = ON_CONFLICT_SETTING.get(settings);
}
// pkg private for testing
/**
* Builds node settings for a tribe client node from the tribe node's global settings,
* combined with tribe specific settings.
*/
static Settings buildClientSettings(String tribeName, Settings globalSettings, Settings tribeSettings) {
Settings.Builder sb = Settings.builder().put(tribeSettings);
sb.put("node.name", globalSettings.get("node.name") + "/" + tribeName);
sb.put(Environment.PATH_HOME_SETTING.getKey(), Environment.PATH_HOME_SETTING.get(globalSettings)); // pass through ES home dir
if (Environment.PATH_CONF_SETTING.exists(globalSettings)) {
sb.put(Environment.PATH_CONF_SETTING.getKey(), Environment.PATH_CONF_SETTING.get(globalSettings));
}
if (Environment.PATH_PLUGINS_SETTING.exists(globalSettings)) {
sb.put(Environment.PATH_PLUGINS_SETTING.getKey(), Environment.PATH_PLUGINS_SETTING.get(globalSettings));
}
if (Environment.PATH_LOGS_SETTING.exists(globalSettings)) {
sb.put(Environment.PATH_LOGS_SETTING.getKey(), Environment.PATH_LOGS_SETTING.get(globalSettings));
}
for (String passthrough : PASS_THROUGH_SETTINGS) {
if (sb.get(passthrough) == null && globalSettings.get(passthrough) != null) {
sb.put(passthrough, globalSettings.get(passthrough));
}
}
sb.put(TRIBE_NAME_SETTING.getKey(), tribeName);
if (sb.get("http.enabled") == null) {
sb.put("http.enabled", false);
}
sb.put(Node.NODE_CLIENT_SETTING.getKey(), true);
return sb.build();
}
@Override
protected void doStart() {
if (nodes.isEmpty() == false) {

View File

@ -0,0 +1,65 @@
/*
* 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.common.settings.Settings;
import org.elasticsearch.test.ESTestCase;
public class TribeServiceTests extends ESTestCase {
public void testMinimalSettings() {
Settings globalSettings = Settings.builder()
.put("node.name", "nodename")
.put("path.home", "some/path").build();
Settings clientSettings = TribeService.buildClientSettings("tribe1", globalSettings, Settings.EMPTY);
assertEquals("some/path", clientSettings.get("path.home"));
assertEquals("nodename/tribe1", clientSettings.get("node.name"));
assertEquals("tribe1", clientSettings.get("tribe.name"));
assertEquals("false", clientSettings.get("http.enabled"));
assertEquals("true", clientSettings.get("node.client"));
assertEquals(5, clientSettings.getAsMap().size());
}
public void testEnvironmentSettings() {
Settings globalSettings = Settings.builder()
.put("node.name", "nodename")
.put("path.home", "some/path")
.put("path.conf", "conf/path")
.put("path.plugins", "plugins/path")
.put("path.logs", "logs/path").build();
Settings clientSettings = TribeService.buildClientSettings("tribe1", globalSettings, Settings.EMPTY);
assertEquals("some/path", clientSettings.get("path.home"));
assertEquals("conf/path", clientSettings.get("path.conf"));
assertEquals("plugins/path", clientSettings.get("path.plugins"));
assertEquals("logs/path", clientSettings.get("path.logs"));
}
public void testPassthroughSettings() {
Settings globalSettings = Settings.builder()
.put("node.name", "nodename")
.put("path.home", "some/path")
.put("network.host", "0.0.0.0")
.put("network.bind_host", "1.1.1.1")
.put("network.publish_host", "2.2.2.2").build();
Settings clientSettings = TribeService.buildClientSettings("tribe1", globalSettings, Settings.EMPTY);
assertEquals("0.0.0.0", clientSettings.get("network.host"));
assertEquals("1.1.1.1", clientSettings.get("network.bind_host"));
assertEquals("2.2.2.2", clientSettings.get("network.publish_host"));
}
}