Skip to content

Commit

Permalink
Update DbSubnetGroupResource.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Russsnizza committed Sep 23, 2024
1 parent 1cdc8e0 commit 20a652c
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/main/java/gyro/aws/rds/DbSubnetGroupResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
* Create a db subnet group.
Expand Down Expand Up @@ -63,7 +66,7 @@ public class DbSubnetGroupResource extends RdsTaggableResource implements Copyab

private String description;
private String name;
private Set<SubnetResource> subnets;
private List<SubnetResource> subnets;

/**
* The description for the DB subnet group.
Expand Down Expand Up @@ -96,23 +99,25 @@ public void setName(String name) {
*/
@Required
@Updatable
public Set<SubnetResource> getSubnets() {
public List<SubnetResource> getSubnets() {
if (subnets == null) {
return new HashSet<>();
return new ArrayList<>();
}

return subnets;
return subnets.stream()
.sorted(Comparator.comparing(SubnetResource::getId))
.collect(Collectors.toList());
}

public void setSubnets(Set<SubnetResource> subnets) {
this.subnets = subnets;
public void setSubnets(List<SubnetResource> subnets) {
this.subnets = new ArrayList<>(subnets);
}

@Override
public void copyFrom(DBSubnetGroup group) {
setDescription(group.dbSubnetGroupDescription());
setName(group.dbSubnetGroupName());
setSubnets(group.subnets().stream().map(s -> findById(SubnetResource.class, s.subnetIdentifier())).collect(Collectors.toSet()));
setSubnets(group.subnets().stream().map(s -> findById(SubnetResource.class, s.subnetIdentifier())).collect(Collectors.toList()));
setArn(group.dbSubnetGroupArn());
}

Expand Down Expand Up @@ -143,8 +148,8 @@ public void doCreate(GyroUI ui, State state) {
RdsClient client = createClient(RdsClient.class);
CreateDbSubnetGroupResponse response = client.createDBSubnetGroup(
r -> r.dbSubnetGroupDescription(getDescription())
.dbSubnetGroupName(getName())
.subnetIds(getSubnets().stream().map(SubnetResource::getId).collect(Collectors.toSet()))
.dbSubnetGroupName(getName())
.subnetIds(getSubnets().stream().map(SubnetResource::getId).collect(Collectors.toList()))
);

setArn(response.dbSubnetGroup().dbSubnetGroupArn());
Expand All @@ -155,8 +160,8 @@ public void doUpdate(Resource current, Set<String> changedProperties) {
RdsClient client = createClient(RdsClient.class);
client.modifyDBSubnetGroup(
r -> r.dbSubnetGroupName(getName())
.dbSubnetGroupDescription(getDescription())
.subnetIds(getSubnets().stream().map(SubnetResource::getId).collect(Collectors.toSet()))
.dbSubnetGroupDescription(getDescription())
.subnetIds(getSubnets().stream().map(SubnetResource::getId).collect(Collectors.toList()))
);
}

Expand All @@ -167,4 +172,4 @@ public void delete(GyroUI ui, State state) {
r -> r.dbSubnetGroupName(getName())
);
}
}
}

0 comments on commit 20a652c

Please sign in to comment.