Skip to content

Commit 55b24bb

Browse files
committed
Fix build
1 parent f138537 commit 55b24bb

File tree

40 files changed

+198
-128
lines changed

40 files changed

+198
-128
lines changed

core/src/main/java/org/elasticsearch/client/transport/TransportClient.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.elasticsearch.common.transport.TransportAddress;
4242
import org.elasticsearch.common.unit.TimeValue;
4343
import org.elasticsearch.common.util.BigArrays;
44+
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
4445
import org.elasticsearch.indices.breaker.CircuitBreakerService;
4546
import org.elasticsearch.node.Node;
4647
import org.elasticsearch.node.internal.InternalSettingsPreparer;
@@ -63,8 +64,11 @@
6364
import java.util.Collections;
6465
import java.util.List;
6566
import java.util.concurrent.TimeUnit;
67+
import java.util.function.Function;
6668
import java.util.stream.Collectors;
69+
import java.util.stream.Stream;
6770

71+
import static java.util.stream.Collectors.toList;
6872
import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds;
6973

7074
/**
@@ -140,6 +144,11 @@ private static ClientTemplate buildTemplate(Settings providedSettings, Settings
140144
.flatMap(p -> p.getNamedWriteables().stream())
141145
.collect(Collectors.toList()));
142146
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(entries);
147+
NamedXContentRegistry xContentRegistry = new NamedXContentRegistry(Stream.of(
148+
searchModule.getNamedXContents().stream(),
149+
pluginsService.filterPlugins(Plugin.class).stream()
150+
.flatMap(p -> p.getNamedXContent().stream())
151+
).flatMap(Function.identity()).collect(toList()));
143152

144153
ModulesBuilder modules = new ModulesBuilder();
145154
// plugin modules must be added here, before others or we can get crazy injection errors...
@@ -158,11 +167,12 @@ private static ClientTemplate buildTemplate(Settings providedSettings, Settings
158167
resourcesToClose.add(bigArrays);
159168
modules.add(settingsModule);
160169
NetworkModule networkModule = new NetworkModule(settings, true, pluginsService.filterPlugins(NetworkPlugin.class), threadPool,
161-
bigArrays, circuitBreakerService, namedWriteableRegistry, networkService);
170+
bigArrays, circuitBreakerService, namedWriteableRegistry, xContentRegistry, networkService);
162171
final Transport transport = networkModule.getTransportSupplier().get();
163172
final TransportService transportService = new TransportService(settings, transport, threadPool,
164173
networkModule.getTransportInterceptor(), null);
165174
modules.add((b -> {
175+
// NOCOMMIT do we need to bind NamedXContentRegistry?
166176
b.bind(BigArrays.class).toInstance(bigArrays);
167177
b.bind(PluginsService.class).toInstance(pluginsService);
168178
b.bind(CircuitBreakerService.class).toInstance(circuitBreakerService);

core/src/main/java/org/elasticsearch/common/network/NetworkModule.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.elasticsearch.common.settings.Setting.Property;
3636
import org.elasticsearch.common.settings.Settings;
3737
import org.elasticsearch.common.util.BigArrays;
38+
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
3839
import org.elasticsearch.http.HttpServerTransport;
3940
import org.elasticsearch.indices.breaker.CircuitBreakerService;
4041
import org.elasticsearch.plugins.NetworkPlugin;
@@ -107,13 +108,14 @@ public NetworkModule(Settings settings, boolean transportClient, List<NetworkPlu
107108
BigArrays bigArrays,
108109
CircuitBreakerService circuitBreakerService,
109110
NamedWriteableRegistry namedWriteableRegistry,
111+
NamedXContentRegistry xContentRegistry,
110112
NetworkService networkService) {
111113
this.settings = settings;
112114
this.transportClient = transportClient;
113115
for (NetworkPlugin plugin : plugins) {
114116
if (transportClient == false && HTTP_ENABLED.get(settings)) {
115117
Map<String, Supplier<HttpServerTransport>> httpTransportFactory = plugin.getHttpTransports(settings, threadPool, bigArrays,
116-
circuitBreakerService, namedWriteableRegistry, networkService);
118+
circuitBreakerService, namedWriteableRegistry, xContentRegistry, networkService);
117119
for (Map.Entry<String, Supplier<HttpServerTransport>> entry : httpTransportFactory.entrySet()) {
118120
registerHttpTransport(entry.getKey(), entry.getValue());
119121
}

core/src/main/java/org/elasticsearch/common/settings/Setting.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.elasticsearch.common.unit.ByteSizeValue;
3333
import org.elasticsearch.common.unit.MemorySizeValue;
3434
import org.elasticsearch.common.unit.TimeValue;
35+
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
3536
import org.elasticsearch.common.xcontent.XContentBuilder;
3637
import org.elasticsearch.common.xcontent.XContentFactory;
3738
import org.elasticsearch.common.xcontent.XContentParser;
@@ -702,7 +703,7 @@ public void diff(Settings.Builder builder, Settings source, Settings defaultSett
702703
}
703704

704705
private static List<String> parseableStringToList(String parsableString) {
705-
try (XContentParser xContentParser = XContentType.JSON.xContent().createParser(parsableString)) {
706+
try (XContentParser xContentParser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, parsableString)) {
706707
XContentParser.Token token = xContentParser.nextToken();
707708
if (token != XContentParser.Token.START_ARRAY) {
708709
throw new IllegalArgumentException("expected START_ARRAY but got " + token);

core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class QueryRewriteContext implements ParseFieldMatcherSupplier {
5151
public QueryRewriteContext(IndexSettings indexSettings, MapperService mapperService, ScriptService scriptService,
5252
NamedXContentRegistry xContentRegistry, IndicesQueriesRegistry indicesQueriesRegistry, Client client, IndexReader reader,
5353
LongSupplier nowInMillis) {
54+
// NOCOMMIT remove xContentRegistry from param lists that include this or QueryShardContext
5455
this.mapperService = mapperService;
5556
this.scriptService = scriptService;
5657
this.indexSettings = indexSettings;

core/src/main/java/org/elasticsearch/node/Node.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,9 @@ protected Node(final Environment environment, Collection<Class<? extends Plugin>
366366
.flatMap(Function.identity()).collect(Collectors.toList());
367367
final NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(namedWriteables);
368368
NamedXContentRegistry xContentRegistry = new NamedXContentRegistry(Stream.of(
369-
searchModule.getNamedXContents().stream()
369+
searchModule.getNamedXContents().stream(),
370+
pluginsService.filterPlugins(Plugin.class).stream()
371+
.flatMap(p -> p.getNamedXContent().stream())
370372
).flatMap(Function.identity()).collect(toList()));
371373
final MetaStateService metaStateService = new MetaStateService(settings, nodeEnvironment);
372374
final IndicesService indicesService = new IndicesService(settings, pluginsService, nodeEnvironment, xContentRegistry,
@@ -377,14 +379,15 @@ protected Node(final Environment environment, Collection<Class<? extends Plugin>
377379

378380
Collection<Object> pluginComponents = pluginsService.filterPlugins(Plugin.class).stream()
379381
.flatMap(p -> p.createComponents(client, clusterService, threadPool, resourceWatcherService,
380-
scriptModule.getScriptService(), searchModule.getSearchRequestParsers()).stream())
382+
scriptModule.getScriptService(), searchModule.getSearchRequestParsers(),
383+
xContentRegistry).stream())
381384
.collect(Collectors.toList());
382385
Collection<UnaryOperator<Map<String, MetaData.Custom>>> customMetaDataUpgraders =
383386
pluginsService.filterPlugins(Plugin.class).stream()
384387
.map(Plugin::getCustomMetaDataUpgrader)
385388
.collect(Collectors.toList());
386-
final NetworkModule networkModule = new NetworkModule(settings, false, pluginsService.filterPlugins(NetworkPlugin.class), threadPool,
387-
bigArrays, circuitBreakerService, namedWriteableRegistry, networkService);
389+
final NetworkModule networkModule = new NetworkModule(settings, false, pluginsService.filterPlugins(NetworkPlugin.class),
390+
threadPool, bigArrays, circuitBreakerService, namedWriteableRegistry, xContentRegistry, networkService);
388391
final MetaDataUpgrader metaDataUpgrader = new MetaDataUpgrader(customMetaDataUpgraders);
389392
final Transport transport = networkModule.getTransportSupplier().get();
390393
final TransportService transportService = newTransportService(settings, transport, threadPool,

core/src/main/java/org/elasticsearch/plugins/NetworkPlugin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.elasticsearch.common.network.NetworkService;
2828
import org.elasticsearch.common.settings.Settings;
2929
import org.elasticsearch.common.util.BigArrays;
30+
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
3031
import org.elasticsearch.http.HttpServerTransport;
3132
import org.elasticsearch.indices.breaker.CircuitBreakerService;
3233
import org.elasticsearch.threadpool.ThreadPool;
@@ -62,9 +63,8 @@ default Map<String, Supplier<Transport>> getTransports(Settings settings, Thread
6263
* See {@link org.elasticsearch.common.network.NetworkModule#HTTP_TYPE_SETTING} to configure a specific implementation.
6364
*/
6465
default Map<String, Supplier<HttpServerTransport>> getHttpTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays,
65-
CircuitBreakerService circuitBreakerService,
66-
NamedWriteableRegistry namedWriteableRegistry,
67-
NetworkService networkService) {
66+
CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry,
67+
NamedXContentRegistry xContentRegistry, NetworkService networkService) {
6868
return Collections.emptyMap();
6969
}
7070
}

