in src/main/java/com/amazon/jenkins/ec2fleet/EC2Api.java [125:146]
public void terminateInstances(final AmazonEC2 ec2, final Set<String> instanceIds) {
final List<String> temp = new ArrayList<>(instanceIds);
while (temp.size() > 0) {
// terminateInstances is idempotent so it can be called until it's successful
try {
ec2.terminateInstances(new TerminateInstancesRequest(temp));
// clear as removed so we can finish
temp.clear();
} catch (AmazonEC2Exception exception) {
// if we cannot find instance, that's fine assume them as terminated
// remove from request and try again
if (exception.getErrorCode().equals(NOT_FOUND_ERROR_CODE)) {
final List<String> notFoundInstanceIds = parseInstanceIdsFromNotFoundException(exception.getMessage());
if (notFoundInstanceIds.isEmpty()) {
// looks like we cannot parse correctly, rethrow
throw exception;
}
temp.removeAll(notFoundInstanceIds);
}
}
}
}