From 9d6ffd7347feda943e4876339a7c47d7f7d6853f Mon Sep 17 00:00:00 2001 From: David Pecollet Date: Wed, 31 Jan 2024 09:23:23 +0000 Subject: [PATCH] added TCP port to discovery address --- README.md | 7 +++++++ src/main/java/cs/neo4j/AsgResolver.java | 12 +++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bf40908..c4c7c76 100644 --- a/README.md +++ b/README.md @@ -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+ @@ -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). \ No newline at end of file diff --git a/src/main/java/cs/neo4j/AsgResolver.java b/src/main/java/cs/neo4j/AsgResolver.java index 4cc4cb8..16f9d11 100644 --- a/src/main/java/cs/neo4j/AsgResolver.java +++ b/src/main/java/cs/neo4j/AsgResolver.java @@ -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; @@ -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; @@ -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) @@ -46,7 +51,12 @@ protected void internalInit(Config config, LogService logService, DependencyReso @Override protected Stream 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()); }