mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(dms): list the default replication subnet group (#5771)
* fix(dms): list the default replication subnet group DescribeReplicationSubnetGroups read stored groups only, so filtering on "default" faulted with ResourceNotFoundFault and the unfiltered list omitted the group that replication instances created without one report. Resolve both paths through findReplicationSubnetGroup, which synthesises "default" from the region's default-VPC subnets. * fix(dms): list the default subnet group only once an instance uses it AWS creates the default replication subnet group the first time an instance needs it, so a region with default subnets but no such instance has no default group. DescribeReplicationSubnetGroups now lists and resolves default only while a replication instance in the region was created without a subnet group, and checks that before calling EC2, so an unused default never seeds the region's default VPC.
This commit is contained in:
1 parent
7ecd225dd1
commit
23e1b3a97c
4 files changed
+166
-10
No files matched your search
@@ -249,12 +249,18 @@ public class DmsService implements Resettable {
|
||||
|
||||
/**
|
||||
* "default" cannot be created, so it is never stored: it resolves to the region's default-VPC
|
||||
* subnets at read time, which is the group an instance created without one lands in.
|
||||
* subnets at read time, which is the group an instance created without one lands in. AWS only
|
||||
* creates that group the first time an instance needs it, so it exists here only while a
|
||||
* replication instance in the region uses it. That check comes first, so a region with no such
|
||||
* instance never reaches EC2 and never seeds its default VPC.
|
||||
*/
|
||||
public Optional<ReplicationSubnetGroup> findReplicationSubnetGroup(String region, String identifier) {
|
||||
if (!"default".equals(identifier)) {
|
||||
return subnetGroups.get(storageKey(region, identifier));
|
||||
}
|
||||
if (!subnetGroupInUse(region, identifier)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
List<String> defaultSubnets = ec2Service.describeSubnets(region, List.of(), Map.of()).stream()
|
||||
.filter(Subnet::isDefaultForAz)
|
||||
.map(Subnet::getSubnetId)
|
||||
@@ -363,7 +369,9 @@ public class DmsService implements Resettable {
|
||||
* Pages by identifier through the shared opaque-cursor helper, so {@code Marker} stays
|
||||
* resumable when a group is created or deleted between requests. DMS documents a default
|
||||
* {@code MaxRecords} of 100 and a valid range of 20 to 100, and rejects a value outside that
|
||||
* range rather than clamping it.
|
||||
* range rather than clamping it. The synthetic {@code default} group is listed and filterable
|
||||
* like a stored one whenever {@link #findReplicationSubnetGroup} resolves it, which is only once
|
||||
* a replication instance in the region uses it.
|
||||
*/
|
||||
public PaginatedResult<ReplicationSubnetGroup> describeReplicationSubnetGroups(JsonNode request, String region) {
|
||||
Integer maxRecords = maxRecords(request);
|
||||
@@ -372,11 +380,12 @@ public class DmsService implements Resettable {
|
||||
List<ReplicationSubnetGroup> matching;
|
||||
if (!requestedIdentifiers.isEmpty()) {
|
||||
matching = requestedIdentifiers.stream()
|
||||
.map(identifier -> subnetGroups.get(storageKey(region, identifier))
|
||||
.map(identifier -> findReplicationSubnetGroup(region, identifier)
|
||||
.orElseThrow(() -> notFound(identifier)))
|
||||
.toList();
|
||||
} else {
|
||||
matching = subnetGroups.scan(key -> key.startsWith(region + "::"));
|
||||
matching = new ArrayList<>(subnetGroups.scan(key -> key.startsWith(region + "::")));
|
||||
findReplicationSubnetGroup(region, "default").ifPresent(matching::add);
|
||||
}
|
||||
return Pagination.paginate(matching, ReplicationSubnetGroup::getReplicationSubnetGroupIdentifier,
|
||||
maxRecords, marker, DEFAULT_MAX_RECORDS, MAXIMUM_MAX_RECORDS,
|
||||
@@ -389,16 +398,19 @@ public class DmsService implements Resettable {
|
||||
if (subnetGroups.get(key).isEmpty()) {
|
||||
throw notFound(identifier);
|
||||
}
|
||||
boolean inUse = regionScan(instances, region).stream()
|
||||
.anyMatch(instance -> identifier.equals(instance.getAttributes()
|
||||
.path("ReplicationSubnetGroup").path("ReplicationSubnetGroupIdentifier").asText(null)));
|
||||
if (inUse) {
|
||||
if (subnetGroupInUse(region, identifier)) {
|
||||
throw invalidState("Replication subnet group " + identifier
|
||||
+ " is in use by a replication instance and cannot be deleted.");
|
||||
}
|
||||
subnetGroups.delete(key);
|
||||
}
|
||||
|
||||
private boolean subnetGroupInUse(String region, String identifier) {
|
||||
return regionScan(instances, region).stream()
|
||||
.anyMatch(instance -> identifier.equals(instance.getAttributes()
|
||||
.path("ReplicationSubnetGroup").path("ReplicationSubnetGroupIdentifier").asText(null)));
|
||||
}
|
||||
|
||||
public List<ResourceTag> listTagsForResource(JsonNode request, String region) {
|
||||
List<String> arnList = arnList(request);
|
||||
if (!arnList.isEmpty()) {
|
||||
|
||||
Reference in new issue
Block a user