Browse Source

Merge pull request #13383 from rjernst/go_away_transport_paths

Remove environment from transport client
Ryan Ernst 10 years ago
parent
commit
55795f8ec2
23 changed files with 349 additions and 296 deletions
  1. 5 6
      core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java
  2. 4 16
      core/src/main/java/org/elasticsearch/client/transport/TransportClient.java
  3. 2 3
      core/src/main/java/org/elasticsearch/common/cli/CliTool.java
  4. 7 3
      core/src/main/java/org/elasticsearch/common/logging/log4j/LogConfigurator.java
  5. 14 16
      core/src/main/java/org/elasticsearch/node/Node.java
  6. 2 14
      core/src/main/java/org/elasticsearch/node/NodeBuilder.java
  7. 129 117
      core/src/main/java/org/elasticsearch/node/internal/InternalSettingsPreparer.java
  8. 1 1
      core/src/main/java/org/elasticsearch/plugins/PluginManager.java
  9. 2 2
      core/src/main/java/org/elasticsearch/plugins/PluginManagerCliParser.java
  10. 10 13
      core/src/main/java/org/elasticsearch/plugins/PluginsService.java
  11. 1 1
      core/src/main/java/org/elasticsearch/tribe/TribeService.java
  12. 1 1
      core/src/test/java/org/elasticsearch/benchmark/scripts/expression/ScriptComparisonBenchmark.java
  13. 1 1
      core/src/test/java/org/elasticsearch/benchmark/scripts/score/ScriptsConstantScoreBenchmark.java
  14. 1 1
      core/src/test/java/org/elasticsearch/benchmark/scripts/score/ScriptsScoreBenchmark.java
  15. 1 1
      core/src/test/java/org/elasticsearch/benchmark/scripts/score/ScriptsScorePayloadSumBenchmark.java
  16. 1 1
      core/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityTests.java
  17. 2 2
      core/src/test/java/org/elasticsearch/node/MockNode.java
  18. 136 76
      core/src/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java
  19. 14 17
      core/src/test/java/org/elasticsearch/plugins/PluginManagerIT.java
  20. 1 1
      core/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java
  21. 2 2
      core/src/test/java/org/elasticsearch/test/InternalTestCluster.java
  22. 1 1
      core/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortIntegrationIT.java
  23. 11 0
      docs/reference/migration/migrate_2_0/java.asciidoc

+ 5 - 6
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();
     }
     
@@ -195,9 +195,9 @@ final class Bootstrap {
         }
     }
 
