From e6080e90178d1e75b64645a613dbb8c0e4f5865c Mon Sep 17 00:00:00 2001 From: David Pilato Date: Fri, 2 Jan 2015 23:57:57 +0100 Subject: [PATCH] Move AwsEc2UnicastHostsProvider to Ec2DiscoveryModule Related to https://github.com/elasticsearch/elasticsearch/pull/9099 --- pom.xml | 8 ----- src/main/assemblies/plugin.xml | 6 ---- .../ec2/AwsEc2UnicastHostsProvider.java | 11 +++---- .../discovery/ec2/Ec2Discovery.java | 29 ++----------------- .../discovery/ec2/Ec2DiscoveryModule.java | 9 ++++++ 5 files changed, 15 insertions(+), 48 deletions(-) diff --git a/pom.xml b/pom.xml index b4f05d9b497..58874a85456 100644 --- a/pom.xml +++ b/pom.xml @@ -73,14 +73,6 @@ ${amazonaws.version} - - - - commons-codec - commons-codec - 1.4 - - log4j log4j diff --git a/src/main/assemblies/plugin.xml b/src/main/assemblies/plugin.xml index 0b20041a9db..c0c2dfc4319 100644 --- a/src/main/assemblies/plugin.xml +++ b/src/main/assemblies/plugin.xml @@ -18,12 +18,6 @@ / true true - - com.amazonaws:aws-java-sdk-core - com.amazonaws:aws-java-sdk-ec2 - com.amazonaws:aws-java-sdk-s3 - commons-codec:commons-codec - diff --git a/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2UnicastHostsProvider.java b/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2UnicastHostsProvider.java index 1722bd77d3b..ac6035ba2a2 100644 --- a/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2UnicastHostsProvider.java +++ b/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2UnicastHostsProvider.java @@ -23,6 +23,7 @@ import com.amazonaws.AmazonClientException; import com.amazonaws.services.ec2.AmazonEC2; import com.amazonaws.services.ec2.model.*; import org.elasticsearch.Version; +import org.elasticsearch.cloud.aws.AwsEc2Service; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.Strings; import org.elasticsearch.common.collect.ImmutableMap; @@ -37,11 +38,7 @@ import org.elasticsearch.discovery.zen.ping.unicast.UnicastHostsProvider; import org.elasticsearch.discovery.zen.ping.unicast.UnicastZenPing; import org.elasticsearch.transport.TransportService; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; /** * @@ -72,10 +69,10 @@ public class AwsEc2UnicastHostsProvider extends AbstractComponent implements Uni private final HostType hostType; @Inject - public AwsEc2UnicastHostsProvider(Settings settings, TransportService transportService, AmazonEC2 client, Version version) { + public AwsEc2UnicastHostsProvider(Settings settings, TransportService transportService, AwsEc2Service awsEc2Service, Version version) { super(settings); this.transportService = transportService; - this.client = client; + this.client = awsEc2Service.client(); this.version = version; this.hostType = HostType.valueOf(componentSettings.get("host_type", "private_ip").toUpperCase()); diff --git a/src/main/java/org/elasticsearch/discovery/ec2/Ec2Discovery.java b/src/main/java/org/elasticsearch/discovery/ec2/Ec2Discovery.java index 2d44e1a265d..de85ce1d931 100755 --- a/src/main/java/org/elasticsearch/discovery/ec2/Ec2Discovery.java +++ b/src/main/java/org/elasticsearch/discovery/ec2/Ec2Discovery.java @@ -19,21 +19,16 @@ package org.elasticsearch.discovery.ec2; -import org.elasticsearch.Version; -import org.elasticsearch.cloud.aws.AwsEc2Service; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.node.DiscoveryNodeService; import org.elasticsearch.cluster.settings.DynamicSettings; -import org.elasticsearch.common.collect.ImmutableList; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.DiscoverySettings; import org.elasticsearch.discovery.zen.ZenDiscovery; import org.elasticsearch.discovery.zen.elect.ElectMasterService; -import org.elasticsearch.discovery.zen.ping.ZenPing; import org.elasticsearch.discovery.zen.ping.ZenPingService; -import org.elasticsearch.discovery.zen.ping.unicast.UnicastZenPing; import org.elasticsearch.node.settings.NodeSettingsService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -46,29 +41,9 @@ public class Ec2Discovery extends ZenDiscovery { @Inject public Ec2Discovery(Settings settings, ClusterName clusterName, ThreadPool threadPool, TransportService transportService, ClusterService clusterService, NodeSettingsService nodeSettingsService, ZenPingService pingService, - DiscoveryNodeService discoveryNodeService, AwsEc2Service ec2Service, DiscoverySettings discoverySettings, - ElectMasterService electMasterService, DynamicSettings dynamicSettings, - Version version) { + DiscoveryNodeService discoveryNodeService, DiscoverySettings discoverySettings, + ElectMasterService electMasterService, DynamicSettings dynamicSettings) { super(settings, clusterName, threadPool, transportService, clusterService, nodeSettingsService, discoveryNodeService, pingService, electMasterService, discoverySettings, dynamicSettings); - if (settings.getAsBoolean("cloud.enabled", true)) { - ImmutableList zenPings = pingService.zenPings(); - UnicastZenPing unicastZenPing = null; - for (ZenPing zenPing : zenPings) { - if (zenPing instanceof UnicastZenPing) { - unicastZenPing = (UnicastZenPing) zenPing; - break; - } - } - - if (unicastZenPing != null) { - // update the unicast zen ping to add cloud hosts provider - // and, while we are at it, use only it and not the multicast for example - unicastZenPing.addHostsProvider(new AwsEc2UnicastHostsProvider(settings, transportService, ec2Service.client(), version)); - pingService.zenPings(ImmutableList.of(unicastZenPing)); - } else { - logger.warn("failed to apply ec2 unicast discovery, no unicast ping found"); - } - } } } diff --git a/src/main/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryModule.java b/src/main/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryModule.java index 6194d41de1d..efa1cbdfb9d 100644 --- a/src/main/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryModule.java +++ b/src/main/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryModule.java @@ -19,6 +19,8 @@ package org.elasticsearch.discovery.ec2; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.Discovery; import org.elasticsearch.discovery.zen.ZenDiscoveryModule; @@ -27,6 +29,13 @@ import org.elasticsearch.discovery.zen.ZenDiscoveryModule; */ public class Ec2DiscoveryModule extends ZenDiscoveryModule { + @Inject + public Ec2DiscoveryModule(Settings settings) { + if (settings.getAsBoolean("cloud.enabled", true)) { + addUnicastHostProvider(AwsEc2UnicastHostsProvider.class); + } + } + @Override protected void bindDiscovery() { bind(Discovery.class).to(Ec2Discovery.class).asEagerSingleton();