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 @@ -11,49 +11,25 @@

import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.logging.DeprecationCategory;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.network.InetAddresses;
import org.elasticsearch.common.transport.BoundTransportAddress;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.common.util.Maps;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.UpdateForV9;
import org.elasticsearch.node.ReportingService;
import org.elasticsearch.xcontent.XContentBuilder;

import java.io.IOException;
import java.util.Map;

import static org.elasticsearch.core.Booleans.parseBoolean;

public class TransportInfo implements ReportingService.Info {

private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(TransportInfo.class);

/** Whether to add hostname to publish host field when serializing. */
@UpdateForV9 // Remove es.transport.cname_in_publish_address property from TransportInfo in 9.0.0
private static final boolean CNAME_IN_PUBLISH_ADDRESS = parseBoolean(
System.getProperty("es.transport.cname_in_publish_address"),
false
);

private final BoundTransportAddress address;
private Map<String, BoundTransportAddress> profileAddresses;
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 cnameInPublishAddressProperty
) {
this.address = address;
this.profileAddresses = profileAddresses;
this.cnameInPublishAddressProperty = cnameInPublishAddressProperty;
}

public TransportInfo(StreamInput in) throws IOException {
Expand All @@ -67,7 +43,6 @@ public TransportInfo(StreamInput in) throws IOException {
profileAddresses.put(key, value);
}
}
this.cnameInPublishAddressProperty = CNAME_IN_PUBLISH_ADDRESS;
}

@Override
Expand Down Expand Up @@ -97,16 +72,7 @@ private String formatPublishAddressString(String propertyName, TransportAddress
String publishAddressString = publishAddress.toString();
String hostString = publishAddress.address().getHostString();
if (InetAddresses.isInetAddress(hostString) == false) {
publishAddressString = hostString + '/' + publishAddress.toString();
if (cnameInPublishAddressProperty) {
deprecationLogger.warn(
DeprecationCategory.SETTINGS,
"cname_in_publish_address",
"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."
);
}
publishAddressString = hostString + '/' + publishAddress;
}
return publishAddressString;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,44 +24,31 @@

public class TransportInfoTests extends ESTestCase {

private TransportInfo createTransportInfo(InetAddress address, int port, boolean cnameInPublishAddressProperty) {
private TransportInfo createTransportInfo(InetAddress address, int port) {
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, cnameInPublishAddressProperty);
return new TransportInfo(boundAddress, profiles);
}

public void testCorrectlyDisplayPublishedCname() throws Exception {
InetAddress address = InetAddress.getByName("localhost");
int port = 9200;
assertPublishAddress(createTransportInfo(address, port, false), "localhost/" + NetworkAddress.format(address) + ':' + port);
}

public void testDeprecatedWarningIfPropertySpecified() throws Exception {
InetAddress address = InetAddress.getByName("localhost");
int port = 9200;
assertPublishAddress(createTransportInfo(address, port, true), "localhost/" + NetworkAddress.format(address) + ':' + port);
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.",

"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."
);
assertPublishAddress(createTransportInfo(address, port), "localhost/" + NetworkAddress.format(address) + ':' + port);
}

public void testCorrectDisplayPublishedIp() throws Exception {
InetAddress address = InetAddress.getByName(NetworkAddress.format(InetAddress.getByName("localhost")));
int port = 9200;
assertPublishAddress(createTransportInfo(address, port, false), NetworkAddress.format(address) + ':' + port);
assertPublishAddress(createTransportInfo(address, port), NetworkAddress.format(address) + ':' + port);
}

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, false), new TransportAddress(address, port).toString());
assertPublishAddress(createTransportInfo(address, port), new TransportAddress(address, port).toString());
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void testDoExecute() throws Exception {
null,
null,
null,
new TransportInfo(new BoundTransportAddress(new TransportAddress[] { n.getAddress() }, n.getAddress()), null, false),
new TransportInfo(new BoundTransportAddress(new TransportAddress[] { n.getAddress() }, n.getAddress()), null),
null,
null,
null,
Expand Down