mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(autoscaling): preserve policy and mixed instances parity (#1437)
* fix(autoscaling): preserve launch template capacity metadata * feat(autoscaling): preserve target tracking policies * feat(autoscaling): preserve mixed instances policies
This commit is contained in:
1 parent
630328547e
commit
9236b40073
12 files changed
+907
-26
No files matched your search
+177
-1
@@ -156,6 +156,7 @@ public class AutoScalingQueryHandler {
|
||||
p.getFirst("LaunchTemplate.LaunchTemplateId"),
|
||||
p.getFirst("LaunchTemplate.LaunchTemplateName"),
|
||||
p.getFirst("LaunchTemplate.Version"),
|
||||
parseMixedInstancesPolicy(p),
|
||||
intParam(p, "MinSize", 0),
|
||||
intParam(p, "MaxSize", 0),
|
||||
intParam(p, "DesiredCapacity", intParam(p, "MinSize", 0)),
|
||||
@@ -184,6 +185,7 @@ public class AutoScalingQueryHandler {
|
||||
p.getFirst("LaunchTemplate.LaunchTemplateId"),
|
||||
p.getFirst("LaunchTemplate.LaunchTemplateName"),
|
||||
p.getFirst("LaunchTemplate.Version"),
|
||||
parseMixedInstancesPolicy(p),
|
||||
p.getFirst("MinSize") != null ? Integer.parseInt(p.getFirst("MinSize")) : null,
|
||||
p.getFirst("MaxSize") != null ? Integer.parseInt(p.getFirst("MaxSize")) : null,
|
||||
p.getFirst("DesiredCapacity") != null ? Integer.parseInt(p.getFirst("DesiredCapacity")) : null,
|
||||
@@ -255,6 +257,7 @@ public class AutoScalingQueryHandler {
|
||||
}
|
||||
xml.end("LaunchTemplate");
|
||||
}
|
||||
appendMixedInstancesPolicyXml(xml, asg.getMixedInstancesPolicy());
|
||||
|
||||
xml.start("AvailabilityZones");
|
||||
for (String az : asg.getAvailabilityZones()) { xml.elem("member", az); }
|
||||
@@ -474,6 +477,64 @@ public class AutoScalingQueryHandler {
|
||||
xml.end("LaunchTemplate");
|
||||
}
|
||||
|
||||
private static void appendMixedInstancesPolicyXml(XmlBuilder xml, MixedInstancesPolicy policy) {
|
||||
if (policy == null) {
|
||||
return;
|
||||
}
|
||||
xml.start("MixedInstancesPolicy");
|
||||
MixedInstancesPolicy.LaunchTemplate launchTemplate = policy.getLaunchTemplate();
|
||||
if (launchTemplate != null) {
|
||||
xml.start("LaunchTemplate");
|
||||
appendMixedLaunchTemplateSpecificationXml(xml, launchTemplate.getLaunchTemplateSpecification());
|
||||
if (!launchTemplate.getOverrides().isEmpty()) {
|
||||
xml.start("Overrides");
|
||||
for (MixedInstancesPolicy.LaunchTemplateOverride override : launchTemplate.getOverrides()) {
|
||||
xml.start("member");
|
||||
if (override.getInstanceType() != null) {
|
||||
xml.elem("InstanceType", override.getInstanceType());
|
||||
}
|
||||
xml.end("member");
|
||||
}
|
||||
xml.end("Overrides");
|
||||
}
|
||||
xml.end("LaunchTemplate");
|
||||
}
|
||||
MixedInstancesPolicy.InstancesDistribution distribution = policy.getInstancesDistribution();
|
||||
if (distribution != null) {
|
||||
xml.start("InstancesDistribution");
|
||||
if (distribution.getOnDemandBaseCapacity() != null) {
|
||||
xml.elem("OnDemandBaseCapacity", String.valueOf(distribution.getOnDemandBaseCapacity()));
|
||||
}
|
||||
if (distribution.getOnDemandPercentageAboveBaseCapacity() != null) {
|
||||
xml.elem("OnDemandPercentageAboveBaseCapacity",
|
||||
String.valueOf(distribution.getOnDemandPercentageAboveBaseCapacity()));
|
||||
}
|
||||
if (distribution.getSpotAllocationStrategy() != null) {
|
||||
xml.elem("SpotAllocationStrategy", distribution.getSpotAllocationStrategy());
|
||||
}
|
||||
xml.end("InstancesDistribution");
|
||||
}
|
||||
xml.end("MixedInstancesPolicy");
|
||||
}
|
||||
|
||||
private static void appendMixedLaunchTemplateSpecificationXml(
|
||||
XmlBuilder xml, MixedInstancesPolicy.LaunchTemplateSpecification specification) {
|
||||
if (specification == null) {
|
||||
return;
|
||||
}
|
||||
xml.start("LaunchTemplateSpecification");
|
||||
if (specification.getLaunchTemplateId() != null) {
|
||||
xml.elem("LaunchTemplateId", specification.getLaunchTemplateId());
|
||||
}
|
||||
if (specification.getLaunchTemplateName() != null) {
|
||||
xml.elem("LaunchTemplateName", specification.getLaunchTemplateName());
|
||||
}
|
||||
if (specification.getVersion() != null) {
|
||||
xml.elem("Version", specification.getVersion());
|
||||
}
|
||||
xml.end("LaunchTemplateSpecification");
|
||||
}
|
||||
|
||||
private Response handleAttachInstances(MultivaluedMap<String, String> p, String region) {
|
||||
service.attachInstances(region, p.getFirst("AutoScalingGroupName"), memberList(p, "InstanceIds"));
|
||||
return ok(new XmlBuilder()
|
||||
@@ -678,7 +739,9 @@ public class AutoScalingQueryHandler {
|
||||
p.getFirst("PolicyType"),
|
||||
p.getFirst("AdjustmentType"),
|
||||
intParam(p, "ScalingAdjustment", 0),
|
||||
intParam(p, "Cooldown", 300));
|
||||
intParam(p, "Cooldown", 300),
|
||||
nullableIntParam(p, "EstimatedInstanceWarmup"),
|
||||
parseTargetTrackingConfiguration(p));
|
||||
return ok(new XmlBuilder()
|
||||
.start("PutScalingPolicyResponse", NS)
|
||||
.start("PutScalingPolicyResult")
|
||||
@@ -713,6 +776,10 @@ public class AutoScalingQueryHandler {
|
||||
.elem("ScalingAdjustment", String.valueOf(policy.getScalingAdjustment()))
|
||||
.elem("Cooldown", String.valueOf(policy.getCooldown()));
|
||||
if (policy.getAdjustmentType() != null) { xml.elem("AdjustmentType", policy.getAdjustmentType()); }
|
||||
if (policy.getEstimatedInstanceWarmup() != null) {
|
||||
xml.elem("EstimatedInstanceWarmup", String.valueOf(policy.getEstimatedInstanceWarmup()));
|
||||
}
|
||||
appendTargetTrackingConfigurationXml(xml, policy.getTargetTrackingConfiguration());
|
||||
xml.end("member");
|
||||
}
|
||||
xml.end("ScalingPolicies")
|
||||
@@ -722,6 +789,44 @@ public class AutoScalingQueryHandler {
|
||||
return ok(xml.build());
|
||||
}
|
||||
|
||||
private static ScalingPolicy.TargetTrackingConfiguration parseTargetTrackingConfiguration(MultivaluedMap<String, String> p) {
|
||||
String predefinedMetricType = p.getFirst("TargetTrackingConfiguration.PredefinedMetricSpecification.PredefinedMetricType");
|
||||
Double targetValue = nullableDoubleParam(p, "TargetTrackingConfiguration.TargetValue");
|
||||
if (predefinedMetricType == null && targetValue == null) {
|
||||
return null;
|
||||
}
|
||||
ScalingPolicy.TargetTrackingConfiguration configuration = new ScalingPolicy.TargetTrackingConfiguration();
|
||||
if (predefinedMetricType != null) {
|
||||
ScalingPolicy.PredefinedMetricSpecification specification =
|
||||
new ScalingPolicy.PredefinedMetricSpecification();
|
||||
specification.setPredefinedMetricType(predefinedMetricType);
|
||||
configuration.setPredefinedMetricSpecification(specification);
|
||||
}
|
||||
configuration.setTargetValue(targetValue);
|
||||
return configuration;
|
||||
}
|
||||
|
||||
private static void appendTargetTrackingConfigurationXml(
|
||||
XmlBuilder xml, ScalingPolicy.TargetTrackingConfiguration configuration) {
|
||||
if (configuration == null) {
|
||||
return;
|
||||
}
|
||||
xml.start("TargetTrackingConfiguration");
|
||||
ScalingPolicy.PredefinedMetricSpecification predefinedMetric =
|
||||
configuration.getPredefinedMetricSpecification();
|
||||
if (predefinedMetric != null) {
|
||||
xml.start("PredefinedMetricSpecification");
|
||||
if (predefinedMetric.getPredefinedMetricType() != null) {
|
||||
xml.elem("PredefinedMetricType", predefinedMetric.getPredefinedMetricType());
|
||||
}
|
||||
xml.end("PredefinedMetricSpecification");
|
||||
}
|
||||
if (configuration.getTargetValue() != null) {
|
||||
xml.elem("TargetValue", String.valueOf(configuration.getTargetValue()));
|
||||
}
|
||||
xml.end("TargetTrackingConfiguration");
|
||||
}
|
||||
|
||||
// ── Activities ────────────────────────────────────────────────────────────
|
||||
|
||||
private Response handleDescribeScalingActivities(MultivaluedMap<String, String> p, String region) {
|
||||
@@ -865,6 +970,71 @@ public class AutoScalingQueryHandler {
|
||||
.toList();
|
||||
}
|
||||
|
||||
private MixedInstancesPolicy parseMixedInstancesPolicy(MultivaluedMap<String, String> p) {
|
||||
if (!hasAnyPrefix(p, "MixedInstancesPolicy.")) {
|
||||
return null;
|
||||
}
|
||||
MixedInstancesPolicy policy = new MixedInstancesPolicy();
|
||||
|
||||
MixedInstancesPolicy.LaunchTemplate launchTemplate = new MixedInstancesPolicy.LaunchTemplate();
|
||||
MixedInstancesPolicy.LaunchTemplateSpecification specification =
|
||||
new MixedInstancesPolicy.LaunchTemplateSpecification();
|
||||
specification.setLaunchTemplateId(p.getFirst(
|
||||
"MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.LaunchTemplateId"));
|
||||
specification.setLaunchTemplateName(p.getFirst(
|
||||
"MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.LaunchTemplateName"));
|
||||
specification.setVersion(p.getFirst(
|
||||
"MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.Version"));
|
||||
if (specification.getLaunchTemplateId() != null
|
||||
|| specification.getLaunchTemplateName() != null
|
||||
|| specification.getVersion() != null) {
|
||||
launchTemplate.setLaunchTemplateSpecification(specification);
|
||||
}
|
||||
launchTemplate.setOverrides(parseMixedLaunchTemplateOverrides(p));
|
||||
if (launchTemplate.getLaunchTemplateSpecification() != null || !launchTemplate.getOverrides().isEmpty()) {
|
||||
policy.setLaunchTemplate(launchTemplate);
|
||||
}
|
||||
|
||||
MixedInstancesPolicy.InstancesDistribution distribution =
|
||||
new MixedInstancesPolicy.InstancesDistribution();
|
||||
distribution.setOnDemandBaseCapacity(nullableIntParam(
|
||||
p, "MixedInstancesPolicy.InstancesDistribution.OnDemandBaseCapacity"));
|
||||
distribution.setOnDemandPercentageAboveBaseCapacity(nullableIntParam(
|
||||
p, "MixedInstancesPolicy.InstancesDistribution.OnDemandPercentageAboveBaseCapacity"));
|
||||
distribution.setSpotAllocationStrategy(
|
||||
p.getFirst("MixedInstancesPolicy.InstancesDistribution.SpotAllocationStrategy"));
|
||||
if (distribution.getOnDemandBaseCapacity() != null
|
||||
|| distribution.getOnDemandPercentageAboveBaseCapacity() != null
|
||||
|| distribution.getSpotAllocationStrategy() != null) {
|
||||
policy.setInstancesDistribution(distribution);
|
||||
}
|
||||
return policy;
|
||||
}
|
||||
|
||||
private static boolean hasAnyPrefix(MultivaluedMap<String, String> p, String prefix) {
|
||||
for (String key : p.keySet()) {
|
||||
if (key.startsWith(prefix)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private List<MixedInstancesPolicy.LaunchTemplateOverride> parseMixedLaunchTemplateOverrides(
|
||||
MultivaluedMap<String, String> p) {
|
||||
List<MixedInstancesPolicy.LaunchTemplateOverride> result = new ArrayList<>();
|
||||
for (int i = 1; ; i++) {
|
||||
String instanceType = p.getFirst("MixedInstancesPolicy.LaunchTemplate.Overrides.member."
|
||||
+ i + ".InstanceType");
|
||||
if (instanceType == null) { break; }
|
||||
MixedInstancesPolicy.LaunchTemplateOverride override =
|
||||
new MixedInstancesPolicy.LaunchTemplateOverride();
|
||||
override.setInstanceType(instanceType);
|
||||
result.add(override);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Map<String, String> parseTags(MultivaluedMap<String, String> p) {
|
||||
Map<String, String> result = new LinkedHashMap<>();
|
||||
for (int i = 1; ; i++) {
|
||||
@@ -934,6 +1104,12 @@ public class AutoScalingQueryHandler {
|
||||
try { return Integer.parseInt(val); } catch (NumberFormatException e) { return null; }
|
||||
}
|
||||
|
||||
private static Double nullableDoubleParam(MultivaluedMap<String, String> p, String key) {
|
||||
String val = p.getFirst(key);
|
||||
if (val == null || val.isBlank()) { return null; }
|
||||
try { return Double.parseDouble(val); } catch (NumberFormatException e) { return null; }
|
||||
}
|
||||
|
||||
private Boolean nullableBoolParam(MultivaluedMap<String, String> p, String key) {
|
||||
String val = p.getFirst(key);
|
||||
if (val == null || val.isBlank()) { return null; }
|
||||
|
||||
+118
-3
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.autoscaling;
|
||||
import io.github.hectorvent.floci.services.autoscaling.model.AsgInstance;
|
||||
import io.github.hectorvent.floci.services.autoscaling.model.AutoScalingGroup;
|
||||
import io.github.hectorvent.floci.services.autoscaling.model.LaunchConfiguration;
|
||||
import io.github.hectorvent.floci.services.autoscaling.model.MixedInstancesPolicy;
|
||||
import io.github.hectorvent.floci.services.ec2.Ec2Service;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Instance;
|
||||
import io.github.hectorvent.floci.services.ec2.model.LaunchTemplate;
|
||||
@@ -128,8 +129,7 @@ public class AutoScalingReconciler {
|
||||
|
||||
private void removeStaleInstances(AutoScalingGroup asg) {
|
||||
List<AsgInstance> staleInstances = asg.getInstances().stream()
|
||||
.filter(instance -> isActiveLifecycleState(instance.getLifecycleState()))
|
||||
.filter(instance -> !ec2Service.isInstanceContainerRunning(instance.getInstanceId()))
|
||||
.filter(instance -> isStaleInstance(asg, instance))
|
||||
.collect(Collectors.toList());
|
||||
if (staleInstances.isEmpty()) {
|
||||
return;
|
||||
@@ -148,6 +148,42 @@ public class AutoScalingReconciler {
|
||||
asg.getAutoScalingGroupName(), instanceIds);
|
||||
}
|
||||
|
||||
private boolean isStaleInstance(AutoScalingGroup asg, AsgInstance instance) {
|
||||
String lifecycleState = instance.getLifecycleState();
|
||||
if ("InService".equals(lifecycleState)) {
|
||||
return !ec2Service.isInstanceContainerRunning(instance.getInstanceId());
|
||||
}
|
||||
if ("Pending".equals(lifecycleState)) {
|
||||
return isMissingOrTerminalEc2Instance(asg, instance);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isMissingOrTerminalEc2Instance(AutoScalingGroup asg, AsgInstance instance) {
|
||||
try {
|
||||
List<Instance> ec2Instances = ec2Service
|
||||
.describeInstances(asg.getRegion(), List.of(instance.getInstanceId()), null)
|
||||
.stream()
|
||||
.flatMap(r -> r.getInstances().stream())
|
||||
.collect(Collectors.toList());
|
||||
if (ec2Instances.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
String state = ec2Instances.getFirst().getState() != null
|
||||
? ec2Instances.getFirst().getState().getName()
|
||||
: null;
|
||||
return "shutting-down".equals(state)
|
||||
|| "terminated".equals(state)
|
||||
|| "stopping".equals(state)
|
||||
|| "stopped".equals(state);
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.debugv("ASG {0}: keeping pending instance {1} during stale check: {2}",
|
||||
asg.getAutoScalingGroupName(), instance.getInstanceId(), e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void removeOrphanedTargetRegistrations(AutoScalingGroup asg) {
|
||||
if (asg.getTargetGroupARNs().isEmpty()) {
|
||||
return;
|
||||
@@ -356,7 +392,7 @@ public class AutoScalingReconciler {
|
||||
version.getInstanceType(),
|
||||
version.getKeyName(),
|
||||
version.getSecurityGroupIds(),
|
||||
List.of(),
|
||||
version.getInstanceTags(),
|
||||
version.getUserData(),
|
||||
null,
|
||||
asg.getLaunchTemplateId(),
|
||||
@@ -364,6 +400,38 @@ public class AutoScalingReconciler {
|
||||
resolvedVersion);
|
||||
}
|
||||
|
||||
MixedInstancesPolicy.LaunchTemplateSpecification specification =
|
||||
mixedInstancesLaunchTemplateSpecification(asg);
|
||||
if (specification != null) {
|
||||
LaunchTemplate mixedLaunchTemplate = resolveMixedInstancesLaunchTemplate(asg, specification);
|
||||
if (mixedLaunchTemplate != null) {
|
||||
LaunchTemplate version = ec2Service.describeLaunchTemplateVersions(
|
||||
asg.getRegion(),
|
||||
mixedLaunchTemplate.getLaunchTemplateId(),
|
||||
null,
|
||||
specification.getVersion() == null ? List.of() : List.of(specification.getVersion()))
|
||||
.getFirst();
|
||||
String resolvedVersion = version.getLatestVersionNumber() != null
|
||||
? version.getLatestVersionNumber()
|
||||
: specification.getVersion();
|
||||
String instanceType = mixedInstancesInstanceType(asg, version);
|
||||
return new LaunchSource(
|
||||
null,
|
||||
version.getImageId(),
|
||||
instanceType,
|
||||
version.getKeyName(),
|
||||
version.getSecurityGroupIds(),
|
||||
version.getInstanceTags(),
|
||||
version.getUserData(),
|
||||
null,
|
||||
specification.getLaunchTemplateId() == null
|
||||
? mixedLaunchTemplate.getLaunchTemplateId()
|
||||
: specification.getLaunchTemplateId(),
|
||||
specification.getLaunchTemplateName(),
|
||||
resolvedVersion);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -391,6 +459,53 @@ public class AutoScalingReconciler {
|
||||
return launchTemplates.isEmpty() ? null : launchTemplates.get(0);
|
||||
}
|
||||
|
||||
private MixedInstancesPolicy.LaunchTemplateSpecification mixedInstancesLaunchTemplateSpecification(
|
||||
AutoScalingGroup asg) {
|
||||
MixedInstancesPolicy policy = asg.getMixedInstancesPolicy();
|
||||
if (policy == null || policy.getLaunchTemplate() == null) {
|
||||
return null;
|
||||
}
|
||||
MixedInstancesPolicy.LaunchTemplateSpecification specification =
|
||||
policy.getLaunchTemplate().getLaunchTemplateSpecification();
|
||||
if (specification == null) {
|
||||
return null;
|
||||
}
|
||||
String ltId = specification.getLaunchTemplateId();
|
||||
String ltName = specification.getLaunchTemplateName();
|
||||
if ((ltId == null || ltId.isBlank()) && (ltName == null || ltName.isBlank())) {
|
||||
return null;
|
||||
}
|
||||
return specification;
|
||||
}
|
||||
|
||||
private LaunchTemplate resolveMixedInstancesLaunchTemplate(
|
||||
AutoScalingGroup asg, MixedInstancesPolicy.LaunchTemplateSpecification specification) {
|
||||
String ltId = specification.getLaunchTemplateId();
|
||||
String ltName = specification.getLaunchTemplateName();
|
||||
List<LaunchTemplate> launchTemplates = ec2Service.describeLaunchTemplates(
|
||||
asg.getRegion(),
|
||||
ltId == null || ltId.isBlank() ? List.of() : List.of(ltId),
|
||||
ltName == null || ltName.isBlank() ? List.of() : List.of(ltName),
|
||||
Map.of());
|
||||
return launchTemplates.isEmpty() ? null : launchTemplates.get(0);
|
||||
}
|
||||
|
||||
private String mixedInstancesInstanceType(AutoScalingGroup asg, LaunchTemplate version) {
|
||||
MixedInstancesPolicy policy = asg.getMixedInstancesPolicy();
|
||||
if (policy != null && policy.getLaunchTemplate() != null) {
|
||||
List<MixedInstancesPolicy.LaunchTemplateOverride> overrides =
|
||||
policy.getLaunchTemplate().getOverrides();
|
||||
if (overrides != null) {
|
||||
for (MixedInstancesPolicy.LaunchTemplateOverride override : overrides) {
|
||||
if (override.getInstanceType() != null && !override.getInstanceType().isBlank()) {
|
||||
return override.getInstanceType();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return version.getInstanceType();
|
||||
}
|
||||
|
||||
private record LaunchSource(
|
||||
String launchConfigurationName,
|
||||
String imageId,
|
||||
|
||||
+45
-2
@@ -111,6 +111,7 @@ public class AutoScalingService {
|
||||
String launchConfigName,
|
||||
String launchTemplateId, String launchTemplateName,
|
||||
String launchTemplateVersion,
|
||||
MixedInstancesPolicy mixedInstancesPolicy,
|
||||
int minSize, int maxSize, int desiredCapacity,
|
||||
int defaultCooldown, List<String> availabilityZones,
|
||||
List<String> subnetIds,
|
||||
@@ -123,7 +124,9 @@ public class AutoScalingService {
|
||||
throw new AwsException("AlreadyExists",
|
||||
"Auto Scaling group '" + name + "' already exists.", 400);
|
||||
}
|
||||
if (launchConfigName == null && launchTemplateId == null && launchTemplateName == null) {
|
||||
validateLaunchSource(launchConfigName, launchTemplateId, launchTemplateName, mixedInstancesPolicy);
|
||||
if (launchConfigName == null && launchTemplateId == null && launchTemplateName == null
|
||||
&& mixedInstancesPolicy == null) {
|
||||
throw new AwsException("ValidationError",
|
||||
"Either LaunchConfigurationName or LaunchTemplate must be specified.", 400);
|
||||
}
|
||||
@@ -137,6 +140,7 @@ public class AutoScalingService {
|
||||
asg.setLaunchTemplateId(launchTemplateId);
|
||||
asg.setLaunchTemplateName(launchTemplateName);
|
||||
asg.setLaunchTemplateVersion(launchTemplateVersion);
|
||||
asg.setMixedInstancesPolicy(mixedInstancesPolicy);
|
||||
asg.setMinSize(minSize);
|
||||
asg.setMaxSize(maxSize);
|
||||
asg.setDesiredCapacity(desiredCapacity);
|
||||
@@ -161,19 +165,34 @@ public class AutoScalingService {
|
||||
String launchConfigName,
|
||||
String launchTemplateId, String launchTemplateName,
|
||||
String launchTemplateVersion,
|
||||
MixedInstancesPolicy mixedInstancesPolicy,
|
||||
Integer minSize, Integer maxSize, Integer desiredCapacity,
|
||||
Integer defaultCooldown, List<String> availabilityZones,
|
||||
List<String> subnetIds,
|
||||
String healthCheckType, Integer healthCheckGracePeriod,
|
||||
List<String> terminationPolicies) {
|
||||
AutoScalingGroup asg = requireGroup(region, name);
|
||||
validateLaunchSource(launchConfigName, launchTemplateId, launchTemplateName, mixedInstancesPolicy);
|
||||
if (launchConfigName != null) {
|
||||
asg.setLaunchConfigurationName(launchConfigName);
|
||||
asg.setLaunchTemplateId(null);
|
||||
asg.setLaunchTemplateName(null);
|
||||
asg.setLaunchTemplateVersion(null);
|
||||
asg.setMixedInstancesPolicy(null);
|
||||
}
|
||||
if (launchTemplateId != null || launchTemplateName != null) {
|
||||
asg.setLaunchConfigurationName(null);
|
||||
asg.setLaunchTemplateId(launchTemplateId);
|
||||
asg.setLaunchTemplateName(launchTemplateName);
|
||||
asg.setLaunchTemplateVersion(launchTemplateVersion);
|
||||
asg.setMixedInstancesPolicy(null);
|
||||
}
|
||||
if (mixedInstancesPolicy != null) {
|
||||
asg.setLaunchConfigurationName(null);
|
||||
asg.setLaunchTemplateId(null);
|
||||
asg.setLaunchTemplateName(null);
|
||||
asg.setLaunchTemplateVersion(null);
|
||||
asg.setMixedInstancesPolicy(mixedInstancesPolicy);
|
||||
}
|
||||
if (minSize != null) { asg.setMinSize(minSize); }
|
||||
if (maxSize != null) { asg.setMaxSize(maxSize); }
|
||||
@@ -506,7 +525,9 @@ public class AutoScalingService {
|
||||
|
||||
public ScalingPolicy putScalingPolicy(String region, String asgName, String policyName,
|
||||
String policyType, String adjustmentType,
|
||||
int scalingAdjustment, int cooldown) {
|
||||
int scalingAdjustment, int cooldown,
|
||||
Integer estimatedInstanceWarmup,
|
||||
ScalingPolicy.TargetTrackingConfiguration targetTrackingConfiguration) {
|
||||
requireGroup(region, asgName);
|
||||
String key = policyKey(region, asgName, policyName);
|
||||
ScalingPolicy policy = policies.computeIfAbsent(key, k -> new ScalingPolicy());
|
||||
@@ -518,6 +539,8 @@ public class AutoScalingService {
|
||||
policy.setAdjustmentType(adjustmentType);
|
||||
policy.setScalingAdjustment(scalingAdjustment);
|
||||
policy.setCooldown(cooldown);
|
||||
policy.setEstimatedInstanceWarmup(estimatedInstanceWarmup);
|
||||
policy.setTargetTrackingConfiguration(targetTrackingConfiguration);
|
||||
policy.setRegion(region);
|
||||
policies.put(key, policy);
|
||||
return policy;
|
||||
@@ -601,6 +624,26 @@ public class AutoScalingService {
|
||||
return region + "::" + asgName + "::" + policyName;
|
||||
}
|
||||
|
||||
private static void validateLaunchSource(String launchConfigName,
|
||||
String launchTemplateId,
|
||||
String launchTemplateName,
|
||||
MixedInstancesPolicy mixedInstancesPolicy) {
|
||||
int sources = 0;
|
||||
if (launchConfigName != null) {
|
||||
sources++;
|
||||
}
|
||||
if (launchTemplateId != null || launchTemplateName != null) {
|
||||
sources++;
|
||||
}
|
||||
if (mixedInstancesPolicy != null) {
|
||||
sources++;
|
||||
}
|
||||
if (sources > 1) {
|
||||
throw new AwsException("ValidationError",
|
||||
"LaunchConfigurationName, LaunchTemplate, and MixedInstancesPolicy are mutually exclusive.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static String instanceRefreshKey(String region, String asgName, String refreshId) {
|
||||
return region + "::" + asgName + "::" + refreshId;
|
||||
}
|
||||
|
||||
+4
@@ -19,6 +19,7 @@ public class AutoScalingGroup {
|
||||
private String launchTemplateId;
|
||||
private String launchTemplateName;
|
||||
private String launchTemplateVersion;
|
||||
private MixedInstancesPolicy mixedInstancesPolicy;
|
||||
private int minSize;
|
||||
private int maxSize;
|
||||
private int desiredCapacity;
|
||||
@@ -56,6 +57,9 @@ public class AutoScalingGroup {
|
||||
public String getLaunchTemplateVersion() { return launchTemplateVersion; }
|
||||
public void setLaunchTemplateVersion(String v) { this.launchTemplateVersion = v; }
|
||||
|
||||
public MixedInstancesPolicy getMixedInstancesPolicy() { return mixedInstancesPolicy; }
|
||||
public void setMixedInstancesPolicy(MixedInstancesPolicy v) { this.mixedInstancesPolicy = v; }
|
||||
|
||||
public int getMinSize() { return minSize; }
|
||||
public void setMinSize(int v) { this.minSize = v; }
|
||||
|
||||
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
package io.github.hectorvent.floci.services.autoscaling.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class MixedInstancesPolicy {
|
||||
private LaunchTemplate launchTemplate;
|
||||
private InstancesDistribution instancesDistribution;
|
||||
|
||||
public MixedInstancesPolicy() {}
|
||||
|
||||
public LaunchTemplate getLaunchTemplate() { return launchTemplate; }
|
||||
public void setLaunchTemplate(LaunchTemplate v) { this.launchTemplate = v; }
|
||||
|
||||
public InstancesDistribution getInstancesDistribution() { return instancesDistribution; }
|
||||
public void setInstancesDistribution(InstancesDistribution v) { this.instancesDistribution = v; }
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class LaunchTemplate {
|
||||
private LaunchTemplateSpecification launchTemplateSpecification;
|
||||
private List<LaunchTemplateOverride> overrides = new ArrayList<>();
|
||||
|
||||
public LaunchTemplate() {}
|
||||
|
||||
public LaunchTemplateSpecification getLaunchTemplateSpecification() { return launchTemplateSpecification; }
|
||||
public void setLaunchTemplateSpecification(LaunchTemplateSpecification v) { this.launchTemplateSpecification = v; }
|
||||
|
||||
public List<LaunchTemplateOverride> getOverrides() { return overrides; }
|
||||
public void setOverrides(List<LaunchTemplateOverride> v) { this.overrides = v; }
|
||||
}
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class LaunchTemplateSpecification {
|
||||
private String launchTemplateId;
|
||||
private String launchTemplateName;
|
||||
private String version;
|
||||
|
||||
public LaunchTemplateSpecification() {}
|
||||
|
||||
public String getLaunchTemplateId() { return launchTemplateId; }
|
||||
public void setLaunchTemplateId(String v) { this.launchTemplateId = v; }
|
||||
|
||||
public String getLaunchTemplateName() { return launchTemplateName; }
|
||||
public void setLaunchTemplateName(String v) { this.launchTemplateName = v; }
|
||||
|
||||
public String getVersion() { return version; }
|
||||
public void setVersion(String v) { this.version = v; }
|
||||
}
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class LaunchTemplateOverride {
|
||||
private String instanceType;
|
||||
|
||||
public LaunchTemplateOverride() {}
|
||||
|
||||
public String getInstanceType() { return instanceType; }
|
||||
public void setInstanceType(String v) { this.instanceType = v; }
|
||||
}
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class InstancesDistribution {
|
||||
private Integer onDemandBaseCapacity;
|
||||
private Integer onDemandPercentageAboveBaseCapacity;
|
||||
private String spotAllocationStrategy;
|
||||
|
||||
public InstancesDistribution() {}
|
||||
|
||||
public Integer getOnDemandBaseCapacity() { return onDemandBaseCapacity; }
|
||||
public void setOnDemandBaseCapacity(Integer v) { this.onDemandBaseCapacity = v; }
|
||||
|
||||
public Integer getOnDemandPercentageAboveBaseCapacity() { return onDemandPercentageAboveBaseCapacity; }
|
||||
public void setOnDemandPercentageAboveBaseCapacity(Integer v) { this.onDemandPercentageAboveBaseCapacity = v; }
|
||||
|
||||
public String getSpotAllocationStrategy() { return spotAllocationStrategy; }
|
||||
public void setSpotAllocationStrategy(String v) { this.spotAllocationStrategy = v; }
|
||||
}
|
||||
}
|
||||
+34
@@ -15,6 +15,8 @@ public class ScalingPolicy {
|
||||
private int scalingAdjustment;
|
||||
private int cooldown;
|
||||
private String metricAggregationType;
|
||||
private Integer estimatedInstanceWarmup;
|
||||
private TargetTrackingConfiguration targetTrackingConfiguration;
|
||||
private String region;
|
||||
|
||||
public ScalingPolicy() {}
|
||||
@@ -43,6 +45,38 @@ public class ScalingPolicy {
|
||||
public String getMetricAggregationType() { return metricAggregationType; }
|
||||
public void setMetricAggregationType(String v) { this.metricAggregationType = v; }
|
||||
|
||||
public Integer getEstimatedInstanceWarmup() { return estimatedInstanceWarmup; }
|
||||
public void setEstimatedInstanceWarmup(Integer v) { this.estimatedInstanceWarmup = v; }
|
||||
|
||||
public TargetTrackingConfiguration getTargetTrackingConfiguration() { return targetTrackingConfiguration; }
|
||||
public void setTargetTrackingConfiguration(TargetTrackingConfiguration v) { this.targetTrackingConfiguration = v; }
|
||||
|
||||
public String getRegion() { return region; }
|
||||
public void setRegion(String v) { this.region = v; }
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class TargetTrackingConfiguration {
|
||||
private PredefinedMetricSpecification predefinedMetricSpecification;
|
||||
private Double targetValue;
|
||||
|
||||
public TargetTrackingConfiguration() {}
|
||||
|
||||
public PredefinedMetricSpecification getPredefinedMetricSpecification() { return predefinedMetricSpecification; }
|
||||
public void setPredefinedMetricSpecification(PredefinedMetricSpecification v) { this.predefinedMetricSpecification = v; }
|
||||
|
||||
public Double getTargetValue() { return targetValue; }
|
||||
public void setTargetValue(Double v) { this.targetValue = v; }
|
||||
}
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class PredefinedMetricSpecification {
|
||||
private String predefinedMetricType;
|
||||
|
||||
public PredefinedMetricSpecification() {}
|
||||
|
||||
public String getPredefinedMetricType() { return predefinedMetricType; }
|
||||
public void setPredefinedMetricType(String v) { this.predefinedMetricType = v; }
|
||||
}
|
||||
}
|
||||
+1
@@ -777,6 +777,7 @@ public class CloudFormationResourceProvisioner {
|
||||
|
||||
var asg = autoScalingService.createAutoScalingGroup(region, name,
|
||||
blankToNull(launchConfigName), null, blankToNull(launchTemplateName), blankToNull(launchTemplateVersion),
|
||||
null,
|
||||
parseIntProp(props, "MinSize", engine, 0),
|
||||
parseIntProp(props, "MaxSize", engine, 0),
|
||||
parseIntProp(props, "DesiredCapacity", engine, 0),
|
||||
|
||||
Reference in new issue
Block a user