Skip to content

Commit

Permalink
exploring instance metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
pecollet committed Feb 1, 2024
1 parent 0213885 commit 64aa169
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cloudformation/neo4j.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ Resources:
- " echo \"dbms.cluster.minimum_initial_system_primaries_count=${nodeCount}\" >> /etc/neo4j/neo4j.conf\n"
- " echo \"dbms.cluster.discovery.resolver_type=EC2-ASG\" >> /etc/neo4j/neo4j.conf\n"
- " echo \"dbms.cluster.discovery.aws.asg_name=$stackName\" >> /etc/neo4j/neo4j.conf\n"
- " echo \"dbms.cluster.discovery.aws.region=$region\" >> /etc/neo4j/neo4j.conf\n"
- " echo \"initial.dbms.automatically_enable_free_servers=true\" >> /etc/neo4j/neo4j.conf\n"
- " fi\n"
- " neo4j-admin server memory-recommendation >> /etc/neo4j/neo4j.conf\n"
- "}\n"
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/cs/neo4j/AsgResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ protected void internalInit(Config config, LogService logService, DependencyReso

private AwsClient instantiateAwsClient(String accessKey, String secretKey, String region, Ec2Settings.AddressType addressType) {
if (accessKey != null && secretKey != null) {
return new AwsClient(accessKey, secretKey, region, addressType);
return new AwsClient(accessKey, secretKey, region, addressType, log);
} else {
return new AwsClient(region, addressType);
return new AwsClient(region, addressType, log);
}
}

Expand All @@ -81,7 +81,7 @@ protected Stream<SocketAddress> resolveInternal() {
@Override
protected String configDescription() {
return format(
"{awsRegion:'%s',ASG name:'%s'}",
"{awsRegion:'%s', ASG name:'%s'}",
awsRegion, selector);
}

Expand Down
12 changes: 8 additions & 4 deletions src/main/java/cs/neo4j/AwsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.neo4j.logging.InternalLog;
import org.neo4j.logging.internal.LogService;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.auth.credentials.InstanceProfileCredentialsProvider;
Expand All @@ -27,21 +29,23 @@ public class AwsClient extends LifecycleAdapter {
private static String region;
private static Ec2Settings.AddressType addressType;


private InternalLog log;
private AutoScalingClient autoScalingClient;
private Ec2Client ec2Client;

public AwsClient(String region, Ec2Settings.AddressType addressType) {
public AwsClient(String region, Ec2Settings.AddressType addressType, InternalLog log) {
this.region=region;
this.addressType=addressType;
this.log=log;
createClients();
}

public AwsClient(String accessKey, String secretKey, String region, Ec2Settings.AddressType addressType) {
public AwsClient(String accessKey, String secretKey, String region, Ec2Settings.AddressType addressType, InternalLog log) {
this.accessKey=accessKey;
this.secretKey=secretKey;
this.region=region;
this.addressType=addressType;
this.log=log;

createClients();
}
Expand All @@ -68,7 +72,7 @@ private void createClients(){
Ec2MetadataClient imdsClient = Ec2MetadataClient.builder()
.build();
Ec2MetadataResponse metadataResponse = imdsClient.get("/latest/meta-data/");
System.out.println(metadataResponse.asString());
log.info(metadataResponse.asString());
}

}
Expand Down

0 comments on commit 64aa169

Please sign in to comment.