-    private static Tuple<Settings, Environment> initialSettings(boolean foreground) {
+    private static Environment initialSettings(boolean foreground) {
         Terminal terminal = foreground ? Terminal.DEFAULT : null;
-        return InternalSettingsPreparer.prepareSettings(EMPTY_SETTINGS, true, terminal);
+        return InternalSettingsPreparer.prepareEnvironment(EMPTY_SETTINGS, terminal);
     }
 
     private void start() {
@@ -234,9 +234,8 @@ final class Bootstrap {
             foreground = false;
         }
 
-        Tuple<Settings, Environment> tuple = initialSettings(foreground);
-        Settings settings = tuple.v1();
-        Environment environment = tuple.v2();
+        Environment environment = initialSettings(foreground);
+        Settings settings = environment.settings();
 
         if (environment.pidFile() != null) {
             PidFile.create(environment.pidFile(), true);

+ 4 - 16
core/src/main/java/org/elasticsearch/client/transport/TransportClient.java

@@ -85,7 +85,6 @@ public class TransportClient extends AbstractClient {
 
         private Settings settings = Settings.EMPTY;
         private List<Class<? extends Plugin>> pluginClasses = new ArrayList<>();
-        private boolean loadConfigSettings = true;
 
         /**
          * The settings to configure the transport client with.
@@ -102,15 +101,6 @@ public class TransportClient extends AbstractClient {
             return this;
         }
 
-        /**
-         * Should the transport client load file based configuration automatically or not (and rely
-         * only on the provided settings), defaults to true.
-         */
-        public Builder loadConfigSettings(boolean loadConfigSettings) {
-            this.loadConfigSettings = loadConfigSettings;
-            return this;
-        }
-
         /**
          * Add the given plugin to the client when it is created.
          */
@@ -123,17 +113,16 @@ public class TransportClient extends AbstractClient {
          * Builds a new instance of the transport client.
          */
         public TransportClient build() {
-            Tuple<Settings, Environment> tuple = InternalSettingsPreparer.prepareSettings(settings, loadConfigSettings);
-            Settings settings = settingsBuilder()
+            Settings settings = InternalSettingsPreparer.prepareSettings(this.settings);
+            settings = settingsBuilder()
                     .put(NettyTransport.PING_SCHEDULE, "5s") // enable by default the transport schedule ping interval
-                    .put(tuple.v1())
+                    .put(settings)
                     .put("network.server", false)
                     .put("node.client", true)
                     .put(CLIENT_TYPE_SETTING, CLIENT_TYPE)
                     .build();
-            Environment environment = tuple.v2();
 
-            PluginsService pluginsService = new PluginsService(settings, tuple.v2(), pluginClasses);
+            PluginsService pluginsService = new PluginsService(settings, null, pluginClasses);
             this.settings = pluginsService.updatedSettings();
 
             Version version = Version.CURRENT;
@@ -149,7 +138,6 @@ public class TransportClient extends AbstractClient {
                     modules.add(pluginModule);
                 }
                 modules.add(new PluginsModule(pluginsService));
-                modules.add(new EnvironmentModule(environment));
                 modules.add(new SettingsModule(this.settings));
                 modules.add(new NetworkModule());
                 modules.add(new ClusterNameModule(this.settings));

+ 2 - 3
core/src/main/java/org/elasticsearch/common/cli/CliTool.java

@@ -104,9 +104,8 @@ public abstract class CliTool {
         Preconditions.checkArgument(config.cmds().size() != 0, "At least one command must be configured");
         this.config = config;
         this.terminal = terminal;
-        Tuple<Settings, Environment> tuple = InternalSettingsPreparer.prepareSettings(EMPTY_SETTINGS, true, terminal);
-        settings = tuple.v1();
-        env = tuple.v2();
+        env = InternalSettingsPreparer.prepareEnvironment(EMPTY_SETTINGS, terminal);
+        settings = env.settings();
     }
 
     public final ExitStatus execute(String... args) {

+ 7 - 3
core/src/main/java/org/elasticsearch/common/logging/log4j/LogConfigurator.java

@@ -40,6 +40,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
+import static org.elasticsearch.common.Strings.cleanPath;
 import static org.elasticsearch.common.settings.Settings.settingsBuilder;
 
 /**
@@ -87,6 +88,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);
@@ -109,6 +111,8 @@ public class LogConfigurator {
                 props.setProperty(key, value);
             }
         }
+        // ensure explicit path to logs dir exists
+        props.put("path.logs", cleanPath(environment.logsFile().toAbsolutePath().toString()));
         PropertyConfigurator.configure(props);
     }
 
@@ -116,11 +120,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<Path>() {
@@ -143,7 +147,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) {

+ 14 - 16
core/src/main/java/org/elasticsearch/node/Node.java

@@ -124,30 +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.<Class<? extends Plugin>>emptyList());
+    public Node(Settings preparedSettings) {
+        this(preparedSettings, Version.CURRENT, Collections.<Class<? extends Plugin>>emptyList());
     }
 
-    Node(Settings preparedSettings, boolean loadConfigSettings, Version version, Collection<Class<? extends Plugin>> classpathPlugins) {
+    Node(Settings preparedSettings, Version version, Collection<Class<? extends Plugin>> classpathPlugins) {
         final Settings pSettings = settingsBuilder().put(preparedSettings)
                 .put(Client.CLIENT_TYPE_SETTING, CLIENT_TYPE).build();
-        Tuple<Settings, Environment> tuple = InternalSettingsPreparer.prepareSettings(pSettings, loadConfigSettings);
-        tuple = new Tuple<>(TribeService.processSettings(tuple.v1()), tuple.v2());
+        Environment tmpEnv = InternalSettingsPreparer.prepareEnvironment(pSettings, null);
+        Settings tmpSettings = TribeService.processSettings(tmpEnv.settings());
 
-        ESLogger logger = Loggers.getLogger(Node.class, tuple.v1().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()) {
-            Environment env = tuple.v2();
             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(tuple.v1(), tuple.v2(), 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());
@@ -171,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));

+ 2 - 14
core/src/main/java/org/elasticsearch/node/NodeBuilder.java

@@ -26,8 +26,7 @@ import org.elasticsearch.common.settings.Settings;
  * <p/>
  * <p>Settings will be loaded relative to the ES home (with or without <tt>config/</tt> prefix) and if not found,
  * within the classpath (with or without <tt>config/<tt> prefix). The settings file loaded can either be named
- * <tt>elasticsearch.yml</tt> or <tt>elasticsearch.json</tt>). Loading settings can be disabled by calling
- * {@link #loadConfigSettings(boolean)} with <tt>false<tt>.
+ * <tt>elasticsearch.yml</tt> or <tt>elasticsearch.json</tt>).
  * <p/>
  * <p>Explicit settings can be passed by using the {@link #settings(org.elasticsearch.common.settings.Settings)} method.
  * <p/>
@@ -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 <tt>true</tt>.
-     */
-    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 (<tt>node.data</tt> is
      * set to <tt>false</tt>) 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());
     }
 
     /**

+ 129 - 117
core/src/main/java/org/elasticsearch/node/internal/InternalSettingsPreparer.java

@@ -21,7 +21,6 @@ package org.elasticsearch.node.internal;
 
 import com.google.common.base.Charsets;
 import com.google.common.collect.Sets;
-import com.google.common.collect.UnmodifiableIterator;
 import org.elasticsearch.cluster.ClusterName;
 import org.elasticsearch.common.Booleans;
 import org.elasticsearch.common.Strings;
@@ -38,13 +37,11 @@ import java.io.InputStreamReader;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ThreadLocalRandom;
 
-import static org.elasticsearch.common.Strings.cleanPath;
 import static org.elasticsearch.common.settings.Settings.settingsBuilder;
 
 /**
@@ -52,22 +49,22 @@ import static org.elasticsearch.common.settings.Settings.settingsBuilder;
  */
 public class InternalSettingsPreparer {
 
-    static final List<String> ALLOWED_SUFFIXES = Arrays.asList(".yml", ".yaml", ".json", ".properties");
+    private static final String[] ALLOWED_SUFFIXES = {".yml", ".yaml", ".json", ".properties"};
+    static final String[] PROPERTY_PREFIXES = {"es.", "elasticsearch."};
+    static final String[] PROPERTY_DEFAULTS_PREFIXES = {"es.default.", "elasticsearch.default."};
 
     public static final String SECRET_PROMPT_VALUE = "${prompt.secret}";
     public static final String TEXT_PROMPT_VALUE = "${prompt.text}";
     public static final String IGNORE_SYSTEM_PROPERTIES_SETTING = "config.ignore_system_properties";
 
     /**
-     * Prepares the settings by gathering all elasticsearch system properties, optionally loading the configuration settings,
-     * and then replacing all property placeholders. This method will not work with settings that have <code>${prompt.text}</code>
-     * or <code>${prompt.secret}</code> as their value unless they have been resolved previously.
-     * @param pSettings The initial settings to use
-     * @param loadConfigSettings flag to indicate whether to load settings from the configuration directory/file
-     * @return the {@link Settings} and {@link Environment} as a {@link Tuple}
+     * Prepares the settings by gathering all elasticsearch system properties and setting defaults.
      */
-    public static Tuple<Settings, Environment> prepareSettings(Settings pSettings, boolean loadConfigSettings) {
-        return prepareSettings(pSettings, loadConfigSettings, null);
+    public static Settings prepareSettings(Settings input) {
+        Settings.Builder output = settingsBuilder();
+        initializeSettings(output, input, true);
+        finalizeSettings(output, null, null);
+        return output.build();
     }
 
     /**
@@ -75,126 +72,138 @@ public class InternalSettingsPreparer {
      * and then replacing all property placeholders. If a {@link Terminal} is provided and configuration settings are loaded,
      * settings with a value of <code>${prompt.text}</code> or <code>${prompt.secret}</code> will result in a prompt for
      * the setting to the user.
-     * @param pSettings The initial settings to use
-     * @param loadConfigSettings flag to indicate whether to load settings from the configuration directory/file
+     * @param input The initial settings to use
      * @param terminal the Terminal to use for input/output
      * @return the {@link Settings} and {@link Environment} as a {@link Tuple}
      */
-    public static Tuple<Settings, Environment> prepareSettings(Settings pSettings, boolean loadConfigSettings, Terminal terminal) {
-        // ignore this prefixes when getting properties from es. and elasticsearch.
-        String[] ignorePrefixes = new String[]{"es.default.", "elasticsearch.default."};
-        boolean useSystemProperties = !pSettings.getAsBoolean(IGNORE_SYSTEM_PROPERTIES_SETTING, false);
-        // just create enough settings to build the environment
-        Settings.Builder settingsBuilder = settingsBuilder().put(pSettings);
-        if (useSystemProperties) {
-            settingsBuilder.putProperties("elasticsearch.default.", System.getProperties())
-                    .putProperties("es.default.", System.getProperties())
-                    .putProperties("elasticsearch.", System.getProperties(), ignorePrefixes)
-                    .putProperties("es.", System.getProperties(), ignorePrefixes);
-        }
-        settingsBuilder.replacePropertyPlaceholders();
+    public static Environment prepareEnvironment(Settings input, Terminal terminal) {
+        // 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());
 
-        Environment environment = new Environment(settingsBuilder.build());
-
-        if (loadConfigSettings) {
-            boolean loadFromEnv = true;
-            if (useSystemProperties) {
-                // if its default, then load it, but also load form env
-                if (Strings.hasText(System.getProperty("es.default.config"))) {
-                    loadFromEnv = true;
-                    settingsBuilder.loadFromPath(environment.configFile().resolve(System.getProperty("es.default.config")));
-                }
-                // if explicit, just load it and don't load from env
-                if (Strings.hasText(System.getProperty("es.config"))) {
-                    loadFromEnv = false;
-                    settingsBuilder.loadFromPath(environment.configFile().resolve(System.getProperty("es.config")));
-                }
-                if (Strings.hasText(System.getProperty("elasticsearch.config"))) {
-                    loadFromEnv = false;
-                    settingsBuilder.loadFromPath(environment.configFile().resolve(System.getProperty("elasticsearch.config")));
-                }
+        // TODO: can we simplify all of this and have a single filename, which is looked up in the config dir?
+        boolean loadFromEnv = true;
+        if (useSystemProperties(input)) {
+            // if its default, then load it, but also load form env
+            if (Strings.hasText(System.getProperty("es.default.config"))) {
+                // TODO: we don't allow multiple config files, but having loadFromEnv true here allows just that
+                loadFromEnv = true;
+                output.loadFromPath(environment.configFile().resolve(System.getProperty("es.default.config")));
+            }
+            // TODO: these should be elseifs so that multiple files cannot be loaded
+            // if explicit, just load it and don't load from env
+            if (Strings.hasText(System.getProperty("es.config"))) {
+                loadFromEnv = false;
+                output.loadFromPath(environment.configFile().resolve(System.getProperty("es.config")));
             }
-            if (loadFromEnv) {
-                boolean settingsFileFound = false;
-                Set<String> foundSuffixes = Sets.newHashSet();
-                for (String allowedSuffix : ALLOWED_SUFFIXES) {
-                    Path path = environment.configFile().resolve("elasticsearch" + allowedSuffix);
-                    if (Files.exists(path)) {
-                        if (!settingsFileFound) {
-                            settingsBuilder.loadFromPath(path);
-                        }
-                        settingsFileFound = true;
-                        foundSuffixes.add(allowedSuffix);
+            if (Strings.hasText(System.getProperty("elasticsearch.config"))) {
+                loadFromEnv = false;
+                output.loadFromPath(environment.configFile().resolve(System.getProperty("elasticsearch.config")));
+            }
+        }
+        if (loadFromEnv) {
+            boolean settingsFileFound = false;
+            Set<String> foundSuffixes = Sets.newHashSet();
+            for (String allowedSuffix : ALLOWED_SUFFIXES) {
+                Path path = environment.configFile().resolve("elasticsearch" + allowedSuffix);
+                if (Files.exists(path)) {
+                    if (!settingsFileFound) {
+                        output.loadFromPath(path);
                     }
+                    settingsFileFound = true;
+                    foundSuffixes.add(allowedSuffix);
                 }
-                if (foundSuffixes.size() > 1) {
-                    throw new SettingsException("multiple settings files found with suffixes: " + Strings.collectionToDelimitedString(foundSuffixes, ","));
-                }
+            }
+            if (foundSuffixes.size() > 1) {
+                throw new SettingsException("multiple settings files found with suffixes: " + Strings.collectionToDelimitedString(foundSuffixes, ","));
             }
         }
 
-        settingsBuilder.put(pSettings);
-        if (useSystemProperties) {
-            settingsBuilder.putProperties("elasticsearch.", System.getProperties(), ignorePrefixes)
-                    .putProperties("es.", System.getProperties(), ignorePrefixes);
+        // re-initialize settings now that the config file has been loaded
+        // TODO: only re-initialize if a config file was actually loaded
+        initializeSettings(output, input, false);
+        finalizeSettings(output, terminal, environment.configFile());
+
+        return new Environment(output.build());
+    }
+
+    private static boolean useSystemProperties(Settings input) {
+        return !input.getAsBoolean(IGNORE_SYSTEM_PROPERTIES_SETTING, false);
+    }
+
+    /**
+     * Initializes the builder with the given input settings, and loads system properties settings if allowed.
+     * If loadDefaults is true, system property default settings are loaded.
+     */
+    private static void initializeSettings(Settings.Builder output, Settings input, boolean loadDefaults) {
+        output.put(input);
+        if (useSystemProperties(input)) {
+            if (loadDefaults) {
+                for (String prefix : PROPERTY_DEFAULTS_PREFIXES) {
+                    output.putProperties(prefix, System.getProperties());
+                }
+            }
+            for (String prefix : PROPERTY_PREFIXES) {
+                output.putProperties(prefix, System.getProperties(), PROPERTY_DEFAULTS_PREFIXES);
+            }
         }
-        settingsBuilder.replacePropertyPlaceholders();
+        output.replacePropertyPlaceholders();
+    }
 
+    /**
+     * Finish preparing settings by replacing forced settings, prompts, and any defaults that need to be added.
+     * The provided terminal is used to prompt for settings needing to be replaced.
+     * The provided configDir is optional and will be used to lookup names.txt if the node name is not set, if provided.
+     */
+    private static void finalizeSettings(Settings.Builder output, Terminal terminal, Path configDir) {
         // allow to force set properties based on configuration of the settings provided
-        for (Map.Entry<String, String> entry : pSettings.getAsMap().entrySet()) {
-            String setting = entry.getKey();
+        List<String> forcedSettings = new ArrayList<>();
+        for (String setting : output.internalMap().keySet()) {
             if (setting.startsWith("force.")) {
-                settingsBuilder.remove(setting);
-                settingsBuilder.put(setting.substring("force.".length()), entry.getValue());
+                forcedSettings.add(setting);
             }
         }
-        settingsBuilder.replacePropertyPlaceholders();
+        for (String forcedSetting : forcedSettings) {
+            String value = output.remove(forcedSetting);
+            output.put(forcedSetting.substring("force.".length()), value);
+        }
+        output.replacePropertyPlaceholders();
 
         // check if name is set in settings, if not look for system property and set it
-        if (settingsBuilder.get("name") == null) {
+        if (output.get("name") == null) {
             String name = System.getProperty("name");
             if (name != null) {
-                settingsBuilder.put("name", name);
+                output.put("name", name);
             }
         }
 
         // put the cluster name
-        if (settingsBuilder.get(ClusterName.SETTING) == null) {
-            settingsBuilder.put(ClusterName.SETTING, ClusterName.DEFAULT.value());
+        if (output.get(ClusterName.SETTING) == null) {
+            output.put(ClusterName.SETTING, ClusterName.DEFAULT.value());
         }
 
-        String v = settingsBuilder.get(Settings.SETTINGS_REQUIRE_UNITS);
+        String v = output.get(Settings.SETTINGS_REQUIRE_UNITS);
         if (v != null) {
             Settings.setSettingsRequireUnits(Booleans.parseBoolean(v, true));
         }
 
-        Settings settings = replacePromptPlaceholders(settingsBuilder.build(), terminal);
+        replacePromptPlaceholders(output, terminal);
         // all settings placeholders have been resolved. resolve the value for the name setting by checking for name,
         // then looking for node.name, and finally generate one if needed
-        if (settings.get("name") == null) {
-            String name = settings.get("node.name");
+        if (output.get("name") == null) {
+            String name = output.get("node.name");
             if (name == null || name.isEmpty()) {
-                name = randomNodeName(environment);
+                name = randomNodeName(configDir);
             }
-            settings = settingsBuilder().put(settings).put("name", name).build();
+            output.put("name", name);
         }
-
-        environment = new Environment(settings);
-
-        // put back the env settings
-        settingsBuilder = settingsBuilder().put(settings);
-        // we put back the path.logs so we can use it in the logging configuration file
-        settingsBuilder.put("path.logs", cleanPath(environment.logsFile().toAbsolutePath().toString()));
-
-        settings = settingsBuilder.build();
-
-        return new Tuple<>(settings, environment);
     }
 
-    static String randomNodeName(Environment environment) {
+    private static String randomNodeName(Path configDir) {
         InputStream input;
-        Path namesPath = environment.configFile().resolve("names.txt");
-        if (Files.exists(namesPath)) {
+        if (configDir != null && Files.exists(configDir.resolve("names.txt"))) {
+            Path namesPath = configDir.resolve("names.txt");
             try {
                 input = Files.newInputStream(namesPath);
             } catch (IOException e) {
@@ -220,37 +229,40 @@ public class InternalSettingsPreparer {
         }
     }
 
-    static Settings replacePromptPlaceholders(Settings settings, Terminal terminal) {
-        UnmodifiableIterator<Map.Entry<String, String>> iter = settings.getAsMap().entrySet().iterator();
-        Settings.Builder builder = Settings.builder();
-
-        while (iter.hasNext()) {
-            Map.Entry<String, String> entry = iter.next();
-            String value = entry.getValue();
-            String key = entry.getKey();
-            switch (value) {
+    private static void replacePromptPlaceholders(Settings.Builder settings, Terminal terminal) {
+        List<String> secretToPrompt = new ArrayList<>();
+        List<String> textToPrompt = new ArrayList<>();
+        for (Map.Entry<String, String> entry : settings.internalMap().entrySet()) {
+            switch (entry.getValue()) {
                 case SECRET_PROMPT_VALUE:
-                    String secretValue = promptForValue(key, terminal, true);
-                    if (Strings.hasLength(secretValue)) {
-                        builder.put(key, secretValue);
-                    }
+                    secretToPrompt.add(entry.getKey());
                     break;
                 case TEXT_PROMPT_VALUE:
-                    String textValue = promptForValue(key, terminal, false);
-                    if (Strings.hasLength(textValue)) {
-                        builder.put(key, textValue);
-                    }
-                    break;
-                default:
-                    builder.put(key, value);
+                    textToPrompt.add(entry.getKey());
                     break;
             }
         }
-
-        return builder.build();
+        for (String setting : secretToPrompt) {
+            String secretValue = promptForValue(setting, terminal, true);
+            if (Strings.hasLength(secretValue)) {
+                settings.put(setting, secretValue);
+            } else {
+                // TODO: why do we remove settings if prompt returns empty??
+                settings.remove(setting);
+            }
+        }
+        for (String setting : textToPrompt) {
+            String textValue = promptForValue(setting, terminal, false);
+            if (Strings.hasLength(textValue)) {
+                settings.put(setting, textValue);
+            } else {
+                // TODO: why do we remove settings if prompt returns empty??
+                settings.remove(setting);
+            }
+        }
     }
 
-    static String promptForValue(String key, Terminal terminal, boolean secret) {
+    private static String promptForValue(String key, Terminal terminal, boolean secret) {
         if (terminal == null) {
             throw new UnsupportedOperationException("found property [" + key + "] with value [" + (secret ? SECRET_PROMPT_VALUE : TEXT_PROMPT_VALUE) +"]. prompting for property values is only supported when running elasticsearch in the foreground");
         }

+ 1 - 1
core/src/main/java/org/elasticsearch/plugins/PluginManager.java

@@ -321,7 +321,7 @@ public class PluginManager {
         }
 
         // read existing bundles. this does some checks on the installation too.
-        List<Bundle> bundles = PluginsService.getPluginBundles(environment);
+        List<Bundle> bundles = PluginsService.getPluginBundles(environment.pluginsFile());
 
         // if we aren't isolated, we need to jarhellcheck against any other non-isolated plugins
         // thats always the first bundle

+ 2 - 2
core/src/main/java/org/elasticsearch/plugins/PluginManagerCliParser.java

@@ -50,8 +50,8 @@ public class PluginManagerCliParser extends CliTool {
             .build();
 
     public static void main(String[] args) {
-        Tuple<Settings, Environment> initialSettings = InternalSettingsPreparer.prepareSettings(EMPTY, true, Terminal.DEFAULT);
-        LogConfigurator.configure(initialSettings.v1());
+        Environment env = InternalSettingsPreparer.prepareEnvironment(EMPTY, Terminal.DEFAULT);
+        LogConfigurator.configure(env.settings());
         int status = new PluginManagerCliParser().execute(args).status();
         System.exit(status);
     }

+ 10 - 13
core/src/main/java/org/elasticsearch/plugins/PluginsService.java

@@ -19,8 +19,6 @@
 
 package org.elasticsearch.plugins;
 
-import com.google.common.collect.ImmutableMap;
-
 import org.apache.lucene.analysis.util.CharFilterFactory;
 import org.apache.lucene.analysis.util.TokenFilterFactory;
 import org.apache.lucene.analysis.util.TokenizerFactory;
@@ -31,7 +29,6 @@ import org.elasticsearch.ElasticsearchException;
 import org.elasticsearch.action.admin.cluster.node.info.PluginsInfo;
 import org.elasticsearch.bootstrap.JarHell;
 import org.elasticsearch.common.Strings;
-import org.elasticsearch.common.collect.MapBuilder;
 import org.elasticsearch.common.collect.Tuple;
 import org.elasticsearch.common.component.AbstractComponent;
 import org.elasticsearch.common.component.LifecycleComponent;
@@ -40,7 +37,6 @@ import org.elasticsearch.common.io.FileSystemUtils;
 import org.elasticsearch.common.logging.ESLogger;
 import org.elasticsearch.common.logging.Loggers;
 import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.env.Environment;
 
 import java.io.Closeable;
 import java.io.IOException;
@@ -87,10 +83,10 @@ public class PluginsService extends AbstractComponent {
     /**
      * Constructs a new PluginService
      * @param settings The settings of the system
-     * @param environment The environment of the system
+     * @param pluginsDirectory The directory plugins exist in, or null if plugins should not be loaded from the filesystem
      * @param classpathPlugins Plugins that exist in the classpath which should be loaded
      */
-    public PluginsService(Settings settings, Environment environment, Collection<Class<? extends Plugin>> classpathPlugins) {
+    public PluginsService(Settings settings, Path pluginsDirectory, Collection<Class<? extends Plugin>> classpathPlugins) {
         super(settings);
 
         List<Tuple<PluginInfo, Plugin>> tupleBuilder = new ArrayList<>();
@@ -106,11 +102,13 @@ public class PluginsService extends AbstractComponent {
         }
 
         // now, find all the ones that are in plugins/
-        try {
-          List<Bundle> bundles = getPluginBundles(environment);
-          tupleBuilder.addAll(loadBundles(bundles));
-        } catch (IOException ex) {
-          throw new IllegalStateException("Unable to initialize plugins", ex);
+        if (pluginsDirectory != null) {
+            try {
+                List<Bundle> bundles = getPluginBundles(pluginsDirectory);
+                tupleBuilder.addAll(loadBundles(bundles));
+            } catch (IOException ex) {
+                throw new IllegalStateException("Unable to initialize plugins", ex);
+            }
         }
 
         plugins = Collections.unmodifiableList(tupleBuilder);
@@ -281,10 +279,9 @@ public class PluginsService extends AbstractComponent {
         List<URL> urls = new ArrayList<>();
     }
 
-    static List<Bundle> getPluginBundles(Environment environment) throws IOException {
+    static List<Bundle> getPluginBundles(Path pluginsDirectory) throws IOException {
         ESLogger logger = Loggers.getLogger(PluginsService.class);
 
-        Path pluginsDirectory = environment.pluginsFile();
         // TODO: remove this leniency, but tests bogusly rely on it
         if (!isAccessibleDirectory(pluginsDirectory, logger)) {
             return Collections.emptyList();

+ 1 - 1
core/src/main/java/org/elasticsearch/tribe/TribeService.java

@@ -137,7 +137,7 @@ public class TribeService extends AbstractLifecycleComponent<TribeService> {
             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;

+ 1 - 1
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<Class<? extends Plugin>> plugins = Collections.<Class<? extends Plugin>>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();

+ 1 - 1
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<Class<? extends Plugin>> plugins = Collections.<Class<? extends Plugin>>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();

+ 1 - 1
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<Class<? extends Plugin>> plugins = Collections.<Class<? extends Plugin>>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();

+ 1 - 1
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<Class<? extends Plugin>> plugins = Collections.<Class<? extends Plugin>>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();

+ 1 - 1
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()) {

+ 2 - 2
core/src/test/java/org/elasticsearch/node/MockNode.java

@@ -38,8 +38,8 @@ public class MockNode extends Node {
     private Version version;
     private Collection<Class<? extends Plugin>> plugins;
 
-    public MockNode(Settings settings, boolean loadConfigSettings, Version version, Collection<Class<? extends Plugin>> classpathPlugins) {
-        super(settings, loadConfigSettings, version, classpathPlugins);
+    public MockNode(Settings settings, Version version, Collection<Class<? extends Plugin>> classpathPlugins) {
+        super(settings, version, classpathPlugins);
         this.version = version;
         this.plugins = classpathPlugins;
     }

+ 136 - 76
core/src/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java

@@ -19,6 +19,7 @@
 
 package org.elasticsearch.node.internal;
 
+import org.elasticsearch.cluster.ClusterName;
 import org.elasticsearch.common.cli.CliToolTestCase;
 import org.elasticsearch.common.cli.Terminal;
 import org.elasticsearch.common.collect.Tuple;
@@ -28,58 +29,113 @@ import org.elasticsearch.env.Environment;
 import org.elasticsearch.test.ESTestCase;
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import static org.elasticsearch.common.settings.Settings.settingsBuilder;
 import static org.hamcrest.Matchers.*;
 
 public class InternalSettingsPreparerTests extends ESTestCase {
-    @Rule
-    public ExpectedException expectedException = ExpectedException.none();
+
+    Map<String, String> savedProperties = new HashMap<>();
+    Settings baseEnvSettings;
 
     @Before
-    public void setupSystemProperties() {
-        System.setProperty("es.node.zone", "foo");
-        System.setProperty("name", "sys-prop-name");
+    public void saveSettingsSystemProperties() {
+        // clear out any properties the settings preparer may look for
+        savedProperties.clear();
+        for (Object propObj : System.getProperties().keySet()) {
+            String property = (String)propObj;
+            // NOTE: these prefixes are prefixes of the defaults, so both are handled here
+            for (String prefix : InternalSettingsPreparer.PROPERTY_PREFIXES) {
+                if (property.startsWith(prefix)) {
+                    savedProperties.put(property, System.getProperty(property));
+                }
+            }
+        }
+        String name = System.getProperty("name");
+        if (name != null) {
+            savedProperties.put("name", name);
+        }
+        for (String property : savedProperties.keySet()) {
+            System.clearProperty(property);
+        }
     }
 
     @After
-    public void cleanupSystemProperties() {
-        System.clearProperty("es.node.zone");
-        System.clearProperty("name");
+    public void restoreSettingsSystemProperties() {
+        for (Map.Entry<String, String> property : savedProperties.entrySet()) {
+            System.setProperty(property.getKey(), property.getValue());
+        }
+    }
+
+    @Before
+    public void createBaseEnvSettings() {
+        baseEnvSettings = settingsBuilder()
+            .put("path.home", createTempDir())
+            .build();
+    }
+
+    @After
+    public void clearBaseEnvSettings() {
+        baseEnvSettings = null;
+    }
+
+    public void testEmptySettings() {
+        Settings settings = InternalSettingsPreparer.prepareSettings(Settings.EMPTY);
+        assertNotNull(settings.get("name")); // a name was set
+        assertNotNull(settings.get(ClusterName.SETTING)); // a cluster name was set
+        assertEquals(settings.toString(), 2, settings.names().size());
+
+        Environment env = InternalSettingsPreparer.prepareEnvironment(baseEnvSettings, null);
+        settings = env.settings();
+        assertNotNull(settings.get("name")); // a name was set
+        assertNotNull(settings.get(ClusterName.SETTING)); // a cluster name was set
+        assertEquals(settings.toString(), 3 /* path.home is in the base settings */, settings.names().size());
+        String home = baseEnvSettings.get("path.home");
+        String configDir = env.configFile().toString();
+        assertTrue(configDir, configDir.startsWith(home));
+    }
+
+    public void testClusterNameDefault() {
+        Settings settings = InternalSettingsPreparer.prepareSettings(Settings.EMPTY);
+        assertEquals(ClusterName.DEFAULT.value(), settings.get(ClusterName.SETTING));
+        settings = InternalSettingsPreparer.prepareEnvironment(baseEnvSettings, null).settings();
+        assertEquals(ClusterName.DEFAULT.value(), settings.get(ClusterName.SETTING));
     }
 
-    @Test
     public void testIgnoreSystemProperties() {
-        Settings settings = settingsBuilder()
+        try {
+            System.setProperty("es.node.zone", "foo");
+            Settings settings = settingsBuilder()
                 .put("node.zone", "bar")
-                .put("path.home", createTempDir().toString())
+                .put(baseEnvSettings)
                 .build();
-        Tuple<Settings, Environment> tuple = InternalSettingsPreparer.prepareSettings(settings, true);
-        // Should use setting from the system property
-        assertThat(tuple.v1().get("node.zone"), equalTo("foo"));
+            Environment env = InternalSettingsPreparer.prepareEnvironment(settings, null);
+            // Should use setting from the system property
+            assertThat(env.settings().get("node.zone"), equalTo("foo"));
 
-        settings = settingsBuilder()
+            settings = settingsBuilder()
                 .put(InternalSettingsPreparer.IGNORE_SYSTEM_PROPERTIES_SETTING, true)
                 .put("node.zone", "bar")
-                .put("path.home", createTempDir().toString())
+                .put(baseEnvSettings)
                 .build();
-        tuple = InternalSettingsPreparer.prepareSettings(settings, true);
-        // Should use setting from the system property
-        assertThat(tuple.v1().get("node.zone"), equalTo("bar"));
+            env = InternalSettingsPreparer.prepareEnvironment(settings, null);
+            // Should use setting from the system property
+            assertThat(env.settings().get("node.zone"), equalTo("bar"));
+        } finally {
+            System.clearProperty("es.node.zone");
+        }
     }
 
-    @Test
     public void testReplacePromptPlaceholders() {
         final List<String> replacedSecretProperties = new ArrayList<>();
         final List<String> replacedTextProperties = new ArrayList<>();
@@ -102,6 +158,7 @@ public class InternalSettingsPreparerTests extends ESTestCase {
         };
 
         Settings.Builder builder = settingsBuilder()
+                .put(baseEnvSettings)
                 .put("password.replace", InternalSettingsPreparer.SECRET_PROMPT_VALUE)
                 .put("dont.replace", "prompt:secret")
                 .put("dont.replace2", "_prompt:secret_")
@@ -109,8 +166,7 @@ public class InternalSettingsPreparerTests extends ESTestCase {
                 .put("dont.replace4", "__prompt:text_")
                 .put("dont.replace5", "prompt:secret__")
                 .put("replace_me", InternalSettingsPreparer.TEXT_PROMPT_VALUE);
-        Settings settings = builder.build();
-        settings = InternalSettingsPreparer.replacePromptPlaceholders(settings, terminal);
+        Settings settings = InternalSettingsPreparer.prepareEnvironment(builder.build(), terminal).settings();
 
         assertThat(replacedSecretProperties.size(), is(1));
         assertThat(replacedTextProperties.size(), is(1));
@@ -125,70 +181,70 @@ public class InternalSettingsPreparerTests extends ESTestCase {
         assertThat(settings.get("dont.replace5"), equalTo("prompt:secret__"));
     }
 
-    @Test
     public void testReplaceSecretPromptPlaceholderWithNullTerminal() {
         Settings.Builder builder = settingsBuilder()
+                .put(baseEnvSettings)
                 .put("replace_me1", InternalSettingsPreparer.SECRET_PROMPT_VALUE);
         try {
-            InternalSettingsPreparer.replacePromptPlaceholders(builder.build(), null);
+            InternalSettingsPreparer.prepareEnvironment(builder.build(), null);
             fail("an exception should have been thrown since no terminal was provided!");
         } catch (UnsupportedOperationException e) {
             assertThat(e.getMessage(), containsString("with value [" + InternalSettingsPreparer.SECRET_PROMPT_VALUE + "]"));
         }
     }
 
-    @Test
     public void testReplaceTextPromptPlaceholderWithNullTerminal() {
         Settings.Builder builder = settingsBuilder()
+                .put(baseEnvSettings)
                 .put("replace_me1", InternalSettingsPreparer.TEXT_PROMPT_VALUE);
         try {
-            InternalSettingsPreparer.replacePromptPlaceholders(builder.build(), null);
+            InternalSettingsPreparer.prepareEnvironment(builder.build(), null);
             fail("an exception should have been thrown since no terminal was provided!");
         } catch (UnsupportedOperationException e) {
             assertThat(e.getMessage(), containsString("with value [" + InternalSettingsPreparer.TEXT_PROMPT_VALUE + "]"));
         }
     }
 
-    @Test
     public void testNameSettingsPreference() {
-        // Test system property overrides node.name
-        Settings settings = settingsBuilder()
+        try {
+            System.setProperty("name", "sys-prop-name");
+            // Test system property overrides node.name
+            Settings settings = settingsBuilder()
                 .put("node.name", "node-name")
-                .put("path.home", createTempDir().toString())
+                .put(baseEnvSettings)
                 .build();
-        Tuple<Settings, Environment> tuple = InternalSettingsPreparer.prepareSettings(settings, true);
-        assertThat(tuple.v1().get("name"), equalTo("sys-prop-name"));
+            Environment env = InternalSettingsPreparer.prepareEnvironment(settings, null);
+            assertThat(env.settings().get("name"), equalTo("sys-prop-name"));
 
-        // test name in settings overrides sys prop and node.name
-        settings = settingsBuilder()
+            // test name in settings overrides sys prop and node.name
+            settings = settingsBuilder()
                 .put("name", "name-in-settings")
                 .put("node.name", "node-name")
-                .put("path.home", createTempDir().toString())
+                .put(baseEnvSettings)
                 .build();
-        tuple = InternalSettingsPreparer.prepareSettings(settings, true);
-        assertThat(tuple.v1().get("name"), equalTo("name-in-settings"));
+            env = InternalSettingsPreparer.prepareEnvironment(settings, null);
+            assertThat(env.settings().get("name"), equalTo("name-in-settings"));
 
-        // test only node.name in settings
-        System.clearProperty("name");
-        settings = settingsBuilder()
+            // test only node.name in settings
+            System.clearProperty("name");
+            settings = settingsBuilder()
                 .put("node.name", "node-name")
-                .put("path.home", createTempDir().toString())
+                .put(baseEnvSettings)
                 .build();
-        tuple = InternalSettingsPreparer.prepareSettings(settings, true);
-        assertThat(tuple.v1().get("name"), equalTo("node-name"));
+            env = InternalSettingsPreparer.prepareEnvironment(settings, null);
+            assertThat(env.settings().get("name"), equalTo("node-name"));
 
-        // test no name at all results in name being set
-        settings = settingsBuilder()
-                .put("path.home", createTempDir().toString())
-                .build();
-        tuple = InternalSettingsPreparer.prepareSettings(settings, true);
-        assertThat(tuple.v1().get("name"), not("name-in-settings"));
-        assertThat(tuple.v1().get("name"), not("sys-prop-name"));
-        assertThat(tuple.v1().get("name"), not("node-name"));
-        assertThat(tuple.v1().get("name"), notNullValue());
+            // test no name at all results in name being set
+            env = InternalSettingsPreparer.prepareEnvironment(baseEnvSettings, null);
+            assertThat(env.settings().get("name"), not("name-in-settings"));
+            assertThat(env.settings().get("name"), not("sys-prop-name"));
+            assertThat(env.settings().get("name"), not("node-name"));
+            assertThat(env.settings().get("name"), notNullValue());
+        } finally {
+            System.clearProperty("name");
+        }
     }
 
-    @Test
     public void testPromptForNodeNameOnlyPromptsOnce() {
         final AtomicInteger counter = new AtomicInteger();
         final Terminal terminal = new CliToolTestCase.MockTerminal() {
@@ -207,27 +263,30 @@ public class InternalSettingsPreparerTests extends ESTestCase {
 
         System.clearProperty("name");
         Settings settings = Settings.builder()
-                .put("path.home", createTempDir())
+                .put(baseEnvSettings)
                 .put("node.name", InternalSettingsPreparer.TEXT_PROMPT_VALUE)
                 .build();
-        Tuple<Settings, Environment> tuple = InternalSettingsPreparer.prepareSettings(settings, false, terminal);
-        settings = tuple.v1();
+        Environment env = InternalSettingsPreparer.prepareEnvironment(settings, terminal);
+        settings = env.settings();
         assertThat(counter.intValue(), is(1));
         assertThat(settings.get("name"), is("prompted name 0"));
         assertThat(settings.get("node.name"), is("prompted name 0"));
     }
 
-    @Test(expected = SettingsException.class)
     public void testGarbageIsNotSwallowed() throws IOException {
-        InputStream garbage = getClass().getResourceAsStream("/config/garbage/garbage.yml");
-        Path home = createTempDir();
-        Path config = home.resolve("config");
-        Files.createDirectory(config);
-        Files.copy(garbage, config.resolve("elasticsearch.yml"));
-        InternalSettingsPreparer.prepareSettings(settingsBuilder()
+        try {
+            InputStream garbage = getClass().getResourceAsStream("/config/garbage/garbage.yml");
+            Path home = createTempDir();
+            Path config = home.resolve("config");
+            Files.createDirectory(config);
+            Files.copy(garbage, config.resolve("elasticsearch.yml"));
+            InternalSettingsPreparer.prepareEnvironment(settingsBuilder()
                 .put("config.ignore_system_properties", true)
-                .put("path.home", home)
-                .build(), true);
+                .put(baseEnvSettings)
+                .build(), null);
+        } catch (SettingsException e) {
+            assertEquals("Failed to load settings from [elasticsearch.yml]", e.getMessage());
+        }
     }
 
     public void testMultipleSettingsFileNotAllowed() throws IOException {
@@ -239,14 +298,15 @@ public class InternalSettingsPreparerTests extends ESTestCase {
         Files.copy(yaml, config.resolve("elasticsearch.yaml"));
         Files.copy(properties, config.resolve("elasticsearch.properties"));
 
-        expectedException.expect(SettingsException.class);
-        expectedException.expectMessage("multiple settings files found with suffixes: ");
-        expectedException.expectMessage("yaml");
-        expectedException.expectMessage("properties");
-
-        InternalSettingsPreparer.prepareSettings(settingsBuilder()
+        try {
+            InternalSettingsPreparer.prepareEnvironment(settingsBuilder()
                 .put("config.ignore_system_properties", true)
-                .put("path.home", home)
-                .build(), true);
+                .put(baseEnvSettings)
+                .build(), null);
+        } catch (SettingsException e) {
+            assertTrue(e.getMessage(), e.getMessage().contains("multiple settings files found with suffixes"));
+            assertTrue(e.getMessage(), e.getMessage().contains(".yaml"));
+            assertTrue(e.getMessage(), e.getMessage().contains(".properties"));
+        }
     }
 }

+ 14 - 17
core/src/test/java/org/elasticsearch/plugins/PluginManagerIT.java

@@ -88,18 +88,18 @@ import static org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1;
 // if its in your classpath, then do not use plugins!!!!!!
 public class PluginManagerIT extends ESIntegTestCase {
 
-    private Tuple<Settings, Environment> initialSettings;
+    private Environment environment;
     private CaptureOutputTerminal terminal = new CaptureOutputTerminal();
 
     @Before
     public void setup() throws Exception {
-        initialSettings = buildInitialSettings();
-        System.setProperty("es.default.path.home", initialSettings.v1().get("path.home"));
-        Path binDir = initialSettings.v2().binFile();
+        environment = buildInitialSettings();
+        System.setProperty("es.default.path.home", environment.settings().get("path.home"));
+        Path binDir = environment.binFile();
         if (!Files.exists(binDir)) {
             Files.createDirectories(binDir);
         }
-        Path configDir = initialSettings.v2().configFile();
+        Path configDir = environment.configFile();
         if (!Files.exists(configDir)) {
             Files.createDirectories(configDir);
         }
@@ -206,11 +206,10 @@ public class PluginManagerIT extends ESIntegTestCase {
             "jvm", "true",
             "classname", "FakePlugin");
 
-        Environment env = initialSettings.v2();
-        Path binDir = env.binFile();
+        Path binDir = environment.binFile();
         Path pluginBinDir = binDir.resolve(pluginName);
 
-        Path pluginConfigDir = env.configFile().resolve(pluginName);
+        Path pluginConfigDir = environment.configFile().resolve(pluginName);
         assertStatusOk("install " + pluginUrl + " --verbose");
 
         terminal.getTerminalOutput().clear();
@@ -252,8 +251,7 @@ public class PluginManagerIT extends ESIntegTestCase {
             "jvm", "true",
             "classname", "FakePlugin");
 
-        Environment env = initialSettings.v2();
-        Path pluginConfigDir = env.configFile().resolve(pluginName);
+        Path pluginConfigDir = environment.configFile().resolve(pluginName);
 
         assertStatusOk(String.format(Locale.ROOT, "install %s --verbose", pluginUrl));
 
@@ -355,8 +353,7 @@ public class PluginManagerIT extends ESIntegTestCase {
             "jvm", "true",
             "classname", "FakePlugin");
 
-        Environment env = initialSettings.v2();
-        Path binDir = env.binFile();
+        Path binDir = environment.binFile();
         Path pluginBinDir = binDir.resolve(pluginName);
 
         assertStatusOk(String.format(Locale.ROOT, "install %s --verbose", pluginUrl));
@@ -372,7 +369,7 @@ public class PluginManagerIT extends ESIntegTestCase {
 
     @Test
     public void testListInstalledEmptyWithExistingPluginDirectory() throws IOException {
-        Files.createDirectory(initialSettings.v2().pluginsFile());
+        Files.createDirectory(environment.pluginsFile());
         assertStatusOk("list");
         assertThat(terminal.getTerminalOutput(), hasItem(containsString("No plugin detected")));
     }
@@ -407,7 +404,7 @@ public class PluginManagerIT extends ESIntegTestCase {
         assertStatusOk(String.format(Locale.ROOT, "install %s --verbose", pluginUrl));
         assertThatPluginIsListed(pluginName);
         // We want to check that Plugin Manager moves content to _site
-        assertFileExists(initialSettings.v2().pluginsFile().resolve(pluginName).resolve("_site"));
+        assertFileExists(environment.pluginsFile().resolve(pluginName).resolve("_site"));
     }
 
     @Test
@@ -423,7 +420,7 @@ public class PluginManagerIT extends ESIntegTestCase {
         assertStatus(String.format(Locale.ROOT, "install %s --verbose", pluginUrl),
                 ExitStatus.IO_ERROR);
         assertThatPluginIsNotListed(pluginName);
-        assertFileNotExists(initialSettings.v2().pluginsFile().resolve(pluginName).resolve("_site"));
+        assertFileNotExists(environment.pluginsFile().resolve(pluginName).resolve("_site"));
     }
 
     private void singlePluginInstallAndRemove(String pluginDescriptor, String pluginName, String pluginCoordinates) throws IOException {
@@ -648,11 +645,11 @@ public class PluginManagerIT extends ESIntegTestCase {
 
 
 
-    private Tuple<Settings, Environment> buildInitialSettings() throws IOException {
+    private Environment buildInitialSettings() throws IOException {
         Settings settings = settingsBuilder()
                 .put("http.enabled", true)
                 .put("path.home", createTempDir()).build();
-        return InternalSettingsPreparer.prepareSettings(settings, false);
+        return InternalSettingsPreparer.prepareEnvironment(settings, null);
     }
 
     private void assertStatusOk(String command) {

+ 1 - 1
core/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java

@@ -57,7 +57,7 @@ public class PluginsServiceTests extends ESTestCase {
     }
 
     static PluginsService newPluginsService(Settings settings, Class<? extends Plugin>... classpathPlugins) {
-        return new PluginsService(settings, new Environment(settings), Arrays.asList(classpathPlugins));
+        return new PluginsService(settings, new Environment(settings).pluginsFile(), Arrays.asList(classpathPlugins));
     }
 
     public void testAdditionalSettings() {

+ 2 - 2
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<Class<? extends Plugin>> plugins = node.getPlugins();
             Version version = node.getVersion();
-            node = new MockNode(finalSettings, true, version, plugins);
+            node = new MockNode(finalSettings, version, plugins);
             node.start();
         }
 

+ 1 - 1
core/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortIntegrationIT.java

@@ -72,7 +72,7 @@ public class NettyTransportMultiPortIntegrationIT extends ESIntegTestCase {
                 .put(TransportModule.TRANSPORT_TYPE_KEY, "netty")
                 .put("path.home", createTempDir().toString())
                 .build();
-        try (TransportClient transportClient = TransportClient.builder().settings(settings).loadConfigSettings(false).build()) {
+        try (TransportClient transportClient = TransportClient.builder().settings(settings).build()) {
             transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), randomPort));
             ClusterHealthResponse response = transportClient.admin().cluster().prepareHealth().get();
             assertThat(response.getStatus(), is(ClusterHealthStatus.GREEN));

+ 11 - 0
docs/reference/migration/migrate_2_0/java.asciidoc

@@ -21,6 +21,17 @@ Settings settings = Settings.settingsBuilder()
 Client client = TransportClient.builder().settings(settings).build();
 --------------------------------------------------
 
+The transport client also no longer supports loading settings from config files.
+If you have have a config file, you can load into settings yourself before
+consturcting the transport client:
+
+[source,java]
+--------------------------------------------------
+Settings settings = Settings.settingsBuilder()
+        .loadFromPath(pathToYourSettingsFile).build();
+Client client = TransportClient.builder().settings(settings).build();
+--------------------------------------------------
+
 ==== Automatically thread client listeners
 
 Previously, the user had to set request listener threads to `true` when on the