fix(autoscaling): retain indexed instance mutation members (#7217)

* fix(autoscaling): retain indexed instance mutation members

Use the existing indexed member parser for AttachInstances, DetachInstances and SetInstanceProtection. Keep all members for service validation before mutation, including after gaps. Preserve existing validation and protocol responses.

Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
Signed-off-by: Andre Kurait <akurait@amazon.com>

* fix(autoscaling): count actual detached instances

Keep every collected instance ID available to validation, but decrement desired capacity only for members actually detached. Cover repeated query values and ignored unknown IDs without changing the false decrement flag.

Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
Signed-off-by: Andre Kurait <akurait@amazon.com>

* test: consolidate Auto Scaling indexed instance fixtures

Cover all five instance-list actions with one sparse, large, repeated and ignored-key parameterized map. Preserve validation-before-mutation and repeated-detach capacity regressions. Addresses upstream review 5729806284.

Signed-off-by: Andre Kurait <akurait@amazon.com>

---------

Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
Signed-off-by: Andre Kurait <akurait@amazon.com>
This commit is contained in:
Andre Kurait authored and GitHub committed 2026-11-01 15:57:58 -04:00
1 parent 87936c19b3
commit 3c5e8936f2
4 files changed
+104 -27

No files matched your search

@@ -638,7 +638,7 @@ public class AutoScalingQueryHandler {
private Response handleSetInstanceProtection(MultivaluedMap<String, String> p, String region) {
String groupName = p.getFirst("AutoScalingGroupName");
List<String> instanceIds = memberList(p, "InstanceIds");
List<String> instanceIds = indexedMembers(p, "InstanceIds");
boolean protectedFromScaleIn = requiredBoolParam(p, "ProtectedFromScaleIn");
service.setInstanceProtection(region, groupName, instanceIds, protectedFromScaleIn);
return ok(new XmlBuilder()
@@ -893,7 +893,7 @@ public class AutoScalingQueryHandler {
}
private Response handleAttachInstances(MultivaluedMap<String, String> p, String region) {
service.attachInstances(region, p.getFirst("AutoScalingGroupName"), memberList(p, "InstanceIds"));
service.attachInstances(region, p.getFirst("AutoScalingGroupName"), indexedMembers(p, "InstanceIds"));
return ok(new XmlBuilder()
.start("AttachInstancesResponse", NS)
.raw(AwsQueryResponse.responseMetadata())
@@ -902,7 +902,7 @@ public class AutoScalingQueryHandler {
private Response handleDetachInstances(MultivaluedMap<String, String> p, String region) {
service.detachInstances(region, p.getFirst("AutoScalingGroupName"),
memberList(p, "InstanceIds"),
indexedMembers(p, "InstanceIds"),
"true".equalsIgnoreCase(p.getFirst("ShouldDecrementDesiredCapacity")));
return ok(new XmlBuilder()
.start("DetachInstancesResponse", NS)
@@ -1016,7 +1016,7 @@ public class AutoScalingService implements PassedRoleLookup {
releaseRefreshOwnership(asg, detached);
asg.getInstances().removeIf(i -> instanceIds.contains(i.getInstanceId()));
if (decrementDesiredCapacity) {
int newDesired = Math.max(asg.getMinSize(), asg.getDesiredCapacity() - instanceIds.size());
int newDesired = Math.max(asg.getMinSize(), asg.getDesiredCapacity() - detached.size());
asg.setDesiredCapacity(newDesired);
}
groups.put(key, asg);