Move AwsEc2UnicastHostsProvider to Ec2DiscoveryModule
Related to https://github.com/elasticsearch/elasticsearch/pull/9099
This commit is contained in:
parent
377e7e0c78
commit
e6080e9017
8
pom.xml
8
pom.xml
|
@ -73,14 +73,6 @@
|
||||||
<version>${amazonaws.version}</version>
|
<version>${amazonaws.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- We need to explicitly set the common codec version since aws-java-sdk pulls the wrong version -->
|
|
||||||
<!-- See https://github.com/elasticsearch/elasticsearch-cloud-aws/issues/29 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>commons-codec</groupId>
|
|
||||||
<artifactId>commons-codec</artifactId>
|
|
||||||
<version>1.4</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>log4j</groupId>
|
<groupId>log4j</groupId>
|
||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
|
|
|
@ -18,12 +18,6 @@
|
||||||
<outputDirectory>/</outputDirectory>
|
<outputDirectory>/</outputDirectory>
|
||||||
<useProjectArtifact>true</useProjectArtifact>
|
<useProjectArtifact>true</useProjectArtifact>
|
||||||
<useTransitiveFiltering>true</useTransitiveFiltering>
|
<useTransitiveFiltering>true</useTransitiveFiltering>
|
||||||
<includes>
|
|
||||||
<include>com.amazonaws:aws-java-sdk-core</include>
|
|
||||||
<include>com.amazonaws:aws-java-sdk-ec2</include>
|
|
||||||
<include>com.amazonaws:aws-java-sdk-s3</include>
|
|
||||||
<include>commons-codec:commons-codec</include>
|
|
||||||
</includes>
|
|
||||||
</dependencySet>
|
</dependencySet>
|
||||||
</dependencySets>
|
</dependencySets>
|
||||||
</assembly>
|
</assembly>
|
||||||
|
|
|
@ -23,6 +23,7 @@ import com.amazonaws.AmazonClientException;
|
||||||
import com.amazonaws.services.ec2.AmazonEC2;
|
import com.amazonaws.services.ec2.AmazonEC2;
|
||||||
import com.amazonaws.services.ec2.model.*;
|
import com.amazonaws.services.ec2.model.*;
|
||||||
import org.elasticsearch.Version;
|
import org.elasticsearch.Version;
|
||||||
|
import org.elasticsearch.cloud.aws.AwsEc2Service;
|
||||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.collect.ImmutableMap;
|
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.discovery.zen.ping.unicast.UnicastZenPing;
|
||||||
import org.elasticsearch.transport.TransportService;
|
import org.elasticsearch.transport.TransportService;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -72,10 +69,10 @@ public class AwsEc2UnicastHostsProvider extends AbstractComponent implements Uni
|
||||||
private final HostType hostType;
|
private final HostType hostType;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public AwsEc2UnicastHostsProvider(Settings settings, TransportService transportService, AmazonEC2 client, Version version) {
|
public AwsEc2UnicastHostsProvider(Settings settings, TransportService transportService, AwsEc2Service awsEc2Service, Version version) {
|
||||||
super(settings);
|
super(settings);
|
||||||
this.transportService = transportService;
|
this.transportService = transportService;
|
||||||
this.client = client;
|
this.client = awsEc2Service.client();
|
||||||
this.version = version;
|
this.version = version;
|
||||||
|
|
||||||
this.hostType = HostType.valueOf(componentSettings.get("host_type", "private_ip").toUpperCase());
|
this.hostType = HostType.valueOf(componentSettings.get("host_type", "private_ip").toUpperCase());
|
||||||
|
|
|
@ -19,21 +19,16 @@
|
||||||
|
|
||||||
package org.elasticsearch.discovery.ec2;
|
package org.elasticsearch.discovery.ec2;
|
||||||
|
|
||||||
import org.elasticsearch.Version;
|
|
||||||
import org.elasticsearch.cloud.aws.AwsEc2Service;
|
|
||||||
import org.elasticsearch.cluster.ClusterName;
|
import org.elasticsearch.cluster.ClusterName;
|
||||||
import org.elasticsearch.cluster.ClusterService;
|
import org.elasticsearch.cluster.ClusterService;
|
||||||
import org.elasticsearch.cluster.node.DiscoveryNodeService;
|
import org.elasticsearch.cluster.node.DiscoveryNodeService;
|
||||||
import org.elasticsearch.cluster.settings.DynamicSettings;
|
import org.elasticsearch.cluster.settings.DynamicSettings;
|
||||||
import org.elasticsearch.common.collect.ImmutableList;
|
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.discovery.DiscoverySettings;
|
import org.elasticsearch.discovery.DiscoverySettings;
|
||||||
import org.elasticsearch.discovery.zen.ZenDiscovery;
|
import org.elasticsearch.discovery.zen.ZenDiscovery;
|
||||||
import org.elasticsearch.discovery.zen.elect.ElectMasterService;
|
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.ZenPingService;
|
||||||
import org.elasticsearch.discovery.zen.ping.unicast.UnicastZenPing;
|
|
||||||
import org.elasticsearch.node.settings.NodeSettingsService;
|
import org.elasticsearch.node.settings.NodeSettingsService;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
import org.elasticsearch.transport.TransportService;
|
import org.elasticsearch.transport.TransportService;
|
||||||
|
@ -46,29 +41,9 @@ public class Ec2Discovery extends ZenDiscovery {
|
||||||
@Inject
|
@Inject
|
||||||
public Ec2Discovery(Settings settings, ClusterName clusterName, ThreadPool threadPool, TransportService transportService,
|
public Ec2Discovery(Settings settings, ClusterName clusterName, ThreadPool threadPool, TransportService transportService,
|
||||||
ClusterService clusterService, NodeSettingsService nodeSettingsService, ZenPingService pingService,
|
ClusterService clusterService, NodeSettingsService nodeSettingsService, ZenPingService pingService,
|
||||||
DiscoveryNodeService discoveryNodeService, AwsEc2Service ec2Service, DiscoverySettings discoverySettings,
|
DiscoveryNodeService discoveryNodeService, DiscoverySettings discoverySettings,
|
||||||
ElectMasterService electMasterService, DynamicSettings dynamicSettings,
|
ElectMasterService electMasterService, DynamicSettings dynamicSettings) {
|
||||||
Version version) {
|
|
||||||
super(settings, clusterName, threadPool, transportService, clusterService, nodeSettingsService,
|
super(settings, clusterName, threadPool, transportService, clusterService, nodeSettingsService,
|
||||||
discoveryNodeService, pingService, electMasterService, discoverySettings, dynamicSettings);
|
discoveryNodeService, pingService, electMasterService, discoverySettings, dynamicSettings);
|
||||||
if (settings.getAsBoolean("cloud.enabled", true)) {
|
|
||||||
ImmutableList<? extends ZenPing> 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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
package org.elasticsearch.discovery.ec2;
|
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.Discovery;
|
||||||
import org.elasticsearch.discovery.zen.ZenDiscoveryModule;
|
import org.elasticsearch.discovery.zen.ZenDiscoveryModule;
|
||||||
|
|
||||||
|
@ -27,6 +29,13 @@ import org.elasticsearch.discovery.zen.ZenDiscoveryModule;
|
||||||
*/
|
*/
|
||||||
public class Ec2DiscoveryModule extends ZenDiscoveryModule {
|
public class Ec2DiscoveryModule extends ZenDiscoveryModule {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public Ec2DiscoveryModule(Settings settings) {
|
||||||
|
if (settings.getAsBoolean("cloud.enabled", true)) {
|
||||||
|
addUnicastHostProvider(AwsEc2UnicastHostsProvider.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void bindDiscovery() {
|
protected void bindDiscovery() {
|
||||||
bind(Discovery.class).to(Ec2Discovery.class).asEagerSingleton();
|
bind(Discovery.class).to(Ec2Discovery.class).asEagerSingleton();
|
||||||
|
|
Loading…
Reference in New Issue