Skip to content

Commit

Permalink
Settings: Remove environment from transport client
Browse files Browse the repository at this point in the history
Transport clients run embedded within external applications, so
elasticsearch should not be doing anything with the filesystem, as there
is not elasticsearch home.

This change makes a number of cleanups to the internal API for loading
settings and creating an environment. The loadFromConfig option was
removed, since it was always true except for tests. We now always
attempt to load settings from config a file when an environment is
created. The prepare methods were also simplified so there is now
prepareSettingsAndEnvironment which nodes use, and prepareSettings which
the transport client uses. I also attempted to improve the tests, but
there is a still a lot of follow up work to do there.

closes elastic#13155
  • Loading branch information
rjernst committed Sep 8, 2015
1 parent 2c20658 commit 1ff49eb
Show file tree
Hide file tree
Showing 12 changed files with 292 additions and 219 deletions.
Expand Up @@ -197,7 +197,7 @@ private static void setupLogging(Settings settings, Environment environment) {

private static Tuple<Settings, Environment> initialSettings(boolean foreground) {
Terminal terminal = foreground ? Terminal.DEFAULT : null;
return InternalSettingsPreparer.prepareSettings(EMPTY_SETTINGS, true, terminal);
return InternalSettingsPreparer.prepareSettingsAndEnvironment(EMPTY_SETTINGS, terminal);
}

private void start() {
Expand Down
Expand Up @@ -85,7 +85,6 @@ public static class Builder {

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.
Expand All @@ -102,15 +101,6 @@ 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;
}

/**
* Add the given plugin to the client when it is created.
*/
Expand All @@ -123,17 +113,16 @@ public Builder addPlugin(Class<? extends Plugin> pluginClass) {
* 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;
Expand All @@ -149,7 +138,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));
Expand Down
Expand Up @@ -104,7 +104,7 @@ 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<Settings, Environment> tuple = InternalSettingsPreparer.prepareSettings(EMPTY_SETTINGS, true, terminal);
Tuple<Settings, Environment> tuple = InternalSettingsPreparer.prepareSettingsAndEnvironment(EMPTY_SETTINGS, terminal);
settings = tuple.v1();
env = tuple.v2();
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/elasticsearch/node/Node.java
Expand Up @@ -133,7 +133,7 @@ public Node(Settings preparedSettings, boolean loadConfigSettings) {
Node(Settings preparedSettings, boolean loadConfigSettings, 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<Settings, Environment> tuple = InternalSettingsPreparer.prepareSettingsAndEnvironment(pSettings, null);
tuple = new Tuple<>(TribeService.processSettings(tuple.v1()), tuple.v2());

ESLogger logger = Loggers.getLogger(Node.class, tuple.v1().get("name"));
Expand All @@ -147,7 +147,7 @@ public Node(Settings preparedSettings, boolean loadConfigSettings) {
env.configFile(), Arrays.toString(env.dataFiles()), env.logsFile(), env.pluginsFile());
}

this.pluginsService = new PluginsService(tuple.v1(), tuple.v2(), classpathPlugins);
this.pluginsService = new PluginsService(tuple.v1(), tuple.v2().pluginsFile(), classpathPlugins);
this.settings = pluginsService.updatedSettings();
// create the environment based on the finalized (processed) view of the settings
this.environment = new Environment(this.settings());
Expand Down

0 comments on commit 1ff49eb

Please sign in to comment.