diff --git a/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java b/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java index 4835d411a8d..b73045abe63 100644 --- a/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java +++ b/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java @@ -164,7 +164,7 @@ final class Bootstrap { .put(InternalSettingsPreparer.IGNORE_SYSTEM_PROPERTIES_SETTING, true) .build(); - NodeBuilder nodeBuilder = NodeBuilder.nodeBuilder().settings(nodeSettings).loadConfigSettings(false); + NodeBuilder nodeBuilder = NodeBuilder.nodeBuilder().settings(nodeSettings); node = nodeBuilder.build(); } diff --git a/core/src/main/java/org/elasticsearch/common/logging/log4j/LogConfigurator.java b/core/src/main/java/org/elasticsearch/common/logging/log4j/LogConfigurator.java index 2e86beff192..d90b2f1f1bd 100644 --- a/core/src/main/java/org/elasticsearch/common/logging/log4j/LogConfigurator.java +++ b/core/src/main/java/org/elasticsearch/common/logging/log4j/LogConfigurator.java @@ -87,6 +87,7 @@ public class LogConfigurator { return; } loaded = true; + // TODO: this is partly a copy of InternalSettingsPreparer...we should pass in Environment and not do all this... Environment environment = new Environment(settings); Settings.Builder settingsBuilder = settingsBuilder().put(settings); resolveConfig(environment, settingsBuilder); @@ -116,11 +117,11 @@ public class LogConfigurator { * sets the loaded flag to false so that logging configuration can be * overridden. Should only be used in tests. */ - public static void reset() { + static void reset() { loaded = false; } - public static void resolveConfig(Environment env, final Settings.Builder settingsBuilder) { + static void resolveConfig(Environment env, final Settings.Builder settingsBuilder) { try { Files.walkFileTree(env.configFile(), EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor() { @@ -143,7 +144,7 @@ public class LogConfigurator { } } - public static void loadConfig(Path file, Settings.Builder settingsBuilder) { + static void loadConfig(Path file, Settings.Builder settingsBuilder) { try { settingsBuilder.loadFromPath(file); } catch (SettingsException | NoClassDefFoundError e) { diff --git a/core/src/main/java/org/elasticsearch/node/Node.java b/core/src/main/java/org/elasticsearch/node/Node.java index 2a385f00a03..cf6d60f6acc 100644 --- a/core/src/main/java/org/elasticsearch/node/Node.java +++ b/core/src/main/java/org/elasticsearch/node/Node.java @@ -124,29 +124,28 @@ public class Node implements Releasable { * Constructs a node with the given settings. * * @param preparedSettings Base settings to configure the node with - * @param loadConfigSettings true if settings should also be loaded and merged from configuration files */ - public Node(Settings preparedSettings, boolean loadConfigSettings) { - this(preparedSettings, loadConfigSettings, Version.CURRENT, Collections.>emptyList()); + public Node(Settings preparedSettings) { + this(preparedSettings, Version.CURRENT, Collections.>emptyList()); } - Node(Settings preparedSettings, boolean loadConfigSettings, Version version, Collection> classpathPlugins) { + Node(Settings preparedSettings, Version version, Collection> classpathPlugins) { final Settings pSettings = settingsBuilder().put(preparedSettings) .put(Client.CLIENT_TYPE_SETTING, CLIENT_TYPE).build(); - Environment env = InternalSettingsPreparer.prepareEnvironment(pSettings, null); - Settings settings = TribeService.processSettings(env.settings()); + Environment tmpEnv = InternalSettingsPreparer.prepareEnvironment(pSettings, null); + Settings tmpSettings = TribeService.processSettings(tmpEnv.settings()); - ESLogger logger = Loggers.getLogger(Node.class, settings.get("name")); + ESLogger logger = Loggers.getLogger(Node.class, tmpSettings.get("name")); logger.info("version[{}], pid[{}], build[{}/{}]", version, JvmInfo.jvmInfo().pid(), Build.CURRENT.hashShort(), Build.CURRENT.timestamp()); logger.info("initializing ..."); if (logger.isDebugEnabled()) { logger.debug("using config [{}], data [{}], logs [{}], plugins [{}]", - env.configFile(), Arrays.toString(env.dataFiles()), env.logsFile(), env.pluginsFile()); + tmpEnv.configFile(), Arrays.toString(tmpEnv.dataFiles()), tmpEnv.logsFile(), tmpEnv.pluginsFile()); } - this.pluginsService = new PluginsService(settings, env.pluginsFile(), classpathPlugins); + this.pluginsService = new PluginsService(tmpSettings, tmpEnv.pluginsFile(), classpathPlugins); this.settings = pluginsService.updatedSettings(); // create the environment based on the finalized (processed) view of the settings this.environment = new Environment(this.settings()); @@ -170,17 +169,17 @@ public class Node implements Releasable { modules.add(pluginModule); } modules.add(new PluginsModule(pluginsService)); - modules.add(new SettingsModule(settings)); + modules.add(new SettingsModule(this.settings)); modules.add(new NodeModule(this)); modules.add(new NetworkModule()); - modules.add(new ScriptModule(settings)); + modules.add(new ScriptModule(this.settings)); modules.add(new EnvironmentModule(environment)); modules.add(new NodeEnvironmentModule(nodeEnvironment)); - modules.add(new ClusterNameModule(settings)); + modules.add(new ClusterNameModule(this.settings)); modules.add(new ThreadPoolModule(threadPool)); - modules.add(new DiscoveryModule(settings)); - modules.add(new ClusterModule(settings)); - modules.add(new RestModule(settings)); + modules.add(new DiscoveryModule(this.settings)); + modules.add(new ClusterModule(this.settings)); + modules.add(new RestModule(this.settings)); modules.add(new TransportModule(settings)); if (settings.getAsBoolean(HTTP_ENABLED, true)) { modules.add(new HttpServerModule(settings)); diff --git a/core/src/main/java/org/elasticsearch/node/NodeBuilder.java b/core/src/main/java/org/elasticsearch/node/NodeBuilder.java index 9107cf0833e..257d3807749 100644 --- a/core/src/main/java/org/elasticsearch/node/NodeBuilder.java +++ b/core/src/main/java/org/elasticsearch/node/NodeBuilder.java @@ -26,8 +26,7 @@ import org.elasticsearch.common.settings.Settings; *

