From 17930930a7191e71b7426fc66afc7d09b29fb6e6 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Tue, 24 Jan 2017 11:24:08 +0100 Subject: [PATCH] Update after review --- docs/plugins/discovery-ec2.asciidoc | 4 +++- .../java/org/elasticsearch/cloud/aws/AwsEc2Service.java | 5 +++-- .../discovery/ec2/AwsEc2UnicastHostsProvider.java | 2 +- .../elasticsearch/discovery/ec2/Ec2DiscoveryTests.java | 8 +++++--- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/docs/plugins/discovery-ec2.asciidoc b/docs/plugins/discovery-ec2.asciidoc index ea08011f329..aaaf7d8e5db 100644 --- a/docs/plugins/discovery-ec2.asciidoc +++ b/docs/plugins/discovery-ec2.asciidoc @@ -176,11 +176,13 @@ The following are a list of settings (prefixed with `discovery.ec2`) that can fu -- The type of host type to use to communicate with other instances. Can be one of `private_ip`, `public_ip`, `private_dns`, `public_dns` or `tag:TAGNAME` where -`TAGNAME` is the tag field you defined for your ec2 instance. +`TAGNAME` refers to a name of a tag configured for all EC2 instances. Instances which don't +have this tag set will be ignored by the discovery process. For example if you defined a tag `my-elasticsearch-host` in ec2 and set it to `myhostname1.mydomain.com`, then setting `host_type: tag:my-elasticsearch-host` will tell Discovery Ec2 plugin to read the host name from the `my-elasticsearch-host` tag. In this case, it will be resolved to `myhostname1.mydomain.com`. +http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html[Read more about EC2 Tags]. Defaults to `private_ip`. -- diff --git a/plugins/discovery-ec2/src/main/java/org/elasticsearch/cloud/aws/AwsEc2Service.java b/plugins/discovery-ec2/src/main/java/org/elasticsearch/cloud/aws/AwsEc2Service.java index 256e64c347e..125dfa4a69a 100644 --- a/plugins/discovery-ec2/src/main/java/org/elasticsearch/cloud/aws/AwsEc2Service.java +++ b/plugins/discovery-ec2/src/main/java/org/elasticsearch/cloud/aws/AwsEc2Service.java @@ -174,8 +174,9 @@ public interface AwsEc2Service { /** * discovery.ec2.host_type: The type of host type to use to communicate with other instances. - * Can be one of private_ip, public_ip, private_dns, public_dns or meta:XXXX where - * XXXX is the metadata field name we will read the address from. Defaults to private_ip. + * Can be one of private_ip, public_ip, private_dns, public_dns or tag:XXXX where + * XXXX refers to a name of a tag configured for all EC2 instances. Instances which don't + * have this tag set will be ignored by the discovery process. Defaults to private_ip. */ Setting HOST_TYPE_SETTING = new Setting<>("discovery.ec2.host_type", HostType.PRIVATE_IP, Function.identity(), Property.NodeScope); diff --git a/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2UnicastHostsProvider.java b/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2UnicastHostsProvider.java index b0f662ffbef..5e97e92fa52 100644 --- a/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2UnicastHostsProvider.java +++ b/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2UnicastHostsProvider.java @@ -181,7 +181,7 @@ public class AwsEc2UnicastHostsProvider extends AbstractComponent implements Uni TransportAddress[] addresses = transportService.addressesFromString(address, 1); for (int i = 0; i < addresses.length; i++) { logger.trace("adding {}, address {}, transport_address {}", instance.getInstanceId(), address, addresses[i]); - discoNodes.add(new DiscoveryNode("#cloud-" + instance.getInstanceId() + "-" + i, addresses[i], + discoNodes.add(new DiscoveryNode(instance.getInstanceId(), "#cloud-" + instance.getInstanceId() + "-" + i, addresses[i], emptyMap(), emptySet(), Version.CURRENT.minimumCompatibilityVersion())); } } catch (Exception e) { diff --git a/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryTests.java b/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryTests.java index b69d24974fa..59193556309 100644 --- a/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryTests.java +++ b/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryTests.java @@ -268,7 +268,7 @@ public class Ec2DiscoveryTests extends ESTestCase { for (int node = 0; node < nodes; node++) { addresses[node] = "192.168.0." + (node + 1); - poorMansDNS.put("bar_" + node, new TransportAddress(InetAddress.getByName(addresses[node]), 9300)); + poorMansDNS.put("node" + (node + 1), new TransportAddress(InetAddress.getByName(addresses[node]), 9300)); } Settings nodeSettings = Settings.builder() @@ -279,7 +279,7 @@ public class Ec2DiscoveryTests extends ESTestCase { for (int node = 0; node < nodes; node++) { List tags = new ArrayList<>(); - tags.add(new Tag("foo", "bar_" + node)); + tags.add(new Tag("foo", "node" + (node + 1))); tagsList.add(tags); } @@ -287,7 +287,9 @@ public class Ec2DiscoveryTests extends ESTestCase { List discoveryNodes = buildDynamicNodes(nodeSettings, nodes, tagsList); assertThat(discoveryNodes, hasSize(nodes)); for (DiscoveryNode discoveryNode : discoveryNodes) { - assertThat(discoveryNode.getHostName(), isOneOf(addresses)); + TransportAddress address = discoveryNode.getAddress(); + TransportAddress expected = poorMansDNS.get(discoveryNode.getName()); + assertEquals(address, expected); } }