Skip to content

Commit

Permalink
Replace more deprecated ParseField.match calls with non-deprecated ca…
Browse files Browse the repository at this point in the history
…ll (#28525)

* Replace more deprecated ParseField.match calls with non-deprecated call

This replaces more of the `ParseField.match` calls with the same call using a
deprecation handler.

Relates to #28504

* Address Nik's comments
  • Loading branch information
dakrone committed Feb 8, 2018
1 parent f0d9faa commit f3df274
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
Expand Down Expand Up @@ -371,28 +374,28 @@ public CreateIndexRequest source(byte[] source, int offset, int length, XContent
*/
public CreateIndexRequest source(BytesReference source, XContentType xContentType) {
Objects.requireNonNull(xContentType);
source(XContentHelper.convertToMap(source, false, xContentType).v2());
source(XContentHelper.convertToMap(source, false, xContentType).v2(), LoggingDeprecationHandler.INSTANCE);
return this;
}

/**
* Sets the settings and mappings as a single source.
*/
@SuppressWarnings("unchecked")
public CreateIndexRequest source(Map<String, ?> source) {
public CreateIndexRequest source(Map<String, ?> source, DeprecationHandler deprecationHandler) {
boolean found = false;
for (Map.Entry<String, ?> entry : source.entrySet()) {
String name = entry.getKey();
if (SETTINGS.match(name)) {
if (SETTINGS.match(name, deprecationHandler)) {
found = true;
settings((Map<String, Object>) entry.getValue());
} else if (MAPPINGS.match(name)) {
} else if (MAPPINGS.match(name, deprecationHandler)) {
found = true;
Map<String, Object> mappings = (Map<String, Object>) entry.getValue();
for (Map.Entry<String, Object> entry1 : mappings.entrySet()) {
mapping(entry1.getKey(), (Map<String, Object>) entry1.getValue());
}
} else if (ALIASES.match(name)) {
} else if (ALIASES.match(name, deprecationHandler)) {
found = true;
aliases((Map<String, Object>) entry.getValue());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentType;

Expand Down Expand Up @@ -219,7 +220,7 @@ public CreateIndexRequestBuilder setSource(byte[] source, int offset, int length
* Sets the settings and mappings as a single source.
*/
public CreateIndexRequestBuilder setSource(Map<String, ?> source) {
request.source(source);
request.source(source, LoggingDeprecationHandler.INSTANCE);
return this;
}

Expand Down
28 changes: 14 additions & 14 deletions server/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,45 +348,45 @@ public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Null
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token.isValue()) {
if (INDEX.match(currentFieldName)){
if (INDEX.match(currentFieldName, parser.getDeprecationHandler())){
if (!allowExplicitIndex) {
throw new IllegalArgumentException("explicit index in bulk is not allowed");
}
index = parser.text();
} else if (TYPE.match(currentFieldName)) {
} else if (TYPE.match(currentFieldName, parser.getDeprecationHandler())) {
type = parser.text();
} else if (ID.match(currentFieldName)) {
} else if (ID.match(currentFieldName, parser.getDeprecationHandler())) {
id = parser.text();
} else if (ROUTING.match(currentFieldName)) {
} else if (ROUTING.match(currentFieldName, parser.getDeprecationHandler())) {
routing = parser.text();
} else if (PARENT.match(currentFieldName)) {
} else if (PARENT.match(currentFieldName, parser.getDeprecationHandler())) {
parent = parser.text();
} else if (OP_TYPE.match(currentFieldName)) {
} else if (OP_TYPE.match(currentFieldName, parser.getDeprecationHandler())) {
opType = parser.text();
} else if (VERSION.match(currentFieldName)) {
} else if (VERSION.match(currentFieldName, parser.getDeprecationHandler())) {
version = parser.longValue();
} else if (VERSION_TYPE.match(currentFieldName)) {
} else if (VERSION_TYPE.match(currentFieldName, parser.getDeprecationHandler())) {
versionType = VersionType.fromString(parser.text());
} else if (RETRY_ON_CONFLICT.match(currentFieldName)) {
} else if (RETRY_ON_CONFLICT.match(currentFieldName, parser.getDeprecationHandler())) {
retryOnConflict = parser.intValue();
} else if (PIPELINE.match(currentFieldName)) {
} else if (PIPELINE.match(currentFieldName, parser.getDeprecationHandler())) {
pipeline = parser.text();
} else if (FIELDS.match(currentFieldName)) {
} else if (FIELDS.match(currentFieldName, parser.getDeprecationHandler())) {
throw new IllegalArgumentException("Action/metadata line [" + line + "] contains a simple value for parameter [fields] while a list is expected");
} else if (SOURCE.match(currentFieldName)) {
} else if (SOURCE.match(currentFieldName, parser.getDeprecationHandler())) {
fetchSourceContext = FetchSourceContext.fromXContent(parser);
} else {
throw new IllegalArgumentException("Action/metadata line [" + line + "] contains an unknown parameter [" + currentFieldName + "]");
}
} else if (token == XContentParser.Token.START_ARRAY) {
if (FIELDS.match(currentFieldName)) {
if (FIELDS.match(currentFieldName, parser.getDeprecationHandler())) {
DEPRECATION_LOGGER.deprecated("Deprecated field [fields] used, expected [_source] instead");
List<Object> values = parser.list();
fields = values.toArray(new String[values.size()]);
} else {
throw new IllegalArgumentException("Malformed action/metadata line [" + line + "], expected a simple value for field [" + currentFieldName + "] but found [" + token + "]");
}
} else if (token == XContentParser.Token.START_OBJECT && SOURCE.match(currentFieldName)) {
} else if (token == XContentParser.Token.START_OBJECT && SOURCE.match(currentFieldName, parser.getDeprecationHandler())) {
fetchSourceContext = FetchSourceContext.fromXContent(parser);
} else if (token != XContentParser.Token.VALUE_NULL) {
throw new IllegalArgumentException("Malformed action/metadata line [" + line + "], expected a simple value for field [" + currentFieldName + "] but found [" + token + "]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,30 +418,30 @@ private static void parseDocuments(XContentParser parser, List<Item> items, @Nul
if (token == Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token.isValue()) {
if (INDEX.match(currentFieldName)) {
if (INDEX.match(currentFieldName, parser.getDeprecationHandler())) {
if (!allowExplicitIndex) {
throw new IllegalArgumentException("explicit index in multi get is not allowed");
}
index = parser.text();
} else if (TYPE.match(currentFieldName)) {
} else if (TYPE.match(currentFieldName, parser.getDeprecationHandler())) {
type = parser.text();
} else if (ID.match(currentFieldName)) {
} else if (ID.match(currentFieldName, parser.getDeprecationHandler())) {
id = parser.text();
} else if (ROUTING.match(currentFieldName)) {
} else if (ROUTING.match(currentFieldName, parser.getDeprecationHandler())) {
routing = parser.text();
} else if (PARENT.match(currentFieldName)) {
} else if (PARENT.match(currentFieldName, parser.getDeprecationHandler())) {
parent = parser.text();
} else if (FIELDS.match(currentFieldName)) {
} else if (FIELDS.match(currentFieldName, parser.getDeprecationHandler())) {
throw new ParsingException(parser.getTokenLocation(),
"Unsupported field [fields] used, expected [stored_fields] instead");
} else if (STORED_FIELDS.match(currentFieldName)) {
} else if (STORED_FIELDS.match(currentFieldName, parser.getDeprecationHandler())) {
storedFields = new ArrayList<>();
storedFields.add(parser.text());
} else if (VERSION.match(currentFieldName)) {
} else if (VERSION.match(currentFieldName, parser.getDeprecationHandler())) {
version = parser.longValue();
} else if (VERSION_TYPE.match(currentFieldName)) {
} else if (VERSION_TYPE.match(currentFieldName, parser.getDeprecationHandler())) {
versionType = VersionType.fromString(parser.text());
} else if (SOURCE.match(currentFieldName)) {
} else if (SOURCE.match(currentFieldName, parser.getDeprecationHandler())) {
// check lenient to avoid interpreting the value as string but parse strict in order to provoke an error early on.
if (parser.isBooleanValueLenient()) {
fetchSourceContext = new FetchSourceContext(parser.booleanValue(), fetchSourceContext.includes(),
Expand All @@ -456,15 +456,15 @@ private static void parseDocuments(XContentParser parser, List<Item> items, @Nul
throw new ElasticsearchParseException("failed to parse multi get request. unknown field [{}]", currentFieldName);
}
} else if (token == Token.START_ARRAY) {
if (FIELDS.match(currentFieldName)) {
if (FIELDS.match(currentFieldName, parser.getDeprecationHandler())) {
throw new ParsingException(parser.getTokenLocation(),
"Unsupported field [fields] used, expected [stored_fields] instead");
} else if (STORED_FIELDS.match(currentFieldName)) {
} else if (STORED_FIELDS.match(currentFieldName, parser.getDeprecationHandler())) {
storedFields = new ArrayList<>();
while ((token = parser.nextToken()) != Token.END_ARRAY) {
storedFields.add(parser.text());
}
} else if (SOURCE.match(currentFieldName)) {
} else if (SOURCE.match(currentFieldName, parser.getDeprecationHandler())) {
ArrayList<String> includes = new ArrayList<>();
while ((token = parser.nextToken()) != Token.END_ARRAY) {
includes.add(parser.text());
Expand All @@ -474,7 +474,7 @@ private static void parseDocuments(XContentParser parser, List<Item> items, @Nul
}

} else if (token == Token.START_OBJECT) {
if (SOURCE.match(currentFieldName)) {
if (SOURCE.match(currentFieldName, parser.getDeprecationHandler())) {
List<String> currentList = null, includes = null, excludes = null;

while ((token = parser.nextToken()) != Token.END_OBJECT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,22 +204,24 @@ private static MultiGetItemResponse parseItem(XContentParser parser) throws IOEx
switch (token) {
case FIELD_NAME:
currentFieldName = parser.currentName();
if (INDEX.match(currentFieldName) == false && TYPE.match(currentFieldName) == false &&
ID.match(currentFieldName) == false && ERROR.match(currentFieldName) == false) {
if (INDEX.match(currentFieldName, parser.getDeprecationHandler()) == false
&& TYPE.match(currentFieldName, parser.getDeprecationHandler()) == false
&& ID.match(currentFieldName, parser.getDeprecationHandler()) == false
&& ERROR.match(currentFieldName, parser.getDeprecationHandler()) == false) {
getResult = GetResult.fromXContentEmbedded(parser, index, type, id);
}
break;
case VALUE_STRING:
if (INDEX.match(currentFieldName)) {
if (INDEX.match(currentFieldName, parser.getDeprecationHandler())) {
index = parser.text();
} else if (TYPE.match(currentFieldName)) {
} else if (TYPE.match(currentFieldName, parser.getDeprecationHandler())) {
type = parser.text();
} else if (ID.match(currentFieldName)) {
} else if (ID.match(currentFieldName, parser.getDeprecationHandler())) {
id = parser.text();
}
break;
case START_OBJECT:
if (ERROR.match(currentFieldName)) {
if (ERROR.match(currentFieldName, parser.getDeprecationHandler())) {
exception = ElasticsearchException.fromXContent(parser);
}
break;
Expand Down
Loading

0 comments on commit f3df274

Please sign in to comment.