Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert db subnet group subnets into list #666

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 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,26 @@ 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::getName))
.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 +149,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 +161,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 Down
Loading