From 5cd65d01f1a0da65e7f544114f222a377e3bd31c Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Tue, 8 Sep 2015 13:28:21 -0700 Subject: [PATCH] Merge pull request #13383 from rjernst/go_away_transport_paths Remove environment from transport client --- .../elasticsearch/bootstrap/Bootstrap.java | 11 +- .../client/transport/TransportClient.java | 20 +- .../org/elasticsearch/common/cli/CliTool.java | 5 +- .../common/logging/log4j/LogConfigurator.java | 10 +- .../java/org/elasticsearch/node/Node.java | 45 ++-- .../org/elasticsearch/node/NodeBuilder.java | 16 +- .../internal/InternalSettingsPreparer.java | 245 +++++++++--------- .../elasticsearch/plugins/PluginManager.java | 2 +- .../plugins/PluginManagerCliParser.java | 4 +- .../elasticsearch/plugins/PluginsService.java | 21 +- .../org/elasticsearch/tribe/TribeService.java | 2 +- .../RoutingBackwardCompatibilityTests.java | 2 +- .../InternalSettingsPreparerTests.java | 212 +++++++++------ .../plugins/PluginManagerIT.java | 31 +-- .../plugins/PluginsServiceTests.java | 4 +- .../NettyTransportMultiPortIntegrationIT.java | 2 +- .../migration/migrate_2_0/java.asciidoc | 11 + 17 files changed, 345 insertions(+), 298 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java b/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java index bf37fc2a9b0ad..b73045abe63b8 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 @@ public void run() { .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 @@ private static void setupLogging(Settings settings, Environment environment) { } } - private static Tuple 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 @@ static void init(String[] args) throws Throwable { foreground = false; } - Tuple 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); diff --git a/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java b/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java index a8e2bf54568a1..eb4945998f951 100644 --- a/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java +++ b/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java @@ -82,7 +82,6 @@ public static Builder builder() { public static class Builder { private Settings settings = Settings.EMPTY; - private boolean loadConfigSettings = true; /** * The settings to configure the transport client with. @@ -99,30 +98,20 @@ public Builder settings(Settings settings) { 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; - } - /** * Builds a new instance of the transport client. */ public TransportClient build() { - Tuple 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()); + PluginsService pluginsService = new PluginsService(settings, null); this.settings = pluginsService.updatedSettings(); Version version = Version.CURRENT; @@ -138,7 +127,6 @@ public TransportClient build() { 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)); diff --git a/core/src/main/java/org/elasticsearch/common/cli/CliTool.java b/core/src/main/java/org/elasticsearch/common/cli/CliTool.java index b3533b59417f1..d264232aba1c2 100644 --- a/core/src/main/java/org/elasticsearch/common/cli/CliTool.java +++ b/core/src/main/java/org/elasticsearch/common/cli/CliTool.java @@ -104,9 +104,8 @@ protected CliTool(CliToolConfig config, Terminal terminal) { Preconditions.checkArgument(config.cmds().size() != 0, "At least one command must be configured"); this.config = config; this.terminal = terminal; - Tuple 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) { 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 0b4cdbdbd4409..3b6e3bf27ef1d 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 @@ -40,6 +40,7 @@ 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 static void configure(Settings settings) { 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 static void configure(Settings settings) { 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 static void configure(Settings settings) { * 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 +147,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO } } - 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 6da2270002a4b..9b7abaca61b4b 100644 --- a/core/src/main/java/org/elasticsearch/node/Node.java +++ b/core/src/main/java/org/elasticsearch/node/Node.java @@ -117,31 +117,31 @@ public class Node implements Releasable { private final PluginsService pluginsService; private final Client client; - public Node() { - this(Settings.Builder.EMPTY_SETTINGS, true); - } - - public Node(Settings preparedSettings, boolean loadConfigSettings) { + /** + * Constructs a node with the given settings. + * + * @param preparedSettings Base settings to configure the node with + */ + public Node(Settings preparedSettings) { final Settings pSettings = settingsBuilder().put(preparedSettings) .put(Client.CLIENT_TYPE_SETTING, CLIENT_TYPE).build(); - Tuple 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()); // The only place we can actually fake the version a node is running on: Version version = pSettings.getAsVersion("tests.mock.version", Version.CURRENT); - 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()); + this.pluginsService = new PluginsService(tmpSettings, tmpEnv.pluginsFile()); this.settings = pluginsService.updatedSettings(); // create the environment based on the finalized (processed) view of the settings this.environment = new Environment(this.settings()); @@ -165,17 +165,17 @@ public Node(Settings preparedSettings, boolean loadConfigSettings) { 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)); @@ -421,15 +421,4 @@ public boolean isClosed() { public Injector injector() { return this.injector; } - - public static void main(String[] args) throws Exception { - final Node node = new Node(); - node.start(); - Runtime.getRuntime().addShutdownHook(new Thread() { - @Override - public void run() { - node.close(); - } - }); - } } diff --git a/core/src/main/java/org/elasticsearch/node/NodeBuilder.java b/core/src/main/java/org/elasticsearch/node/NodeBuilder.java index 9107cf0833e20..257d380774929 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 @@ *

