mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 10:25:15 +00:00
Index Templates settings provided in a config file fails to load properly, closes #1960.
This commit is contained in:
parent
d031662da3
commit
be01e8fe19
@ -35,6 +35,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
|
|||||||
import org.elasticsearch.common.regex.Regex;
|
import org.elasticsearch.common.regex.Regex;
|
||||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
import org.elasticsearch.common.settings.loader.SettingsLoader;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
@ -562,14 +563,7 @@ public class IndexMetaData {
|
|||||||
currentFieldName = parser.currentName();
|
currentFieldName = parser.currentName();
|
||||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||||
if ("settings".equals(currentFieldName)) {
|
if ("settings".equals(currentFieldName)) {
|
||||||
ImmutableSettings.Builder settingsBuilder = settingsBuilder();
|
builder.settings(ImmutableSettings.settingsBuilder().put(SettingsLoader.Helper.loadNestedFromMap(parser.mapOrdered())));
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
|
||||||
String key = parser.currentName();
|
|
||||||
token = parser.nextToken();
|
|
||||||
String value = parser.text();
|
|
||||||
settingsBuilder.put(key, value);
|
|
||||||
}
|
|
||||||
builder.settings(settingsBuilder.build());
|
|
||||||
} else if ("mappings".equals(currentFieldName)) {
|
} else if ("mappings".equals(currentFieldName)) {
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||||
if (token == XContentParser.Token.FIELD_NAME) {
|
if (token == XContentParser.Token.FIELD_NAME) {
|
||||||
|
@ -26,6 +26,7 @@ import org.elasticsearch.common.io.stream.StreamInput;
|
|||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
import org.elasticsearch.common.settings.loader.SettingsLoader;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
@ -282,14 +283,7 @@ public class IndexTemplateMetaData {
|
|||||||
currentFieldName = parser.currentName();
|
currentFieldName = parser.currentName();
|
||||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||||
if ("settings".equals(currentFieldName)) {
|
if ("settings".equals(currentFieldName)) {
|
||||||
ImmutableSettings.Builder settingsBuilder = ImmutableSettings.settingsBuilder();
|
builder.settings(ImmutableSettings.settingsBuilder().put(SettingsLoader.Helper.loadNestedFromMap(parser.mapOrdered())));
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
|
||||||
String key = parser.currentName();
|
|
||||||
token = parser.nextToken();
|
|
||||||
String value = parser.text();
|
|
||||||
settingsBuilder.put(key, value);
|
|
||||||
}
|
|
||||||
builder.settings(settingsBuilder.build());
|
|
||||||
} else if ("mappings".equals(currentFieldName)) {
|
} else if ("mappings".equals(currentFieldName)) {
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||||
if (token == XContentParser.Token.FIELD_NAME) {
|
if (token == XContentParser.Token.FIELD_NAME) {
|
||||||
|
@ -32,6 +32,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
|
|||||||
import org.elasticsearch.common.regex.Regex;
|
import org.elasticsearch.common.regex.Regex;
|
||||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
import org.elasticsearch.common.settings.loader.SettingsLoader;
|
||||||
import org.elasticsearch.common.xcontent.*;
|
import org.elasticsearch.common.xcontent.*;
|
||||||
import org.elasticsearch.index.Index;
|
import org.elasticsearch.index.Index;
|
||||||
import org.elasticsearch.indices.IndexMissingException;
|
import org.elasticsearch.indices.IndexMissingException;
|
||||||
@ -904,14 +905,7 @@ public class MetaData implements Iterable<IndexMetaData> {
|
|||||||
currentFieldName = parser.currentName();
|
currentFieldName = parser.currentName();
|
||||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||||
if ("settings".equals(currentFieldName)) {
|
if ("settings".equals(currentFieldName)) {
|
||||||
ImmutableSettings.Builder settingsBuilder = settingsBuilder();
|
builder.persistentSettings(ImmutableSettings.settingsBuilder().put(SettingsLoader.Helper.loadNestedFromMap(parser.mapOrdered())).build());
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
|
||||||
String key = parser.currentName();
|
|
||||||
token = parser.nextToken();
|
|
||||||
String value = parser.text();
|
|
||||||
settingsBuilder.put(key, value);
|
|
||||||
}
|
|
||||||
builder.persistentSettings(settingsBuilder.build());
|
|
||||||
} else if ("indices".equals(currentFieldName)) {
|
} else if ("indices".equals(currentFieldName)) {
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||||
builder.put(IndexMetaData.Builder.fromXContent(parser), false);
|
builder.put(IndexMetaData.Builder.fromXContent(parser), false);
|
||||||
|
@ -19,17 +19,82 @@
|
|||||||
|
|
||||||
package org.elasticsearch.common.settings.loader;
|
package org.elasticsearch.common.settings.loader;
|
||||||
|
|
||||||
|
import org.elasticsearch.common.Nullable;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static com.google.common.collect.Lists.newArrayList;
|
||||||
|
import static com.google.common.collect.Maps.newHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides the ability to load settings (in the form of a simple Map) from
|
* Provides the ability to load settings (in the form of a simple Map) from
|
||||||
* the actual source content that represents them.
|
* the actual source content that represents them.
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface SettingsLoader {
|
public interface SettingsLoader {
|
||||||
|
|
||||||
|
static class Helper {
|
||||||
|
|
||||||
|
public static Map<String, String> loadNestedFromMap(@Nullable Map map) {
|
||||||
|
Map<String, String> settings = newHashMap();
|
||||||
|
if (map == null) {
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
List<String> path = newArrayList();
|
||||||
|
serializeMap(settings, sb, path, map);
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void serializeMap(Map<String, String> settings, StringBuilder sb, List<String> path, Map<Object, Object> map) {
|
||||||
|
for (Map.Entry<Object, Object> entry : map.entrySet()) {
|
||||||
|
if (entry.getValue() instanceof Map) {
|
||||||
|
path.add((String) entry.getKey());
|
||||||
|
serializeMap(settings, sb, path, (Map<Object, Object>) entry.getValue());
|
||||||
|
path.remove(path.size() - 1);
|
||||||
|
} else if (entry.getValue() instanceof List) {
|
||||||
|
path.add((String) entry.getKey());
|
||||||
|
serializeList(settings, sb, path, (List) entry.getValue());
|
||||||
|
path.remove(path.size() - 1);
|
||||||
|
} else {
|
||||||
|
serializeValue(settings, sb, path, (String) entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void serializeList(Map<String, String> settings, StringBuilder sb, List<String> path, List list) {
|
||||||
|
int counter = 0;
|
||||||
|
for (Object listEle : list) {
|
||||||
|
if (listEle instanceof Map) {
|
||||||
|
path.add(Integer.toString(counter));
|
||||||
|
serializeMap(settings, sb, path, (Map<Object, Object>) listEle);
|
||||||
|
path.remove(path.size() - 1);
|
||||||
|
} else if (listEle instanceof List) {
|
||||||
|
path.add(Integer.toString(counter));
|
||||||
|
serializeList(settings, sb, path, (List) listEle);
|
||||||
|
path.remove(path.size() - 1);
|
||||||
|
} else {
|
||||||
|
serializeValue(settings, sb, path, Integer.toString(counter), listEle);
|
||||||
|
}
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void serializeValue(Map<String, String> settings, StringBuilder sb, List<String> path, String name, Object value) {
|
||||||
|
if (value == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sb.setLength(0);
|
||||||
|
for (String pathEle : path) {
|
||||||
|
sb.append(pathEle).append('.');
|
||||||
|
}
|
||||||
|
sb.append(name);
|
||||||
|
settings.put(sb.toString(), value.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads (parses) the settings from a source string.
|
* Loads (parses) the settings from a source string.
|
||||||
*/
|
*/
|
||||||
|
@ -23,17 +23,11 @@ import org.elasticsearch.common.io.FastByteArrayInputStream;
|
|||||||
import org.yaml.snakeyaml.Yaml;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static com.google.common.collect.Lists.newArrayList;
|
|
||||||
import static com.google.common.collect.Maps.newHashMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Settings loader that loads (parses) the settings in a yaml format by flattening them
|
* Settings loader that loads (parses) the settings in a yaml format by flattening them
|
||||||
* into a map.
|
* into a map.
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class YamlSettingsLoader implements SettingsLoader {
|
public class YamlSettingsLoader implements SettingsLoader {
|
||||||
|
|
||||||
@ -43,73 +37,13 @@ public class YamlSettingsLoader implements SettingsLoader {
|
|||||||
source = source.replace("\t", " ");
|
source = source.replace("\t", " ");
|
||||||
Yaml yaml = new Yaml();
|
Yaml yaml = new Yaml();
|
||||||
Map<Object, Object> yamlMap = (Map<Object, Object>) yaml.load(source);
|
Map<Object, Object> yamlMap = (Map<Object, Object>) yaml.load(source);
|
||||||
StringBuilder sb = new StringBuilder();
|
return Helper.loadNestedFromMap(yamlMap);
|
||||||
Map<String, String> settings = newHashMap();
|
|
||||||
if (yamlMap == null) {
|
|
||||||
return settings;
|
|
||||||
}
|
|
||||||
List<String> path = newArrayList();
|
|
||||||
serializeMap(settings, sb, path, yamlMap);
|
|
||||||
return settings;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> load(byte[] source) throws IOException {
|
public Map<String, String> load(byte[] source) throws IOException {
|
||||||
Yaml yaml = new Yaml();
|
Yaml yaml = new Yaml();
|
||||||
Map<Object, Object> yamlMap = (Map<Object, Object>) yaml.load(new FastByteArrayInputStream(source));
|
Map<Object, Object> yamlMap = (Map<Object, Object>) yaml.load(new FastByteArrayInputStream(source));
|
||||||
StringBuilder sb = new StringBuilder();
|
return Helper.loadNestedFromMap(yamlMap);
|
||||||
Map<String, String> settings = newHashMap();
|
|
||||||
if (yamlMap == null) {
|
|
||||||
return settings;
|
|
||||||
}
|
|
||||||
List<String> path = newArrayList();
|
|
||||||
serializeMap(settings, sb, path, yamlMap);
|
|
||||||
return settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void serializeMap(Map<String, String> settings, StringBuilder sb, List<String> path, Map<Object, Object> yamlMap) {
|
|
||||||
for (Map.Entry<Object, Object> entry : yamlMap.entrySet()) {
|
|
||||||
if (entry.getValue() instanceof Map) {
|
|
||||||
path.add((String) entry.getKey());
|
|
||||||
serializeMap(settings, sb, path, (Map<Object, Object>) entry.getValue());
|
|
||||||
path.remove(path.size() - 1);
|
|
||||||
} else if (entry.getValue() instanceof List) {
|
|
||||||
path.add((String) entry.getKey());
|
|
||||||
serializeList(settings, sb, path, (List) entry.getValue());
|
|
||||||
path.remove(path.size() - 1);
|
|
||||||
} else {
|
|
||||||
serializeValue(settings, sb, path, (String) entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void serializeList(Map<String, String> settings, StringBuilder sb, List<String> path, List yamlList) {
|
|
||||||
int counter = 0;
|
|
||||||
for (Object listEle : yamlList) {
|
|
||||||
if (listEle instanceof Map) {
|
|
||||||
path.add(Integer.toString(counter));
|
|
||||||
serializeMap(settings, sb, path, (Map<Object, Object>) listEle);
|
|
||||||
path.remove(path.size() - 1);
|
|
||||||
} else if (listEle instanceof List) {
|
|
||||||
path.add(Integer.toString(counter));
|
|
||||||
serializeList(settings, sb, path, (List) listEle);
|
|
||||||
path.remove(path.size() - 1);
|
|
||||||
} else {
|
|
||||||
serializeValue(settings, sb, path, Integer.toString(counter), listEle);
|
|
||||||
}
|
|
||||||
counter++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void serializeValue(Map<String, String> settings, StringBuilder sb, List<String> path, String name, Object value) {
|
|
||||||
if (value == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
sb.setLength(0);
|
|
||||||
for (String pathEle : path) {
|
|
||||||
sb.append(pathEle).append('.');
|
|
||||||
}
|
|
||||||
sb.append(name);
|
|
||||||
settings.put(sb.toString(), value.toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user