Skip to content

Commit

Permalink
Merge pull request #13383 from rjernst/go_away_transport_paths
Browse files Browse the repository at this point in the history
Remove environment from transport client
  • Loading branch information
rjernst committed Sep 8, 2015
1 parent 9e10e88 commit 5cd65d0
Show file tree
Hide file tree
Showing 17 changed files with 345 additions and 298 deletions.
11 changes: 5 additions & 6 deletions core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java
Expand Up @@ -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();
}

Expand Down Expand Up @@ -195,9 +195,9 @@ private static void setupLogging(Settings settings, Environment environment) {
}
}

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() {
Expand Down Expand Up @@ -234,9 +234,8 @@ static void init(String[] args) throws Throwable {
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);
Expand Down
Expand Up @@ -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.
Expand All @@ -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<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());
PluginsService pluginsService = new PluginsService(settings, null);
this.settings = pluginsService.updatedSettings();

Version version = Version.CURRENT;
Expand All @@ -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));
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/java/org/elasticsearch/common/cli/CliTool.java
Expand Up @@ -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<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) {
Expand Down
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
Expand All @@ -109,18 +111,20 @@ 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);
}

/**
* 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>() {
Expand All @@ -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) {
Expand Down
45 changes: 17 additions & 28 deletions core/src/main/java/org/elasticsearch/node/Node.java
Expand Up @@ -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<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());

// 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());
Expand All @@ -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));
Expand Down Expand Up @@ -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();
}
});
}
}
16 changes: 2 additions & 14 deletions core/src/main/java/org/elasticsearch/node/NodeBuilder.java
Expand Up @@ -26,8 +26,7 @@
* <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/>
Expand Down Expand Up @@ -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}.
*/
Expand Down Expand Up @@ -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 <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.
Expand Down Expand Up @@ -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());
}

/**
Expand Down

0 comments on commit 5cd65d0

Please sign in to comment.