Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read configuration file with .yaml suffix #10909

Merged
merged 2 commits into from May 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -19,6 +19,7 @@

package org.elasticsearch.node.internal;

import com.google.common.collect.ImmutableList;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.common.Names;
import org.elasticsearch.common.Strings;
Expand All @@ -28,6 +29,7 @@
import org.elasticsearch.env.Environment;
import org.elasticsearch.env.FailedToResolveConfigException;

import java.util.List;
import java.util.Map;

import static org.elasticsearch.common.Strings.cleanPath;
Expand All @@ -38,6 +40,8 @@
*/
public class InternalSettingsPreparer {

static final List<String> ALLOWED_SUFFIXES = ImmutableList.of(".yml", ".yaml", ".json", ".properties");

public static Tuple<Settings, Environment> prepareSettings(Settings pSettings, boolean loadConfigSettings) {
// ignore this prefixes when getting properties from es. and elasticsearch.
String[] ignorePrefixes = new String[]{"es.default.", "elasticsearch.default."};
Expand Down Expand Up @@ -73,22 +77,12 @@ public static Tuple<Settings, Environment> prepareSettings(Settings pSettings, b
}
}
if (loadFromEnv) {
try {
settingsBuilder.loadFromUrl(environment.resolveConfig("elasticsearch.yml"));
} catch (FailedToResolveConfigException e) {
// ignore
} catch (NoClassDefFoundError e) {
// ignore, no yaml
}
try {
settingsBuilder.loadFromUrl(environment.resolveConfig("elasticsearch.json"));
} catch (FailedToResolveConfigException e) {
// ignore
}
try {
settingsBuilder.loadFromUrl(environment.resolveConfig("elasticsearch.properties"));
} catch (FailedToResolveConfigException e) {
// ignore
for (String allowedSuffix : ALLOWED_SUFFIXES) {
try {
settingsBuilder.loadFromUrl(environment.resolveConfig("elasticsearch" + allowedSuffix));
} catch (FailedToResolveConfigException e) {
// ignore
}
}
}
}
Expand Down
Expand Up @@ -52,4 +52,16 @@ public void testIgnoreSystemProperties() {
// Should use setting from the system property
assertThat(tuple.v1().get("node.zone"), equalTo("bar"));
}

@Test
public void testAlternateConfigFileSuffixes() {
// test that we can read config files with .yaml, .json, and .properties suffixes
Tuple<Settings, Environment> tuple = InternalSettingsPreparer.prepareSettings(settingsBuilder()
.put("config.ignore_system_properties", true)
.build(), true);

assertThat(tuple.v1().get("yaml.config.exists"), equalTo("true"));
assertThat(tuple.v1().get("json.config.exists"), equalTo("true"));
assertThat(tuple.v1().get("properties.config.exists"), equalTo("true"));
}
}
3 changes: 3 additions & 0 deletions src/test/resources/config/elasticsearch.json
@@ -0,0 +1,3 @@
{
"json.config.exists" : "true"
}
2 changes: 2 additions & 0 deletions src/test/resources/config/elasticsearch.properties
@@ -0,0 +1,2 @@

properties.config.exists: true
3 changes: 3 additions & 0 deletions src/test/resources/config/elasticsearch.yaml
@@ -0,0 +1,3 @@

yaml.config.exists: true