core/src/main/java/org/elasticsearch/plugins/Plugin.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@
1919

2020
package org.elasticsearch.plugins;
2121

22-
import java.io.Closeable;
23-
import java.io.IOException;
24-
import java.util.Collection;
25-
import java.util.Collections;
26-
import java.util.List;
27-
2822
import org.elasticsearch.action.ActionModule;
2923
import org.elasticsearch.bootstrap.BootstrapCheck;
3024
import org.elasticsearch.client.Client;
@@ -39,6 +33,8 @@
3933
import org.elasticsearch.common.settings.Setting;
4034
import org.elasticsearch.common.settings.Settings;
4135
import org.elasticsearch.common.settings.SettingsModule;
36+
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
37+
import org.elasticsearch.common.xcontent.XContentParser;
4238
import org.elasticsearch.discovery.DiscoveryModule;
4339
import org.elasticsearch.index.IndexModule;
4440
import org.elasticsearch.indices.analysis.AnalysisModule;
@@ -51,6 +47,11 @@
5147
import org.elasticsearch.threadpool.ThreadPool;
5248
import org.elasticsearch.watcher.ResourceWatcherService;
5349

50+
import java.io.Closeable;
51+
import java.io.IOException;
52+
import java.util.Collection;
53+
import java.util.Collections;
54+
import java.util.List;
5455
import java.util.Map;
5556
import java.util.function.UnaryOperator;
5657

