mirror of
https://github.com/floci-io/floci.git
synced 2026-11-30 00:45:17 -05:00
feat(ec2): associate instances with capacity reservations (#6336)
Associate eligible instances with capacity reservations across EC2, AutoScaling and CloudFormation. Preserve account ownership, rollback, physical stop/start ordering and bounded targeted quota admission. Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
1 parent
7b2f0737ee
commit
d05399feb1
21 files changed
+1287
-111
No files matched your search
+9
-5
@@ -555,7 +555,8 @@ public class AutoScalingReconciler {
|
||||
launchSource.associatePublicIpAddress(), null, 0, null, launchSource.metadataOptions(), null,
|
||||
launchSource.encodedUserData() != null ? launchSource.encodedUserData()
|
||||
: encodeLegacyUserData(launchSource.userData()),
|
||||
false, null, null, launchSource.blockDeviceMappings());
|
||||
false, null, null, launchSource.blockDeviceMappings(), false, null,
|
||||
launchSource.capacityReservationSpecification());
|
||||
} catch (RuntimeException launchFailure) {
|
||||
if (!refreshLaunch) {
|
||||
throw launchFailure;
|
||||
@@ -851,7 +852,7 @@ public class AutoScalingReconciler {
|
||||
// subnet's MapPublicIpOnLaunch, and only null means
|
||||
// "fall back to the subnet default".
|
||||
lc.getAssociatePublicIpAddress(),
|
||||
null, lc.getMetadataOptions());
|
||||
null, lc.getMetadataOptions(), null);
|
||||
}
|
||||
|
||||
LaunchTemplate launchTemplate = resolveLaunchTemplate(asg);
|
||||
@@ -880,7 +881,8 @@ public class AutoScalingReconciler {
|
||||
asg.getLaunchTemplateName(),
|
||||
resolvedVersion,
|
||||
version.getData().effectiveAssociatePublicIpAddress(),
|
||||
version.getData().getBlockDeviceMappings(), version.getData().getMetadataOptions());
|
||||
version.getData().getBlockDeviceMappings(), version.getData().getMetadataOptions(),
|
||||
version.getData().getCapacityReservationSpecification());
|
||||
}
|
||||
|
||||
MixedInstancesPolicy.LaunchTemplateSpecification specification =
|
||||
@@ -915,7 +917,8 @@ public class AutoScalingReconciler {
|
||||
specification.getLaunchTemplateName(),
|
||||
resolvedVersion,
|
||||
version.getData().effectiveAssociatePublicIpAddress(),
|
||||
version.getData().getBlockDeviceMappings(), version.getData().getMetadataOptions());
|
||||
version.getData().getBlockDeviceMappings(), version.getData().getMetadataOptions(),
|
||||
version.getData().getCapacityReservationSpecification());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1028,7 +1031,8 @@ public class AutoScalingReconciler {
|
||||
String launchTemplateVersion,
|
||||
Boolean associatePublicIpAddress,
|
||||
List<LaunchTemplateData.BlockDeviceMapping> blockDeviceMappings,
|
||||
LaunchTemplateData.MetadataOptions metadataOptions) {}
|
||||
LaunchTemplateData.MetadataOptions metadataOptions,
|
||||
LaunchTemplateData.CapacityReservationSpecification capacityReservationSpecification) {}
|
||||
|
||||
// Override for describeAutoScalingGroups with null region (all regions)
|
||||
// The service only filters by region when non-null; null means all.
|
||||
|
||||
+28
@@ -73,6 +73,9 @@ public class Ec2LaunchTemplateCfnProvisioner implements CfnResourceProvisioner {
|
||||
? written.get("MetadataOptions") : null;
|
||||
data.setMetadataOptions(Ec2CfnMetadataOptions.read("LaunchTemplateData/MetadataOptions",
|
||||
metadataOptions, Ec2CfnMetadataOptions.LAUNCH_TEMPLATE_SHAPE, ctx.engine()));
|
||||
JsonNode capacity = written.isObject() && !CloudFormationTemplateEngine.callsIntrinsic(written)
|
||||
? written.get("CapacityReservationSpecification") : null;
|
||||
data.setCapacityReservationSpecification(capacityReservationSpecification(capacity, ctx.engine()));
|
||||
if (node.has("SecurityGroupIds")) {
|
||||
List<String> securityGroupIds = new ArrayList<>();
|
||||
for (JsonNode securityGroup : node.get("SecurityGroupIds")) {
|
||||
@@ -166,6 +169,31 @@ public class Ec2LaunchTemplateCfnProvisioner implements CfnResourceProvisioner {
|
||||
}
|
||||
}
|
||||
|
||||
private LaunchTemplateData.CapacityReservationSpecification capacityReservationSpecification(
|
||||
JsonNode raw, CloudFormationTemplateEngine engine) {
|
||||
CfnPropertyTypes.Reader types = new CfnPropertyTypes.Reader(engine);
|
||||
String shape = CfnPropertyTypes.memberShape(
|
||||
CfnPropertyTypes.propertyShape("AWS::EC2::LaunchTemplate", "LaunchTemplateData"),
|
||||
"CapacityReservationSpecification");
|
||||
JsonNode block = types.read("LaunchTemplateData/CapacityReservationSpecification", raw, shape);
|
||||
types.finish();
|
||||
if (block == null || block.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
LaunchTemplateData.CapacityReservationSpecification specification =
|
||||
new LaunchTemplateData.CapacityReservationSpecification();
|
||||
specification.setCapacityReservationPreference(block.path("CapacityReservationPreference").asText(null));
|
||||
JsonNode targetNode = block.path("CapacityReservationTarget");
|
||||
if (targetNode.isObject()) {
|
||||
LaunchTemplateData.CapacityReservationTarget target = new LaunchTemplateData.CapacityReservationTarget();
|
||||
target.setCapacityReservationId(targetNode.path("CapacityReservationId").asText(null));
|
||||
target.setCapacityReservationResourceGroupArn(
|
||||
targetNode.path("CapacityReservationResourceGroupArn").asText(null));
|
||||
specification.setCapacityReservationTarget(target);
|
||||
}
|
||||
return specification;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps the form CloudFormation supplied. EC2 stores {@code Arn} and {@code Name} as given and
|
||||
* derives the ARN only at launch time, so normalizing {@code Name} into an ARN here would put
|
||||
|
||||
@@ -52,6 +52,7 @@ import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
@@ -153,6 +154,7 @@ public class Ec2ContainerManager {
|
||||
private final Ec2InstanceTypeCatalog instanceTypeCatalog;
|
||||
private SecurityGroupFirewallManager firewallManager;
|
||||
private final ExecutorService executor;
|
||||
private final Map<String, CompletableFuture<Void>> lifecycleOperations = new ConcurrentHashMap<>();
|
||||
private final Duration userDataExecutionTimeout;
|
||||
private final Set<ResultCallback<Frame>> activeUserDataCallbacks = ConcurrentHashMap.newKeySet();
|
||||
|
||||
@@ -916,6 +918,31 @@ public class Ec2ContainerManager {
|
||||
}
|
||||
}
|
||||
|
||||
private void submitLifecycleOperation(String containerId, Runnable operation) {
|
||||
synchronized (lifecycleOperations) {
|
||||
CompletableFuture<Void> previous = lifecycleOperations.getOrDefault(containerId,
|
||||
CompletableFuture.completedFuture(null));
|
||||
CompletableFuture<Void> completed = new CompletableFuture<>();
|
||||
lifecycleOperations.put(containerId, completed);
|
||||
previous.whenComplete((ignored, priorFailure) -> {
|
||||
try {
|
||||
executor.submit(() -> {
|
||||
try {
|
||||
operation.run();
|
||||
} finally {
|
||||
lifecycleOperations.remove(containerId, completed);
|
||||
completed.complete(null);
|
||||
}
|
||||
});
|
||||
} catch (RuntimeException failure) {
|
||||
lifecycleOperations.remove(containerId, completed);
|
||||
completed.completeExceptionally(failure);
|
||||
LOG.warnv(failure, "Could not schedule lifecycle operation for EC2 container {0}", containerId);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gracefully stops a running container (30 second timeout then SIGKILL).
|
||||
* Updates instance state through stopping → stopped.
|
||||
@@ -926,19 +953,20 @@ public class Ec2ContainerManager {
|
||||
instance.setState(InstanceState.stopped());
|
||||
return;
|
||||
}
|
||||
instance.setState(InstanceState.stopping());
|
||||
executor.submit(() -> {
|
||||
InstanceState stopping = InstanceState.stopping();
|
||||
instance.setState(stopping);
|
||||
submitLifecycleOperation(containerId, () -> {
|
||||
// Sidecars forward to the container's current IP, which Docker reassigns on the
|
||||
// next start; tear them down so no forward is left pointing at a stale address.
|
||||
portForwardManager.unpublishAll(instance);
|
||||
try {
|
||||
dockerClient.stopContainerCmd(containerId).withTimeout(30).exec();
|
||||
} catch (NotFoundException e) {
|
||||
// already gone
|
||||
} catch (NotFoundException ignored) {
|
||||
// An already removed container needs no further stop.
|
||||
} catch (Exception e) {
|
||||
LOG.warnv("Error stopping EC2 container {0}: {1}", containerId, e.getMessage());
|
||||
}
|
||||
instance.setState(InstanceState.stopped());
|
||||
instance.compareAndSetState(stopping, InstanceState.stopped());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -962,8 +990,9 @@ public class Ec2ContainerManager {
|
||||
}
|
||||
return;
|
||||
}
|
||||
instance.setState(InstanceState.pending());
|
||||
executor.submit(() -> {
|
||||
InstanceState pending = InstanceState.pending();
|
||||
instance.setState(pending);
|
||||
submitLifecycleOperation(containerId, () -> {
|
||||
try {
|
||||
dockerClient.startContainerCmd(containerId).exec();
|
||||
boolean running = false;
|
||||
@@ -1000,14 +1029,16 @@ public class Ec2ContainerManager {
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
instance.setState(InstanceState.stopped());
|
||||
instance.compareAndSetState(pending, InstanceState.stopped());
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
LOG.warnv("Error starting EC2 container {0}: {1}", containerId, e.getMessage());
|
||||
instance.setState(InstanceState.stopped());
|
||||
instance.compareAndSetState(pending, InstanceState.stopped());
|
||||
return;
|
||||
}
|
||||
if (!instance.compareAndSetState(pending, InstanceState.running())) {
|
||||
return;
|
||||
}
|
||||
instance.setState(InstanceState.running());
|
||||
if (postStart != null) {
|
||||
try {
|
||||
postStart.run();
|
||||
|
||||
@@ -872,12 +872,28 @@ public class Ec2QueryHandler {
|
||||
}
|
||||
}
|
||||
|
||||
LaunchTemplateData.CapacityReservationSpecification capacitySpecification = launchTemplateData == null
|
||||
? null : launchTemplateData.getCapacityReservationSpecification();
|
||||
if (anyParamStartsWith(p, "CapacityReservationSpecification.")) {
|
||||
capacitySpecification = new LaunchTemplateData.CapacityReservationSpecification();
|
||||
capacitySpecification.setCapacityReservationPreference(
|
||||
p.getFirst("CapacityReservationSpecification.CapacityReservationPreference"));
|
||||
if (anyParamStartsWith(p, "CapacityReservationSpecification.CapacityReservationTarget.")) {
|
||||
LaunchTemplateData.CapacityReservationTarget target = new LaunchTemplateData.CapacityReservationTarget();
|
||||
target.setCapacityReservationId(
|
||||
p.getFirst("CapacityReservationSpecification.CapacityReservationTarget.CapacityReservationId"));
|
||||
target.setCapacityReservationResourceGroupArn(p.getFirst(
|
||||
"CapacityReservationSpecification.CapacityReservationTarget.CapacityReservationResourceGroupArn"));
|
||||
capacitySpecification.setCapacityReservationTarget(target);
|
||||
}
|
||||
}
|
||||
|
||||
Reservation res = service.runInstances(region, imageId, instanceType, minCount, maxCount,
|
||||
keyName, sgIds, subnetId, clientToken, instanceTags, userData, iamInstanceProfileArn,
|
||||
associatePublicIp, networkInterfaceId, networkInterfaceDeviceIndex, null, metadataOptions,
|
||||
creditSpecificationCpuCredits, userDataEncoded, Boolean.parseBoolean(p.getFirst("DryRun")),
|
||||
p.getFirst("Placement.HostId"), p.getFirst("Placement.Tenancy"), blockDeviceMappings,
|
||||
"spot".equals(marketType), privateIpAddress);
|
||||
"spot".equals(marketType), privateIpAddress, capacitySpecification);
|
||||
|
||||
if (!networkInterfaceTags.isEmpty()) {
|
||||
List<String> eniIds = new ArrayList<>();
|
||||
@@ -896,8 +912,9 @@ public class Ec2QueryHandler {
|
||||
.elem("ownerId", res.getOwnerId())
|
||||
.start("groupSet").end("groupSet")
|
||||
.start("instancesSet");
|
||||
Map<String, String> capacityAssociations = service.capacityReservationAssociations(region);
|
||||
for (Instance inst : res.getInstances()) {
|
||||
xml.start("item").raw(instanceXml(inst)).end("item");
|
||||
xml.start("item").raw(instanceXml(inst, capacityAssociations)).end("item");
|
||||
}
|
||||
xml.end("instancesSet")
|
||||
.end("RunInstancesResponse");
|
||||
@@ -1021,7 +1038,8 @@ public class Ec2QueryHandler {
|
||||
null,
|
||||
0,
|
||||
launch.availabilityZone(), launch.metadataOptions(), null, launch.encodedUserData(), false,
|
||||
null, null, launch.blockDeviceMappings(), "spot".equals(capacityType));
|
||||
null, null, launch.blockDeviceMappings(), "spot".equals(capacityType), null,
|
||||
launch.capacityReservationSpecification());
|
||||
Instance instance = reservation.getInstances().get(0);
|
||||
launchedInstanceIds.add(instance.getInstanceId());
|
||||
results.add(new FleetLaunchResult(instance, launch));
|
||||
@@ -1185,7 +1203,7 @@ public class Ec2QueryHandler {
|
||||
template.getMetadataOptions(),
|
||||
template.effectiveSecurityGroupIds(),
|
||||
new ArrayList<>(tags.values()),
|
||||
template.getBlockDeviceMappings());
|
||||
template.getBlockDeviceMappings(), template.getCapacityReservationSpecification());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1233,7 +1251,8 @@ public class Ec2QueryHandler {
|
||||
Boolean associatePublicIpAddress,
|
||||
LaunchTemplateData.MetadataOptions metadataOptions,
|
||||
List<String> securityGroupIds, List<Tag> instanceTags,
|
||||
List<LaunchTemplateData.BlockDeviceMapping> blockDeviceMappings) {}
|
||||
List<LaunchTemplateData.BlockDeviceMapping> blockDeviceMappings,
|
||||
LaunchTemplateData.CapacityReservationSpecification capacityReservationSpecification) {}
|
||||
|
||||
private record FleetLaunchKey(String launchTemplateId, String launchTemplateName, String launchTemplateVersion,
|
||||
String instanceType, String imageId, String subnetId, String availabilityZone) {
|
||||
@@ -1355,6 +1374,7 @@ public class Ec2QueryHandler {
|
||||
.start("DescribeInstancesResponse", AwsNamespaces.EC2)
|
||||
.elem("requestId", UUID.randomUUID().toString())
|
||||
.start("reservationSet");
|
||||
Map<String, String> capacityAssociations = service.capacityReservationAssociations(region);
|
||||
for (Reservation res : reservations) {
|
||||
xml.start("item")
|
||||
.elem("reservationId", res.getReservationId())
|
||||
@@ -1362,7 +1382,7 @@ public class Ec2QueryHandler {
|
||||
.start("groupSet").end("groupSet")
|
||||
.start("instancesSet");
|
||||
for (Instance inst : res.getInstances()) {
|
||||
xml.start("item").raw(instanceXml(inst)).end("item");
|
||||
xml.start("item").raw(instanceXml(inst, capacityAssociations)).end("item");
|
||||
}
|
||||
xml.end("instancesSet").end("item");
|
||||
}
|
||||
@@ -4254,6 +4274,10 @@ public class Ec2QueryHandler {
|
||||
p.getFirst("OutpostArn"),
|
||||
p.getFirst("PlacementGroupArn"));
|
||||
applyResourceTags(resourceTags, region, reservation.getCapacityReservationId());
|
||||
if (!resourceTags.isEmpty()) {
|
||||
reservation = service.describeCapacityReservations(
|
||||
region, List.of(reservation.getCapacityReservationId()), Map.of()).getFirst();
|
||||
}
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
.start("CreateCapacityReservationResponse", AwsNamespaces.EC2)
|
||||
.elem("requestId", UUID.randomUUID().toString())
|
||||
@@ -4928,7 +4952,7 @@ public class Ec2QueryHandler {
|
||||
|
||||
// ─── XML fragment builders ────────────────────────────────────────────────
|
||||
|
||||
private String instanceXml(Instance inst) {
|
||||
private String instanceXml(Instance inst, Map<String, String> capacityAssociations) {
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
.elem("instanceId", inst.getInstanceId())
|
||||
.elem("imageId", inst.getImageId())
|
||||
@@ -5045,8 +5069,17 @@ public class Ec2QueryHandler {
|
||||
.elem("enableResourceNameDnsAAAARecord", "false")
|
||||
.end("privateDnsNameOptions")
|
||||
.start("capacityReservationSpecification")
|
||||
.elem("capacityReservationPreference", "open")
|
||||
.end("capacityReservationSpecification");
|
||||
.elem("capacityReservationPreference", inst.getCapacityReservationPreference());
|
||||
if (inst.getCapacityReservationTarget() != null) {
|
||||
xml.start("capacityReservationTarget")
|
||||
.elem("capacityReservationId", inst.getCapacityReservationTarget())
|
||||
.end("capacityReservationTarget");
|
||||
}
|
||||
xml.end("capacityReservationSpecification");
|
||||
String capacityReservationId = capacityAssociations.get(inst.getInstanceId());
|
||||
if (capacityReservationId != null) {
|
||||
xml.elem("capacityReservationId", capacityReservationId);
|
||||
}
|
||||
if (inst.getRootVolumeId() != null) {
|
||||
xml.start("blockDeviceMapping")
|
||||
.start("item")
|
||||
|
||||
@@ -307,6 +307,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
// resourceId → List<Tag>
|
||||
private final StorageBackend<String, List<Tag>> tags;
|
||||
private final StorageBackend<String, CapacityReservation> capacityReservations;
|
||||
private final Object capacityReservationLock = new Object();
|
||||
private final StorageBackend<String, Host> hosts;
|
||||
private final StorageBackend<String, EgressOnlyInternetGateway> egressOnlyInternetGateways;
|
||||
// Serialises a launch onto a host against ModifyHosts/ReleaseHosts, so a host cannot be
|
||||
@@ -3651,6 +3652,41 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
String hostId, String tenancy,
|
||||
List<LaunchTemplateData.BlockDeviceMapping> blockDeviceMappings, boolean spot,
|
||||
String privateIpAddress) {
|
||||
return runInstances(region, imageId, instanceType, minCount, maxCount, keyName,
|
||||
securityGroupIds, subnetId, clientToken, instanceTags, userData, iamInstanceProfileArn,
|
||||
associatePublicIp, networkInterfaceId, networkInterfaceDeviceIndex, availabilityZone,
|
||||
metadataOptions, creditSpecificationCpuCredits, encodedUserData, dryRun, hostId, tenancy,
|
||||
blockDeviceMappings, spot, privateIpAddress, null);
|
||||
}
|
||||
|
||||
public Reservation runInstances(String region, String imageId, String instanceType,
|
||||
int minCount, int maxCount, String keyName,
|
||||
List<String> securityGroupIds, String subnetId,
|
||||
String clientToken, List<Tag> instanceTags,
|
||||
String userData, String iamInstanceProfileArn,
|
||||
Boolean associatePublicIp, String networkInterfaceId,
|
||||
int networkInterfaceDeviceIndex, String availabilityZone,
|
||||
LaunchTemplateData.MetadataOptions metadataOptions,
|
||||
String creditSpecificationCpuCredits, String encodedUserData, boolean dryRun,
|
||||
String hostId, String tenancy,
|
||||
List<LaunchTemplateData.BlockDeviceMapping> blockDeviceMappings, boolean spot,
|
||||
String privateIpAddress,
|
||||
LaunchTemplateData.CapacityReservationSpecification capacitySpecification) {
|
||||
String capacityPreference = capacitySpecification == null
|
||||
|| capacitySpecification.getCapacityReservationPreference() == null ? "open"
|
||||
: capacitySpecification.getCapacityReservationPreference();
|
||||
LaunchTemplateData.CapacityReservationTarget capacityTarget = capacitySpecification == null ? null
|
||||
: capacitySpecification.getCapacityReservationTarget();
|
||||
String capacityTargetId = capacityTarget == null ? null : capacityTarget.getCapacityReservationId();
|
||||
if (!Set.of("open", "none").contains(capacityPreference)) {
|
||||
throw new AwsException("InvalidParameterValue", "Invalid Capacity Reservation preference.", 400);
|
||||
}
|
||||
if (capacityTarget != null && capacityTarget.getCapacityReservationResourceGroupArn() != null) {
|
||||
throw new AwsException("Unsupported", "Capacity Reservation resource group targeting is not supported.", 400);
|
||||
}
|
||||
if (capacityTargetId != null && ("none".equals(capacityPreference) || spot)) {
|
||||
throw new AwsException("InvalidParameterCombination", "Invalid Capacity Reservation target combination.", 400);
|
||||
}
|
||||
if (privateIpAddress != null && privateIpAddress.isBlank()) {
|
||||
privateIpAddress = null;
|
||||
}
|
||||
@@ -3753,6 +3789,29 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
if (privateIpAddress != null) {
|
||||
privateIpAddress = validateRequestedPrivateIp(privateIpAddress, subnet, suppliedEni, maxCount);
|
||||
}
|
||||
int capacityMaxCount = maxCount;
|
||||
if (capacityTargetId != null) {
|
||||
synchronized (capacityReservationLock) {
|
||||
reconcileCapacityMembership(region);
|
||||
CapacityReservation target = getRequiredCapacityReservation(region, capacityTargetId);
|
||||
Instance requested = new Instance();
|
||||
requested.setOwnerId(callerAccountId());
|
||||
requested.setRegion(region);
|
||||
requested.setCapacityReservationPlatform(capacityReservationPlatform(region, imageId));
|
||||
requested.setInstanceType(effectiveInstanceType);
|
||||
Placement requestedPlacement = new Placement(az);
|
||||
if (tenancy != null && !tenancy.isBlank()) {
|
||||
requestedPlacement.setTenancy(tenancy);
|
||||
}
|
||||
requested.setPlacement(requestedPlacement);
|
||||
if (!matchesCapacityReservation(requested, target) || target.getAvailableInstanceCount() < minCount) {
|
||||
throw new AwsException("InsufficientInstanceCapacity",
|
||||
"The targeted Capacity Reservation has no matching available capacity.", 400);
|
||||
}
|
||||
capacityMaxCount = Math.min(maxCount, target.getAvailableInstanceCount());
|
||||
count = capacityMaxCount;
|
||||
}
|
||||
}
|
||||
String architecture = architectureFor(region, imageId, effectiveInstanceType);
|
||||
// An entry with NoDevice set removes its device whatever else it names, as on AWS.
|
||||
List<LaunchTemplateData.BlockDeviceMapping> mappedDevices = blockDeviceMappings == null ? List.of()
|
||||
@@ -3796,7 +3855,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
}
|
||||
synchronized (privateIpAllocationLock) {
|
||||
int admitted = !config.services().ec2().enforceVcpuQuotas() || spot || "host".equals(tenancy)
|
||||
? count : admittedInstanceCount(region, effectiveInstanceType, minCount, maxCount);
|
||||
? count : admittedInstanceCount(region, effectiveInstanceType, minCount, capacityMaxCount);
|
||||
synchronized (hostLock) {
|
||||
if (hostId != null) {
|
||||
// Re-checked under hostLock: a ReleaseHosts or ModifyHosts may have landed
|
||||
@@ -3816,6 +3875,9 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
inst.setState(InstanceState.pending());
|
||||
inst.setInstanceType(effectiveInstanceType);
|
||||
inst.setSpot(spot);
|
||||
inst.setCapacityReservationPlatform(capacityReservationPlatform(region, imageId));
|
||||
inst.setCapacityReservationPreference(capacityTargetId == null ? capacityPreference : null);
|
||||
inst.setCapacityReservationTarget(capacityTargetId);
|
||||
Placement placement = new Placement(az);
|
||||
placement.setHostId(hostId);
|
||||
if (tenancy != null && !tenancy.isBlank()) {
|
||||
@@ -3931,6 +3993,18 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
acquireCapacity(region, launched);
|
||||
} catch (RuntimeException failure) {
|
||||
try {
|
||||
terminateInstances(region, launched.stream().map(Instance::getInstanceId).toList());
|
||||
} catch (RuntimeException cleanupFailure) {
|
||||
failure.addSuppressed(cleanupFailure);
|
||||
LOG.errorv(cleanupFailure, "Failed to clean up rejected capacity launch in {0}", region);
|
||||
}
|
||||
throw failure;
|
||||
}
|
||||
|
||||
// Outside the lock: the containers are what the lock protects a reference to, not part of
|
||||
// the registry, and a launch is slow.
|
||||
if (!config.services().ec2().mock()) {
|
||||
@@ -4754,6 +4828,9 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
detachAttachedVolumesOnTermination(region, inst);
|
||||
releaseStandaloneInterfacesOnTermination(region, inst);
|
||||
instances.put(key(region, id), inst);
|
||||
synchronized (capacityReservationLock) {
|
||||
reconcileCapacityMembership(region);
|
||||
}
|
||||
// The last instance depending on a deregistered AMI's capture has just gone away.
|
||||
// Cheap and usually sufficient: by here the container is often already removed.
|
||||
reclaimCapturesPinnedBy(region, inst, terminating);
|
||||
@@ -4860,6 +4937,9 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
}
|
||||
}
|
||||
instances.put(key(region, id), inst);
|
||||
synchronized (capacityReservationLock) {
|
||||
reconcileCapacityMembership(region);
|
||||
}
|
||||
Map<String, String> entry = new LinkedHashMap<>();
|
||||
entry.put("instanceId", id);
|
||||
entry.put("previousState", prev.getName());
|
||||
@@ -4913,6 +4993,19 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
"The instance '" + id + "' is not in a state from which it can be started.", 400);
|
||||
}
|
||||
InstanceState prev = inst.getState();
|
||||
synchronized (capacityReservationLock) {
|
||||
if ("stopped".equals(prev.getName()) || "stopping".equals(prev.getName())) {
|
||||
inst.setState(InstanceState.pending());
|
||||
try {
|
||||
instances.put(key(region, id), inst);
|
||||
acquireCapacity(region, List.of(inst));
|
||||
} catch (RuntimeException failure) {
|
||||
inst.setState(prev);
|
||||
instances.put(key(region, id), inst);
|
||||
throw failure;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (config.services().ec2().mock()) {
|
||||
completeMockLaunch(region, inst, true);
|
||||
} else {
|
||||
@@ -9495,8 +9588,17 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
}
|
||||
Vpc vpc = vpcs.get(storeKey).orElse(null);
|
||||
if (vpc != null) { vpc.setTags(new ArrayList<>(tagList)); vpcs.put(storeKey, vpc); return; }
|
||||
CapacityReservation cr = capacityReservations.get(storeKey).orElse(null);
|
||||
if (cr != null) { cr.setTags(new ArrayList<>(tagList)); capacityReservations.put(storeKey, cr); return; }
|
||||
if (resourceId.startsWith("cr-")) {
|
||||
synchronized (capacityReservationLock) {
|
||||
CapacityReservation reservation = capacityReservations.get(storeKey).orElse(null);
|
||||
if (reservation != null) {
|
||||
CapacityReservation updated = new CapacityReservation(reservation);
|
||||
updated.setTags(new ArrayList<>(tagList));
|
||||
capacityReservations.put(storeKey, updated);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
Host host = hosts.get(storeKey).orElse(null);
|
||||
if (host != null) {
|
||||
host.setTags(new ArrayList<>(tagList));
|
||||
@@ -9833,6 +9935,123 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
|
||||
// ─── Capacity Reservations ─────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Membership lives with the reservation and is published atomically with its available
|
||||
* capacity. The instance stores only
|
||||
* launch eligibility, never a second authoritative copy of the acquired reservation.
|
||||
*/
|
||||
public String instanceCapacityReservationId(Instance instance) {
|
||||
return Objects.equals(callerAccountId(), instance.getOwnerId())
|
||||
? capacityReservationAssociations(instance.getRegion()).get(instance.getInstanceId()) : null;
|
||||
}
|
||||
|
||||
Map<String, String> capacityReservationAssociations(String region) {
|
||||
synchronized (capacityReservationLock) {
|
||||
reconcileCapacityMembership(region);
|
||||
Map<String, String> associations = new HashMap<>();
|
||||
for (CapacityReservation reservation : capacityReservations.scan(k -> k.startsWith(region + "::"))) {
|
||||
for (String instanceId : reservation.getInstanceIds()) {
|
||||
associations.put(instanceId, reservation.getCapacityReservationId());
|
||||
}
|
||||
}
|
||||
return associations;
|
||||
}
|
||||
}
|
||||
|
||||
private void reconcileCapacityMembership(String region) {
|
||||
Map<String, CapacityReservation> changed = new LinkedHashMap<>();
|
||||
for (CapacityReservation stored : capacityReservations.scan(k -> k.startsWith(region + "::"))) {
|
||||
CapacityReservation updated = new CapacityReservation(stored);
|
||||
boolean expired = "active".equals(updated.getState()) && updated.getEndDate() != null
|
||||
&& !updated.getEndDate().isAfter(Instant.now());
|
||||
if (expired) {
|
||||
updated.setState("expired");
|
||||
}
|
||||
updated.getInstanceIds().removeIf(id -> !"active".equals(updated.getState())
|
||||
|| instances.get(key(region, id)).map(instance -> !holdsCapacity(instance)).orElse(true));
|
||||
int released = stored.getInstanceIds().size() - updated.getInstanceIds().size();
|
||||
if (expired || released > 0) {
|
||||
updated.setAvailableInstanceCount("active".equals(updated.getState())
|
||||
? updated.getAvailableInstanceCount() + released : 0);
|
||||
changed.put(key(region, updated.getCapacityReservationId()), updated);
|
||||
}
|
||||
}
|
||||
if (!changed.isEmpty()) {
|
||||
persistCapacityMembership(changed);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean holdsCapacity(Instance instance) {
|
||||
return instance.getState() != null && ("pending".equals(instance.getState().getName())
|
||||
|| "running".equals(instance.getState().getName()));
|
||||
}
|
||||
|
||||
void acquireCapacity(String region, List<Instance> admitted) {
|
||||
synchronized (capacityReservationLock) {
|
||||
reconcileCapacityMembership(region);
|
||||
List<CapacityReservation> candidates = capacityReservations.scan(k -> k.startsWith(region + "::"))
|
||||
.stream().map(CapacityReservation::new).toList();
|
||||
Map<String, CapacityReservation> changed = new LinkedHashMap<>();
|
||||
for (Instance instance : admitted) {
|
||||
if (!holdsCapacity(instance) || instance.isSpot()
|
||||
|| "none".equals(instance.getCapacityReservationPreference())) {
|
||||
continue;
|
||||
}
|
||||
if (candidates.stream().anyMatch(r -> r.getInstanceIds().contains(instance.getInstanceId()))) {
|
||||
continue;
|
||||
}
|
||||
String target = instance.getCapacityReservationTarget();
|
||||
CapacityReservation selected = candidates.stream()
|
||||
.filter(r -> target == null ? "open".equals(r.getInstanceMatchCriteria())
|
||||
: target.equals(r.getCapacityReservationId()))
|
||||
.filter(r -> matchesCapacityReservation(instance, r))
|
||||
.filter(r -> r.getAvailableInstanceCount() > 0).findFirst().orElse(null);
|
||||
if (selected == null) {
|
||||
if (target != null) {
|
||||
getRequiredCapacityReservation(region, target);
|
||||
throw new AwsException("InsufficientInstanceCapacity",
|
||||
"The targeted Capacity Reservation has no matching available capacity.", 400);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
selected.getInstanceIds().add(instance.getInstanceId());
|
||||
selected.setAvailableInstanceCount(selected.getAvailableInstanceCount() - 1);
|
||||
changed.put(key(region, selected.getCapacityReservationId()), selected);
|
||||
}
|
||||
if (!changed.isEmpty()) {
|
||||
persistCapacityMembership(changed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void persistCapacityMembership(Map<String, CapacityReservation> changed) {
|
||||
try {
|
||||
capacityReservations.putAllAtomically(changed);
|
||||
} catch (RuntimeException failure) {
|
||||
LOG.errorv(failure, "Failed to persist Capacity Reservation membership for {0}", changed.keySet());
|
||||
AwsException error = new AwsException("InternalError", "Could not persist capacity membership.", 500);
|
||||
error.initCause(failure);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
private String capacityReservationPlatform(String region, String imageId) {
|
||||
String platform = registeredImages.get(key(region, imageId)).map(Image::getPlatform)
|
||||
.or(() -> imageCatalog.findByIdOrAlias(imageId).map(image -> image.platform)).orElse("");
|
||||
return "windows".equals(platform) ? "Windows" : "Linux/UNIX";
|
||||
}
|
||||
|
||||
private boolean matchesCapacityReservation(Instance instance, CapacityReservation reservation) {
|
||||
return "active".equals(reservation.getState())
|
||||
&& Objects.equals(instance.getOwnerId(), reservation.getOwnerId())
|
||||
&& Objects.equals(instance.getInstanceType(), reservation.getInstanceType())
|
||||
&& instance.getPlacement() != null
|
||||
&& Objects.equals(instance.getPlacement().getAvailabilityZone(),
|
||||
capacityReservationZone(instance.getRegion(), reservation))
|
||||
&& Objects.equals(instance.getPlacement().getTenancy(), reservation.getTenancy())
|
||||
&& Objects.equals(instance.getCapacityReservationPlatform(), reservation.getInstancePlatform());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Capacity Reservation, {@code active} on the create response and on the first
|
||||
* describe. Real AWS passes through {@code payment-pending}/{@code assessing} first;
|
||||
@@ -9862,6 +10081,9 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
"The request must contain the parameter AvailabilityZone or AvailabilityZoneId.", 400);
|
||||
}
|
||||
int count = requirePositiveInstanceCount(instanceCount);
|
||||
if (isSet(availabilityZoneId)) {
|
||||
zoneNameForZoneId(region, availabilityZoneId);
|
||||
}
|
||||
CapacityReservation reservation = new CapacityReservation();
|
||||
reservation.setCapacityReservationId("cr-" + randomHex(17));
|
||||
String ownerAccountId = callerAccountId();
|
||||
@@ -9886,7 +10108,27 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
reservation.setInstanceMatchCriteria(instanceMatchCriteria != null ? instanceMatchCriteria : "open");
|
||||
reservation.setOutpostArn(outpostArn);
|
||||
reservation.setPlacementGroupArn(placementGroupArn);
|
||||
capacityReservations.put(key(region, reservation.getCapacityReservationId()), reservation);
|
||||
synchronized (capacityReservationLock) {
|
||||
reconcileCapacityMembership(region);
|
||||
if ("open".equals(reservation.getInstanceMatchCriteria())) {
|
||||
Set<String> associated = capacityReservations.scan(k -> k.startsWith(region + "::")).stream()
|
||||
.flatMap(existing -> existing.getInstanceIds().stream()).collect(Collectors.toSet());
|
||||
for (Instance instance : instances.scan(k -> k.startsWith(region + "::"))) {
|
||||
if (reservation.getAvailableInstanceCount() == 0) {
|
||||
break;
|
||||
}
|
||||
if ("running".equals(instance.getState().getName()) && !instance.isSpot()
|
||||
&& "open".equals(instance.getCapacityReservationPreference())
|
||||
&& instance.getCapacityReservationTarget() == null
|
||||
&& !associated.contains(instance.getInstanceId())
|
||||
&& matchesCapacityReservation(instance, reservation)) {
|
||||
reservation.getInstanceIds().add(instance.getInstanceId());
|
||||
reservation.setAvailableInstanceCount(reservation.getAvailableInstanceCount() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
capacityReservations.put(key(region, reservation.getCapacityReservationId()), reservation);
|
||||
}
|
||||
return reservation;
|
||||
}
|
||||
|
||||
@@ -9897,15 +10139,19 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
|
||||
List<CapacityReservation> describeCapacityReservations(String region, List<String> ids,
|
||||
List<Map.Entry<String, List<String>>> filters) {
|
||||
ensureDefaultResources(region);
|
||||
for (String id : ids) {
|
||||
getRequiredCapacityReservation(region, id);
|
||||
synchronized (capacityReservationLock) {
|
||||
ensureDefaultResources(region);
|
||||
reconcileCapacityMembership(region);
|
||||
for (String id : ids) {
|
||||
getRequiredCapacityReservation(region, id);
|
||||
}
|
||||
return capacityReservations.scan(k -> true).stream()
|
||||
.filter(r -> r.getRegion().equals(region))
|
||||
.filter(r -> ids.isEmpty() || ids.contains(r.getCapacityReservationId()))
|
||||
.filter(r -> matchesFilters(r, filters, region))
|
||||
.map(CapacityReservation::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return capacityReservations.scan(k -> true).stream()
|
||||
.filter(r -> r.getRegion().equals(region))
|
||||
.filter(r -> ids.isEmpty() || ids.contains(r.getCapacityReservationId()))
|
||||
.filter(r -> matchesFilters(r, filters, region))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -9915,29 +10161,37 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
*/
|
||||
public CapacityReservation modifyCapacityReservation(String region, String capacityReservationId,
|
||||
Integer instanceCount, java.time.Instant endDate, String endDateType, String instanceMatchCriteria) {
|
||||
ensureDefaultResources(region);
|
||||
CapacityReservation reservation = getRequiredCapacityReservation(region, capacityReservationId);
|
||||
if (instanceCount != null) {
|
||||
int delta = requirePositiveInstanceCount(instanceCount) - reservation.getTotalInstanceCount();
|
||||
reservation.setTotalInstanceCount(instanceCount);
|
||||
reservation.setAvailableInstanceCount(Math.max(0, reservation.getAvailableInstanceCount() + delta));
|
||||
synchronized (capacityReservationLock) {
|
||||
ensureDefaultResources(region);
|
||||
reconcileCapacityMembership(region);
|
||||
CapacityReservation reservation = new CapacityReservation(
|
||||
getRequiredCapacityReservation(region, capacityReservationId));
|
||||
if (instanceCount != null) {
|
||||
int delta = requirePositiveInstanceCount(instanceCount) - reservation.getTotalInstanceCount();
|
||||
if (reservation.getAvailableInstanceCount() + delta < 0) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"The instance count cannot be less than the consumed capacity.", 400);
|
||||
}
|
||||
reservation.setTotalInstanceCount(instanceCount);
|
||||
reservation.setAvailableInstanceCount(reservation.getAvailableInstanceCount() + delta);
|
||||
}
|
||||
if (endDateType != null) {
|
||||
reservation.setEndDateType(endDateType);
|
||||
}
|
||||
// AWS clears EndDate when EndDateType moves back to "unlimited"; ModifyCapacityReservation
|
||||
// has no way to explicitly clear EndDate otherwise (CancelCapacityReservation is the only
|
||||
// other transition), so mirror that here rather than leaving a stale date behind.
|
||||
if ("unlimited".equals(reservation.getEndDateType())) {
|
||||
reservation.setEndDate(null);
|
||||
} else if (endDate != null) {
|
||||
reservation.setEndDate(endDate);
|
||||
}
|
||||
if (instanceMatchCriteria != null) {
|
||||
reservation.setInstanceMatchCriteria(instanceMatchCriteria);
|
||||
}
|
||||
capacityReservations.put(key(region, capacityReservationId), reservation);
|
||||
return reservation;
|
||||
}
|
||||
if (endDateType != null) {
|
||||
reservation.setEndDateType(endDateType);
|
||||
}
|
||||
// AWS clears EndDate when EndDateType moves back to "unlimited"; ModifyCapacityReservation
|
||||
// has no way to explicitly clear EndDate otherwise (CancelCapacityReservation is the only
|
||||
// other transition), so mirror that here rather than leaving a stale date behind.
|
||||
if ("unlimited".equals(reservation.getEndDateType())) {
|
||||
reservation.setEndDate(null);
|
||||
} else if (endDate != null) {
|
||||
reservation.setEndDate(endDate);
|
||||
}
|
||||
if (instanceMatchCriteria != null) {
|
||||
reservation.setInstanceMatchCriteria(instanceMatchCriteria);
|
||||
}
|
||||
capacityReservations.put(key(region, capacityReservationId), reservation);
|
||||
return reservation;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -9946,11 +10200,16 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
* appears in DescribeCapacityReservations.
|
||||
*/
|
||||
public void cancelCapacityReservation(String region, String capacityReservationId) {
|
||||
ensureDefaultResources(region);
|
||||
CapacityReservation reservation = getRequiredCapacityReservation(region, capacityReservationId);
|
||||
reservation.setState("cancelled");
|
||||
reservation.setAvailableInstanceCount(0);
|
||||
capacityReservations.put(key(region, capacityReservationId), reservation);
|
||||
synchronized (capacityReservationLock) {
|
||||
ensureDefaultResources(region);
|
||||
reconcileCapacityMembership(region);
|
||||
CapacityReservation reservation = new CapacityReservation(
|
||||
getRequiredCapacityReservation(region, capacityReservationId));
|
||||
reservation.setState("cancelled");
|
||||
reservation.getInstanceIds().clear();
|
||||
reservation.setAvailableInstanceCount(0);
|
||||
capacityReservations.put(key(region, capacityReservationId), reservation);
|
||||
}
|
||||
}
|
||||
|
||||
private int requirePositiveInstanceCount(int instanceCount) {
|
||||
@@ -9962,6 +10221,15 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
return instanceCount;
|
||||
}
|
||||
|
||||
private String capacityReservationZone(String region, CapacityReservation reservation) {
|
||||
if (!isSet(reservation.getAvailabilityZoneId())) {
|
||||
return reservation.getAvailabilityZone();
|
||||
}
|
||||
int index = AvailabilityZoneIds.indexOf(region, reservation.getAvailabilityZoneId());
|
||||
return index >= 1 && index <= MODELLED_ZONE_SUFFIXES.length
|
||||
? region + MODELLED_ZONE_SUFFIXES[index - 1] : null;
|
||||
}
|
||||
|
||||
private CapacityReservation getRequiredCapacityReservation(String region, String capacityReservationId) {
|
||||
CapacityReservation reservation = capacityReservations.get(key(region, capacityReservationId)).orElse(null);
|
||||
if (reservation == null) {
|
||||
|
||||
@@ -43,9 +43,36 @@ public class CapacityReservation {
|
||||
private String placementGroupArn;
|
||||
private String region;
|
||||
private List<Tag> tags = new ArrayList<>();
|
||||
private List<String> instanceIds = new ArrayList<>();
|
||||
|
||||
public CapacityReservation() {}
|
||||
|
||||
public CapacityReservation(CapacityReservation other) {
|
||||
capacityReservationId = other.capacityReservationId;
|
||||
ownerId = other.ownerId;
|
||||
capacityReservationArn = other.capacityReservationArn;
|
||||
availabilityZone = other.availabilityZone;
|
||||
availabilityZoneId = other.availabilityZoneId;
|
||||
instanceType = other.instanceType;
|
||||
instancePlatform = other.instancePlatform;
|
||||
tenancy = other.tenancy;
|
||||
totalInstanceCount = other.totalInstanceCount;
|
||||
availableInstanceCount = other.availableInstanceCount;
|
||||
ebsOptimized = other.ebsOptimized;
|
||||
ephemeralStorage = other.ephemeralStorage;
|
||||
state = other.state;
|
||||
startDate = other.startDate;
|
||||
endDate = other.endDate;
|
||||
endDateType = other.endDateType;
|
||||
instanceMatchCriteria = other.instanceMatchCriteria;
|
||||
createDate = other.createDate;
|
||||
outpostArn = other.outpostArn;
|
||||
placementGroupArn = other.placementGroupArn;
|
||||
region = other.region;
|
||||
tags = new ArrayList<>(other.tags);
|
||||
instanceIds = new ArrayList<>(other.instanceIds);
|
||||
}
|
||||
|
||||
public String getCapacityReservationId() { return capacityReservationId; }
|
||||
public void setCapacityReservationId(String capacityReservationId) { this.capacityReservationId = capacityReservationId; }
|
||||
|
||||
@@ -110,4 +137,8 @@ public class CapacityReservation {
|
||||
|
||||
public List<Tag> getTags() { return tags; }
|
||||
public void setTags(List<Tag> tags) { this.tags = tags; }
|
||||
|
||||
public List<String> getInstanceIds() { return instanceIds; }
|
||||
public void setInstanceIds(List<String> instanceIds) { this.instanceIds = instanceIds; }
|
||||
|
||||
}
|
||||
@@ -19,6 +19,9 @@ public class Instance {
|
||||
private String stateTransitionReason;
|
||||
private String instanceType;
|
||||
private boolean spot;
|
||||
private String capacityReservationPlatform = "Linux/UNIX";
|
||||
private String capacityReservationPreference = "open";
|
||||
private String capacityReservationTarget;
|
||||
private Placement placement;
|
||||
private String subnetId;
|
||||
private String vpcId;
|
||||
@@ -106,11 +109,26 @@ public class Instance {
|
||||
public void setImageId(String imageId) { this.imageId = imageId; }
|
||||
|
||||
public InstanceState getState() { return state; }
|
||||
public void setState(InstanceState state) { this.state = state; }
|
||||
public synchronized void setState(InstanceState state) { this.state = state; }
|
||||
|
||||
public synchronized boolean compareAndSetState(InstanceState expected, InstanceState updated) {
|
||||
if (state != expected) {
|
||||
return false;
|
||||
}
|
||||
state = updated;
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getStateTransitionReason() { return stateTransitionReason; }
|
||||
public void setStateTransitionReason(String stateTransitionReason) { this.stateTransitionReason = stateTransitionReason; }
|
||||
|
||||
public String getCapacityReservationPlatform() { return capacityReservationPlatform; }
|
||||
public void setCapacityReservationPlatform(String platform) { capacityReservationPlatform = platform; }
|
||||
public String getCapacityReservationPreference() { return capacityReservationPreference; }
|
||||
public void setCapacityReservationPreference(String preference) { capacityReservationPreference = preference; }
|
||||
public String getCapacityReservationTarget() { return capacityReservationTarget; }
|
||||
public void setCapacityReservationTarget(String target) { capacityReservationTarget = target; }
|
||||
|
||||
public boolean isSpot() { return spot; }
|
||||
public void setSpot(boolean spot) { this.spot = spot; }
|
||||
|
||||
|
||||
Reference in new issue
Block a user