*

Settings will be loaded relative to the ES home (with or without config/ prefix) and if not found, * within the classpath (with or without config/ prefix). The settings file loaded can either be named - * elasticsearch.yml or elasticsearch.json). Loading settings can be disabled by calling - * {@link #loadConfigSettings(boolean)} with false. + * elasticsearch.yml or elasticsearch.json). *

*

Explicit settings can be passed by using the {@link #settings(org.elasticsearch.common.settings.Settings)} method. *

@@ -57,8 +56,6 @@ public class NodeBuilder { private final Settings.Builder settings = Settings.settingsBuilder(); - private boolean loadConfigSettings = true; - /** * A convenient factory method to create a {@link NodeBuilder}. */ @@ -95,15 +92,6 @@ public class NodeBuilder { return this; } - /** - * Should the node builder automatically try and load config settings from the file system / classpath. Defaults - * to true. - */ - public NodeBuilder loadConfigSettings(boolean loadConfigSettings) { - this.loadConfigSettings = loadConfigSettings; - return this; - } - /** * Is the node going to be a client node which means it will hold no data (node.data is * set to false) and other optimizations by different modules. @@ -154,7 +142,7 @@ public class NodeBuilder { * Builds the node without starting it. */ public Node build() { - return new Node(settings.build(), loadConfigSettings); + return new Node(settings.build()); } /** diff --git a/core/src/main/java/org/elasticsearch/node/internal/InternalSettingsPreparer.java b/core/src/main/java/org/elasticsearch/node/internal/InternalSettingsPreparer.java index c6c79d9068b..330ad5a5338 100644 --- a/core/src/main/java/org/elasticsearch/node/internal/InternalSettingsPreparer.java +++ b/core/src/main/java/org/elasticsearch/node/internal/InternalSettingsPreparer.java @@ -81,7 +81,7 @@ public class InternalSettingsPreparer { * @return the {@link Settings} and {@link Environment} as a {@link Tuple} */ public static Environment prepareEnvironment(Settings input, Terminal terminal) { - // just create enough settings to build the environment + // just create enough settings to build the environment, to get the config dir Settings.Builder output = settingsBuilder(); initializeSettings(output, input, true); Environment environment = new Environment(output.build()); @@ -129,11 +129,6 @@ public class InternalSettingsPreparer { initializeSettings(output, input, false); finalizeSettings(output, terminal, environment.configFile()); - environment = new Environment(output.build()); - - // we put back the path.logs so we can use it in the logging configuration file - output.put("path.logs", cleanPath(environment.logsFile().toAbsolutePath().toString())); - return new Environment(output.build()); } diff --git a/core/src/main/java/org/elasticsearch/tribe/TribeService.java b/core/src/main/java/org/elasticsearch/tribe/TribeService.java index 3cc7b779019..854c5c659ad 100644 --- a/core/src/main/java/org/elasticsearch/tribe/TribeService.java +++ b/core/src/main/java/org/elasticsearch/tribe/TribeService.java @@ -137,7 +137,7 @@ public class TribeService extends AbstractLifecycleComponent { if (sb.get("http.enabled") == null) { sb.put("http.enabled", false); } - nodes.add(NodeBuilder.nodeBuilder().settings(sb).client(true).loadConfigSettings(false).build()); + nodes.add(NodeBuilder.nodeBuilder().settings(sb).client(true).build()); } String[] blockIndicesWrite = Strings.EMPTY_ARRAY; diff --git a/core/src/test/java/org/elasticsearch/benchmark/scripts/expression/ScriptComparisonBenchmark.java b/core/src/test/java/org/elasticsearch/benchmark/scripts/expression/ScriptComparisonBenchmark.java index 6581cd2e98e..ce4cbf11577 100644 --- a/core/src/test/java/org/elasticsearch/benchmark/scripts/expression/ScriptComparisonBenchmark.java +++ b/core/src/test/java/org/elasticsearch/benchmark/scripts/expression/ScriptComparisonBenchmark.java @@ -111,7 +111,7 @@ public class ScriptComparisonBenchmark { Settings settings = settingsBuilder().put("name", "node1") .put("cluster.name", clusterName).build(); Collection> plugins = Collections.>singletonList(NativeScriptPlugin.class); - Node node1 = new MockNode(settings, true, Version.CURRENT, plugins); + Node node1 = new MockNode(settings, Version.CURRENT, plugins); node1.start(); Client client = node1.client(); client.admin().cluster().prepareHealth(indexName).setWaitForGreenStatus().setTimeout("10s").execute().actionGet(); diff --git a/core/src/test/java/org/elasticsearch/benchmark/scripts/score/ScriptsConstantScoreBenchmark.java b/core/src/test/java/org/elasticsearch/benchmark/scripts/score/ScriptsConstantScoreBenchmark.java index 7ad1837c215..53baf78d4c1 100644 --- a/core/src/test/java/org/elasticsearch/benchmark/scripts/score/ScriptsConstantScoreBenchmark.java +++ b/core/src/test/java/org/elasticsearch/benchmark/scripts/score/ScriptsConstantScoreBenchmark.java @@ -56,7 +56,7 @@ public class ScriptsConstantScoreBenchmark extends BasicScriptBenchmark { Settings settings = settingsBuilder().put("name", "node1") .put("cluster.name", clusterName).build(); Collection> plugins = Collections.>singletonList(NativeScriptExamplesPlugin.class); - Node node1 = new MockNode(settings, true, Version.CURRENT, plugins); + Node node1 = new MockNode(settings, Version.CURRENT, plugins); node1.start(); Client client = node1.client(); client.admin().cluster().prepareHealth("test").setWaitForGreenStatus().setTimeout("10s").execute().actionGet(); diff --git a/core/src/test/java/org/elasticsearch/benchmark/scripts/score/ScriptsScoreBenchmark.java b/core/src/test/java/org/elasticsearch/benchmark/scripts/score/ScriptsScoreBenchmark.java index 712b6130488..53c34a2c88e 100644 --- a/core/src/test/java/org/elasticsearch/benchmark/scripts/score/ScriptsScoreBenchmark.java +++ b/core/src/test/java/org/elasticsearch/benchmark/scripts/score/ScriptsScoreBenchmark.java @@ -55,7 +55,7 @@ public class ScriptsScoreBenchmark extends BasicScriptBenchmark { Settings settings = settingsBuilder().put("name", "node1") .put("cluster.name", clusterName).build(); Collection> plugins = Collections.>singletonList(NativeScriptExamplesPlugin.class); - Node node1 = new MockNode(settings, true, Version.CURRENT, plugins); + Node node1 = new MockNode(settings, Version.CURRENT, plugins); node1.start(); Client client = node1.client(); client.admin().cluster().prepareHealth("test").setWaitForGreenStatus().setTimeout("10s").execute().actionGet(); diff --git a/core/src/test/java/org/elasticsearch/benchmark/scripts/score/ScriptsScorePayloadSumBenchmark.java b/core/src/test/java/org/elasticsearch/benchmark/scripts/score/ScriptsScorePayloadSumBenchmark.java index 556c224f1f3..b80919290c5 100644 --- a/core/src/test/java/org/elasticsearch/benchmark/scripts/score/ScriptsScorePayloadSumBenchmark.java +++ b/core/src/test/java/org/elasticsearch/benchmark/scripts/score/ScriptsScorePayloadSumBenchmark.java @@ -55,7 +55,7 @@ public class ScriptsScorePayloadSumBenchmark extends BasicScriptBenchmark { Settings settings = settingsBuilder().put("name", "node1") .put("cluster.name", clusterName).build(); Collection> plugins = Collections.>singletonList(NativeScriptExamplesPlugin.class); - Node node1 = new MockNode(settings, true, Version.CURRENT, plugins); + Node node1 = new MockNode(settings, Version.CURRENT, plugins); node1.start(); Client client = node1.client(); client.admin().cluster().prepareHealth("test").setWaitForGreenStatus().setTimeout("10s").execute().actionGet(); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityTests.java index 7a794977c8b..a2dbf786812 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityTests.java @@ -39,7 +39,7 @@ public class RoutingBackwardCompatibilityTests extends ESTestCase { public void testBackwardCompatibility() throws Exception { Path baseDir = createTempDir(); - Node node = new Node(Settings.builder().put("path.home", baseDir.toString()).build(), false); + Node node = new Node(Settings.builder().put("path.home", baseDir.toString()).build()); try { try (BufferedReader reader = new BufferedReader(new InputStreamReader(RoutingBackwardCompatibilityTests.class.getResourceAsStream("/org/elasticsearch/cluster/routing/shard_routes.txt"), "UTF-8"))) { for (String line = reader.readLine(); line != null; line = reader.readLine()) { diff --git a/core/src/test/java/org/elasticsearch/node/MockNode.java b/core/src/test/java/org/elasticsearch/node/MockNode.java index 04762641f00..c5592fef48d 100644 --- a/core/src/test/java/org/elasticsearch/node/MockNode.java +++ b/core/src/test/java/org/elasticsearch/node/MockNode.java @@ -38,8 +38,8 @@ public class MockNode extends Node { private Version version; private Collection> plugins; - public MockNode(Settings settings, boolean loadConfigSettings, Version version, Collection> classpathPlugins) { - super(settings, loadConfigSettings, version, classpathPlugins); + public MockNode(Settings settings, Version version, Collection> classpathPlugins) { + super(settings, version, classpathPlugins); this.version = version; this.plugins = classpathPlugins; } diff --git a/core/src/test/java/org/elasticsearch/test/InternalTestCluster.java b/core/src/test/java/org/elasticsearch/test/InternalTestCluster.java index 1a5eede4321..48ad3f8d7c7 100644 --- a/core/src/test/java/org/elasticsearch/test/InternalTestCluster.java +++ b/core/src/test/java/org/elasticsearch/test/InternalTestCluster.java @@ -633,7 +633,7 @@ public final class InternalTestCluster extends TestCluster { .put("name", name) .put("discovery.id.seed", seed) .build(); - MockNode node = new MockNode(finalSettings, true, version, plugins); + MockNode node = new MockNode(finalSettings, version, plugins); return new NodeAndClient(name, node); } @@ -881,7 +881,7 @@ public final class InternalTestCluster extends TestCluster { Settings finalSettings = Settings.builder().put(node.settings()).put(newSettings).build(); Collection> plugins = node.getPlugins(); Version version = node.getVersion(); - node = new MockNode(finalSettings, true, version, plugins); + node = new MockNode(finalSettings, version, plugins); node.start(); }