@@ -106,7 +107,7 @@ public Collection<Class<? extends LifecycleComponent>> getGuiceServiceClasses()
106107
*/
107108
public Collection<Object> createComponents(Client client, ClusterService clusterService, ThreadPool threadPool,
108109
ResourceWatcherService resourceWatcherService, ScriptService scriptService,
109-
SearchRequestParsers searchRequestParsers) {
110+
SearchRequestParsers searchRequestParsers, NamedXContentRegistry xContentRegistry) {
110111
return Collections.emptyList();
111112
}
112113

@@ -126,6 +127,14 @@ public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
126127
return Collections.emptyList();
127128
}
128129

130+
/**
131+
* Returns parsers for named objects this plugin will parse from {@link XContentParser#namedObject(Class, String, Object)}.
132+
* @see NamedWriteableRegistry
133+
*/
134+
public List<NamedXContentRegistry.Entry> getNamedXContent() {
135+
return Collections.emptyList();
136+
}
137+
129138
/**
130139
* Called before a new index is created on a node. The given module can be used to register index-level
131140
* extensions.

core/src/main/java/org/elasticsearch/rest/RestRequest.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.elasticsearch.common.bytes.BytesReference;
2929
import org.elasticsearch.common.unit.ByteSizeValue;
3030
import org.elasticsearch.common.unit.TimeValue;
31+
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
3132
import org.elasticsearch.common.xcontent.ToXContent;
3233
import org.elasticsearch.common.xcontent.XContentFactory;
3334
import org.elasticsearch.common.xcontent.XContentParser;
@@ -46,11 +47,13 @@
4647

4748
public abstract class RestRequest implements ToXContent.Params {
4849

50+
private final NamedXContentRegistry xContentRegistry;
4951
private final Map<String, String> params;
5052
private final String rawPath;
5153
private final Set<String> consumedParams = new HashSet<>();
5254

53-
public RestRequest(String uri) {
55+
public RestRequest(NamedXContentRegistry xContentRegistry, String uri) {
56+
this.xContentRegistry = xContentRegistry;
5457
final Map<String, String> params = new HashMap<>();
5558
int pathEndPos = uri.indexOf('?');
5659
if (pathEndPos < 0) {
@@ -62,7 +65,8 @@ public RestRequest(String uri) {
6265
this.params = params;
6366
}
6467

65-
public RestRequest(Map<String, String> params, String path) {
68+
public RestRequest(NamedXContentRegistry xContentRegistry, Map<String, String> params, String path) {
69+
this.xContentRegistry = xContentRegistry;
6670
this.params = params;
6771
this.rawPath = path;
6872
}
@@ -238,7 +242,7 @@ public final XContentParser contentParser() throws IOException {
238242
if (content.length() == 0) {
239243
throw new ElasticsearchParseException("Body required");
240244
}
241-
return XContentFactory.xContent(content).createParser(content);
245+
return XContentFactory.xContent(content).createParser(xContentRegistry, content);
242246
}
243247

244248
/**
@@ -270,7 +274,7 @@ public final XContentParser contentOrSourceParamParser() throws IOException {
270274
if (content.length() == 0) {
271275
throw new ElasticsearchParseException("Body required");
272276
}
273-
return XContentFactory.xContent(content).createParser(content);
277+
return XContentFactory.xContent(content).createParser(xContentRegistry, content);
274278
}
275279

276280
/**
@@ -281,7 +285,7 @@ public final XContentParser contentOrSourceParamParser() throws IOException {
281285
public final void withContentOrSourceParamParserOrNull(CheckedConsumer<XContentParser, IOException> withParser) throws IOException {
282286
BytesReference content = contentOrSourceParam();
283287
if (content.length() > 0) {
284-
try (XContentParser parser = XContentFactory.xContent(content).createParser(content)) {
288+
try (XContentParser parser = XContentFactory.xContent(content).createParser(xContentRegistry, content)) {
285289
withParser.accept(parser);
286290
}
287291
} else {

core/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.elasticsearch.common.bytes.BytesReference;
3030
import org.elasticsearch.common.inject.Inject;
3131
import org.elasticsearch.common.settings.Settings;
32+
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
3233
import org.elasticsearch.common.xcontent.XContent;
3334
import org.elasticsearch.common.xcontent.XContentFactory;
3435
import org.elasticsearch.common.xcontent.XContentParser;
@@ -53,11 +54,14 @@
5354
public class RestMultiSearchAction extends BaseRestHandler {
5455

5556
private final boolean allowExplicitIndex;
57+
private final NamedXContentRegistry xContentRegistry;
5658
private final SearchRequestParsers searchRequestParsers;
5759

5860
@Inject
59-
public RestMultiSearchAction(Settings settings, RestController controller, SearchRequestParsers searchRequestParsers) {
61+
public RestMultiSearchAction(Settings settings, RestController controller, NamedXContentRegistry xContentRegistry,
62+
SearchRequestParsers searchRequestParsers) {
6063
super(settings);
64+
this.xContentRegistry = xContentRegistry;
6165
this.searchRequestParsers = searchRequestParsers;
6266

6367
controller.registerHandler(GET, "/_msearch", this);
@@ -72,23 +76,24 @@ public RestMultiSearchAction(Settings settings, RestController controller, Searc
7276

7377
@Override
7478
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
75-
MultiSearchRequest multiSearchRequest = parseRequest(request, allowExplicitIndex, searchRequestParsers, parseFieldMatcher);
79+
MultiSearchRequest multiSearchRequest = parseRequest(request, allowExplicitIndex, xContentRegistry, searchRequestParsers,
80+
parseFieldMatcher);
7681
return channel -> client.multiSearch(multiSearchRequest, new RestToXContentListener<>(channel));
7782
}
7883

7984
/**
8085
* Parses a {@link RestRequest} body and returns a {@link MultiSearchRequest}
8186
*/
8287
public static MultiSearchRequest parseRequest(RestRequest restRequest, boolean allowExplicitIndex,
83-
SearchRequestParsers searchRequestParsers,
88+
NamedXContentRegistry xContentRegistry, SearchRequestParsers searchRequestParsers,
8489
ParseFieldMatcher parseFieldMatcher) throws IOException {
8590

8691
MultiSearchRequest multiRequest = new MultiSearchRequest();
8792
if (restRequest.hasParam("max_concurrent_searches")) {
8893
multiRequest.maxConcurrentSearchRequests(restRequest.paramAsInt("max_concurrent_searches", 0));
8994
}
9095

91-
parseMultiLineRequest(restRequest, multiRequest.indicesOptions(), allowExplicitIndex, (searchRequest, parser) -> {
96+
parseMultiLineRequest(restRequest, multiRequest.indicesOptions(), allowExplicitIndex, xContentRegistry, (searchRequest, parser) -> {
9297
try {
9398
final QueryParseContext queryParseContext = new QueryParseContext(searchRequestParsers.queryParsers, parser,
9499
parseFieldMatcher);
@@ -107,7 +112,7 @@ public static MultiSearchRequest parseRequest(RestRequest restRequest, boolean a
107112
* Parses a multi-line {@link RestRequest} body, instanciating a {@link SearchRequest} for each line and applying the given consumer.
108113
*/
109114
public static void parseMultiLineRequest(RestRequest request, IndicesOptions indicesOptions, boolean allowExplicitIndex,
110-
BiConsumer<SearchRequest, XContentParser> consumer) throws IOException {
115+
NamedXContentRegistry xContentRegistry, BiConsumer<SearchRequest, XContentParser> consumer) throws IOException {
111116

112117
String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
113118
String[] types = Strings.splitStringByCommaToArray(request.param("type"));
@@ -153,7 +158,7 @@ public static void parseMultiLineRequest(RestRequest request, IndicesOptions ind
153158

154159
// now parse the action
155160
if (nextMarker - from > 0) {
156-
try (XContentParser parser = xContent.createParser(data.slice(from, nextMarker - from))) {
161+
try (XContentParser parser = xContent.createParser(xContentRegistry, data.slice(from, nextMarker - from))) {
157162
Map<String, Object> source = parser.map();
158163
for (Map.Entry<String, Object> entry : source.entrySet()) {
159164
Object value = entry.getValue();
@@ -187,7 +192,7 @@ public static void parseMultiLineRequest(RestRequest request, IndicesOptions ind
187192
break;
188193
}
189194
BytesReference bytes = data.slice(from, nextMarker - from);
190-
try (XContentParser parser = XContentFactory.xContent(bytes).createParser(bytes)) {
195+
try (XContentParser parser = XContentFactory.xContent(bytes).createParser(xContentRegistry, bytes)) {
191196
consumer.accept(searchRequest, parser);
192197
}
193198
// move pointers

0 commit comments

Comments
 (0)