Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ public class TransportInfo implements Writeable, ToXContentFragment {

private BoundTransportAddress address;
private Map<String, BoundTransportAddress> profileAddresses;
private final boolean cnameInPublishAddress;
private final boolean cnameInPublishAddressProperty;

public TransportInfo(BoundTransportAddress address, @Nullable Map<String, BoundTransportAddress> profileAddresses) {
this(address, profileAddresses, CNAME_IN_PUBLISH_ADDRESS);
}

public TransportInfo(BoundTransportAddress address, @Nullable Map<String, BoundTransportAddress> profileAddresses,
boolean cnameInPublishAddress) {
boolean cnameInPublishAddressProperty) {
this.address = address;
this.profileAddresses = profileAddresses;
this.cnameInPublishAddress = cnameInPublishAddress;
this.cnameInPublishAddressProperty = cnameInPublishAddressProperty;
}

public TransportInfo(StreamInput in) throws IOException {
Expand All @@ -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
Expand All @@ -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."
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, BoundTransportAddress> 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
);
}
Expand All @@ -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()
);
}
Expand Down