Settings: Remove support for yaml and json config files (#24664)
This commit removes the deprecated support for .yaml and .json files. If the files still exist, the node will fail to start, indicating the file must be converted or renamed. closes #19391
This commit is contained in:
parent
e6535bc771
commit
17f8d2debd
|
@ -298,7 +298,6 @@ final class Bootstrap {
|
|||
throw new BootstrapException(e);
|
||||
}
|
||||
checkForCustomConfFile();
|
||||
checkConfigExtension(environment.configExtension());
|
||||
|
||||
if (environment.pidFile() != null) {
|
||||
try {
|
||||
|
@ -414,14 +413,6 @@ final class Bootstrap {
|
|||
}
|
||||
}
|
||||
|
||||
// pkg private for tests
|
||||
static void checkConfigExtension(String extension) {
|
||||
if (".yaml".equals(extension) || ".json".equals(extension)) {
|
||||
final DeprecationLogger deprecationLogger = new DeprecationLogger(Loggers.getLogger(Bootstrap.class));
|
||||
deprecationLogger.deprecated("elasticsearch{} is deprecated; rename your configuration file to elasticsearch.yml", extension);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressForbidden(reason = "Allowed to exit explicitly in bootstrap phase")
|
||||
private static void exit(int status) {
|
||||
System.exit(status);
|
||||
|
|
|
@ -71,8 +71,6 @@ public class Environment {
|
|||
|
||||
private final Settings settings;
|
||||
|
||||
private final String configExtension;
|
||||
|
||||
private final Path[] dataFiles;
|
||||
|
||||
private final Path[] dataWithClusterFiles;
|
||||
|
@ -104,12 +102,6 @@ public class Environment {
|
|||
private final Path tmpFile = PathUtils.get(System.getProperty("java.io.tmpdir"));
|
||||
|
||||
public Environment(Settings settings) {
|
||||
this(settings, null);
|
||||
}
|
||||
|
||||
// Note: Do not use this ctor, it is for correct deprecation logging in 5.5 and will be removed
|
||||
public Environment(Settings settings, String configExtension) {
|
||||
this.configExtension = configExtension;
|
||||
final Path homeFile;
|
||||
if (PATH_HOME_SETTING.exists(settings)) {
|
||||
homeFile = PathUtils.get(cleanPath(PATH_HOME_SETTING.get(settings)));
|
||||
|
@ -281,11 +273,6 @@ public class Environment {
|
|||
}
|
||||
}
|
||||
|
||||
/** Return then extension of the config file that was loaded, or*/
|
||||
public String configExtension() {
|
||||
return configExtension;
|
||||
}
|
||||
|
||||
// TODO: rename all these "file" methods to "dir"
|
||||
/**
|
||||
* The config directory.
|
||||
|
|
|
@ -86,26 +86,22 @@ public class InternalSettingsPreparer {
|
|||
initializeSettings(output, input, properties);
|
||||
Environment environment = new Environment(output.build());
|
||||
|
||||
output = Settings.builder(); // start with a fresh output
|
||||
boolean settingsFileFound = false;
|
||||
Set<String> foundSuffixes = new HashSet<>();
|
||||
for (String allowedSuffix : ALLOWED_SUFFIXES) {
|
||||
Path path = environment.configFile().resolve("elasticsearch" + allowedSuffix);
|
||||
if (Files.exists(path)) {
|
||||
if (!settingsFileFound) {
|
||||
try {
|
||||
output.loadFromPath(path);
|
||||
} catch (IOException e) {
|
||||
throw new SettingsException("Failed to load settings from " + path.toString(), e);
|
||||
}
|
||||
}
|
||||
settingsFileFound = true;
|
||||
foundSuffixes.add(allowedSuffix);
|
||||
}
|
||||
if (Files.exists(environment.configFile().resolve("elasticsearch.yaml"))) {
|
||||
throw new SettingsException("elasticsearch.yaml was deprecated in 5.5.0 and must be renamed to elasticsearch.yml");
|
||||
}
|
||||
if (foundSuffixes.size() > 1) {
|
||||
throw new SettingsException("multiple settings files found with suffixes: "
|
||||
+ Strings.collectionToDelimitedString(foundSuffixes, ","));
|
||||
|
||||
if (Files.exists(environment.configFile().resolve("elasticsearch.json"))) {
|
||||
throw new SettingsException("elasticsearch.json was deprecated in 5.5.0 and must be converted to elasticsearch.yml");
|
||||
}
|
||||
|
||||
output = Settings.builder(); // start with a fresh output
|
||||
Path path = environment.configFile().resolve("elasticsearch.yml");
|
||||
if (Files.exists(path)) {
|
||||
try {
|
||||
output.loadFromPath(path);
|
||||
} catch (IOException e) {
|
||||
throw new SettingsException("Failed to load settings from " + path.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
// re-initialize settings now that the config file has been loaded
|
||||
|
@ -116,8 +112,7 @@ public class InternalSettingsPreparer {
|
|||
|
||||
// we put back the path.logs so we can use it in the logging configuration file
|
||||
output.put(Environment.PATH_LOGS_SETTING.getKey(), cleanPath(environment.logsFile().toAbsolutePath().toString()));
|
||||
String configExtension = foundSuffixes.isEmpty() ? null : foundSuffixes.iterator().next();
|
||||
return new Environment(output.build(), configExtension);
|
||||
return new Environment(output.build());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.bootstrap;
|
||||
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
public class BootstrapTests extends ESTestCase {
|
||||
|
||||
public void testConfigDeprecation() {
|
||||
Bootstrap.checkConfigExtension(".json");
|
||||
assertWarnings("elasticsearch.json is deprecated; rename your configuration file to elasticsearch.yml");
|
||||
Bootstrap.checkConfigExtension(".yaml");
|
||||
assertWarnings("elasticsearch.yaml is deprecated; rename your configuration file to elasticsearch.yml");
|
||||
Bootstrap.checkConfigExtension(".yml"); // no warnings, will be checked in @After
|
||||
}
|
||||
}
|
|
@ -150,38 +150,24 @@ public class InternalSettingsPreparerTests extends ESTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public void testMultipleSettingsFileNotAllowed() throws IOException {
|
||||
InputStream yaml = getClass().getResourceAsStream("/config/elasticsearch.yaml");
|
||||
InputStream json = getClass().getResourceAsStream("/config/elasticsearch.json");
|
||||
public void testYamlNotAllowed() throws IOException {
|
||||
InputStream yaml = getClass().getResourceAsStream("/config/elasticsearch.yml");
|
||||
Path config = homeDir.resolve("config");
|
||||
Files.createDirectory(config);
|
||||
Files.copy(yaml, config.resolve("elasticsearch.yaml"));
|
||||
Files.copy(json, config.resolve("elasticsearch.json"));
|
||||
|
||||
SettingsException e = expectThrows(SettingsException.class, () ->
|
||||
InternalSettingsPreparer.prepareEnvironment(Settings.builder().put(baseEnvSettings).build(), null)
|
||||
);
|
||||
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(".json"));
|
||||
InternalSettingsPreparer.prepareEnvironment(Settings.builder().put(baseEnvSettings).build(), null));
|
||||
assertEquals("elasticsearch.yaml was deprecated in 5.5.0 and must be renamed to elasticsearch.yml", e.getMessage());
|
||||
}
|
||||
|
||||
public void testYmlExtension() throws IOException {
|
||||
InputStream yaml = getClass().getResourceAsStream("/config/elasticsearch.yaml");
|
||||
Path config = homeDir.resolve("config");
|
||||
Files.createDirectory(config);
|
||||
Files.copy(yaml, config.resolve("elasticsearch.yml"));
|
||||
Environment env = InternalSettingsPreparer.prepareEnvironment(Settings.builder().put(baseEnvSettings).build(), null);
|
||||
assertEquals(".yml", env.configExtension());
|
||||
}
|
||||
|
||||
public void testJsonExtension() throws IOException {
|
||||
public void testJsonNotAllowed() throws IOException {
|
||||
InputStream yaml = getClass().getResourceAsStream("/config/elasticsearch.json");
|
||||
Path config = homeDir.resolve("config");
|
||||
Files.createDirectory(config);
|
||||
Files.copy(yaml, config.resolve("elasticsearch.json"));
|
||||
Environment env = InternalSettingsPreparer.prepareEnvironment(Settings.builder().put(baseEnvSettings).build(), null);
|
||||
assertEquals(".json", env.configExtension());
|
||||
SettingsException e = expectThrows(SettingsException.class, () ->
|
||||
InternalSettingsPreparer.prepareEnvironment(Settings.builder().put(baseEnvSettings).build(), null));
|
||||
assertEquals("elasticsearch.json was deprecated in 5.5.0 and must be converted to elasticsearch.yml", e.getMessage());
|
||||
}
|
||||
|
||||
public void testSecureSettings() {
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
|
||||
properties.config.exists: true
|
Loading…
Reference in New Issue