Skip to content

Commit

Permalink
Merge pull request #10909 from aleph-zero/issues/9706
Browse files Browse the repository at this point in the history
Read configuration file with .yaml suffix
  • Loading branch information
brwe committed May 28, 2015
2 parents 2f57ae9 + 4a13a56 commit 334763a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
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 @@ -27,6 +28,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 @@ -37,6 +39,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 @@ -72,22 +76,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 @@ -61,4 +61,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

0 comments on commit 334763a

Please sign in to comment.