Finish removing loadConfigSettings, and fix node startup to use correct
settings object
This commit is contained in:
parent
92b62c0c6b
commit
2e63290548
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -87,6 +87,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);
|
||||
|
@ -116,11 +117,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 +144,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) {
|
||||
|
|
|
@ -124,29 +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();
|
||||
Environment env = InternalSettingsPreparer.prepareEnvironment(pSettings, null);
|
||||
Settings settings = TribeService.processSettings(env.settings());
|
||||
Environment tmpEnv = InternalSettingsPreparer.prepareEnvironment(pSettings, null);
|
||||
Settings tmpSettings = TribeService.processSettings(tmpEnv.settings());
|
||||
|
||||
ESLogger logger = Loggers.getLogger(Node.class, settings.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()) {
|
||||
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(settings, env.pluginsFile(), 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());
|
||||
|
@ -170,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));
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -81,7 +81,7 @@ public class InternalSettingsPreparer {
|
|||
* @return the {@link Settings} and {@link Environment} as a {@link Tuple}
|
||||
*/
|
||||
public static Environment prepareEnvironment(Settings input, Terminal terminal) {
|
||||
// just create enough settings to build the environment
|
||||
// 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());
|
||||
|
@ -129,11 +129,6 @@ public class InternalSettingsPreparer {
|
|||
initializeSettings(output, input, false);
|
||||
finalizeSettings(output, terminal, environment.configFile());
|
||||
|
||||
environment = new Environment(output.build());
|
||||
|
||||
// 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 Environment(output.build());
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue