diff --git a/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java b/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java index 8a88695aa01..4835d411a8d 100644 --- a/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java +++ b/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java @@ -195,9 +195,9 @@ final class Bootstrap { } } - private static Tuple initialSettings(boolean foreground) { + private static Environment initialSettings(boolean foreground) { Terminal terminal = foreground ? Terminal.DEFAULT : null; - return InternalSettingsPreparer.prepareSettingsAndEnvironment(EMPTY_SETTINGS, terminal); + return InternalSettingsPreparer.prepareEnvironment(EMPTY_SETTINGS, terminal); } private void start() { @@ -234,9 +234,8 @@ final class Bootstrap { 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/common/cli/CliTool.java b/core/src/main/java/org/elasticsearch/common/cli/CliTool.java index 80426df217e..d264232aba1 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 @@ public abstract class CliTool { Preconditions.checkArgument(config.cmds().size() != 0, "At least one command must be configured"); this.config = config; this.terminal = terminal; - Tuple tuple = InternalSettingsPreparer.prepareSettingsAndEnvironment(EMPTY_SETTINGS, 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/node/Node.java b/core/src/main/java/org/elasticsearch/node/Node.java index 8097062da75..2a385f00a03 100644 --- a/core/src/main/java/org/elasticsearch/node/Node.java +++ b/core/src/main/java/org/elasticsearch/node/Node.java @@ -133,21 +133,20 @@ public class Node implements Releasable { Node(Settings preparedSettings, boolean loadConfigSettings, Version version, Collection> classpathPlugins) { final Settings pSettings = settingsBuilder().put(preparedSettings) .put(Client.CLIENT_TYPE_SETTING, CLIENT_TYPE).build(); - Tuple tuple = InternalSettingsPreparer.prepareSettingsAndEnvironment(pSettings, null); - tuple = new Tuple<>(TribeService.processSettings(tuple.v1()), tuple.v2()); + Environment env = InternalSettingsPreparer.prepareEnvironment(pSettings, null); + Settings settings = TribeService.processSettings(env.settings()); - ESLogger logger = Loggers.getLogger(Node.class, tuple.v1().get("name")); + ESLogger logger = Loggers.getLogger(Node.class, settings.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()); } - this.pluginsService = new PluginsService(tuple.v1(), tuple.v2().pluginsFile(), classpathPlugins); + this.pluginsService = new PluginsService(settings, env.pluginsFile(), classpathPlugins); this.settings = pluginsService.updatedSettings(); // create the environment based on the finalized (processed) view of the settings this.environment = new Environment(this.settings()); 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 4751ad9023b..c6c79d9068b 100644 --- a/core/src/main/java/org/elasticsearch/node/internal/InternalSettingsPreparer.java +++ b/core/src/main/java/org/elasticsearch/node/internal/InternalSettingsPreparer.java @@ -80,7 +80,7 @@ public class InternalSettingsPreparer { * @param terminal the Terminal to use for input/output * @return the {@link Settings} and {@link Environment} as a {@link Tuple} */ - public static Tuple prepareSettingsAndEnvironment(Settings input, Terminal terminal) { + public static Environment prepareEnvironment(Settings input, Terminal terminal) { // just create enough settings to build the environment Settings.Builder output = settingsBuilder(); initializeSettings(output, input, true); @@ -134,7 +134,7 @@ public class InternalSettingsPreparer { // we put back the path.logs so we can use it in the logging configuration file output.put("path.logs", cleanPath(environment.logsFile().toAbsolutePath().toString())); - return new Tuple<>(output.build(), environment); + return new Environment(output.build()); } private static boolean useSystemProperties(Settings input) { diff --git a/core/src/main/java/org/elasticsearch/plugins/PluginManagerCliParser.java b/core/src/main/java/org/elasticsearch/plugins/PluginManagerCliParser.java index 6c1faa9f26d..c24b823c959 100644 --- a/core/src/main/java/org/elasticsearch/plugins/PluginManagerCliParser.java +++ b/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 initialSettings = InternalSettingsPreparer.prepareSettingsAndEnvironment(EMPTY, 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/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java b/core/src/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java index a94e27a4d22..4cd61ebdd14 100644 --- a/core/src/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java +++ b/core/src/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java @@ -29,9 +29,6 @@ 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; @@ -98,20 +95,20 @@ public class InternalSettingsPreparerTests extends ESTestCase { assertNotNull(settings.get(ClusterName.SETTING)); // a cluster name was set assertEquals(settings.toString(), 2, settings.names().size()); - Tuple settingsAndEnv = InternalSettingsPreparer.prepareSettingsAndEnvironment(baseEnvSettings, null); - settings = settingsAndEnv.v1(); + 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 = settingsAndEnv.v2().configFile().toString(); + 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.prepareSettingsAndEnvironment(baseEnvSettings, null).v1(); + settings = InternalSettingsPreparer.prepareEnvironment(baseEnvSettings, null).settings(); assertEquals(ClusterName.DEFAULT.value(), settings.get(ClusterName.SETTING)); } @@ -122,18 +119,18 @@ public class InternalSettingsPreparerTests extends ESTestCase { .put("node.zone", "bar") .put(baseEnvSettings) .build(); - Tuple tuple = InternalSettingsPreparer.prepareSettingsAndEnvironment(settings, null); + Environment env = InternalSettingsPreparer.prepareEnvironment(settings, null); // Should use setting from the system property - assertThat(tuple.v1().get("node.zone"), equalTo("foo")); + assertThat(env.settings().get("node.zone"), equalTo("foo")); settings = settingsBuilder() .put(InternalSettingsPreparer.IGNORE_SYSTEM_PROPERTIES_SETTING, true) .put("node.zone", "bar") .put(baseEnvSettings) .build(); - tuple = InternalSettingsPreparer.prepareSettingsAndEnvironment(settings, null); + env = InternalSettingsPreparer.prepareEnvironment(settings, null); // Should use setting from the system property - assertThat(tuple.v1().get("node.zone"), equalTo("bar")); + assertThat(env.settings().get("node.zone"), equalTo("bar")); } finally { System.clearProperty("es.node.zone"); } @@ -169,7 +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 = InternalSettingsPreparer.prepareSettingsAndEnvironment(builder.build(), terminal).v1(); + Settings settings = InternalSettingsPreparer.prepareEnvironment(builder.build(), terminal).settings(); assertThat(replacedSecretProperties.size(), is(1)); assertThat(replacedTextProperties.size(), is(1)); @@ -189,7 +186,7 @@ public class InternalSettingsPreparerTests extends ESTestCase { .put(baseEnvSettings) .put("replace_me1", InternalSettingsPreparer.SECRET_PROMPT_VALUE); try { - InternalSettingsPreparer.prepareSettingsAndEnvironment(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 + "]")); @@ -201,7 +198,7 @@ public class InternalSettingsPreparerTests extends ESTestCase { .put(baseEnvSettings) .put("replace_me1", InternalSettingsPreparer.TEXT_PROMPT_VALUE); try { - InternalSettingsPreparer.prepareSettingsAndEnvironment(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 + "]")); @@ -216,8 +213,8 @@ public class InternalSettingsPreparerTests extends ESTestCase { .put("node.name", "node-name") .put(baseEnvSettings) .build(); - Tuple tuple = InternalSettingsPreparer.prepareSettingsAndEnvironment(settings, null); - 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() @@ -225,8 +222,8 @@ public class InternalSettingsPreparerTests extends ESTestCase { .put("node.name", "node-name") .put(baseEnvSettings) .build(); - tuple = InternalSettingsPreparer.prepareSettingsAndEnvironment(settings, null); - 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"); @@ -234,15 +231,15 @@ public class InternalSettingsPreparerTests extends ESTestCase { .put("node.name", "node-name") .put(baseEnvSettings) .build(); - tuple = InternalSettingsPreparer.prepareSettingsAndEnvironment(settings, null); - 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 - tuple = InternalSettingsPreparer.prepareSettingsAndEnvironment(baseEnvSettings, null); - 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()); + 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"); } @@ -269,8 +266,8 @@ public class InternalSettingsPreparerTests extends ESTestCase { .put(baseEnvSettings) .put("node.name", InternalSettingsPreparer.TEXT_PROMPT_VALUE) .build(); - Tuple tuple = InternalSettingsPreparer.prepareSettingsAndEnvironment(settings, 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")); @@ -283,7 +280,7 @@ public class InternalSettingsPreparerTests extends ESTestCase { Path config = home.resolve("config"); Files.createDirectory(config); Files.copy(garbage, config.resolve("elasticsearch.yml")); - InternalSettingsPreparer.prepareSettingsAndEnvironment(settingsBuilder() + InternalSettingsPreparer.prepareEnvironment(settingsBuilder() .put("config.ignore_system_properties", true) .put(baseEnvSettings) .build(), null); @@ -302,7 +299,7 @@ public class InternalSettingsPreparerTests extends ESTestCase { Files.copy(properties, config.resolve("elasticsearch.properties")); try { - InternalSettingsPreparer.prepareSettingsAndEnvironment(settingsBuilder() + InternalSettingsPreparer.prepareEnvironment(settingsBuilder() .put("config.ignore_system_properties", true) .put(baseEnvSettings) .build(), null); diff --git a/core/src/test/java/org/elasticsearch/plugins/PluginManagerIT.java b/core/src/test/java/org/elasticsearch/plugins/PluginManagerIT.java index 73b4d22100e..6a32359bf56 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 @@ 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 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 buildInitialSettings() throws IOException { + private Environment buildInitialSettings() throws IOException { Settings settings = settingsBuilder() .put("http.enabled", true) .put("path.home", createTempDir()).build(); - return InternalSettingsPreparer.prepareSettingsAndEnvironment(settings, null); + return InternalSettingsPreparer.prepareEnvironment(settings, null); } private void assertStatusOk(String command) {