feat(applicationautoscaling): add Application Auto Scaling control plane (#2159)

* feat(applicationautoscaling): add Application Auto Scaling control plane

Adds a services/applicationautoscaling package emulating the Application
Auto Scaling API (JSON 1.1, AnyScaleFrontendService. target prefix,
application-autoscaling signing name). This is a distinct service from the
existing EC2 Auto Scaling package, which speaks Query under the
autoscaling signing name.

Implements the nine actions Terraform exercises: RegisterScalableTarget,
DescribeScalableTargets, DeregisterScalableTarget, PutScalingPolicy,
DescribeScalingPolicies, DeleteScalingPolicy, and the ListTagsForResource
/ TagResource / UntagResource trio.

Notable behaviours:

- Identity is the (ServiceNamespace, ResourceId, ScalableDimension)
  triple; RegisterScalableTarget upserts on it and leaves unsupplied
  parameters unchanged, matching AWS.
- ScalableTargetARN uses the application-autoscaling service name while
  PolicyARN uses plain autoscaling and embeds the resource path and policy
  name — the two ARN families genuinely differ.
- Tagging resolves by ScalableTargetARN because the Terraform provider's
  transparent-tagging interceptor calls ListTagsForResource on every read,
  keyed on the ARN it reads from DescribeScalableTargets.
- Target-tracking policies create the real pair of CloudWatch alarms AWS
  creates on the caller's behalf; deregistering a scalable target deletes
  its policies and their alarms.
- Optional configuration fields are only echoed back when supplied, so
  Terraform never sees a value it did not configure.

Scaling policies are stored and described but inert: nothing evaluates
them and no capacity is adjusted, mirroring EC2 Auto Scaling's existing
PutScalingPolicy. This is documented in docs/services/applicationautoscaling.md.

Closes #2157

* refactor(applicationautoscaling): stop exposing the scalable target's tag map

getTags() handed out the live internal map, and the service mutated it in
place at three call sites. listTagsForResource also returned that same
live reference out to the handler layer, so a caller could alter stored
state without going through the service.

getTags() now returns an unmodifiable view, with putTags/removeTags for
the mutations the service actually needs, and a test pins the read-only
contract.

Reported by github-code-quality on #2159.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-08-07 17:27:36 -05:00
1 parent b1f953efb1
commit 1795e131a2
24 files changed
+2063 -3

No files matched your search

@@ -570,6 +570,7 @@ public interface EmulatorConfig {
CodeDeployServiceConfig codedeploy();
CodePipelineServiceConfig codepipeline();
AutoScalingServiceConfig autoscaling();
ApplicationAutoScalingServiceConfig applicationautoscaling();
ElasticBeanstalkServiceConfig elasticbeanstalk();
BackupServiceConfig backup();
NeptuneServiceConfig neptune();
@@ -693,6 +694,11 @@ public interface EmulatorConfig {
boolean enabled();
}
interface ApplicationAutoScalingServiceConfig {
@WithDefault("true")
boolean enabled();
}
interface ElasticBeanstalkServiceConfig {
@WithDefault("true")
boolean enabled();
@@ -20,6 +20,7 @@ import io.github.hectorvent.floci.services.resourcegroupstagging.ResourceGroupsT
import io.github.hectorvent.floci.services.bcmdataexports.BcmDataExportsJsonHandler;
import io.github.hectorvent.floci.services.ce.CostExplorerJsonHandler;
import io.github.hectorvent.floci.services.cloudtrail.CloudTrailJsonHandler;
import io.github.hectorvent.floci.services.applicationautoscaling.ApplicationAutoScalingJsonHandler;
import io.github.hectorvent.floci.services.cloudcontrol.CloudControlJsonHandler;
import io.github.hectorvent.floci.services.configservice.ConfigServiceJsonHandler;
import io.github.hectorvent.floci.services.cur.CurJsonHandler;
@@ -99,6 +100,7 @@ public class AwsJson11Controller {
private final CloudTrailJsonHandler cloudTrailJsonHandler;
private final LightsailJsonHandler lightsailJsonHandler;
private final CloudControlJsonHandler cloudControlJsonHandler;
private final ApplicationAutoScalingJsonHandler applicationAutoScalingJsonHandler;
@Inject
public AwsJson11Controller(ObjectMapper objectMapper, ResolvedServiceCatalog catalog,
@@ -132,7 +134,8 @@ public class AwsJson11Controller {
ConfigServiceJsonHandler configServiceJsonHandler,
CloudTrailJsonHandler cloudTrailJsonHandler,
LightsailJsonHandler lightsailJsonHandler,
CloudControlJsonHandler cloudControlJsonHandler) {
CloudControlJsonHandler cloudControlJsonHandler,
ApplicationAutoScalingJsonHandler applicationAutoScalingJsonHandler) {
this.objectMapper = objectMapper;
this.strictBodyReader = objectMapper.reader().with(DeserializationFeature.FAIL_ON_TRAILING_TOKENS);
this.catalog = catalog;
@@ -171,6 +174,7 @@ public class AwsJson11Controller {
this.cloudTrailJsonHandler = cloudTrailJsonHandler;
this.lightsailJsonHandler = lightsailJsonHandler;
this.cloudControlJsonHandler = cloudControlJsonHandler;
this.applicationAutoScalingJsonHandler = applicationAutoScalingJsonHandler;
}
@POST
@@ -238,6 +242,7 @@ public class AwsJson11Controller {
case "bcm-data-exports" -> bcmDataExportsJsonHandler.handle(action, request, region);
case "config" -> configServiceJsonHandler.handle(action, request, region);
case "cloudtrail" -> cloudTrailJsonHandler.handle(action, request, region);
case "application-autoscaling" -> applicationAutoScalingJsonHandler.handle(action, request, region);
case "lightsail" -> lightsailJsonHandler.handle(action, request, region);
case "cloudcontrol" -> cloudControlJsonHandler.handle(action, request, region);
default -> null;
@@ -330,6 +330,12 @@ public class ResolvedServiceCatalog {
"autoscaling", config.storage().mode(), 5000L, AwsNamespaces.AUTOSCALING, ServiceProtocol.QUERY,
protocols(ServiceProtocol.QUERY),
Set.of(), Set.of("autoscaling"), Set.of(), Set.of()),
descriptor("application-autoscaling", "applicationautoscaling",
config.services().applicationautoscaling().enabled(), true,
"applicationautoscaling", config.storage().mode(), 5000L, null, ServiceProtocol.JSON,
protocols(ServiceProtocol.JSON),
Set.of("AnyScaleFrontendService."), Set.of("application-autoscaling"),
Set.of(), Set.of()),
descriptor("elasticbeanstalk", "elasticbeanstalk",
config.services().elasticbeanstalk().enabled(), true,
"elasticbeanstalk",
@@ -0,0 +1,395 @@
package io.github.hectorvent.floci.services.applicationautoscaling;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsErrorResponse;
import io.github.hectorvent.floci.services.applicationautoscaling.model.Alarm;
import io.github.hectorvent.floci.services.applicationautoscaling.model.PredefinedMetricSpecification;
import io.github.hectorvent.floci.services.applicationautoscaling.model.ScalableTarget;
import io.github.hectorvent.floci.services.applicationautoscaling.model.ScalingPolicy;
import io.github.hectorvent.floci.services.applicationautoscaling.model.StepAdjustment;
import io.github.hectorvent.floci.services.applicationautoscaling.model.StepScalingConfiguration;
import io.github.hectorvent.floci.services.applicationautoscaling.model.SuspendedState;
import io.github.hectorvent.floci.services.applicationautoscaling.model.TargetTrackingConfiguration;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.core.Response;
import org.jboss.logging.Logger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* JSON 1.1 handler for the Application Auto Scaling API.
*
* <p>Requests arrive with the {@code AnyScaleFrontendService.} target prefix and are signed
* with the {@code application-autoscaling} credential scope.</p>
*
* @see <a href="https://docs.aws.amazon.com/autoscaling/application/APIReference/Welcome.html">Application Auto Scaling API Reference</a>
*/
@ApplicationScoped
public class ApplicationAutoScalingJsonHandler {
private static final Logger LOG = Logger.getLogger(ApplicationAutoScalingJsonHandler.class);
private final ApplicationAutoScalingService service;
private final ObjectMapper objectMapper;
@Inject
public ApplicationAutoScalingJsonHandler(ApplicationAutoScalingService service, ObjectMapper objectMapper) {
this.service = service;
this.objectMapper = objectMapper;
}
public Response handle(String action, JsonNode request, String region) {
return switch (action) {
case "RegisterScalableTarget" -> handleRegisterScalableTarget(request, region);
case "DescribeScalableTargets" -> handleDescribeScalableTargets(request, region);
case "DeregisterScalableTarget" -> handleDeregisterScalableTarget(request, region);
case "PutScalingPolicy" -> handlePutScalingPolicy(request, region);
case "DescribeScalingPolicies" -> handleDescribeScalingPolicies(request, region);
case "DeleteScalingPolicy" -> handleDeleteScalingPolicy(request, region);
case "ListTagsForResource" -> handleListTagsForResource(request, region);
case "TagResource" -> handleTagResource(request, region);
case "UntagResource" -> handleUntagResource(request, region);
default -> Response.status(400)
.entity(new AwsErrorResponse("UnsupportedOperation",
"Operation " + action + " is not supported."))
.build();
};
}
// ---------------------------------------------------------------- scalable targets
private Response handleRegisterScalableTarget(JsonNode request, String region) {
ScalableTarget target = service.registerScalableTarget(
text(request, "ServiceNamespace"),
text(request, "ResourceId"),
text(request, "ScalableDimension"),
integer(request, "MinCapacity"),
integer(request, "MaxCapacity"),
text(request, "RoleARN"),
parseSuspendedState(request.path("SuspendedState")),
parseTags(request.path("Tags")),
region);
ObjectNode response = objectMapper.createObjectNode();
response.put("ScalableTargetARN", target.getScalableTargetArn());
return Response.ok(response).build();
}
private Response handleDescribeScalableTargets(JsonNode request, String region) {
List<ScalableTarget> found = service.describeScalableTargets(
text(request, "ServiceNamespace"),
stringList(request.path("ResourceIds")),
text(request, "ScalableDimension"),
region);
ObjectNode response = objectMapper.createObjectNode();
ArrayNode array = response.putArray("ScalableTargets");
found.forEach(t -> array.add(scalableTargetJson(t)));
return Response.ok(response).build();
}
private Response handleDeregisterScalableTarget(JsonNode request, String region) {
service.deregisterScalableTarget(
text(request, "ServiceNamespace"),
text(request, "ResourceId"),
text(request, "ScalableDimension"),
region);
return Response.ok(objectMapper.createObjectNode()).build();
}
// ---------------------------------------------------------------- scaling policies
private Response handlePutScalingPolicy(JsonNode request, String region) {
ScalingPolicy policy = service.putScalingPolicy(
text(request, "PolicyName"),
text(request, "PolicyType"),
text(request, "ServiceNamespace"),
text(request, "ResourceId"),
text(request, "ScalableDimension"),
parseTargetTracking(request.path("TargetTrackingScalingPolicyConfiguration")),
parseStepScaling(request.path("StepScalingPolicyConfiguration")),
region);
ObjectNode response = objectMapper.createObjectNode();
response.put("PolicyARN", policy.getPolicyArn());
ArrayNode alarms = response.putArray("Alarms");
policy.getAlarms().forEach(a -> alarms.add(alarmJson(a)));
return Response.ok(response).build();
}
private Response handleDescribeScalingPolicies(JsonNode request, String region) {
List<ScalingPolicy> found = service.describeScalingPolicies(
text(request, "ServiceNamespace"),
text(request, "ResourceId"),
text(request, "ScalableDimension"),
stringList(request.path("PolicyNames")),
region);
ObjectNode response = objectMapper.createObjectNode();
ArrayNode array = response.putArray("ScalingPolicies");
found.forEach(p -> array.add(scalingPolicyJson(p)));
return Response.ok(response).build();
}
private Response handleDeleteScalingPolicy(JsonNode request, String region) {
service.deleteScalingPolicy(
text(request, "PolicyName"),
text(request, "ServiceNamespace"),
text(request, "ResourceId"),
text(request, "ScalableDimension"),
region);
return Response.ok(objectMapper.createObjectNode()).build();
}
// ---------------------------------------------------------------- tagging
private Response handleListTagsForResource(JsonNode request, String region) {
Map<String, String> tags = service.listTagsForResource(text(request, "ResourceARN"), region);
ObjectNode response = objectMapper.createObjectNode();
ObjectNode node = response.putObject("Tags");
tags.forEach(node::put);
return Response.ok(response).build();
}
private Response handleTagResource(JsonNode request, String region) {
service.tagResource(text(request, "ResourceARN"), parseTags(request.path("Tags")), region);
return Response.ok(objectMapper.createObjectNode()).build();
}
private Response handleUntagResource(JsonNode request, String region) {
service.untagResource(text(request, "ResourceARN"), stringList(request.path("TagKeys")), region);
return Response.ok(objectMapper.createObjectNode()).build();
}
// ---------------------------------------------------------------- serialization
private ObjectNode scalableTargetJson(ScalableTarget t) {
ObjectNode node = objectMapper.createObjectNode();
node.put("ServiceNamespace", t.getServiceNamespace());
node.put("ResourceId", t.getResourceId());
node.put("ScalableDimension", t.getScalableDimension());
node.put("MinCapacity", t.getMinCapacity());
node.put("MaxCapacity", t.getMaxCapacity());
node.put("RoleARN", t.getRoleArn());
node.put("ScalableTargetARN", t.getScalableTargetArn());
node.put("CreationTime", t.getCreationTime());
SuspendedState state = t.getSuspendedState();
ObjectNode suspended = node.putObject("SuspendedState");
suspended.put("DynamicScalingInSuspended", state.isDynamicScalingInSuspended());
suspended.put("DynamicScalingOutSuspended", state.isDynamicScalingOutSuspended());
suspended.put("ScheduledScalingSuspended", state.isScheduledScalingSuspended());
return node;
}
private ObjectNode scalingPolicyJson(ScalingPolicy p) {
ObjectNode node = objectMapper.createObjectNode();
node.put("PolicyARN", p.getPolicyArn());
node.put("PolicyName", p.getPolicyName());
node.put("PolicyType", p.getPolicyType());
node.put("ServiceNamespace", p.getServiceNamespace());
node.put("ResourceId", p.getResourceId());
node.put("ScalableDimension", p.getScalableDimension());
node.put("CreationTime", p.getCreationTime());
ArrayNode alarms = node.putArray("Alarms");
p.getAlarms().forEach(a -> alarms.add(alarmJson(a)));
if (p.getTargetTrackingConfiguration() != null) {
node.set("TargetTrackingScalingPolicyConfiguration",
targetTrackingJson(p.getTargetTrackingConfiguration()));
}
if (p.getStepScalingConfiguration() != null) {
node.set("StepScalingPolicyConfiguration", stepScalingJson(p.getStepScalingConfiguration()));
}
return node;
}
/**
* Emits only the fields that were supplied. Defaulting absent optionals here would make
* Terraform see a value it never configured and report perpetual drift.
*/
private ObjectNode targetTrackingJson(TargetTrackingConfiguration config) {
ObjectNode node = objectMapper.createObjectNode();
if (config.getTargetValue() != null) {
node.put("TargetValue", config.getTargetValue());
}
if (config.getPredefinedMetricSpecification() != null) {
PredefinedMetricSpecification spec = config.getPredefinedMetricSpecification();
ObjectNode specNode = node.putObject("PredefinedMetricSpecification");
specNode.put("PredefinedMetricType", spec.getPredefinedMetricType());
if (spec.getResourceLabel() != null) {
specNode.put("ResourceLabel", spec.getResourceLabel());
}
}
if (config.getCustomizedMetricSpecification() != null) {
node.set("CustomizedMetricSpecification",
objectMapper.valueToTree(config.getCustomizedMetricSpecification()));
}
if (config.getDisableScaleIn() != null) {
node.put("DisableScaleIn", config.getDisableScaleIn());
}
if (config.getScaleInCooldown() != null) {
node.put("ScaleInCooldown", config.getScaleInCooldown());
}
if (config.getScaleOutCooldown() != null) {
node.put("ScaleOutCooldown", config.getScaleOutCooldown());
}
return node;
}
private ObjectNode stepScalingJson(StepScalingConfiguration config) {
ObjectNode node = objectMapper.createObjectNode();
if (config.getAdjustmentType() != null) {
node.put("AdjustmentType", config.getAdjustmentType());
}
if (config.getCooldown() != null) {
node.put("Cooldown", config.getCooldown());
}
if (config.getMetricAggregationType() != null) {
node.put("MetricAggregationType", config.getMetricAggregationType());
}
if (config.getMinAdjustmentMagnitude() != null) {
node.put("MinAdjustmentMagnitude", config.getMinAdjustmentMagnitude());
}
if (!config.getStepAdjustments().isEmpty()) {
ArrayNode steps = node.putArray("StepAdjustments");
for (StepAdjustment step : config.getStepAdjustments()) {
ObjectNode stepNode = steps.addObject();
if (step.getMetricIntervalLowerBound() != null) {
stepNode.put("MetricIntervalLowerBound", step.getMetricIntervalLowerBound());
}
if (step.getMetricIntervalUpperBound() != null) {
stepNode.put("MetricIntervalUpperBound", step.getMetricIntervalUpperBound());
}
if (step.getScalingAdjustment() != null) {
stepNode.put("ScalingAdjustment", step.getScalingAdjustment());
}
}
}
return node;
}
private ObjectNode alarmJson(Alarm alarm) {
ObjectNode node = objectMapper.createObjectNode();
node.put("AlarmName", alarm.getAlarmName());
node.put("AlarmARN", alarm.getAlarmArn());
return node;
}
// ---------------------------------------------------------------- parsing
private SuspendedState parseSuspendedState(JsonNode node) {
if (node == null || node.isMissingNode() || node.isNull()) {
return null;
}
SuspendedState state = new SuspendedState();
state.setDynamicScalingInSuspended(node.path("DynamicScalingInSuspended").asBoolean(false));
state.setDynamicScalingOutSuspended(node.path("DynamicScalingOutSuspended").asBoolean(false));
state.setScheduledScalingSuspended(node.path("ScheduledScalingSuspended").asBoolean(false));
return state;
}
private TargetTrackingConfiguration parseTargetTracking(JsonNode node) {
if (node == null || node.isMissingNode() || node.isNull()) {
return null;
}
TargetTrackingConfiguration config = new TargetTrackingConfiguration();
if (node.hasNonNull("TargetValue")) {
config.setTargetValue(node.get("TargetValue").asDouble());
}
JsonNode predefined = node.path("PredefinedMetricSpecification");
if (predefined.isObject()) {
PredefinedMetricSpecification spec = new PredefinedMetricSpecification();
spec.setPredefinedMetricType(text(predefined, "PredefinedMetricType"));
spec.setResourceLabel(text(predefined, "ResourceLabel"));
config.setPredefinedMetricSpecification(spec);
}
JsonNode customized = node.path("CustomizedMetricSpecification");
if (customized.isObject()) {
config.setCustomizedMetricSpecification(
objectMapper.convertValue(customized, new com.fasterxml.jackson.core.type.TypeReference<>() {}));
}
if (node.hasNonNull("DisableScaleIn")) {
config.setDisableScaleIn(node.get("DisableScaleIn").asBoolean());
}
if (node.hasNonNull("ScaleInCooldown")) {
config.setScaleInCooldown(node.get("ScaleInCooldown").asInt());
}
if (node.hasNonNull("ScaleOutCooldown")) {
config.setScaleOutCooldown(node.get("ScaleOutCooldown").asInt());
}
return config;
}
private StepScalingConfiguration parseStepScaling(JsonNode node) {
if (node == null || node.isMissingNode() || node.isNull()) {
return null;
}
StepScalingConfiguration config = new StepScalingConfiguration();
config.setAdjustmentType(text(node, "AdjustmentType"));
config.setMetricAggregationType(text(node, "MetricAggregationType"));
if (node.hasNonNull("Cooldown")) {
config.setCooldown(node.get("Cooldown").asInt());
}
if (node.hasNonNull("MinAdjustmentMagnitude")) {
config.setMinAdjustmentMagnitude(node.get("MinAdjustmentMagnitude").asInt());
}
List<StepAdjustment> steps = new ArrayList<>();
for (JsonNode stepNode : node.path("StepAdjustments")) {
StepAdjustment step = new StepAdjustment();
if (stepNode.hasNonNull("MetricIntervalLowerBound")) {
step.setMetricIntervalLowerBound(stepNode.get("MetricIntervalLowerBound").asDouble());
}
if (stepNode.hasNonNull("MetricIntervalUpperBound")) {
step.setMetricIntervalUpperBound(stepNode.get("MetricIntervalUpperBound").asDouble());
}
if (stepNode.hasNonNull("ScalingAdjustment")) {
step.setScalingAdjustment(stepNode.get("ScalingAdjustment").asInt());
}
steps.add(step);
}
config.setStepAdjustments(steps);
return config;
}
private Map<String, String> parseTags(JsonNode node) {
if (node == null || !node.isObject()) {
return null;
}
Map<String, String> tags = new HashMap<>();
Iterator<Map.Entry<String, JsonNode>> fields = node.fields();
while (fields.hasNext()) {
Map.Entry<String, JsonNode> entry = fields.next();
tags.put(entry.getKey(), entry.getValue().asText());
}
return tags;
}
private static List<String> stringList(JsonNode node) {
if (node == null || !node.isArray()) {
return List.of();
}
List<String> values = new ArrayList<>();
node.forEach(item -> values.add(item.asText()));
return values;
}
private static String text(JsonNode node, String field) {
JsonNode value = node.path(field);
return value.isMissingNode() || value.isNull() ? null : value.asText();
}
private static Integer integer(JsonNode node, String field) {
JsonNode value = node.path(field);
return value.isMissingNode() || value.isNull() ? null : value.asInt();
}
}
@@ -0,0 +1,493 @@
package io.github.hectorvent.floci.services.applicationautoscaling;
import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.applicationautoscaling.model.Alarm;
import io.github.hectorvent.floci.services.applicationautoscaling.model.ScalableTarget;
import io.github.hectorvent.floci.services.applicationautoscaling.model.ScalingPolicy;
import io.github.hectorvent.floci.services.applicationautoscaling.model.StepScalingConfiguration;
import io.github.hectorvent.floci.services.applicationautoscaling.model.SuspendedState;
import io.github.hectorvent.floci.services.applicationautoscaling.model.TargetTrackingConfiguration;
import io.github.hectorvent.floci.services.cloudwatch.metrics.CloudWatchMetricsService;
import io.github.hectorvent.floci.services.cloudwatch.metrics.model.MetricAlarm;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.jboss.logging.Logger;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
/**
* Application Auto Scaling control plane.
*
* <p>Scalable targets and scaling policies are stored and described faithfully, but
* policies are <strong>inert</strong>: nothing evaluates them and no capacity is ever
* adjusted. This mirrors the existing EC2 Auto Scaling {@code PutScalingPolicy} behaviour
* and is documented in {@code docs/services/applicationautoscaling.md}.</p>
*
* @see <a href="https://docs.aws.amazon.com/autoscaling/application/APIReference/Welcome.html">Application Auto Scaling API Reference</a>
*/
@ApplicationScoped
public class ApplicationAutoScalingService {
private static final Logger LOG = Logger.getLogger(ApplicationAutoScalingService.class);
static final Set<String> SERVICE_NAMESPACES = Set.of(
"ecs", "elasticmapreduce", "ec2", "appstream", "dynamodb", "rds", "sagemaker",
"custom-resource", "comprehend", "lambda", "cassandra", "kafka", "elasticache",
"neptune", "workspaces");
static final Set<String> SCALABLE_DIMENSIONS = Set.of(
"ecs:service:DesiredCount",
"ec2:spot-fleet-request:TargetCapacity",
"elasticmapreduce:instancegroup:InstanceCount",
"appstream:fleet:DesiredCapacity",
"dynamodb:table:ReadCapacityUnits",
"dynamodb:table:WriteCapacityUnits",
"dynamodb:index:ReadCapacityUnits",
"dynamodb:index:WriteCapacityUnits",
"rds:cluster:ReadReplicaCount",
"sagemaker:variant:DesiredInstanceCount",
"custom-resource:ResourceType:Property",
"comprehend:document-classifier-endpoint:DesiredInferenceUnits",
"comprehend:entity-recognizer-endpoint:DesiredInferenceUnits",
"lambda:function:ProvisionedConcurrency",
"cassandra:table:ReadCapacityUnits",
"cassandra:table:WriteCapacityUnits",
"kafka:broker-storage:VolumeSize",
"elasticache:cache-cluster:Nodes",
"elasticache:replication-group:NodeGroups",
"elasticache:replication-group:Replicas",
"neptune:cluster:ReadReplicaCount",
"sagemaker:variant:DesiredProvisionedConcurrency",
"sagemaker:inference-component:DesiredCopyCount",
"workspaces:workspacespool:DesiredUserSessions");
private static final Set<String> POLICY_TYPES =
Set.of("StepScaling", "TargetTrackingScaling", "PredictiveScaling");
private final StorageBackend<String, ScalableTarget> targets;
private final StorageBackend<String, ScalingPolicy> policies;
private final RegionResolver regionResolver;
private final CloudWatchMetricsService cloudWatchMetricsService;
@Inject
public ApplicationAutoScalingService(StorageFactory factory,
RegionResolver regionResolver,
CloudWatchMetricsService cloudWatchMetricsService) {
this(factory.create("applicationautoscaling", "application-autoscaling-targets.json",
new TypeReference<Map<String, ScalableTarget>>() {}),
factory.create("applicationautoscaling", "application-autoscaling-policies.json",
new TypeReference<Map<String, ScalingPolicy>>() {}),
regionResolver,
cloudWatchMetricsService);
}
ApplicationAutoScalingService(StorageBackend<String, ScalableTarget> targets,
StorageBackend<String, ScalingPolicy> policies,
RegionResolver regionResolver,
CloudWatchMetricsService cloudWatchMetricsService) {
this.targets = targets;
this.policies = policies;
this.regionResolver = regionResolver;
this.cloudWatchMetricsService = cloudWatchMetricsService;
}
// ---------------------------------------------------------------- scalable targets
public ScalableTarget registerScalableTarget(String serviceNamespace, String resourceId,
String scalableDimension, Integer minCapacity,
Integer maxCapacity, String roleArn,
SuspendedState suspendedState,
Map<String, String> tags, String region) {
validateTriple(serviceNamespace, resourceId, scalableDimension);
String key = targetKey(region, serviceNamespace, resourceId, scalableDimension);
ScalableTarget existing = targets.get(key).orElse(null);
if (existing == null) {
if (minCapacity == null || maxCapacity == null) {
throw new AwsException("ValidationException",
"Min and max capacity are required when registering a new scalable target.", 400);
}
ScalableTarget target = new ScalableTarget();
target.setServiceNamespace(serviceNamespace);
target.setResourceId(resourceId);
target.setScalableDimension(scalableDimension);
target.setMinCapacity(minCapacity);
target.setMaxCapacity(maxCapacity);
target.setRoleArn(roleArn != null ? roleArn : serviceLinkedRoleArn(serviceNamespace));
target.setScalableTargetArn(buildScalableTargetArn(region));
target.setCreationTime(nowEpochSeconds());
target.setSuspendedState(suspendedState != null ? suspendedState : new SuspendedState());
if (tags != null) {
target.setTags(tags);
}
targets.put(key, target);
LOG.infov("RegisterScalableTarget: {0} {1} {2} in {3}",
serviceNamespace, resourceId, scalableDimension, region);
return target;
}
// Update semantics: only supplied parameters change.
if (minCapacity != null) {
existing.setMinCapacity(minCapacity);
}
if (maxCapacity != null) {
existing.setMaxCapacity(maxCapacity);
}
if (roleArn != null) {
existing.setRoleArn(roleArn);
}
if (suspendedState != null) {
existing.setSuspendedState(suspendedState);
}
if (tags != null && !tags.isEmpty()) {
existing.putTags(tags);
}
targets.put(key, existing);
LOG.infov("RegisterScalableTarget (update): {0} {1} {2} in {3}",
serviceNamespace, resourceId, scalableDimension, region);
return existing;
}
public List<ScalableTarget> describeScalableTargets(String serviceNamespace, List<String> resourceIds,
String scalableDimension, String region) {
requireNamespace(serviceNamespace);
if (scalableDimension != null && (resourceIds == null || resourceIds.isEmpty())) {
throw new AwsException("ValidationException",
"A resource ID must be specified when a scalable dimension is specified.", 400);
}
String prefix = region + "::" + serviceNamespace + "::";
return targets.scan(k -> k.startsWith(prefix)).stream()
.filter(t -> resourceIds == null || resourceIds.isEmpty() || resourceIds.contains(t.getResourceId()))
.filter(t -> scalableDimension == null || scalableDimension.equals(t.getScalableDimension()))
.sorted(Comparator.comparing(ScalableTarget::getResourceId)
.thenComparing(ScalableTarget::getScalableDimension))
.toList();
}
/**
* Deregisters a scalable target and, per AWS semantics, deletes every scaling policy
* attached to it along with the CloudWatch alarms those policies own.
*/
public void deregisterScalableTarget(String serviceNamespace, String resourceId,
String scalableDimension, String region) {
validateTriple(serviceNamespace, resourceId, scalableDimension);
String key = targetKey(region, serviceNamespace, resourceId, scalableDimension);
if (targets.get(key).isEmpty()) {
throw new AwsException("ObjectNotFoundException",
"No scalable target found for service namespace: " + serviceNamespace
+ ", resource ID: " + resourceId
+ ", scalable dimension: " + scalableDimension, 400);
}
for (ScalingPolicy policy : findPolicies(region, serviceNamespace, resourceId, scalableDimension)) {
deleteAlarms(policy, region);
policies.delete(policyKey(region, serviceNamespace, resourceId, scalableDimension, policy.getPolicyName()));
}
targets.delete(key);
LOG.infov("DeregisterScalableTarget: {0} {1} {2} in {3}",
serviceNamespace, resourceId, scalableDimension, region);
}
// ---------------------------------------------------------------- scaling policies
public ScalingPolicy putScalingPolicy(String policyName, String policyType, String serviceNamespace,
String resourceId, String scalableDimension,
TargetTrackingConfiguration targetTracking,
StepScalingConfiguration stepScaling, String region) {
validateTriple(serviceNamespace, resourceId, scalableDimension);
if (policyName == null || policyName.isBlank()) {
throw new AwsException("ValidationException", "PolicyName is required.", 400);
}
if (policyType != null && !POLICY_TYPES.contains(policyType)) {
throw new AwsException("ValidationException",
"Unsupported policy type: " + policyType, 400);
}
String targetKey = targetKey(region, serviceNamespace, resourceId, scalableDimension);
if (targets.get(targetKey).isEmpty()) {
throw new AwsException("ObjectNotFoundException",
"No scalable target found for service namespace: " + serviceNamespace
+ ", resource ID: " + resourceId
+ ", scalable dimension: " + scalableDimension, 400);
}
String key = policyKey(region, serviceNamespace, resourceId, scalableDimension, policyName);
ScalingPolicy existing = policies.get(key).orElse(null);
ScalingPolicy policy = existing != null ? existing : new ScalingPolicy();
policy.setPolicyName(policyName);
policy.setPolicyType(policyType != null ? policyType : "StepScaling");
policy.setServiceNamespace(serviceNamespace);
policy.setResourceId(resourceId);
policy.setScalableDimension(scalableDimension);
policy.setTargetTrackingConfiguration(targetTracking);
policy.setStepScalingConfiguration(stepScaling);
if (existing == null) {
policy.setCreationTime(nowEpochSeconds());
policy.setPolicyArn(buildPolicyArn(region, serviceNamespace, resourceId, policyName));
}
if ("TargetTrackingScaling".equals(policy.getPolicyType())) {
if (existing != null) {
deleteAlarms(existing, region);
}
policy.setAlarms(createTargetTrackingAlarms(policy, region));
} else {
policy.setAlarms(new ArrayList<>());
}
policies.put(key, policy);
LOG.infov("PutScalingPolicy: {0} ({1}) for {2} {3} in {4}",
policyName, policy.getPolicyType(), serviceNamespace, resourceId, region);
return policy;
}
public List<ScalingPolicy> describeScalingPolicies(String serviceNamespace, String resourceId,
String scalableDimension, List<String> policyNames,
String region) {
requireNamespace(serviceNamespace);
if (scalableDimension != null && (resourceId == null || resourceId.isBlank())) {
throw new AwsException("ValidationException",
"A resource ID must be specified when a scalable dimension is specified.", 400);
}
String prefix = region + "::" + serviceNamespace + "::";
return policies.scan(k -> k.startsWith(prefix)).stream()
.filter(p -> resourceId == null || resourceId.equals(p.getResourceId()))
.filter(p -> scalableDimension == null || scalableDimension.equals(p.getScalableDimension()))
.filter(p -> policyNames == null || policyNames.isEmpty() || policyNames.contains(p.getPolicyName()))
.sorted(Comparator.comparing(ScalingPolicy::getPolicyName))
.toList();
}
public void deleteScalingPolicy(String policyName, String serviceNamespace, String resourceId,
String scalableDimension, String region) {
validateTriple(serviceNamespace, resourceId, scalableDimension);
if (policyName == null || policyName.isBlank()) {
throw new AwsException("ValidationException", "PolicyName is required.", 400);
}
String key = policyKey(region, serviceNamespace, resourceId, scalableDimension, policyName);
ScalingPolicy policy = policies.get(key).orElseThrow(() -> new AwsException("ObjectNotFoundException",
"No scaling policy found for service namespace: " + serviceNamespace
+ ", resource ID: " + resourceId
+ ", scalable dimension: " + scalableDimension
+ ", policy name: " + policyName, 400));
deleteAlarms(policy, region);
policies.delete(key);
LOG.infov("DeleteScalingPolicy: {0} for {1} {2} in {3}",
policyName, serviceNamespace, resourceId, region);
}
// ---------------------------------------------------------------- tagging
public Map<String, String> listTagsForResource(String resourceArn, String region) {
return findTargetByArn(resourceArn, region).getTags();
}
public void tagResource(String resourceArn, Map<String, String> tags, String region) {
if (tags == null || tags.isEmpty()) {
throw new AwsException("ValidationException", "Tags are required.", 400);
}
ScalableTarget target = findTargetByArn(resourceArn, region);
target.putTags(tags);
targets.put(targetKey(region, target.getServiceNamespace(), target.getResourceId(),
target.getScalableDimension()), target);
}
public void untagResource(String resourceArn, List<String> tagKeys, String region) {
if (tagKeys == null || tagKeys.isEmpty()) {
throw new AwsException("ValidationException", "TagKeys are required.", 400);
}
ScalableTarget target = findTargetByArn(resourceArn, region);
target.removeTags(tagKeys);
targets.put(targetKey(region, target.getServiceNamespace(), target.getResourceId(),
target.getScalableDimension()), target);
}
// ---------------------------------------------------------------- internals
private ScalableTarget findTargetByArn(String resourceArn, String region) {
if (resourceArn == null || resourceArn.isBlank()) {
throw new AwsException("ValidationException", "ResourceARN is required.", 400);
}
String prefix = region + "::";
return targets.scan(k -> k.startsWith(prefix)).stream()
.filter(t -> resourceArn.equals(t.getScalableTargetArn()))
.findFirst()
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
"Resource not found: " + resourceArn, 400));
}
private List<ScalingPolicy> findPolicies(String region, String serviceNamespace, String resourceId,
String scalableDimension) {
String prefix = region + "::" + serviceNamespace + "::";
return policies.scan(k -> k.startsWith(prefix)).stream()
.filter(p -> resourceId.equals(p.getResourceId()))
.filter(p -> scalableDimension.equals(p.getScalableDimension()))
.toList();
}
/**
* Creates the pair of CloudWatch alarms that AWS provisions on behalf of a target
* tracking policy. The alarms are real: they show up in DescribeAlarms exactly as they
* would in AWS, even though nothing evaluates them here.
*/
private List<Alarm> createTargetTrackingAlarms(ScalingPolicy policy, String region) {
List<Alarm> alarms = new ArrayList<>();
for (String suffix : List.of("AlarmHigh", "AlarmLow")) {
String alarmName = "TargetTracking-" + policy.getResourceId() + "-" + suffix + "-"
+ UUID.randomUUID();
MetricAlarm alarm = new MetricAlarm();
alarm.setAlarmName(alarmName);
alarm.setAlarmDescription("DO NOT EDIT OR DELETE. For TargetTrackingScaling policy "
+ policy.getPolicyArn() + ".");
alarm.setNamespace(cloudWatchNamespace(policy.getServiceNamespace()));
alarm.setMetricName(predefinedMetricType(policy));
alarm.setStatistic("Average");
alarm.setPeriod(60);
alarm.setEvaluationPeriods("AlarmHigh".equals(suffix) ? 3 : 15);
alarm.setThreshold(targetValue(policy));
alarm.setComparisonOperator("AlarmHigh".equals(suffix)
? "GreaterThanThreshold" : "LessThanThreshold");
alarm.setAlarmActions(List.of(policy.getPolicyArn()));
cloudWatchMetricsService.putMetricAlarm(alarm, region);
alarms.add(new Alarm(alarmName, alarm.getAlarmArn()));
}
return alarms;
}
private void deleteAlarms(ScalingPolicy policy, String region) {
List<String> names = policy.getAlarms().stream().map(Alarm::getAlarmName).toList();
if (names.isEmpty()) {
return;
}
try {
cloudWatchMetricsService.deleteAlarms(names, region);
} catch (RuntimeException e) {
// Alarm cleanup is best-effort: a user may have deleted them out of band.
LOG.debugv(e, "Could not delete target-tracking alarms {0} in {1}", names, region);
}
}
private static String cloudWatchNamespace(String serviceNamespace) {
return switch (serviceNamespace) {
case "ecs" -> "AWS/ECS";
case "kafka" -> "AWS/Kafka";
case "dynamodb" -> "AWS/DynamoDB";
case "lambda" -> "AWS/Lambda";
case "rds" -> "AWS/RDS";
case "elasticache" -> "AWS/ElastiCache";
default -> "AWS/" + serviceNamespace.toUpperCase(Locale.ROOT);
};
}
private static String predefinedMetricType(ScalingPolicy policy) {
TargetTrackingConfiguration config = policy.getTargetTrackingConfiguration();
if (config != null && config.getPredefinedMetricSpecification() != null
&& config.getPredefinedMetricSpecification().getPredefinedMetricType() != null) {
return config.getPredefinedMetricSpecification().getPredefinedMetricType();
}
return "CustomizedMetric";
}
private static double targetValue(ScalingPolicy policy) {
TargetTrackingConfiguration config = policy.getTargetTrackingConfiguration();
return config != null && config.getTargetValue() != null ? config.getTargetValue() : 0.0d;
}
private void validateTriple(String serviceNamespace, String resourceId, String scalableDimension) {
requireNamespace(serviceNamespace);
if (resourceId == null || resourceId.isBlank()) {
throw new AwsException("ValidationException", "ResourceId is required.", 400);
}
if (scalableDimension == null || scalableDimension.isBlank()) {
throw new AwsException("ValidationException", "ScalableDimension is required.", 400);
}
if (!SCALABLE_DIMENSIONS.contains(scalableDimension)) {
throw new AwsException("ValidationException",
"Value '" + scalableDimension + "' at 'scalableDimension' failed to satisfy constraint: "
+ "Member must satisfy enum value set.", 400);
}
}
private void requireNamespace(String serviceNamespace) {
if (serviceNamespace == null || serviceNamespace.isBlank()) {
throw new AwsException("ValidationException", "ServiceNamespace is required.", 400);
}
if (!SERVICE_NAMESPACES.contains(serviceNamespace)) {
throw new AwsException("ValidationException",
"Value '" + serviceNamespace + "' at 'serviceNamespace' failed to satisfy constraint: "
+ "Member must satisfy enum value set.", 400);
}
}
/**
* The scalable-target ARN must match
* {@code ^arn:.+:application-autoscaling:.+:[0-9]+:scalable-target/[a-zA-Z0-9-]+$},
* so the suffix is a dashless UUID.
*/
private String buildScalableTargetArn(String region) {
String id = UUID.randomUUID().toString().replace("-", "");
return regionResolver.buildArn("application-autoscaling", region, "scalable-target/" + id);
}
/**
* Policy ARNs use the {@code autoscaling} service name — not
* {@code application-autoscaling} — and embed the resource path and policy name.
*/
private String buildPolicyArn(String region, String serviceNamespace, String resourceId, String policyName) {
String resource = "scalingPolicy:" + UUID.randomUUID()
+ ":resource/" + serviceNamespace + "/" + resourceId
+ ":policyName/" + policyName;
return regionResolver.buildArn("autoscaling", region, resource);
}
/**
* AWS creates and returns a service-linked role when the caller supplies none, so the
* emulator synthesizes one in the same shape to keep the Computed attribute stable.
*/
private String serviceLinkedRoleArn(String serviceNamespace) {
String suffix = switch (serviceNamespace) {
case "ecs" -> "ECSService";
case "kafka" -> "KafkaCluster";
case "dynamodb" -> "DynamoDBTable";
case "lambda" -> "LambdaConcurrency";
case "rds" -> "RDSCluster";
case "elasticache" -> "ElastiCacheRG";
default -> "CustomResource";
};
return "arn:aws:iam::" + regionResolver.getAccountId()
+ ":role/aws-service-role/" + serviceNamespace + ".application-autoscaling.amazonaws.com/"
+ "AWSServiceRoleForApplicationAutoScaling_" + suffix;
}
private static double nowEpochSeconds() {
Instant now = Instant.now();
return now.getEpochSecond() + (now.getNano() / 1_000_000 / 1000.0d);
}
private static String targetKey(String region, String serviceNamespace, String resourceId,
String scalableDimension) {
return region + "::" + serviceNamespace + "::" + scalableDimension + "::" + resourceId;
}
private static String policyKey(String region, String serviceNamespace, String resourceId,
String scalableDimension, String policyName) {
return targetKey(region, serviceNamespace, resourceId, scalableDimension) + "::" + policyName;
}
Optional<ScalableTarget> findTarget(String region, String serviceNamespace, String resourceId,
String scalableDimension) {
return targets.get(targetKey(region, serviceNamespace, resourceId, scalableDimension));
}
}
@@ -0,0 +1,29 @@
package io.github.hectorvent.floci.services.applicationautoscaling.model;
import io.quarkus.runtime.annotations.RegisterForReflection;
/**
* A CloudWatch alarm associated with a scaling policy.
*
* @see <a href="https://docs.aws.amazon.com/autoscaling/application/APIReference/API_Alarm.html">Alarm</a>
*/
@RegisterForReflection
public class Alarm {
private String alarmName;
private String alarmArn;
public Alarm() {
}
public Alarm(String alarmName, String alarmArn) {
this.alarmName = alarmName;
this.alarmArn = alarmArn;
}
public String getAlarmName() { return alarmName; }
public void setAlarmName(String alarmName) { this.alarmName = alarmName; }
public String getAlarmArn() { return alarmArn; }
public void setAlarmArn(String alarmArn) { this.alarmArn = alarmArn; }
}
@@ -0,0 +1,25 @@
package io.github.hectorvent.floci.services.applicationautoscaling.model;
import io.quarkus.runtime.annotations.RegisterForReflection;
/**
* A predefined metric for a target tracking scaling policy.
*
* <p>{@code resourceLabel} is required for load-balancer metrics such as
* {@code ALBRequestCountPerTarget} and must round-trip exactly, otherwise Terraform
* reports perpetual drift.</p>
*
* @see <a href="https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PredefinedMetricSpecification.html">PredefinedMetricSpecification</a>
*/
@RegisterForReflection
public class PredefinedMetricSpecification {
private String predefinedMetricType;
private String resourceLabel;
public String getPredefinedMetricType() { return predefinedMetricType; }
public void setPredefinedMetricType(String v) { this.predefinedMetricType = v; }
public String getResourceLabel() { return resourceLabel; }
public void setResourceLabel(String v) { this.resourceLabel = v; }
}
@@ -0,0 +1,77 @@
package io.github.hectorvent.floci.services.applicationautoscaling.model;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* A registered scalable target.
*
* <p>Identity is the triple (serviceNamespace, resourceId, scalableDimension); there is no
* separate identifier. {@code scalableTargetArn} is the tagging identifier that the
* Terraform provider reads from DescribeScalableTargets and then passes to
* ListTagsForResource, so it must always be populated.</p>
*
* @see <a href="https://docs.aws.amazon.com/autoscaling/application/APIReference/API_ScalableTarget.html">ScalableTarget</a>
*/
@RegisterForReflection
public class ScalableTarget {
private String serviceNamespace;
private String resourceId;
private String scalableDimension;
private Integer minCapacity;
private Integer maxCapacity;
private String roleArn;
private String scalableTargetArn;
private double creationTime;
private SuspendedState suspendedState = new SuspendedState();
private Map<String, String> tags = new HashMap<>();
public String getServiceNamespace() { return serviceNamespace; }
public void setServiceNamespace(String v) { this.serviceNamespace = v; }
public String getResourceId() { return resourceId; }
public void setResourceId(String v) { this.resourceId = v; }
public String getScalableDimension() { return scalableDimension; }
public void setScalableDimension(String v) { this.scalableDimension = v; }
public Integer getMinCapacity() { return minCapacity; }
public void setMinCapacity(Integer v) { this.minCapacity = v; }
public Integer getMaxCapacity() { return maxCapacity; }
public void setMaxCapacity(Integer v) { this.maxCapacity = v; }
public String getRoleArn() { return roleArn; }
public void setRoleArn(String v) { this.roleArn = v; }
public String getScalableTargetArn() { return scalableTargetArn; }
public void setScalableTargetArn(String v) { this.scalableTargetArn = v; }
public double getCreationTime() { return creationTime; }
public void setCreationTime(double v) { this.creationTime = v; }
public SuspendedState getSuspendedState() { return suspendedState; }
public void setSuspendedState(SuspendedState v) { this.suspendedState = v == null ? new SuspendedState() : v; }
/** Read-only view; mutate through {@link #putTags} and {@link #removeTags}. */
public Map<String, String> getTags() { return Collections.unmodifiableMap(tags); }
/** Copies defensively so that a caller passing an immutable map stays mutable here. */
public void setTags(Map<String, String> v) { this.tags = v == null ? new HashMap<>() : new HashMap<>(v); }
public void putTags(Map<String, String> additional) {
if (additional != null) {
tags.putAll(additional);
}
}
public void removeTags(Collection<String> tagKeys) {
if (tagKeys != null) {
tagKeys.forEach(tags::remove);
}
}
}
@@ -0,0 +1,59 @@
package io.github.hectorvent.floci.services.applicationautoscaling.model;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.util.ArrayList;
import java.util.List;
/**
* A scaling policy attached to a scalable target.
*
* <p>Note that {@code policyArn} uses the {@code autoscaling} service name rather than
* {@code application-autoscaling} — the two ARN families differ, which AWS does not
* document in one place.</p>
*
* @see <a href="https://docs.aws.amazon.com/autoscaling/application/APIReference/API_ScalingPolicy.html">ScalingPolicy</a>
*/
@RegisterForReflection
public class ScalingPolicy {
private String policyArn;
private String policyName;
private String policyType;
private String serviceNamespace;
private String resourceId;
private String scalableDimension;
private double creationTime;
private List<Alarm> alarms = new ArrayList<>();
private TargetTrackingConfiguration targetTrackingConfiguration;
private StepScalingConfiguration stepScalingConfiguration;
public String getPolicyArn() { return policyArn; }
public void setPolicyArn(String v) { this.policyArn = v; }
public String getPolicyName() { return policyName; }
public void setPolicyName(String v) { this.policyName = v; }
public String getPolicyType() { return policyType; }
public void setPolicyType(String v) { this.policyType = v; }
public String getServiceNamespace() { return serviceNamespace; }
public void setServiceNamespace(String v) { this.serviceNamespace = v; }
public String getResourceId() { return resourceId; }
public void setResourceId(String v) { this.resourceId = v; }
public String getScalableDimension() { return scalableDimension; }
public void setScalableDimension(String v) { this.scalableDimension = v; }
public double getCreationTime() { return creationTime; }
public void setCreationTime(double v) { this.creationTime = v; }
public List<Alarm> getAlarms() { return alarms; }
public void setAlarms(List<Alarm> v) { this.alarms = v == null ? new ArrayList<>() : new ArrayList<>(v); }
public TargetTrackingConfiguration getTargetTrackingConfiguration() { return targetTrackingConfiguration; }
public void setTargetTrackingConfiguration(TargetTrackingConfiguration v) { this.targetTrackingConfiguration = v; }
public StepScalingConfiguration getStepScalingConfiguration() { return stepScalingConfiguration; }
public void setStepScalingConfiguration(StepScalingConfiguration v) { this.stepScalingConfiguration = v; }
}
@@ -0,0 +1,28 @@
package io.github.hectorvent.floci.services.applicationautoscaling.model;
import io.quarkus.runtime.annotations.RegisterForReflection;
/**
* One step of a step scaling policy.
*
* <p>The bounds are nullable: an omitted lower bound means negative infinity and an
* omitted upper bound means positive infinity, so they must not be defaulted to zero.</p>
*
* @see <a href="https://docs.aws.amazon.com/autoscaling/application/APIReference/API_StepAdjustment.html">StepAdjustment</a>
*/
@RegisterForReflection
public class StepAdjustment {
private Double metricIntervalLowerBound;
private Double metricIntervalUpperBound;
private Integer scalingAdjustment;
public Double getMetricIntervalLowerBound() { return metricIntervalLowerBound; }
public void setMetricIntervalLowerBound(Double v) { this.metricIntervalLowerBound = v; }
public Double getMetricIntervalUpperBound() { return metricIntervalUpperBound; }
public void setMetricIntervalUpperBound(Double v) { this.metricIntervalUpperBound = v; }
public Integer getScalingAdjustment() { return scalingAdjustment; }
public void setScalingAdjustment(Integer v) { this.scalingAdjustment = v; }
}
@@ -0,0 +1,37 @@
package io.github.hectorvent.floci.services.applicationautoscaling.model;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.util.ArrayList;
import java.util.List;
/**
* Step scaling configuration for a scaling policy.
*
* @see <a href="https://docs.aws.amazon.com/autoscaling/application/APIReference/API_StepScalingPolicyConfiguration.html">StepScalingPolicyConfiguration</a>
*/
@RegisterForReflection
public class StepScalingConfiguration {
private String adjustmentType;
private Integer cooldown;
private String metricAggregationType;
private Integer minAdjustmentMagnitude;
private List<StepAdjustment> stepAdjustments = new ArrayList<>();
public String getAdjustmentType() { return adjustmentType; }
public void setAdjustmentType(String v) { this.adjustmentType = v; }
public Integer getCooldown() { return cooldown; }
public void setCooldown(Integer v) { this.cooldown = v; }
public String getMetricAggregationType() { return metricAggregationType; }
public void setMetricAggregationType(String v) { this.metricAggregationType = v; }
public Integer getMinAdjustmentMagnitude() { return minAdjustmentMagnitude; }
public void setMinAdjustmentMagnitude(Integer v) { this.minAdjustmentMagnitude = v; }
public List<StepAdjustment> getStepAdjustments() { return stepAdjustments; }
public void setStepAdjustments(List<StepAdjustment> v) {
this.stepAdjustments = v == null ? new ArrayList<>() : new ArrayList<>(v);
}
}
@@ -0,0 +1,25 @@
package io.github.hectorvent.floci.services.applicationautoscaling.model;
import io.quarkus.runtime.annotations.RegisterForReflection;
/**
* Suspension flags for a scalable target's automatic scaling activities.
*
* @see <a href="https://docs.aws.amazon.com/autoscaling/application/APIReference/API_SuspendedState.html">SuspendedState</a>
*/
@RegisterForReflection
public class SuspendedState {
private boolean dynamicScalingInSuspended;
private boolean dynamicScalingOutSuspended;
private boolean scheduledScalingSuspended;
public boolean isDynamicScalingInSuspended() { return dynamicScalingInSuspended; }
public void setDynamicScalingInSuspended(boolean v) { this.dynamicScalingInSuspended = v; }
public boolean isDynamicScalingOutSuspended() { return dynamicScalingOutSuspended; }
public void setDynamicScalingOutSuspended(boolean v) { this.dynamicScalingOutSuspended = v; }
public boolean isScheduledScalingSuspended() { return scheduledScalingSuspended; }
public void setScheduledScalingSuspended(boolean v) { this.scheduledScalingSuspended = v; }
}
@@ -0,0 +1,42 @@
package io.github.hectorvent.floci.services.applicationautoscaling.model;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.util.Map;
/**
* Target tracking configuration for a scaling policy.
*
* <p>Every field here is echoed back by DescribeScalingPolicies. Optional numerics stay
* nullable so that omitted values are not invented on read, which would surface as
* Terraform drift.</p>
*
* @see <a href="https://docs.aws.amazon.com/autoscaling/application/APIReference/API_TargetTrackingScalingPolicyConfiguration.html">TargetTrackingScalingPolicyConfiguration</a>
*/
@RegisterForReflection
public class TargetTrackingConfiguration {
private Double targetValue;
private PredefinedMetricSpecification predefinedMetricSpecification;
private Map<String, Object> customizedMetricSpecification;
private Boolean disableScaleIn;
private Integer scaleInCooldown;
private Integer scaleOutCooldown;
public Double getTargetValue() { return targetValue; }
public void setTargetValue(Double v) { this.targetValue = v; }
public PredefinedMetricSpecification getPredefinedMetricSpecification() { return predefinedMetricSpecification; }
public void setPredefinedMetricSpecification(PredefinedMetricSpecification v) { this.predefinedMetricSpecification = v; }
public Map<String, Object> getCustomizedMetricSpecification() { return customizedMetricSpecification; }
public void setCustomizedMetricSpecification(Map<String, Object> v) { this.customizedMetricSpecification = v; }
public Boolean getDisableScaleIn() { return disableScaleIn; }
public void setDisableScaleIn(Boolean v) { this.disableScaleIn = v; }
public Integer getScaleInCooldown() { return scaleInCooldown; }
public void setScaleInCooldown(Integer v) { this.scaleInCooldown = v; }
public Integer getScaleOutCooldown() { return scaleOutCooldown; }
public void setScaleOutCooldown(Integer v) { this.scaleOutCooldown = v; }
}