Skip to content

Commit

Permalink
added TCP port to discovery address
Browse files Browse the repository at this point in the history
  • Loading branch information
pecollet committed Jan 31, 2024
1 parent b4e04d8 commit 9d6ffd7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
This neo4j plugin implements cluster discovery for a cluster deployed in an AWS EC2 Auto-scaling group.
It retrieves the list of network addresses of the group's VMs, and feeds it to Neo4j's cluster discovery module.

Notes:
- It retrieves the VMs' private DnsName or IpAddress.
- It retrieves the discovery TCP port from the neo4j setting "server.discovery.listen_address"


**Compatilibity**

Neo4j 5.7+
Expand Down Expand Up @@ -32,3 +37,5 @@ The AWS User requires the following permissions :
- "ec2:DescribeInstances",
- "autoscaling:DescribeAutoScalingGroups"


The auto-scaling group VMs require a Security Group that allows traffic on TCP ports 5000, 6000, 7000, 7688 (for internal cluster communication) as well as TCP ports 7474 and 7687 (for external access).
12 changes: 11 additions & 1 deletion src/main/java/cs/neo4j/AsgResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static java.lang.String.format;

import com.neo4j.causalclustering.discovery.resolve.BaseRemotesResolver;
import com.neo4j.configuration.DiscoverySettings;
import org.neo4j.annotations.service.ServiceProvider;
import org.neo4j.common.DependencyResolver;
import org.neo4j.configuration.Config;
Expand All @@ -22,6 +23,7 @@ public class AsgResolver extends BaseRemotesResolver {
private String awsKey;
private String awsSecret;
private String awsRegion;
private int discoveryPort;
private AwsClient awsClient;
private InternalLog log;

Expand All @@ -36,6 +38,9 @@ protected void internalInit(Config config, LogService logService, DependencyReso
awsKey = checkConfig(config, Ec2Settings.aws_key);
awsSecret = checkConfig(config, Ec2Settings.aws_secret);
awsRegion = checkConfig(config, Ec2Settings.aws_region);

discoveryPort = checkConfig(config, DiscoverySettings.discovery_listen_address).getPort();

log = logService.getUserLog(AsgResolver.class);
log.info("Init of discovery plugin "+this.configDescription());
awsClient = externalDependencies.containsDependency(AwsClient.class)
Expand All @@ -46,7 +51,12 @@ protected void internalInit(Config config, LogService logService, DependencyReso
@Override
protected Stream<SocketAddress> resolveInternal() {
try {
return awsClient.getVmAddressesByAsgName(selector).map(s -> new SocketAddress(s));
return awsClient.getVmAddressesByAsgName(selector)
.map(s -> {
SocketAddress addr = new SocketAddress(s, discoveryPort);

return addr;
});
} catch (Exception e) {
log.error("Failed discovery "+e.getMessage());
}
Expand Down

0 comments on commit 9d6ffd7

Please sign in to comment.