use of org.elasticsearch.common.settings.SettingsException in project elasticsearch by elastic.
the class InternalSettingsPreparer method prepareEnvironment.
/**
* Prepares the settings by gathering all elasticsearch system properties, optionally loading the configuration settings,
* and then replacing all property placeholders. If a {@link Terminal} is provided and configuration settings are loaded,
* settings with a value of <code>${prompt.text}</code> or <code>${prompt.secret}</code> will result in a prompt for
* the setting to the user.
* @param input The custom settings to use. These are not overwritten by settings in the configuration file.
* @param terminal the Terminal to use for input/output
* @param properties Map of properties key/value pairs (usually from the command-line)
* @return the {@link Settings} and {@link Environment} as a {@link Tuple}
*/
public static Environment prepareEnvironment(Settings input, Terminal terminal, Map<String, String> properties) {
// just create enough settings to build the environment, to get the config dir
Settings.Builder output = Settings.builder();
initializeSettings(output, input, properties);
Environment environment = new Environment(output.build());
// start with a fresh output
output = Settings.builder();
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 (foundSuffixes.size() > 1) {
throw new SettingsException("multiple settings files found with suffixes: " + Strings.collectionToDelimitedString(foundSuffixes, ","));
}
// re-initialize settings now that the config file has been loaded
initializeSettings(output, input, properties);
finalizeSettings(output, terminal);
environment = new Environment(output.build());
// 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()));
return new Environment(output.build());
}
use of org.elasticsearch.common.settings.SettingsException in project elasticsearch by elastic.
the class AzureSettingsParserTests method testParseTwoSettingsNoDefault.
public void testParseTwoSettingsNoDefault() {
Settings settings = Settings.builder().put("cloud.azure.storage.azure1.account", "myaccount1").put("cloud.azure.storage.azure1.key", "mykey1").put("cloud.azure.storage.azure2.account", "myaccount2").put("cloud.azure.storage.azure2.key", "mykey2").build();
try {
AzureStorageSettings.parse(settings);
fail("Should have failed with a SettingsException (no default data store)");
} catch (SettingsException ex) {
assertEquals(ex.getMessage(), "No default Azure data store configured");
}
}
use of org.elasticsearch.common.settings.SettingsException in project elasticsearch by elastic.
the class InternalSettingsPreparerTests method testMultipleSettingsFileNotAllowed.
public void testMultipleSettingsFileNotAllowed() throws IOException {
InputStream yaml = getClass().getResourceAsStream("/config/elasticsearch.yaml");
InputStream properties = getClass().getResourceAsStream("/config/elasticsearch.properties");
Path home = createTempDir();
Path config = home.resolve("config");
Files.createDirectory(config);
Files.copy(yaml, config.resolve("elasticsearch.yaml"));
Files.copy(properties, config.resolve("elasticsearch.properties"));
try {
InternalSettingsPreparer.prepareEnvironment(Settings.builder().put(baseEnvSettings).build(), null);
} catch (SettingsException e) {
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(".properties"));
}
}
use of org.elasticsearch.common.settings.SettingsException in project elasticsearch by elastic.
the class YamlSettingsLoaderTests method testDuplicateKeysThrowsException.
public void testDuplicateKeysThrowsException() {
assumeFalse("Test only makes sense if XContent parser doesn't have strict duplicate checks enabled", XContent.isStrictDuplicateDetectionEnabled());
String yaml = "foo: bar\nfoo: baz";
SettingsException e = expectThrows(SettingsException.class, () -> {
Settings.builder().loadFromSource(yaml, XContentType.YAML);
});
assertEquals(e.getCause().getClass(), ElasticsearchParseException.class);
String msg = e.getCause().getMessage();
assertTrue(msg, msg.contains("duplicate settings key [foo] found at line number [2], column number [6], " + "previous value [bar], current value [baz]"));
}
use of org.elasticsearch.common.settings.SettingsException in project play2-elasticsearch by cleverage.
the class IndexClient method loadSettings.
/**
* Load settings from resource file
*
* @return
* @throws Exception
*/
private Settings.Builder loadSettings() throws Exception {
Settings.Builder settings = Settings.settingsBuilder();
// set default settings
settings.put("client.transport.sniff", config.sniffing);
if (config.clusterName != null && !config.clusterName.isEmpty()) {
settings.put("cluster.name", config.clusterName);
}
// load settings
if (config.localConfig != null && !config.localConfig.isEmpty()) {
Logger.debug("Elasticsearch : Load settings from " + config.localConfig);
try {
settings.loadFromPath(Paths.get(this.getClass().getClassLoader().getResource(config.localConfig).toURI()));
} catch (SettingsException settingsException) {
Logger.error("Elasticsearch : Error when loading settings from " + config.localConfig);
throw new Exception(settingsException);
}
}
settings.build();
Logger.info("Elasticsearch : Settings " + settings.internalMap().toString());
return settings;
}
Aggregations