Skip to content

Commit

Permalink
Remove deprecated es.http.cname_in_publish_address setting (elastic#4…
Browse files Browse the repository at this point in the history
…5616)

Follow up on elastic#32806.

The system property es.http.cname_in_publish_address is deprecated
starting from 7.0.0 and deprecation warning should be added if the
property is specified.
This PR will go to 7.x and master.
Follow-up PR to remove es.http.cname_in_publish_address property
completely will go to the master.
  • Loading branch information
Andrey Ershov committed Aug 22, 2019
1 parent fab31ab commit a5ceca7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
16 changes: 7 additions & 9 deletions server/src/main/java/org/elasticsearch/http/HttpInfo.java
Expand Up @@ -45,7 +45,7 @@ public class HttpInfo implements Writeable, ToXContentFragment {

private final BoundTransportAddress address;
private final long maxContentLength;
private final boolean cnameInPublishHost;
private final boolean cnameInPublishHostProperty;

public HttpInfo(StreamInput in) throws IOException {
this(new BoundTransportAddress(in), in.readLong(), CNAME_IN_PUBLISH_HOST);
Expand All @@ -55,10 +55,10 @@ public HttpInfo(BoundTransportAddress address, long maxContentLength) {
this(address, maxContentLength, CNAME_IN_PUBLISH_HOST);
}

HttpInfo(BoundTransportAddress address, long maxContentLength, boolean cnameInPublishHost) {
HttpInfo(BoundTransportAddress address, long maxContentLength, boolean cnameInPublishHostProperty) {
this.address = address;
this.maxContentLength = maxContentLength;
this.cnameInPublishHost = cnameInPublishHost;
this.cnameInPublishHostProperty = cnameInPublishHostProperty;
}

@Override
Expand All @@ -83,13 +83,11 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
String publishAddressString = publishAddress.toString();
String hostString = publishAddress.address().getHostString();
if (InetAddresses.isInetAddress(hostString) == false) {
if (cnameInPublishHost) {
publishAddressString = hostString + '/' + publishAddress.toString();
} else {
publishAddressString = hostString + '/' + publishAddress.toString();
if (cnameInPublishHostProperty) {
deprecationLogger.deprecated(
"[http.publish_host] 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.http.cname_in_publish_address=true to enforce non-deprecated formatting."
"es.http.cname_in_publish_address system property is deprecated and no longer affects http.publish_address " +
"formatting. Remove this property to get rid of this deprecation warning."
);
}
}
Expand Down
23 changes: 13 additions & 10 deletions server/src/test/java/org/elasticsearch/http/HttpInfoTests.java
Expand Up @@ -40,22 +40,25 @@ public void testCorrectlyDisplayPublishedCname() throws Exception {
new BoundTransportAddress(
new TransportAddress[]{new TransportAddress(localhost, port)},
new TransportAddress(localhost, port)
), 0L, true
), 0L, false
), "localhost/" + NetworkAddress.format(localhost) + ':' + port
);
}

public void hideCnameIfDeprecatedFormat() throws Exception {
public void testDeprecatedWarningIfPropertySpecified() throws Exception {
InetAddress localhost = InetAddress.getByName("localhost");
int port = 9200;
assertPublishAddress(
new HttpInfo(
new BoundTransportAddress(
new TransportAddress[]{new TransportAddress(localhost, port)},
new TransportAddress(localhost, port)
), 0L, false
), NetworkAddress.format(localhost) + ':' + port
new HttpInfo(
new BoundTransportAddress(
new TransportAddress[]{new TransportAddress(localhost, port)},
new TransportAddress(localhost, port)
), 0L, true
), "localhost/" + NetworkAddress.format(localhost) + ':' + port
);
assertWarnings(
"es.http.cname_in_publish_address system property is deprecated and no longer affects http.publish_address " +
"formatting. Remove this property to get rid of this deprecation warning.");
}

public void testCorrectDisplayPublishedIp() throws Exception {
Expand All @@ -66,7 +69,7 @@ public void testCorrectDisplayPublishedIp() throws Exception {
new BoundTransportAddress(
new TransportAddress[]{new TransportAddress(localhost, port)},
new TransportAddress(localhost, port)
), 0L, true
), 0L, false
), NetworkAddress.format(localhost) + ':' + port
);
}
Expand All @@ -77,7 +80,7 @@ public void testCorrectDisplayPublishedIpv6() throws Exception {
new TransportAddress(InetAddress.getByName(NetworkAddress.format(InetAddress.getByName("0:0:0:0:0:0:0:1"))), port);
assertPublishAddress(
new HttpInfo(
new BoundTransportAddress(new TransportAddress[]{localhost}, localhost), 0L, true
new BoundTransportAddress(new TransportAddress[]{localhost}, localhost), 0L, false
), localhost.toString()
);
}
Expand Down

0 comments on commit a5ceca7

Please sign in to comment.