HLRC: Ban LoggingDeprecationHandler (#32756)
LoggingDeprecationHandler requires log4j2 but we don't require log4j2 in the client. This bans LoggingDeprecationHandler and removes all uses of it in the high level client. Closes #32151
This commit is contained in:
parent
22f7b03430
commit
2df80ca7e3
|
@ -96,7 +96,7 @@ import org.elasticsearch.common.SuppressForbidden;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.lucene.uid.Versions;
|
import org.elasticsearch.common.lucene.uid.Versions;
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
|
import org.elasticsearch.common.xcontent.DeprecationHandler;
|
||||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContent;
|
import org.elasticsearch.common.xcontent.XContent;
|
||||||
|
@ -424,8 +424,14 @@ final class RequestConverters {
|
||||||
BytesReference indexSource = indexRequest.source();
|
BytesReference indexSource = indexRequest.source();
|
||||||
XContentType indexXContentType = indexRequest.getContentType();
|
XContentType indexXContentType = indexRequest.getContentType();
|
||||||
|
|
||||||
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY,
|
try (XContentParser parser = XContentHelper.createParser(
|
||||||
LoggingDeprecationHandler.INSTANCE, indexSource, indexXContentType)) {
|
/*
|
||||||
|
* EMPTY and THROW are fine here because we just call
|
||||||
|
* copyCurrentStructure which doesn't touch the
|
||||||
|
* registry or deprecation.
|
||||||
|
*/
|
||||||
|
NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
|
||||||
|
indexSource, indexXContentType)) {
|
||||||
try (XContentBuilder builder = XContentBuilder.builder(bulkContentType.xContent())) {
|
try (XContentBuilder builder = XContentBuilder.builder(bulkContentType.xContent())) {
|
||||||
builder.copyCurrentStructure(parser);
|
builder.copyCurrentStructure(parser);
|
||||||
source = BytesReference.bytes(builder).toBytesRef();
|
source = BytesReference.bytes(builder).toBytesRef();
|
||||||
|
|
|
@ -59,7 +59,7 @@ import org.elasticsearch.common.CheckedConsumer;
|
||||||
import org.elasticsearch.common.CheckedFunction;
|
import org.elasticsearch.common.CheckedFunction;
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.xcontent.ContextParser;
|
import org.elasticsearch.common.xcontent.ContextParser;
|
||||||
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
|
import org.elasticsearch.common.xcontent.DeprecationHandler;
|
||||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
|
@ -1090,8 +1090,7 @@ public class RestHighLevelClient implements Closeable {
|
||||||
if (xContentType == null) {
|
if (xContentType == null) {
|
||||||
throw new IllegalStateException("Unsupported Content-Type: " + entity.getContentType().getValue());
|
throw new IllegalStateException("Unsupported Content-Type: " + entity.getContentType().getValue());
|
||||||
}
|
}
|
||||||
try (XContentParser parser = xContentType.xContent().createParser(registry,
|
try (XContentParser parser = xContentType.xContent().createParser(registry, DEPRECATION_HANDLER, entity.getContent())) {
|
||||||
LoggingDeprecationHandler.INSTANCE, entity.getContent())) {
|
|
||||||
return entityParser.apply(parser);
|
return entityParser.apply(parser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1109,6 +1108,19 @@ public class RestHighLevelClient implements Closeable {
|
||||||
return response.getStatusLine().getStatusCode() == 200;
|
return response.getStatusLine().getStatusCode() == 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ignores deprecation warnings. This is appropriate because it is only
|
||||||
|
* used to parse responses from Elasticsearch. Any deprecation warnings
|
||||||
|
* emitted there just mean that you are talking to an old version of
|
||||||
|
* Elasticsearch. There isn't anything you can do about the deprecation.
|
||||||
|
*/
|
||||||
|
private static final DeprecationHandler DEPRECATION_HANDLER = new DeprecationHandler() {
|
||||||
|
@Override
|
||||||
|
public void usedDeprecatedName(String usedName, String modernName) {}
|
||||||
|
@Override
|
||||||
|
public void usedDeprecatedField(String usedName, String replacedWith) {}
|
||||||
|
};
|
||||||
|
|
||||||
static List<NamedXContentRegistry.Entry> getDefaultNamedXContents() {
|
static List<NamedXContentRegistry.Entry> getDefaultNamedXContents() {
|
||||||
Map<String, ContextParser<Object, ? extends Aggregation>> map = new HashMap<>();
|
Map<String, ContextParser<Object, ? extends Aggregation>> map = new HashMap<>();
|
||||||
map.put(CardinalityAggregationBuilder.NAME, (p, c) -> ParsedCardinality.fromXContent(p, (String) c));
|
map.put(CardinalityAggregationBuilder.NAME, (p, c) -> ParsedCardinality.fromXContent(p, (String) c));
|
||||||
|
|
|
@ -19,3 +19,6 @@ org.apache.http.entity.ContentType#create(java.lang.String)
|
||||||
org.apache.http.entity.ContentType#create(java.lang.String,java.lang.String)
|
org.apache.http.entity.ContentType#create(java.lang.String,java.lang.String)
|
||||||
org.apache.http.entity.ContentType#create(java.lang.String,java.nio.charset.Charset)
|
org.apache.http.entity.ContentType#create(java.lang.String,java.nio.charset.Charset)
|
||||||
org.apache.http.entity.ContentType#create(java.lang.String,org.apache.http.NameValuePair[])
|
org.apache.http.entity.ContentType#create(java.lang.String,org.apache.http.NameValuePair[])
|
||||||
|
|
||||||
|
@defaultMessage We can't rely on log4j2 being on the classpath so don't log deprecations!
|
||||||
|
org.elasticsearch.common.xcontent.LoggingDeprecationHandler
|
||||||
|
|
|
@ -24,7 +24,7 @@ import org.elasticsearch.cluster.routing.ShardRouting;
|
||||||
import org.elasticsearch.cluster.routing.ShardRoutingState;
|
import org.elasticsearch.cluster.routing.ShardRoutingState;
|
||||||
import org.elasticsearch.cluster.routing.TestShardRouting;
|
import org.elasticsearch.cluster.routing.TestShardRouting;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
|
import org.elasticsearch.common.xcontent.DeprecationHandler;
|
||||||
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.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
|
@ -63,7 +63,7 @@ public class SyncedFlushResponseTests extends ESTestCase {
|
||||||
.xContent()
|
.xContent()
|
||||||
.createParser(
|
.createParser(
|
||||||
xContentRegistry(),
|
xContentRegistry(),
|
||||||
LoggingDeprecationHandler.INSTANCE,
|
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
|
||||||
BytesReference.bytes(serverResponsebuilder).streamInput()
|
BytesReference.bytes(serverResponsebuilder).streamInput()
|
||||||
).map()
|
).map()
|
||||||
);
|
);
|
||||||
|
@ -74,7 +74,7 @@ public class SyncedFlushResponseTests extends ESTestCase {
|
||||||
.xContent()
|
.xContent()
|
||||||
.createParser(
|
.createParser(
|
||||||
xContentRegistry(),
|
xContentRegistry(),
|
||||||
LoggingDeprecationHandler.INSTANCE,
|
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
|
||||||
BytesReference.bytes(clientResponsebuilder).streamInput()
|
BytesReference.bytes(clientResponsebuilder).streamInput()
|
||||||
)
|
)
|
||||||
.map()
|
.map()
|
||||||
|
@ -94,7 +94,9 @@ public class SyncedFlushResponseTests extends ESTestCase {
|
||||||
.contentType()
|
.contentType()
|
||||||
.xContent()
|
.xContent()
|
||||||
.createParser(
|
.createParser(
|
||||||
xContentRegistry(), LoggingDeprecationHandler.INSTANCE, BytesReference.bytes(builder).streamInput()
|
xContentRegistry(),
|
||||||
|
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
|
||||||
|
BytesReference.bytes(builder).streamInput()
|
||||||
);
|
);
|
||||||
SyncedFlushResponse originalResponse = plan.clientResult;
|
SyncedFlushResponse originalResponse = plan.clientResult;
|
||||||
SyncedFlushResponse parsedResponse = SyncedFlushResponse.fromXContent(parser);
|
SyncedFlushResponse parsedResponse = SyncedFlushResponse.fromXContent(parser);
|
||||||
|
@ -175,7 +177,8 @@ public class SyncedFlushResponseTests extends ESTestCase {
|
||||||
.contentType()
|
.contentType()
|
||||||
.xContent()
|
.xContent()
|
||||||
.createParser(
|
.createParser(
|
||||||
xContentRegistry(), LoggingDeprecationHandler.INSTANCE,
|
xContentRegistry(),
|
||||||
|
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
|
||||||
BytesReference.bytes(builder).streamInput()
|
BytesReference.bytes(builder).streamInput()
|
||||||
)
|
)
|
||||||
.map();
|
.map();
|
||||||
|
|
Loading…
Reference in New Issue