Skip to content

Commit f138537

Browse files
committed
iter
1 parent 11cdf2e commit f138537

File tree

40 files changed

+143
-86
lines changed

40 files changed

+143
-86
lines changed

core/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.elasticsearch.common.logging.Loggers;
4040
import org.elasticsearch.common.lucene.uid.Versions;
4141
import org.elasticsearch.common.unit.TimeValue;
42+
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
4243
import org.elasticsearch.common.xcontent.XContent;
4344
import org.elasticsearch.common.xcontent.XContentFactory;
4445
import org.elasticsearch.common.xcontent.XContentParser;
@@ -283,7 +284,7 @@ public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Null
283284
line++;
284285

285286
// now parse the action
286-
try (XContentParser parser = xContent.createParser(data.slice(from, nextMarker - from))) {
287+
try (XContentParser parser = xContent.createParser(NamedXContentRegistry.EMPTY, data.slice(from, nextMarker - from))) {
287288
// move pointers
288289
from = nextMarker + 1;
289290

@@ -400,7 +401,7 @@ public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Null
400401
.version(version).versionType(versionType)
401402
.routing(routing)
402403
.parent(parent);
403-
try (XContentParser sliceParser = xContent.createParser(data.slice(from, nextMarker - from))) {
404+
try (XContentParser sliceParser = xContent.createParser(NamedXContentRegistry.EMPTY, data.slice(from, nextMarker - from))) {
404405
updateRequest.fromXContent(sliceParser);
405406
}
406407
if (fetchSourceContext != null) {

core/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.carrotsearch.hppc.cursors.IntObjectCursor;
2424
import com.carrotsearch.hppc.cursors.ObjectCursor;
2525
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
26+
2627
import org.elasticsearch.Version;
2728
import org.elasticsearch.action.support.ActiveShardCount;
2829
import org.elasticsearch.cluster.Diff;
@@ -45,6 +46,7 @@
4546
import org.elasticsearch.common.settings.Settings;
4647
import org.elasticsearch.common.settings.loader.SettingsLoader;
4748
import org.elasticsearch.common.xcontent.FromXContentBuilder;
49+
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
4850
import org.elasticsearch.common.xcontent.ToXContent;
4951
import org.elasticsearch.common.xcontent.XContentBuilder;
5052
import org.elasticsearch.common.xcontent.XContentFactory;
@@ -831,7 +833,7 @@ public MappingMetaData mapping(String type) {
831833
}
832834

833835
public Builder putMapping(String type, String source) throws IOException {
834-
try (XContentParser parser = XContentFactory.xContent(source).createParser(source)) {
836+
try (XContentParser parser = XContentFactory.xContent(source).createParser(NamedXContentRegistry.EMPTY, source)) {
835837
putMapping(new MappingMetaData(type, parser.mapOrdered()));
836838
}
837839
return this;
@@ -1048,7 +1050,7 @@ public static void toXContent(IndexMetaData indexMetaData, XContentBuilder build
10481050
builder.value(cursor.value.source().compressed());
10491051
} else {
10501052
byte[] data = cursor.value.source().uncompressed();
1051-
try (XContentParser parser = XContentFactory.xContent(data).createParser(data)) {
1053+
try (XContentParser parser = XContentFactory.xContent(data).createParser(NamedXContentRegistry.EMPTY, data)) {
10521054
Map<String, Object> mapping = parser.mapOrdered();
10531055
builder.map(mapping);
10541056
}

core/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetaData.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.elasticsearch.common.settings.Settings;
3535
import org.elasticsearch.common.settings.loader.SettingsLoader;
3636
import org.elasticsearch.common.util.set.Sets;
37+
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
3738
import org.elasticsearch.common.xcontent.ToXContent;
3839
import org.elasticsearch.common.xcontent.XContentBuilder;
3940
import org.elasticsearch.common.xcontent.XContentFactory;
@@ -396,7 +397,8 @@ public static void toXContent(IndexTemplateMetaData indexTemplateMetaData, XCont
396397
for (ObjectObjectCursor<String, CompressedXContent> cursor : indexTemplateMetaData.mappings()) {
397398
byte[] mappingSource = cursor.value.uncompressed();
398399
Map<String, Object> mapping;
399-
try (XContentParser parser = XContentFactory.xContent(mappingSource).createParser(mappingSource)) {;
400+
try (XContentParser parser = XContentFactory.xContent(mappingSource).createParser(NamedXContentRegistry.EMPTY,
401+
mappingSource)) {
400402
mapping = parser.map();
401403
}
402404
if (mapping.size() == 1 && mapping.containsKey(cursor.key)) {
@@ -411,7 +413,7 @@ public static void toXContent(IndexTemplateMetaData indexTemplateMetaData, XCont
411413
builder.startArray("mappings");
412414
for (ObjectObjectCursor<String, CompressedXContent> cursor : indexTemplateMetaData.mappings()) {
413415
byte[] data = cursor.value.uncompressed();
414-
try (XContentParser parser = XContentFactory.xContent(data).createParser(data)) {
416+
try (XContentParser parser = XContentFactory.xContent(data).createParser(NamedXContentRegistry.EMPTY, data)) {
415417
Map<String, Object> mapping = parser.mapOrdered();
416418
builder.map(mapping);
417419
}

core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import org.elasticsearch.common.regex.Regex;
6060
import org.elasticsearch.common.settings.IndexScopedSettings;
6161
import org.elasticsearch.common.settings.Settings;
62+
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
6263
import org.elasticsearch.common.xcontent.XContentHelper;
6364
import org.elasticsearch.env.Environment;
6465
import org.elasticsearch.index.Index;
@@ -112,12 +113,14 @@ public class MetaDataCreateIndexService extends AbstractComponent {
112113
private final Environment env;
113114
private final IndexScopedSettings indexScopedSettings;
114115
private final ActiveShardsObserver activeShardsObserver;
116+
private final NamedXContentRegistry xContentRegistry;
115117

116118
@Inject
117119
public MetaDataCreateIndexService(Settings settings, ClusterService clusterService,
118120
IndicesService indicesService, AllocationService allocationService,
119121
AliasValidator aliasValidator, Environment env,
120-
IndexScopedSettings indexScopedSettings, ThreadPool threadPool) {
122+
IndexScopedSettings indexScopedSettings, ThreadPool threadPool,
123+
NamedXContentRegistry xContentRegistry) {
121124
super(settings);
122125
this.clusterService = clusterService;
123126
this.indicesService = indicesService;
@@ -126,6 +129,7 @@ public MetaDataCreateIndexService(Settings settings, ClusterService clusterServi
126129
this.env = env;
127130
this.indexScopedSettings = indexScopedSettings;
128131
this.activeShardsObserver = new ActiveShardsObserver(settings, clusterService, threadPool);
132+
this.xContentRegistry = xContentRegistry;
129133
}
130134

131135
/**
@@ -247,7 +251,7 @@ public ClusterState execute(ClusterState currentState) throws Exception {
247251
List<String> templateNames = new ArrayList<>();
248252

249253
for (Map.Entry<String, String> entry : request.mappings().entrySet()) {
250-
mappings.put(entry.getKey(), MapperService.parseMapping(entry.getValue()));
254+
mappings.put(entry.getKey(), MapperService.parseMapping(xContentRegistry, entry.getValue()));
251255
}
252256

253257
for (Map.Entry<String, Custom> entry : request.customs().entrySet()) {
@@ -259,9 +263,10 @@ public ClusterState execute(ClusterState currentState) throws Exception {
259263
templateNames.add(template.getName());
260264
for (ObjectObjectCursor<String, CompressedXContent> cursor : template.mappings()) {
261265
if (mappings.containsKey(cursor.key)) {
262-
XContentHelper.mergeDefaults(mappings.get(cursor.key), MapperService.parseMapping(cursor.value.string()));
266+
XContentHelper.mergeDefaults(mappings.get(cursor.key),
267+
MapperService.parseMapping(xContentRegistry, cursor.value.string()));
263268
} else {
264-
mappings.put(cursor.key, MapperService.parseMapping(cursor.value.string()));
269+
mappings.put(cursor.key, MapperService.parseMapping(xContentRegistry, cursor.value.string()));
265270
}
266271
}
267272
// handle custom
@@ -367,12 +372,13 @@ public ClusterState execute(ClusterState currentState) throws Exception {
367372
final QueryShardContext queryShardContext = indexService.newQueryShardContext(0, null, () -> 0L);
368373
for (Alias alias : request.aliases()) {
369374
if (Strings.hasLength(alias.filter())) {
370-
aliasValidator.validateAliasFilter(alias.name(), alias.filter(), queryShardContext);
375+
aliasValidator.validateAliasFilter(alias.name(), alias.filter(), queryShardContext, xContentRegistry);
371376
}
372377
}
373378
for (AliasMetaData aliasMetaData : templatesAliases.values()) {
374379
if (aliasMetaData.filter() != null) {
375-
aliasValidator.validateAliasFilter(aliasMetaData.alias(), aliasMetaData.filter().uncompressed(), queryShardContext);
380+
aliasValidator.validateAliasFilter(aliasMetaData.alias(), aliasMetaData.filter().uncompressed(),
381+
queryShardContext, xContentRegistry);
376382
}
377383
}
378384

core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexAliasesService.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.elasticsearch.common.component.AbstractComponent;
3434
import org.elasticsearch.common.inject.Inject;
3535
import org.elasticsearch.common.settings.Settings;
36+
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
3637
import org.elasticsearch.index.Index;
3738
import org.elasticsearch.index.IndexNotFoundException;
3839
import org.elasticsearch.index.IndexService;
@@ -64,18 +65,17 @@ public class MetaDataIndexAliasesService extends AbstractComponent {
6465

6566
private final MetaDataDeleteIndexService deleteIndexService;
6667

68+
private final NamedXContentRegistry xContentRegistry;
69+
6770
@Inject
68-
public MetaDataIndexAliasesService(
69-
Settings settings,
70-
ClusterService clusterService,
71-
IndicesService indicesService,
72-
AliasValidator aliasValidator,
73-
MetaDataDeleteIndexService deleteIndexService) {
71+
public MetaDataIndexAliasesService(Settings settings, ClusterService clusterService, IndicesService indicesService,
72+
AliasValidator aliasValidator, MetaDataDeleteIndexService deleteIndexService, NamedXContentRegistry xContentRegistry) {
7473
super(settings);
7574
this.clusterService = clusterService;
7675
this.indicesService = indicesService;
7776
this.aliasValidator = aliasValidator;
7877
this.deleteIndexService = deleteIndexService;
78+
this.xContentRegistry = xContentRegistry;
7979
}
8080

8181
public void indicesAliases(final IndicesAliasesClusterStateUpdateRequest request,
@@ -155,7 +155,8 @@ ClusterState innerExecute(ClusterState currentState, Iterable<AliasAction> actio
155155
}
156156
// the context is only used for validation so it's fine to pass fake values for the shard id and the current
157157
// timestamp
158-
aliasValidator.validateAliasFilter(alias, filter, indexService.newQueryShardContext(0, null, () -> 0L));
158+
aliasValidator.validateAliasFilter(alias, filter, indexService.newQueryShardContext(0, null, () -> 0L),
159+
xContentRegistry);
159160
}
160161
};
161162
changed |= action.apply(newAliasValidator, metadata, index);

core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexTemplateService.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.elasticsearch.common.settings.IndexScopedSettings;
3636
import org.elasticsearch.common.settings.Settings;
3737
import org.elasticsearch.common.unit.TimeValue;
38+
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
3839
import org.elasticsearch.index.Index;
3940
import org.elasticsearch.index.IndexService;
4041
import org.elasticsearch.index.mapper.MapperParsingException;
@@ -64,18 +65,20 @@ public class MetaDataIndexTemplateService extends AbstractComponent {
6465
private final IndicesService indicesService;
6566
private final MetaDataCreateIndexService metaDataCreateIndexService;
6667
private final IndexScopedSettings indexScopedSettings;
68+
private final NamedXContentRegistry xContentRegistry;
6769

6870
@Inject
6971
public MetaDataIndexTemplateService(Settings settings, ClusterService clusterService,
7072
MetaDataCreateIndexService metaDataCreateIndexService,
7173
AliasValidator aliasValidator, IndicesService indicesService,
72-
IndexScopedSettings indexScopedSettings) {
74+
IndexScopedSettings indexScopedSettings, NamedXContentRegistry xContentRegistry) {
7375
super(settings);
7476
this.clusterService = clusterService;
7577
this.aliasValidator = aliasValidator;
7678
this.indicesService = indicesService;
7779
this.metaDataCreateIndexService = metaDataCreateIndexService;
7880
this.indexScopedSettings = indexScopedSettings;
81+
this.xContentRegistry = xContentRegistry;
7982
}
8083

8184
public void removeTemplates(final RemoveRequest request, final RemoveListener listener) {
@@ -164,7 +167,7 @@ public ClusterState execute(ClusterState currentState) throws Exception {
164167
throw new IllegalArgumentException("index_template [" + request.name + "] already exists");
165168
}
166169

167-
validateAndAddTemplate(request, templateBuilder, indicesService);
170+
validateAndAddTemplate(request, templateBuilder, indicesService, xContentRegistry);
168171

169172
for (Alias alias : request.aliases) {
170173
AliasMetaData aliasMetaData = AliasMetaData.builder(alias.name()).filter(alias.filter())
@@ -189,7 +192,7 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS
189192
}
190193

191194
private static void validateAndAddTemplate(final PutRequest request, IndexTemplateMetaData.Builder templateBuilder,
192-
IndicesService indicesService) throws Exception {
195+
IndicesService indicesService, NamedXContentRegistry xContentRegistry) throws Exception {
193196
Index createdIndex = null;
194197
final String temporaryIndexName = UUIDs.randomBase64UUID();
195198
try {
@@ -219,7 +222,7 @@ private static void validateAndAddTemplate(final PutRequest request, IndexTempla
219222
} catch (Exception e) {
220223
throw new MapperParsingException("Failed to parse mapping [{}]: {}", e, entry.getKey(), e.getMessage());
221224
}
222-
mappingsForValidation.put(entry.getKey(), MapperService.parseMapping(entry.getValue()));
225+
mappingsForValidation.put(entry.getKey(), MapperService.parseMapping(xContentRegistry, entry.getValue()));
223226
}
224227

225228
dummyIndexService.mapperService().merge(mappingsForValidation, false);

core/src/main/java/org/elasticsearch/common/settings/loader/XContentSettingsLoader.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.elasticsearch.common.settings.loader;
2121

2222
import org.elasticsearch.ElasticsearchParseException;
23+
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
2324
import org.elasticsearch.common.xcontent.XContentFactory;
2425
import org.elasticsearch.common.xcontent.XContentParser;
2526
import org.elasticsearch.common.xcontent.XContentType;
@@ -46,14 +47,14 @@ public abstract class XContentSettingsLoader implements SettingsLoader {
4647

4748
@Override
4849
public Map<String, String> load(String source) throws IOException {
49-
try (XContentParser parser = XContentFactory.xContent(contentType()).createParser(source)) {
50+
try (XContentParser parser = XContentFactory.xContent(contentType()).createParser(NamedXContentRegistry.EMPTY, source)) {
5051
return load(parser);
5152
}
5253
}
5354

5455
@Override
5556
public Map<String, String> load(byte[] source) throws IOException {
56-
try (XContentParser parser = XContentFactory.xContent(contentType()).createParser(source)) {
57+
try (XContentParser parser = XContentFactory.xContent(contentType()).createParser(NamedXContentRegistry.EMPTY, source)) {
5758
return load(parser);
5859
}
5960
}

core/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,15 @@ enum NumberType {
250250
XContentLocation getTokenLocation();
251251

252252
// TODO remove context entirely when it isn't needed
253+
/**
254+
* Parse an object by name.
255+
*/
253256
<T> T namedObject(Class<T> categoryClass, String name, Object context) throws IOException;
254257

258+
/**
259+
* The registry used to resolve {@link #namedObject(Class, String, Object)}.
260+
*/
261+
NamedXContentRegistry getXContentRegistry();
262+
255263
boolean isClosed();
256264
}

core/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentParser.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,11 @@ public <T> T namedObject(Class<T> categoryClass, String name, Object context) th
366366
return xContentRegistry.parseNamedObject(categoryClass, name, this, context);
367367
}
368368

369+
@Override
370+
public NamedXContentRegistry getXContentRegistry() {
371+
return xContentRegistry;
372+
}
373+
369374
@Override
370375
public abstract boolean isClosed();
371376
}

core/src/main/java/org/elasticsearch/index/IndexService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ public IndexSettings getIndexSettings() {
478478
public QueryShardContext newQueryShardContext(int shardId, IndexReader indexReader, LongSupplier nowInMillis) {
479479
return new QueryShardContext(
480480
shardId, indexSettings, indexCache.bitsetFilterCache(), indexFieldData, mapperService(),
481-
similarityService(), scriptService, queryRegistry,
481+
similarityService(), scriptService, xContentRegistry, queryRegistry,
482482
client, indexReader,
483483
nowInMillis);
484484
}

0 commit comments

Comments
 (0)