From 32f18d0b97820b3dbf1387c35d10be694cb11ff7 Mon Sep 17 00:00:00 2001 From: Andrey Ershov Date: Fri, 16 Aug 2019 17:52:02 +0200 Subject: [PATCH] Log deprecation warning if es.transport.cname_in_publish_address property is specified --- .../transport/TransportInfo.java | 20 ++++++------ .../transport/TransportInfoTests.java | 31 ++++++++++--------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/transport/TransportInfo.java b/server/src/main/java/org/elasticsearch/transport/TransportInfo.java index 9212fef631776..ead1af8faca50 100644 --- a/server/src/main/java/org/elasticsearch/transport/TransportInfo.java +++ b/server/src/main/java/org/elasticsearch/transport/TransportInfo.java @@ -47,17 +47,17 @@ public class TransportInfo implements Writeable, ToXContentFragment { private BoundTransportAddress address; private Map profileAddresses; - private final boolean cnameInPublishAddress; + private final boolean cnameInPublishAddressProperty; public TransportInfo(BoundTransportAddress address, @Nullable Map profileAddresses) { this(address, profileAddresses, CNAME_IN_PUBLISH_ADDRESS); } public TransportInfo(BoundTransportAddress address, @Nullable Map profileAddresses, - boolean cnameInPublishAddress) { + boolean cnameInPublishAddressProperty) { this.address = address; this.profileAddresses = profileAddresses; - this.cnameInPublishAddress = cnameInPublishAddress; + this.cnameInPublishAddressProperty = cnameInPublishAddressProperty; } public TransportInfo(StreamInput in) throws IOException { @@ -71,7 +71,7 @@ public TransportInfo(StreamInput in) throws IOException { profileAddresses.put(key, value); } } - this.cnameInPublishAddress = CNAME_IN_PUBLISH_ADDRESS; + this.cnameInPublishAddressProperty = CNAME_IN_PUBLISH_ADDRESS; } @Override @@ -97,17 +97,15 @@ static final class Fields { static final String PROFILES = "profiles"; } - private String formatPublishAddressString(String propertyName, TransportAddress publishAddress){ + private String formatPublishAddressString(String propertyName, TransportAddress publishAddress) { String publishAddressString = publishAddress.toString(); String hostString = publishAddress.address().getHostString(); if (InetAddresses.isInetAddress(hostString) == false) { - if (cnameInPublishAddress) { - publishAddressString = hostString + '/' + publishAddress.toString(); - } else { + publishAddressString = hostString + '/' + publishAddress.toString(); + if (cnameInPublishAddressProperty) { deprecationLogger.deprecated( - propertyName + " was printed as [ip:port] instead of [hostname/ip:port]. " - + "This format is deprecated and will change to [hostname/ip:port] in a future version. " - + "Use -Des.transport.cname_in_publish_address=true to enforce non-deprecated formatting." + "es.transport.cname_in_publish_address system property is deprecated and no longer affects " + propertyName + + " formatting. Remove this property to get rid of this deprecation warning." ); } } diff --git a/server/src/test/java/org/elasticsearch/transport/TransportInfoTests.java b/server/src/test/java/org/elasticsearch/transport/TransportInfoTests.java index ea6ca96bb9b64..61dc3970093d7 100644 --- a/server/src/test/java/org/elasticsearch/transport/TransportInfoTests.java +++ b/server/src/test/java/org/elasticsearch/transport/TransportInfoTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.transport; +import org.elasticsearch.Version; import org.elasticsearch.common.network.NetworkAddress; import org.elasticsearch.common.transport.BoundTransportAddress; import org.elasticsearch.common.transport.TransportAddress; @@ -34,45 +35,47 @@ public class TransportInfoTests extends ESTestCase { - private TransportInfo createTransportInfo(InetAddress address, int port, boolean cnameInPublishAddress) { + private TransportInfo createTransportInfo(InetAddress address, int port, boolean cnameInPublishAddressProperty) { BoundTransportAddress boundAddress = new BoundTransportAddress( new TransportAddress[]{new TransportAddress(address, port)}, new TransportAddress(address, port) ); Map profiles = Collections.singletonMap("test_profile", boundAddress); - return new TransportInfo(boundAddress, profiles, cnameInPublishAddress); + return new TransportInfo(boundAddress, profiles, cnameInPublishAddressProperty); + } + + public void testDoNotForgetToRemoveProperty() { + assertTrue("Remove es.transport.cname_in_publish_address property from TransportInfo in 9.0.0", Version.CURRENT.major < 9); } public void testCorrectlyDisplayPublishedCname() throws Exception { InetAddress address = InetAddress.getByName("localhost"); int port = 9200; assertPublishAddress( - createTransportInfo(address, port,true), + createTransportInfo(address, port, false), "localhost/" + NetworkAddress.format(address) + ':' + port ); } - public void testHideCnameIfDeprecatedFormat() throws Exception { + public void testDeprecatedWarningIfPropertySpecified() throws Exception { InetAddress address = InetAddress.getByName("localhost"); int port = 9200; assertPublishAddress( - createTransportInfo(address, port,false), - NetworkAddress.format(address) + ':' + port + createTransportInfo(address, port, true), + "localhost/" + NetworkAddress.format(address) + ':' + port ); - assertWarnings("transport.publish_address was printed as [ip:port] instead of [hostname/ip:port]. " + - "This format is deprecated and will change to [hostname/ip:port] in a future version. " + - "Use -Des.transport.cname_in_publish_address=true to enforce non-deprecated formatting.", + assertWarnings("es.transport.cname_in_publish_address system property is deprecated and no longer affects " + + "transport.publish_address formatting. Remove this property to get rid of this deprecation warning.", - "transport.test_profile.publish_address was printed as [ip:port] instead of [hostname/ip:port]. " + - "This format is deprecated and will change to [hostname/ip:port] in a future version. " + - "Use -Des.transport.cname_in_publish_address=true to enforce non-deprecated formatting."); + "es.transport.cname_in_publish_address system property is deprecated and no longer affects " + + "transport.test_profile.publish_address formatting. Remove this property to get rid of this deprecation warning."); } public void testCorrectDisplayPublishedIp() throws Exception { InetAddress address = InetAddress.getByName(NetworkAddress.format(InetAddress.getByName("localhost"))); int port = 9200; assertPublishAddress( - createTransportInfo(address, port,true), + createTransportInfo(address, port, false), NetworkAddress.format(address) + ':' + port ); } @@ -81,7 +84,7 @@ public void testCorrectDisplayPublishedIpv6() throws Exception { InetAddress address = InetAddress.getByName(NetworkAddress.format(InetAddress.getByName("0:0:0:0:0:0:0:1"))); int port = 9200; assertPublishAddress( - createTransportInfo(address, port,true), + createTransportInfo(address, port, false), new TransportAddress(address, port).toString() ); }