*

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 NodeBuilder settings(Settings settings) { 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 NodeBuilder clusterName(String clusterName) { * 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 3eb2ed67ccd73..18dd8d4cdcbe9 100644 --- a/core/src/main/java/org/elasticsearch/node/internal/InternalSettingsPreparer.java +++ b/core/src/main/java/org/elasticsearch/node/internal/InternalSettingsPreparer.java @@ -22,7 +22,6 @@ import com.google.common.base.Charsets; import com.google.common.collect.ImmutableList; 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; @@ -44,7 +43,6 @@ 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 +50,22 @@ */ public class InternalSettingsPreparer { - static final List ALLOWED_SUFFIXES = ImmutableList.of(".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 ${prompt.text} - * or ${prompt.secret} 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 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 +73,138 @@ public static Tuple prepareSettings(Settings pSettings, b * and then replacing all property placeholders. If a {@link Terminal} is provided and configuration settings are loaded, * settings with a value of ${prompt.text} or ${prompt.secret} 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 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 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 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 entry : pSettings.getAsMap().entrySet()) { - String setting = entry.getKey(); + List 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 +230,40 @@ static String randomNodeName(Environment environment) { } } - static Settings replacePromptPlaceholders(Settings settings, Terminal terminal) { - UnmodifiableIterator> iter = settings.getAsMap().entrySet().iterator(); - Settings.Builder builder = Settings.builder(); - - while (iter.hasNext()) { - Map.Entry entry = iter.next(); - String value = entry.getValue(); - String key = entry.getKey(); - switch (value) { + private static void replacePromptPlaceholders(Settings.Builder settings, Terminal terminal) { + List secretToPrompt = new ArrayList<>(); + List textToPrompt = new ArrayList<>(); + for (Map.Entry 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"); } diff --git a/core/src/main/java/org/elasticsearch/plugins/PluginManager.java b/core/src/main/java/org/elasticsearch/plugins/PluginManager.java index 8025be2784f0b..162f5daeb9953 100644 --- a/core/src/main/java/org/elasticsearch/plugins/PluginManager.java +++ b/core/src/main/java/org/elasticsearch/plugins/PluginManager.java @@ -320,7 +320,7 @@ private void jarHellCheck(Path candidate, boolean isolated) throws IOException { } // read existing bundles. this does some checks on the installation too. - List bundles = PluginsService.getPluginBundles(environment); + List 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 diff --git a/core/src/main/java/org/elasticsearch/plugins/PluginManagerCliParser.java b/core/src/main/java/org/elasticsearch/plugins/PluginManagerCliParser.java index 7f521fd4339ad..f3e799ca25f79 100644 --- a/core/src/main/java/org/elasticsearch/plugins/PluginManagerCliParser.java +++ b/core/src/main/java/org/elasticsearch/plugins/PluginManagerCliParser.java @@ -51,8 +51,8 @@ public class PluginManagerCliParser extends CliTool { .build(); public static void main(String[] args) { - Tuple 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); } diff --git a/core/src/main/java/org/elasticsearch/plugins/PluginsService.java b/core/src/main/java/org/elasticsearch/plugins/PluginsService.java index 30014b8b09f6a..a282b6538be50 100644 --- a/core/src/main/java/org/elasticsearch/plugins/PluginsService.java +++ b/core/src/main/java/org/elasticsearch/plugins/PluginsService.java @@ -21,7 +21,6 @@ import com.google.common.collect.ImmutableList; 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; @@ -41,7 +40,6 @@ 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; @@ -88,9 +86,9 @@ static class OnModuleReference { /** * 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 */ - public PluginsService(Settings settings, Environment environment) { + public PluginsService(Settings settings, Path pluginsDirectory) { super(settings); ImmutableList.Builder> tupleBuilder = ImmutableList.builder(); @@ -108,11 +106,13 @@ public PluginsService(Settings settings, Environment environment) { } // now, find all the ones that are in plugins/ - try { - List bundles = getPluginBundles(environment); - tupleBuilder.addAll(loadBundles(bundles)); - } catch (IOException ex) { - throw new IllegalStateException("Unable to initialize plugins", ex); + if (pluginsDirectory != null) { + try { + List bundles = getPluginBundles(pluginsDirectory); + tupleBuilder.addAll(loadBundles(bundles)); + } catch (IOException ex) { + throw new IllegalStateException("Unable to initialize plugins", ex); + } } plugins = tupleBuilder.build(); @@ -283,10 +283,9 @@ static class Bundle { List urls = new ArrayList<>(); } - static List getPluginBundles(Environment environment) throws IOException { + static List 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(); diff --git a/core/src/main/java/org/elasticsearch/tribe/TribeService.java b/core/src/main/java/org/elasticsearch/tribe/TribeService.java index f2f21a1d1ca77..5b8a21c0e6794 100644 --- a/core/src/main/java/org/elasticsearch/tribe/TribeService.java +++ b/core/src/main/java/org/elasticsearch/tribe/TribeService.java @@ -133,7 +133,7 @@ public TribeService(Settings settings, ClusterService clusterService, DiscoveryS 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/cluster/routing/RoutingBackwardCompatibilityTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityTests.java index 7a794977c8bfd..a2dbf78681201 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/internal/InternalSettingsPreparerTests.java b/core/src/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java index b5bd8006c025a..4cd61ebdd1432 100644 --- a/core/src/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java +++ b/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.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 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 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 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 replacedSecretProperties = new ArrayList<>(); final List replacedTextProperties = new ArrayList<>(); @@ -102,6 +158,7 @@ public String readText(String message, Object... args) { }; 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 String readText(String message, Object... args) { .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 String readText(String message, Object... args) { 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 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 String readText(String message, Object... args) { System.clearProperty("name"); Settings settings = Settings.builder() - .put("path.home", createTempDir()) + .put(baseEnvSettings) .put("node.name", InternalSettingsPreparer.TEXT_PROMPT_VALUE) .build(); - Tuple 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 void testMultipleSettingsFileNotAllowed() throws IOException { 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")); + } } } diff --git a/core/src/test/java/org/elasticsearch/plugins/PluginManagerIT.java b/core/src/test/java/org/elasticsearch/plugins/PluginManagerIT.java index 8e56b36d9124e..a4faa11678d24 100644 --- a/core/src/test/java/org/elasticsearch/plugins/PluginManagerIT.java +++ b/core/src/test/java/org/elasticsearch/plugins/PluginManagerIT.java @@ -88,18 +88,18 @@ // if its in your classpath, then do not use plugins!!!!!! public class PluginManagerIT extends ESIntegTestCase { - private Tuple 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 void testLocalPluginInstallWithBinAndConfig() throws Exception { "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 void testLocalPluginInstallWithBinAndConfigInAlreadyExistingConfigDir_789 "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 void testLocalPluginInstallWithBinOnly_7152() throws Exception { "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 void testListInstalledEmpty() throws IOException { @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 void testInstallSitePlugin() throws IOException { 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 void testInstallPluginWithBadChecksum() throws IOException { 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 { @@ -647,11 +644,11 @@ public void messageReceived(final ChannelHandlerContext ctx, final MessageEvent - private Tuple 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) { diff --git a/core/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java b/core/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java index 857495a252e64..c064f00b70a33 100644 --- a/core/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java +++ b/core/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java @@ -60,7 +60,7 @@ public void testAdditionalSettings() { .put("my.setting", "test") .put(IndexStoreModule.STORE_TYPE, IndexStoreModule.Type.SIMPLEFS.getSettingsKey()) .putArray("plugin.types", AdditionalSettingsPlugin1.class.getName()).build(); - PluginsService service = new PluginsService(settings, new Environment(settings)); + PluginsService service = new PluginsService(settings, new Environment(settings).pluginsFile()); Settings newSettings = service.updatedSettings(); assertEquals("test", newSettings.get("my.setting")); // previous settings still exist assertEquals("1", newSettings.get("foo.bar")); // added setting exists @@ -71,7 +71,7 @@ public void testAdditionalSettingsClash() { Settings settings = Settings.builder() .put("path.home", createTempDir()) .putArray("plugin.types", AdditionalSettingsPlugin1.class.getName(), AdditionalSettingsPlugin2.class.getName()).build(); - PluginsService service = new PluginsService(settings, new Environment(settings)); + PluginsService service = new PluginsService(settings, new Environment(settings).pluginsFile()); try { service.updatedSettings(); fail("Expected exception when building updated settings"); diff --git a/core/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortIntegrationIT.java b/core/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortIntegrationIT.java index e945f165e76c8..48c02153f27bc 100644 --- a/core/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortIntegrationIT.java +++ b/core/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortIntegrationIT.java @@ -72,7 +72,7 @@ public void testThatTransportClientCanConnect() throws Exception { .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)); diff --git a/docs/reference/migration/migrate_2_0/java.asciidoc b/docs/reference/migration/migrate_2_0/java.asciidoc index f96d79047480a..9871df4e68d29 100644 --- a/docs/reference/migration/migrate_2_0/java.asciidoc +++ b/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