mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(cloudformation): forward ECS service and task definition settings (#7644)
This commit is contained in:
1 parent
6e75e4096e
commit
062389b370
10 files changed
+775
-140
No files matched your search
+5
-1
@@ -329,7 +329,11 @@ public class CloudFormationTemplateEngine {
|
||||
return attribute.isTextual() ? resolveDynamicReferences(attribute.textValue()) : attribute;
|
||||
}
|
||||
if (node.has("Fn::Select")) {
|
||||
return resolveNode(selectedElement(node.get("Fn::Select")));
|
||||
// The chosen element becomes the value, so AWS::NoValue inside it is left out as it is
|
||||
// from a value written in place. A directly chosen AWS::NoValue keeps resolving to "".
|
||||
JsonNode selected = selectedElement(node.get("Fn::Select"));
|
||||
JsonNode omitted = omitNoValue(selected);
|
||||
return resolveNode(omitted.isMissingNode() ? selected : omitted);
|
||||
}
|
||||
if (node.has("Fn::FindInMap")) {
|
||||
return resolveNode(findMappedValue(node.get("Fn::FindInMap")));
|
||||
|
||||
+218
-28
@@ -10,20 +10,26 @@ import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.services.cloudformation.model.StackResource;
|
||||
import io.floci.aws.services.ecs.EcsService;
|
||||
import io.floci.aws.services.ecs.model.AwsVpcConfiguration;
|
||||
import io.floci.aws.services.ecs.model.CapacityProviderStrategyItem;
|
||||
import io.floci.aws.services.ecs.model.ClusterSetting;
|
||||
import io.floci.aws.services.ecs.model.ContainerDefinition;
|
||||
import io.floci.aws.services.ecs.model.CreateServiceRequest;
|
||||
import io.floci.aws.services.ecs.model.EcsCluster;
|
||||
import io.floci.aws.services.ecs.model.EcsLoadBalancer;
|
||||
import io.floci.aws.services.ecs.model.EcsServiceModel;
|
||||
import io.floci.aws.services.ecs.model.FirelensConfiguration;
|
||||
import io.floci.aws.services.ecs.model.HealthCheck;
|
||||
import io.floci.aws.services.ecs.model.KeyValuePair;
|
||||
import io.floci.aws.services.ecs.model.LaunchType;
|
||||
import io.floci.aws.services.ecs.model.LogConfiguration;
|
||||
import io.floci.aws.services.ecs.model.NetworkConfiguration;
|
||||
import io.floci.aws.services.ecs.model.NetworkMode;
|
||||
import io.floci.aws.services.ecs.model.PortMapping;
|
||||
import io.floci.aws.services.ecs.model.RegisterTaskDefinitionRequest;
|
||||
import io.floci.aws.services.ecs.model.RuntimePlatform;
|
||||
import io.floci.aws.services.ecs.model.Secret;
|
||||
import io.floci.aws.services.ecs.model.TaskDefinition;
|
||||
import io.floci.aws.services.ecs.model.UpdateServiceRequest;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
@@ -32,6 +38,7 @@ import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -252,16 +259,18 @@ public class EcsCfnProvisioner implements CfnResourceProvisioner {
|
||||
if (family == null || family.isBlank()) {
|
||||
family = ctx.generatePhysicalName(r.getLogicalId(), 255, false);
|
||||
}
|
||||
List<ContainerDefinition> containerDefs = parseContainerDefinitions(props.get("ContainerDefinitions"), ctx);
|
||||
NetworkMode networkMode = parseEnum(NetworkMode.class, ctx.resolveOptional(props, "NetworkMode"));
|
||||
String cpu = ctx.resolveOptional(props, "Cpu");
|
||||
String memory = ctx.resolveOptional(props, "Memory");
|
||||
String taskRoleArn = ctx.resolveOptional(props, "TaskRoleArn");
|
||||
String executionRoleArn = ctx.resolveOptional(props, "ExecutionRoleArn");
|
||||
List<String> requiresCompatibilities = ctx.resolveStringList(props, "RequiresCompatibilities");
|
||||
RegisterTaskDefinitionRequest request = new RegisterTaskDefinitionRequest();
|
||||
request.setFamily(family);
|
||||
request.setContainerDefinitions(parseContainerDefinitions(props.get("ContainerDefinitions"), ctx));
|
||||
request.setNetworkMode(parseEnum(NetworkMode.class, ctx.resolveOptional(props, "NetworkMode")));
|
||||
request.setCpu(ctx.resolveOptional(props, "Cpu"));
|
||||
request.setMemory(ctx.resolveOptional(props, "Memory"));
|
||||
request.setTaskRoleArn(ctx.resolveOptional(props, "TaskRoleArn"));
|
||||
request.setExecutionRoleArn(ctx.resolveOptional(props, "ExecutionRoleArn"));
|
||||
request.setRequiresCompatibilities(ctx.resolveStringList(props, "RequiresCompatibilities"));
|
||||
request.setRuntimePlatform(parseRuntimePlatform(props.path("RuntimePlatform")));
|
||||
|
||||
TaskDefinition td = ecsService.registerTaskDefinition(family, containerDefs, networkMode, cpu, memory,
|
||||
taskRoleArn, executionRoleArn, requiresCompatibilities, ctx.region());
|
||||
TaskDefinition td = ecsService.registerTaskDefinition(request, ctx.region());
|
||||
|
||||
r.setPhysicalId(td.getTaskDefinitionArn());
|
||||
r.getAttributes().put("TaskDefinitionArn", td.getTaskDefinitionArn());
|
||||
@@ -275,6 +284,9 @@ public class EcsCfnProvisioner implements CfnResourceProvisioner {
|
||||
* displaced one deleted once the stack update commits, through the replacement cleanup. Either
|
||||
* way the resource completes only once the service is stable, as CloudFormation's does; an
|
||||
* in-place update that does not stabilize is put back on the prior configuration.
|
||||
* {@code AWS::ECS::Service} has no vendored property types, so a value a {@code String}
|
||||
* parameter gives arrives as text and is converted where ECS expects an integer or a boolean,
|
||||
* as CloudFormation's handler converts it (measured).
|
||||
*/
|
||||
private void provisionService(StackResource r, JsonNode props, ProvisionContext ctx) {
|
||||
String clusterRef = ctx.resolveOptional(props, "Cluster");
|
||||
@@ -285,6 +297,12 @@ public class EcsCfnProvisioner implements CfnResourceProvisioner {
|
||||
parseLoadBalancers(props != null ? props.get("LoadBalancers") : null, ctx);
|
||||
NetworkConfiguration networkConfiguration =
|
||||
parseNetworkConfiguration(props != null ? props.get("NetworkConfiguration") : null, ctx);
|
||||
Map<String, Object> deploymentConfiguration =
|
||||
parseDeploymentConfiguration(props != null ? props.get("DeploymentConfiguration") : null, ctx);
|
||||
List<CapacityProviderStrategyItem> capacityProviderStrategy =
|
||||
parseCapacityProviderStrategy(props != null ? props.get("CapacityProviderStrategy") : null, ctx);
|
||||
List<Map<String, Object>> serviceRegistries =
|
||||
parseServiceRegistries(props != null ? props.get("ServiceRegistries") : null, ctx);
|
||||
|
||||
String priorName = r.getAttributes().get("Name");
|
||||
String serviceName = ctx.resolveOptional(props, "ServiceName");
|
||||
@@ -298,17 +316,34 @@ public class EcsCfnProvisioner implements CfnResourceProvisioner {
|
||||
EcsServiceModel svc;
|
||||
boolean inPlace = ctx.isUpdate() && serviceName.equals(priorName)
|
||||
&& clusterName(clusterRef).equals(clusterOfServiceArn(ctx.priorPhysicalId()));
|
||||
// Read before updateService, which changes this same model in place.
|
||||
EcsServiceModel prior = inPlace ? ecsService.serviceByArn(ctx.priorPhysicalId()) : null;
|
||||
String priorTaskDefinition = prior != null ? prior.getTaskDefinition() : null;
|
||||
Integer priorDesiredCount = prior != null ? prior.getDesiredCount() : null;
|
||||
NetworkConfiguration priorNetworkConfiguration = prior != null ? prior.getNetworkConfiguration() : null;
|
||||
UpdateServiceRequest restore;
|
||||
if (inPlace) {
|
||||
svc = ecsService.updateService(clusterRef, serviceName, taskDefinition,
|
||||
desiredCount, networkConfiguration, ctx.region());
|
||||
UpdateServiceRequest update = new UpdateServiceRequest();
|
||||
update.setCluster(clusterRef);
|
||||
update.setService(serviceName);
|
||||
update.setTaskDefinition(taskDefinition);
|
||||
update.setDesiredCount(desiredCount);
|
||||
update.setNetworkConfiguration(networkConfiguration);
|
||||
update.setDeploymentConfiguration(deploymentConfiguration);
|
||||
update.setCapacityProviderStrategy(capacityProviderStrategy);
|
||||
update.setServiceRegistries(serviceRegistries);
|
||||
// Built before updateService, which changes this same model in place.
|
||||
restore = restoreRequest(update, ecsService.serviceByArn(ctx.priorPhysicalId()));
|
||||
svc = ecsService.updateService(update, ctx.region());
|
||||
} else {
|
||||
svc = ecsService.createService(clusterRef, serviceName, taskDefinition,
|
||||
desiredCount, launchType, loadBalancers, networkConfiguration, ctx.region());
|
||||
CreateServiceRequest create = new CreateServiceRequest();
|
||||
create.setCluster(clusterRef);
|
||||
create.setServiceName(serviceName);
|
||||
create.setTaskDefinition(taskDefinition);
|
||||
create.setDesiredCount(desiredCount);
|
||||
create.setLaunchType(launchType);
|
||||
create.setLoadBalancers(loadBalancers);
|
||||
create.setNetworkConfiguration(networkConfiguration);
|
||||
create.setDeploymentConfiguration(deploymentConfiguration);
|
||||
create.setCapacityProviderStrategy(capacityProviderStrategy);
|
||||
create.setServiceRegistries(serviceRegistries);
|
||||
restore = null;
|
||||
svc = ecsService.createService(create, ctx.region());
|
||||
}
|
||||
|
||||
r.setPhysicalId(svc.getServiceArn());
|
||||
@@ -318,9 +353,8 @@ public class EcsCfnProvisioner implements CfnResourceProvisioner {
|
||||
try {
|
||||
ecsService.awaitServiceStable(svc);
|
||||
} catch (RuntimeException failure) {
|
||||
restoreInPlace(r, failure, () -> ecsService.awaitServiceStable(ecsService.updateService(clusterRef,
|
||||
svc.getServiceName(), priorTaskDefinition, priorDesiredCount, priorNetworkConfiguration,
|
||||
ctx.region())));
|
||||
restoreInPlace(r, failure, () -> ecsService.awaitServiceStable(
|
||||
ecsService.updateService(restore, ctx.region())));
|
||||
throw failure;
|
||||
}
|
||||
} else {
|
||||
@@ -329,13 +363,42 @@ public class EcsCfnProvisioner implements CfnResourceProvisioner {
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts a service updated in place back on the task definition, desired count and network
|
||||
* configuration it had, when the update does not stabilize, and waits for the restored
|
||||
* configuration to stabilize, as CloudFormation's rollback does. CloudFormationService restores
|
||||
* the prior resource record and reports the rollback complete unless told otherwise, so without
|
||||
* this the stack would claim a rollback while ECS still runs the failed configuration. A
|
||||
* restore that fails or does not stabilize is attached to the original failure and recorded as
|
||||
* a rollback failure.
|
||||
* The update that puts {@code prior} back on what {@code update} changed: its task definition,
|
||||
* desired count and network configuration, and each setting the update declared. A deployment
|
||||
* configuration, capacity provider strategy or service registries the service did not have are
|
||||
* put back empty, so a registry the update added is deregistered; a setting the update left
|
||||
* unchanged is left unchanged again, so the restore rolls no deployment for registries nobody
|
||||
* touched.
|
||||
*/
|
||||
private static UpdateServiceRequest restoreRequest(UpdateServiceRequest update, EcsServiceModel prior) {
|
||||
UpdateServiceRequest restore = new UpdateServiceRequest();
|
||||
restore.setCluster(update.getCluster());
|
||||
restore.setService(update.getService());
|
||||
if (prior == null) {
|
||||
return restore;
|
||||
}
|
||||
restore.setTaskDefinition(prior.getTaskDefinition());
|
||||
restore.setDesiredCount(prior.getDesiredCount());
|
||||
restore.setNetworkConfiguration(prior.getNetworkConfiguration());
|
||||
if (update.getDeploymentConfiguration() != null) {
|
||||
restore.setDeploymentConfiguration(Objects.requireNonNullElse(prior.getDeploymentConfiguration(), Map.of()));
|
||||
}
|
||||
if (update.getCapacityProviderStrategy() != null) {
|
||||
restore.setCapacityProviderStrategy(Objects.requireNonNullElse(prior.getCapacityProviderStrategy(), List.of()));
|
||||
}
|
||||
if (update.getServiceRegistries() != null) {
|
||||
restore.setServiceRegistries(Objects.requireNonNullElse(prior.getServiceRegistries(), List.of()));
|
||||
}
|
||||
return restore;
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts a service updated in place back on the configuration {@link #restoreRequest} captured
|
||||
* when the update does not stabilize, and waits for the restored configuration to stabilize,
|
||||
* as CloudFormation's rollback does. CloudFormationService restores the prior resource record
|
||||
* and reports the rollback complete unless told otherwise, so without this the stack would
|
||||
* claim a rollback while ECS still runs the failed configuration. A restore that fails or does
|
||||
* not stabilize is attached to the original failure and recorded as a rollback failure.
|
||||
*/
|
||||
private void restoreInPlace(StackResource r, RuntimeException failure, Runnable restore) {
|
||||
try {
|
||||
@@ -466,11 +529,36 @@ public class EcsCfnProvisioner implements CfnResourceProvisioner {
|
||||
if (item.path("EntryPoint").isArray()) {
|
||||
def.setEntryPoint(toStringList(item.path("EntryPoint")));
|
||||
}
|
||||
if (item.hasNonNull("User")) {
|
||||
def.setUser(item.path("User").asText());
|
||||
}
|
||||
def.setHealthCheck(parseHealthCheck(item.path("HealthCheck")));
|
||||
result.add(def);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static HealthCheck parseHealthCheck(JsonNode node) {
|
||||
if (!node.isObject()) {
|
||||
return null;
|
||||
}
|
||||
return new HealthCheck(toStringList(node.path("Command")), optionalInt(node, "Interval"),
|
||||
optionalInt(node, "Timeout"), optionalInt(node, "Retries"), optionalInt(node, "StartPeriod"));
|
||||
}
|
||||
|
||||
private static Integer optionalInt(JsonNode node, String member) {
|
||||
return node.hasNonNull(member) ? node.path(member).asInt() : null;
|
||||
}
|
||||
|
||||
private static RuntimePlatform parseRuntimePlatform(JsonNode node) {
|
||||
String cpuArchitecture = node.path("CpuArchitecture").asText(null);
|
||||
String operatingSystemFamily = node.path("OperatingSystemFamily").asText(null);
|
||||
if (cpuArchitecture == null && operatingSystemFamily == null) {
|
||||
return null;
|
||||
}
|
||||
return new RuntimePlatform(cpuArchitecture, operatingSystemFamily);
|
||||
}
|
||||
|
||||
private static LogConfiguration parseLogConfiguration(JsonNode node) {
|
||||
if (node == null || !node.isObject() || !node.hasNonNull("LogDriver")) {
|
||||
return null;
|
||||
@@ -641,6 +729,108 @@ public class EcsCfnProvisioner implements CfnResourceProvisioner {
|
||||
return networkConfiguration;
|
||||
}
|
||||
|
||||
private static List<Map<String, Object>> parseServiceRegistries(JsonNode node, ProvisionContext ctx) {
|
||||
JsonNode resolved = ctx.engine().resolveNode(node);
|
||||
if (resolved == null || !resolved.isArray()) {
|
||||
return null;
|
||||
}
|
||||
List<Map<String, Object>> result = new ArrayList<>();
|
||||
for (JsonNode item : resolved) {
|
||||
// An entry that resolved to AWS::NoValue is not an object.
|
||||
if (item.isObject()) {
|
||||
Map<String, Object> registry = new LinkedHashMap<>();
|
||||
putText(registry, "registryArn", item, "RegistryArn");
|
||||
putInt(registry, "port", item, "Port");
|
||||
putText(registry, "containerName", item, "ContainerName");
|
||||
putInt(registry, "containerPort", item, "ContainerPort");
|
||||
result.add(registry);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/** As the ECS handler reads it: an empty strategy is none. */
|
||||
private static List<CapacityProviderStrategyItem> parseCapacityProviderStrategy(JsonNode node,
|
||||
ProvisionContext ctx) {
|
||||
JsonNode resolved = ctx.engine().resolveNode(node);
|
||||
if (resolved == null || !resolved.isArray()) {
|
||||
return null;
|
||||
}
|
||||
List<CapacityProviderStrategyItem> result = new ArrayList<>();
|
||||
for (JsonNode item : resolved) {
|
||||
// An entry that resolved to AWS::NoValue is not an object.
|
||||
if (item.isObject()) {
|
||||
result.add(new CapacityProviderStrategyItem(item.path("CapacityProvider").asText(),
|
||||
item.path("Weight").asInt(0), item.path("Base").asInt(0)));
|
||||
}
|
||||
}
|
||||
return result.isEmpty() ? null : result;
|
||||
}
|
||||
|
||||
/**
|
||||
* The members of a {@code DeploymentConfiguration} in the API's shape. Its canary, linear and
|
||||
* lifecycle hook members are not forwarded.
|
||||
*/
|
||||
private static Map<String, Object> parseDeploymentConfiguration(JsonNode node, ProvisionContext ctx) {
|
||||
JsonNode resolved = ctx.engine().resolveNode(node);
|
||||
if (resolved == null || !resolved.isObject()) {
|
||||
return null;
|
||||
}
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
putInt(result, "maximumPercent", resolved, "MaximumPercent");
|
||||
putInt(result, "minimumHealthyPercent", resolved, "MinimumHealthyPercent");
|
||||
JsonNode breaker = resolved.path("DeploymentCircuitBreaker");
|
||||
if (breaker.isObject()) {
|
||||
Map<String, Object> circuitBreaker = new LinkedHashMap<>();
|
||||
putBoolean(circuitBreaker, "enable", breaker, "Enable");
|
||||
putBoolean(circuitBreaker, "rollback", breaker, "Rollback");
|
||||
putBoolean(circuitBreaker, "resetOnHealthyTask", breaker, "ResetOnHealthyTask");
|
||||
JsonNode threshold = breaker.path("ThresholdConfiguration");
|
||||
if (threshold.isObject()) {
|
||||
Map<String, Object> thresholdConfiguration = new LinkedHashMap<>();
|
||||
putText(thresholdConfiguration, "type", threshold, "Type");
|
||||
putInt(thresholdConfiguration, "value", threshold, "Value");
|
||||
circuitBreaker.put("thresholdConfiguration", thresholdConfiguration);
|
||||
}
|
||||
result.put("deploymentCircuitBreaker", circuitBreaker);
|
||||
}
|
||||
JsonNode alarms = resolved.path("Alarms");
|
||||
if (alarms.isObject()) {
|
||||
Map<String, Object> deploymentAlarms = new LinkedHashMap<>();
|
||||
if (alarms.hasNonNull("AlarmNames")) {
|
||||
// Read unresolved, so a list parameter is its items rather than their joined text,
|
||||
// unless an intrinsic such as Fn::Select produced the member and only the resolved value holds it.
|
||||
JsonNode names = ctx.engine().omitNoValue(node).path("Alarms").path("AlarmNames");
|
||||
deploymentAlarms.put("alarmNames", ctx.engine().resolveStringList(
|
||||
names.isMissingNode() ? alarms.get("AlarmNames") : names));
|
||||
}
|
||||
putBoolean(deploymentAlarms, "enable", alarms, "Enable");
|
||||
putBoolean(deploymentAlarms, "rollback", alarms, "Rollback");
|
||||
result.put("alarms", deploymentAlarms);
|
||||
}
|
||||
putText(result, "strategy", resolved, "Strategy");
|
||||
putInt(result, "bakeTimeInMinutes", resolved, "BakeTimeInMinutes");
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void putText(Map<String, Object> target, String key, JsonNode source, String member) {
|
||||
if (source.hasNonNull(member)) {
|
||||
target.put(key, source.path(member).asText());
|
||||
}
|
||||
}
|
||||
|
||||
private static void putInt(Map<String, Object> target, String key, JsonNode source, String member) {
|
||||
if (source.hasNonNull(member)) {
|
||||
target.put(key, source.path(member).asInt());
|
||||
}
|
||||
}
|
||||
|
||||
private static void putBoolean(Map<String, Object> target, String key, JsonNode source, String member) {
|
||||
if (source.hasNonNull(member)) {
|
||||
target.put(key, Boolean.parseBoolean(source.path(member).asText().trim()));
|
||||
}
|
||||
}
|
||||
|
||||
/** An absent or unknown enum value means "not set", as the switch arms treated it. */
|
||||
private static <E extends Enum<E>> E parseEnum(Class<E> type, String value) {
|
||||
if (value == null || value.isBlank()) {
|
||||
|
||||
@@ -1485,9 +1485,6 @@ public class EcsJsonHandler {
|
||||
if (node == null || !node.isObject()) {
|
||||
return null;
|
||||
}
|
||||
if (!node.hasNonNull("command") || !node.path("command").isArray() || node.path("command").isEmpty()) {
|
||||
throw new AwsException("ClientException", "HealthCheck command is required.", 400);
|
||||
}
|
||||
List<String> command = jsonArrayToList(node.path("command"));
|
||||
Integer interval = node.has("interval") ? node.path("interval").asInt() : null;
|
||||
Integer timeout = node.has("timeout") ? node.path("timeout").asInt() : null;
|
||||
|
||||
@@ -49,6 +49,7 @@ import io.floci.aws.services.ecs.model.EcsTaskAddress;
|
||||
import io.floci.aws.services.ecs.model.EphemeralStorage;
|
||||
import io.floci.aws.services.ecs.model.Failure;
|
||||
import io.floci.aws.services.ecs.model.FirelensConfiguration;
|
||||
import io.floci.aws.services.ecs.model.HealthCheck;
|
||||
import io.floci.aws.services.ecs.model.KeyValuePair;
|
||||
import io.floci.aws.services.ecs.model.LaunchType;
|
||||
import io.floci.aws.services.ecs.model.ListTasksRequest;
|
||||
@@ -957,6 +958,7 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
public TaskDefinition registerTaskDefinition(RegisterTaskDefinitionRequest request, String region) {
|
||||
List<ContainerDefinition> containerDefs = request.getContainerDefinitions();
|
||||
boolean fargate = request.isFargate();
|
||||
validateHealthChecks(containerDefs);
|
||||
validateTaskSize(request, fargate);
|
||||
validateEphemeralStorage(request.getEphemeralStorage());
|
||||
validateContainerDependencies(containerDefs);
|
||||
@@ -1135,6 +1137,18 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateHealthChecks(List<ContainerDefinition> containerDefs) {
|
||||
if (containerDefs == null) {
|
||||
return;
|
||||
}
|
||||
for (ContainerDefinition def : containerDefs) {
|
||||
HealthCheck healthCheck = def.getHealthCheck();
|
||||
if (healthCheck != null && (healthCheck.command() == null || healthCheck.command().isEmpty())) {
|
||||
throw new AwsException("ClientException", "HealthCheck command is required.", 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@code dependsOn} entry may only name another container of the same task definition, and
|
||||
* the graph they form has to be acyclic: a cycle would leave every container in it waiting for
|
||||
@@ -2948,6 +2962,10 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
throw new AwsException("ServiceNotActiveException",
|
||||
"Service " + serviceName + " is not active.", 400);
|
||||
}
|
||||
// Resolved before anything is applied: a request naming a task definition that cannot
|
||||
// launch fails without changing the service.
|
||||
TaskDefinition resolved = request.getTaskDefinition() == null ? null
|
||||
: resolveLaunchableTaskDefinition(request.getTaskDefinition(), region);
|
||||
// Settle the outgoing deployment against the service as it stands, before this request
|
||||
// changes its desired count or task definition: one whose tasks are up has finished,
|
||||
// whether or not anything read it. recordServiceDeployment stops it if it has not.
|
||||
@@ -3019,8 +3037,7 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
}
|
||||
boolean taskDefChanged = false;
|
||||
String platformVersionBefore = svc.getPlatformVersion();
|
||||
if (request.getTaskDefinition() != null) {
|
||||
TaskDefinition resolved = resolveLaunchableTaskDefinition(request.getTaskDefinition(), region);
|
||||
if (resolved != null) {
|
||||
taskDefChanged = !resolved.getTaskDefinitionArn().equals(svc.getTaskDefinition());
|
||||
svc.setTaskDefinition(resolved.getTaskDefinitionArn());
|
||||
applyServicePlatform(svc, resolved, request.getPlatformVersion() != null
|
||||
|
||||
+205
@@ -0,0 +1,205 @@
|
||||
package io.floci.aws.services.cloudformation;
|
||||
|
||||
import io.floci.aws.services.ec2.Ec2Service;
|
||||
import io.floci.aws.testing.CfnStackWaits;
|
||||
import io.floci.aws.testing.PartitionCleanup;
|
||||
import io.floci.aws.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static io.floci.aws.testing.CfnRequests.cfn;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* The service and task definition settings an ECS stack declares reach ECS, so DescribeServices
|
||||
* and DescribeTaskDefinition report them. Measured on AWS (eu-west-1) with this template's
|
||||
* shape: a value a {@code String} parameter gives an {@code AWS::ECS::Service} comes back typed,
|
||||
* {@code maximumPercent} 150, {@code enable} true and {@code weight} 2.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class CloudFormationEcsForwardedSettingsIntegrationTest {
|
||||
|
||||
private static final String ECS_TARGET = "AmazonEC2ContainerServiceV20141113";
|
||||
|
||||
private static final String TEMPLATE = """
|
||||
{
|
||||
"Parameters": {
|
||||
"MaxPercent": {"Type": "String", "Default": "150"},
|
||||
"Flag": {"Type": "String", "Default": "true"},
|
||||
"Weight": {"Type": "String", "Default": "2"},
|
||||
"Arch": {"Type": "String", "Default": "ARM64"},
|
||||
"Os": {"Type": "String", "Default": "LINUX"}
|
||||
},
|
||||
"Conditions": {"Never": {"Fn::Equals": ["a", "b"]}},
|
||||
"Resources": {
|
||||
"Namespace": {
|
||||
"Type": "AWS::ServiceDiscovery::HttpNamespace",
|
||||
"Properties": {"Name": "%1$s"}
|
||||
},
|
||||
"Registry": {
|
||||
"Type": "AWS::ServiceDiscovery::Service",
|
||||
"Properties": {"Name": "app", "NamespaceId": {"Ref": "Namespace"}}
|
||||
},
|
||||
"Cluster": {
|
||||
"Type": "AWS::ECS::Cluster",
|
||||
"Properties": {"ClusterName": "%1$s"}
|
||||
},
|
||||
"TaskDef": {
|
||||
"Type": "AWS::ECS::TaskDefinition",
|
||||
"Properties": {
|
||||
"Family": "%1$s-td",
|
||||
"Cpu": "256",
|
||||
"Memory": "512",
|
||||
"NetworkMode": "awsvpc",
|
||||
"RequiresCompatibilities": ["FARGATE"],
|
||||
"RuntimePlatform": {"CpuArchitecture": {"Ref": "Arch"}, "OperatingSystemFamily": {"Ref": "Os"}},
|
||||
"ContainerDefinitions": [{
|
||||
"Name": "app",
|
||||
"Image": "app:v1",
|
||||
"User": "1000",
|
||||
"HealthCheck": {"Command": ["CMD-SHELL", "true"], "Interval": 30, "Retries": 3}
|
||||
}]
|
||||
}
|
||||
},
|
||||
"Service": {
|
||||
"Type": "AWS::ECS::Service",
|
||||
"Properties": {
|
||||
"ServiceName": "%1$s-svc",
|
||||
"Cluster": {"Ref": "Cluster"},
|
||||
"TaskDefinition": {"Ref": "TaskDef"},
|
||||
"DesiredCount": 1,
|
||||
"CapacityProviderStrategy": [{"CapacityProvider": "FARGATE", "Weight": {"Ref": "Weight"}}],
|
||||
"DeploymentConfiguration": {
|
||||
"MaximumPercent": {"Ref": "MaxPercent"},
|
||||
"MinimumHealthyPercent": 0,
|
||||
"DeploymentCircuitBreaker": {
|
||||
"Enable": {"Ref": "Flag"},
|
||||
"Rollback": true,
|
||||
"ResetOnHealthyTask": false,
|
||||
"ThresholdConfiguration": {"Type": "COUNT", "Value": 3}
|
||||
},
|
||||
"Alarms": {"Fn::Select": [0, [{"AlarmNames": ["high-errors"], "Enable": false, "Rollback": false}]]}
|
||||
},
|
||||
"ServiceRegistries": [{"Fn::Select": [0, [{
|
||||
"RegistryArn": {"Fn::GetAtt": ["Registry", "Arn"]},
|
||||
"Port": {"Fn::If": ["Never", 80, {"Ref": "AWS::NoValue"}]}
|
||||
}]]}],
|
||||
"NetworkConfiguration": {"AwsvpcConfiguration": {"Subnets": ["%2$s"]}}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
@RegisterExtension
|
||||
final PartitionCleanup cleanup = new PartitionCleanup();
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
void createStack_ecsServiceAndTaskDefinition_reportTheDeclaredSettings() {
|
||||
String name = stackName();
|
||||
submit("CreateStack", name, null);
|
||||
assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(name).status());
|
||||
|
||||
ecs("DescribeTaskDefinition", "{\"taskDefinition\": \"" + name + "-td\"}")
|
||||
.body("taskDefinition.runtimePlatform.cpuArchitecture", equalTo("ARM64"))
|
||||
.body("taskDefinition.runtimePlatform.operatingSystemFamily", equalTo("LINUX"))
|
||||
.body("taskDefinition.containerDefinitions[0].user", equalTo("1000"))
|
||||
.body("taskDefinition.containerDefinitions[0].healthCheck.command", equalTo(List.of("CMD-SHELL", "true")))
|
||||
.body("taskDefinition.containerDefinitions[0].healthCheck.interval", equalTo(30))
|
||||
.body("taskDefinition.containerDefinitions[0].healthCheck.retries", equalTo(3));
|
||||
describeService(name)
|
||||
.body("services[0].deploymentConfiguration.maximumPercent", equalTo(150))
|
||||
.body("services[0].deploymentConfiguration.minimumHealthyPercent", equalTo(0))
|
||||
.body("services[0].deploymentConfiguration.deploymentCircuitBreaker.enable", equalTo(true))
|
||||
.body("services[0].deploymentConfiguration.deploymentCircuitBreaker.rollback", equalTo(true))
|
||||
.body("services[0].deploymentConfiguration.deploymentCircuitBreaker.resetOnHealthyTask", equalTo(false))
|
||||
.body("services[0].deploymentConfiguration.deploymentCircuitBreaker.thresholdConfiguration.type",
|
||||
equalTo("COUNT"))
|
||||
.body("services[0].deploymentConfiguration.deploymentCircuitBreaker.thresholdConfiguration.value",
|
||||
equalTo(3))
|
||||
.body("services[0].deploymentConfiguration.alarms.alarmNames", equalTo(List.of("high-errors")))
|
||||
.body("services[0].capacityProviderStrategy[0].capacityProvider", equalTo("FARGATE"))
|
||||
.body("services[0].capacityProviderStrategy[0].weight", equalTo(2))
|
||||
.body("services[0].capacityProviderStrategy[0].base", equalTo(0))
|
||||
.body("services[0].serviceRegistries[0].registryArn", containsString(":servicediscovery:us-east-1:"))
|
||||
.body("services[0].serviceRegistries[0].port", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateStack_ecsService_appliesAChangedSettingAndKeepsTheOthers() {
|
||||
String name = stackName();
|
||||
submit("CreateStack", name, null);
|
||||
assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(name).status());
|
||||
|
||||
submit("UpdateStack", name, "200");
|
||||
assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(name).status());
|
||||
|
||||
describeService(name)
|
||||
.body("services[0].deploymentConfiguration.maximumPercent", equalTo(200))
|
||||
.body("services[0].capacityProviderStrategy[0].weight", equalTo(2))
|
||||
.body("services[0].serviceRegistries[0].registryArn", containsString(":servicediscovery:us-east-1:"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createStack_healthCheckWithoutACommand_failsAsRegisterTaskDefinitionDoes() {
|
||||
String name = stackName();
|
||||
cfn("CreateStack", name)
|
||||
.formParam("TemplateBody", """
|
||||
{"Resources": {"TaskDef": {"Type": "AWS::ECS::TaskDefinition", "Properties": {
|
||||
"ContainerDefinitions": [{"Name": "app", "Image": "app:v1", "HealthCheck": {"Interval": 30}}]
|
||||
}}}}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
assertEquals("ROLLBACK_COMPLETE", CfnStackWaits.awaitTerminal(name).status());
|
||||
assertEquals("HealthCheck command is required.", CfnStackWaits.failedResourceReason(name));
|
||||
}
|
||||
|
||||
private String stackName() {
|
||||
String name = "cfn-ecs-settings-" + Long.toString(System.nanoTime(), 36);
|
||||
cleanup.register(() -> CfnStackWaits.deleteStack(name));
|
||||
return name;
|
||||
}
|
||||
|
||||
/** Submits the template for {@code stackName}, with {@code maxPercent} as its MaxPercent when not null. */
|
||||
private static void submit(String action, String stackName, String maxPercent) {
|
||||
RequestSpecification request = cfn(action, stackName)
|
||||
.formParam("TemplateBody", TEMPLATE.formatted(stackName, Ec2Service.defaultSubnetId("us-east-1", "a")));
|
||||
if (maxPercent != null) {
|
||||
request.formParam("Parameters.member.1.ParameterKey", "MaxPercent")
|
||||
.formParam("Parameters.member.1.ParameterValue", maxPercent);
|
||||
}
|
||||
request
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
private static ValidatableResponse describeService(String name) {
|
||||
return ecs("DescribeServices", "{\"cluster\": \"" + name + "\", \"services\": [\"" + name + "-svc\"]}");
|
||||
}
|
||||
|
||||
private static ValidatableResponse ecs(String action, String body) {
|
||||
return RestAssuredJsonUtils.awsAction(ECS_TARGET, action, body)
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
}
|
||||
+11
@@ -291,6 +291,17 @@ class CloudFormationTemplateEngineTest {
|
||||
engineWithCondition("Include", false).resolveNodeOmittingNoValue(source));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aValueFnSelectChoosesLeavesOutWhatNoValueStandsForInsideIt() {
|
||||
CloudFormationTemplateEngine e = engineWithCondition("Include", false);
|
||||
JsonNode source = json("""
|
||||
{"Fn::Select":[0,[{"Port":{"Fn::If":["Include",80,{"Ref":"AWS::NoValue"}]},
|
||||
"Names":["a",{"Fn::If":["Include","b",{"Ref":"AWS::NoValue"}]}],"Name":""}]]}
|
||||
""");
|
||||
assertEquals(json("{\"Names\":[\"a\"],\"Name\":\"\"}"), e.resolveNode(source));
|
||||
assertEquals(json("\"\""), e.resolveNode(json("{\"Fn::Select\":[0,[{\"Ref\":\"AWS::NoValue\"}]]}")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void optionalNodeResolutionPreservesTheLegacyNoValueContract() {
|
||||
JsonNode noValue = json("{\"Ref\":\"AWS::NoValue\"}");
|
||||
|
||||
+281
-99
@@ -8,15 +8,21 @@ import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.services.cloudformation.CloudFormationTemplateEngine;
|
||||
import io.floci.aws.services.cloudformation.model.StackResource;
|
||||
import io.floci.aws.services.ecs.EcsService;
|
||||
import io.floci.aws.services.ecs.model.CapacityProviderStrategyItem;
|
||||
import io.floci.aws.services.ecs.model.ClusterSetting;
|
||||
import io.floci.aws.services.ecs.model.ContainerDefinition;
|
||||
import io.floci.aws.services.ecs.model.CreateServiceRequest;
|
||||
import io.floci.aws.services.ecs.model.EcsCluster;
|
||||
import io.floci.aws.services.ecs.model.EcsLoadBalancer;
|
||||
import io.floci.aws.services.ecs.model.EcsServiceModel;
|
||||
import io.floci.aws.services.ecs.model.HealthCheck;
|
||||
import io.floci.aws.services.ecs.model.LaunchType;
|
||||
import io.floci.aws.services.ecs.model.NetworkConfiguration;
|
||||
import io.floci.aws.services.ecs.model.NetworkMode;
|
||||
import io.floci.aws.services.ecs.model.RegisterTaskDefinitionRequest;
|
||||
import io.floci.aws.services.ecs.model.RuntimePlatform;
|
||||
import io.floci.aws.services.ecs.model.TaskDefinition;
|
||||
import io.floci.aws.services.ecs.model.UpdateServiceRequest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.NullSource;
|
||||
@@ -40,9 +46,9 @@ import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyList;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.isNull;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
@@ -51,6 +57,7 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -65,6 +72,17 @@ class EcsCfnProvisionerTest {
|
||||
private static final String CLUSTER_ARN = "arn:aws:ecs:us-east-1:000000000000:cluster/web";
|
||||
private static final String TASK_DEF_ARN = "arn:aws:ecs:us-east-1:000000000000:task-definition/web:3";
|
||||
private static final String SERVICE_ARN = "arn:aws:ecs:us-east-1:000000000000:service/web/front";
|
||||
private static final String REGISTRY_ARN = "arn:aws:servicediscovery:us-east-1:000000000000:service/srv-1";
|
||||
private static final List<Map<String, Object>> REGISTRIES =
|
||||
List.of(Map.of("registryArn", REGISTRY_ARN, "containerName", "app", "containerPort", 80));
|
||||
private static final Map<String, Object> DEPLOYMENT_CONFIGURATION = Map.of(
|
||||
"maximumPercent", 150,
|
||||
"minimumHealthyPercent", 50,
|
||||
"deploymentCircuitBreaker", Map.of("enable", true, "rollback", false, "resetOnHealthyTask", false,
|
||||
"thresholdConfiguration", Map.of("type", "COUNT", "value", 3)),
|
||||
"alarms", Map.of("alarmNames", List.of("high-errors"), "enable", true, "rollback", false));
|
||||
private static final List<CapacityProviderStrategyItem> STRATEGY =
|
||||
List.of(new CapacityProviderStrategyItem("FARGATE", 2, 0));
|
||||
|
||||
private final EcsService ecs = mock(EcsService.class);
|
||||
private final EcsCfnProvisioner provisioner = new EcsCfnProvisioner(ecs);
|
||||
@@ -154,9 +172,7 @@ class EcsCfnProvisionerTest {
|
||||
void taskDefinitionRegistersTheParsedContainersAndExposesTheArn() {
|
||||
TaskDefinition td = new TaskDefinition();
|
||||
td.setTaskDefinitionArn(TASK_DEF_ARN);
|
||||
when(ecs.registerTaskDefinition(eq("web"), anyList(), eq(NetworkMode.awsvpc), eq("256"), eq("512"),
|
||||
eq("arn:aws:iam::000000000000:role/task"), eq("arn:aws:iam::000000000000:role/exec"),
|
||||
eq(List.of("FARGATE")), eq(REGION))).thenReturn(td);
|
||||
when(ecs.registerTaskDefinition(any(RegisterTaskDefinitionRequest.class), eq(REGION))).thenReturn(td);
|
||||
|
||||
ObjectNode props = mapper.createObjectNode()
|
||||
.put("Family", "web").put("NetworkMode", "awsvpc").put("Cpu", "256").put("Memory", "512")
|
||||
@@ -179,11 +195,16 @@ class EcsCfnProvisionerTest {
|
||||
|
||||
assertEquals(TASK_DEF_ARN, r.getPhysicalId());
|
||||
assertEquals(TASK_DEF_ARN, r.getAttributes().get("TaskDefinitionArn"));
|
||||
@SuppressWarnings("unchecked")
|
||||
ArgumentCaptor<List<ContainerDefinition>> defs = ArgumentCaptor.forClass(List.class);
|
||||
verify(ecs).registerTaskDefinition(eq("web"), defs.capture(), eq(NetworkMode.awsvpc), eq("256"),
|
||||
eq("512"), anyString(), anyString(), anyList(), eq(REGION));
|
||||
ContainerDefinition def = defs.getValue().get(0);
|
||||
RegisterTaskDefinitionRequest request = registered();
|
||||
assertEquals("web", request.getFamily());
|
||||
assertEquals(NetworkMode.awsvpc, request.getNetworkMode());
|
||||
assertEquals("256", request.getCpu());
|
||||
assertEquals("512", request.getMemory());
|
||||
assertEquals("arn:aws:iam::000000000000:role/task", request.getTaskRoleArn());
|
||||
assertEquals("arn:aws:iam::000000000000:role/exec", request.getExecutionRoleArn());
|
||||
assertEquals(List.of("FARGATE"), request.getRequiresCompatibilities());
|
||||
assertNull(request.getRuntimePlatform());
|
||||
ContainerDefinition def = request.getContainerDefinitions().get(0);
|
||||
assertEquals("app", def.getName());
|
||||
assertEquals("nginx:1", def.getImage());
|
||||
assertEquals(128, def.getCpu());
|
||||
@@ -209,8 +230,7 @@ class EcsCfnProvisionerTest {
|
||||
void taskDefinitionValuesAreReadAsTheEcsHandlerConvertsThem() {
|
||||
TaskDefinition td = new TaskDefinition();
|
||||
td.setTaskDefinitionArn(TASK_DEF_ARN);
|
||||
when(ecs.registerTaskDefinition(eq("web"), anyList(), isNull(), isNull(), isNull(), isNull(), isNull(),
|
||||
anyList(), eq(REGION))).thenReturn(td);
|
||||
when(ecs.registerTaskDefinition(any(RegisterTaskDefinitionRequest.class), eq(REGION))).thenReturn(td);
|
||||
ObjectNode props = mapper.createObjectNode().put("Family", "web");
|
||||
props.putArray("ContainerDefinitions").addObject()
|
||||
.put("Name", "app").put("Image", "nginx:1").put("Cpu", " 64").put("Memory", "+128")
|
||||
@@ -218,11 +238,11 @@ class EcsCfnProvisionerTest {
|
||||
|
||||
provisioner.provision(resource("AWS::ECS::TaskDefinition", "TaskDef"), props, ctx());
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ArgumentCaptor<List<ContainerDefinition>> defs = ArgumentCaptor.forClass(List.class);
|
||||
verify(ecs).registerTaskDefinition(eq("web"), defs.capture(), isNull(), isNull(), isNull(), isNull(),
|
||||
isNull(), anyList(), eq(REGION));
|
||||
ContainerDefinition def = defs.getValue().get(0);
|
||||
RegisterTaskDefinitionRequest request = registered();
|
||||
assertEquals("web", request.getFamily());
|
||||
assertNull(request.getNetworkMode());
|
||||
assertNull(request.getCpu());
|
||||
ContainerDefinition def = request.getContainerDefinitions().get(0);
|
||||
assertEquals(64, def.getCpu());
|
||||
assertEquals(128, def.getMemory());
|
||||
assertFalse(def.isEssential());
|
||||
@@ -243,8 +263,7 @@ class EcsCfnProvisionerTest {
|
||||
void containerLinuxParametersReachTheTaskDefinitionInTheApiShape() {
|
||||
TaskDefinition td = new TaskDefinition();
|
||||
td.setTaskDefinitionArn(TASK_DEF_ARN);
|
||||
when(ecs.registerTaskDefinition(anyString(), anyList(), any(), any(), any(), any(), any(), anyList(),
|
||||
eq(REGION))).thenReturn(td);
|
||||
when(ecs.registerTaskDefinition(any(RegisterTaskDefinitionRequest.class), eq(REGION))).thenReturn(td);
|
||||
|
||||
ObjectNode props = mapper.createObjectNode().put("Family", "web");
|
||||
ObjectNode container = props.putArray("ContainerDefinitions").addObject()
|
||||
@@ -281,8 +300,7 @@ class EcsCfnProvisionerTest {
|
||||
void linuxParametersGivenAsTextAreReadAsTheEcsHandlerConvertsThem() {
|
||||
TaskDefinition td = new TaskDefinition();
|
||||
td.setTaskDefinitionArn(TASK_DEF_ARN);
|
||||
when(ecs.registerTaskDefinition(anyString(), anyList(), any(), any(), any(), any(), any(), anyList(),
|
||||
eq(REGION))).thenReturn(td);
|
||||
when(ecs.registerTaskDefinition(any(RegisterTaskDefinitionRequest.class), eq(REGION))).thenReturn(td);
|
||||
|
||||
ObjectNode props = mapper.createObjectNode().put("Family", "web");
|
||||
props.putArray("ContainerDefinitions").addObject().put("Name", "app").put("Image", "nginx:1")
|
||||
@@ -299,8 +317,7 @@ class EcsCfnProvisionerTest {
|
||||
void aContainerWithoutLinuxParametersCarriesNone() {
|
||||
TaskDefinition td = new TaskDefinition();
|
||||
td.setTaskDefinitionArn(TASK_DEF_ARN);
|
||||
when(ecs.registerTaskDefinition(anyString(), anyList(), any(), any(), any(), any(), any(), anyList(),
|
||||
eq(REGION))).thenReturn(td);
|
||||
when(ecs.registerTaskDefinition(any(RegisterTaskDefinitionRequest.class), eq(REGION))).thenReturn(td);
|
||||
|
||||
ObjectNode props = mapper.createObjectNode().put("Family", "web");
|
||||
props.putArray("ContainerDefinitions").addObject().put("Name", "app").put("Image", "nginx:1");
|
||||
@@ -309,34 +326,50 @@ class EcsCfnProvisionerTest {
|
||||
assertNull(registeredContainer().getUnparsed());
|
||||
}
|
||||
|
||||
private RegisterTaskDefinitionRequest registered() {
|
||||
ArgumentCaptor<RegisterTaskDefinitionRequest> request = ArgumentCaptor.forClass(RegisterTaskDefinitionRequest.class);
|
||||
verify(ecs).registerTaskDefinition(request.capture(), eq(REGION));
|
||||
return request.getValue();
|
||||
}
|
||||
|
||||
/** A CreateService request for {@code service} in {@code cluster} that declares TASK_DEF_ARN and nothing else. */
|
||||
private static CreateServiceRequest creating(String cluster, String service) {
|
||||
return argThat(request -> request != null && cluster.equals(request.getCluster())
|
||||
&& service.equals(request.getServiceName()) && TASK_DEF_ARN.equals(request.getTaskDefinition())
|
||||
&& request.getDesiredCount() == 1 && request.getLaunchType() == null
|
||||
&& request.getNetworkConfiguration() == null);
|
||||
}
|
||||
|
||||
/** An UpdateService request for {@code service} in {@code cluster} with this task definition and desired count. */
|
||||
private static UpdateServiceRequest updating(String cluster, String service, String taskDefinition,
|
||||
int desiredCount) {
|
||||
return argThat(request -> request != null && cluster.equals(request.getCluster())
|
||||
&& service.equals(request.getService()) && taskDefinition.equals(request.getTaskDefinition())
|
||||
&& Integer.valueOf(desiredCount).equals(request.getDesiredCount())
|
||||
&& request.getNetworkConfiguration() == null);
|
||||
}
|
||||
|
||||
private ContainerDefinition registeredContainer() {
|
||||
@SuppressWarnings("unchecked")
|
||||
ArgumentCaptor<List<ContainerDefinition>> defs = ArgumentCaptor.forClass(List.class);
|
||||
verify(ecs).registerTaskDefinition(anyString(), defs.capture(), any(), any(), any(), any(), any(),
|
||||
anyList(), eq(REGION));
|
||||
return defs.getValue().get(0);
|
||||
return registered().getContainerDefinitions().get(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void taskDefinitionWithoutFamilyGeneratesOneAndIgnoresAnUnknownNetworkMode() {
|
||||
TaskDefinition td = new TaskDefinition();
|
||||
td.setTaskDefinitionArn(TASK_DEF_ARN);
|
||||
when(ecs.registerTaskDefinition(anyString(), anyList(), isNull(), isNull(), isNull(), isNull(), isNull(),
|
||||
anyList(), eq(REGION))).thenReturn(td);
|
||||
when(ecs.registerTaskDefinition(any(RegisterTaskDefinitionRequest.class), eq(REGION))).thenReturn(td);
|
||||
|
||||
StackResource r = resource("AWS::ECS::TaskDefinition", "TaskDef");
|
||||
provisioner.provision(r, mapper.createObjectNode().put("NetworkMode", "not-a-mode"), ctx());
|
||||
|
||||
ArgumentCaptor<String> family = ArgumentCaptor.forClass(String.class);
|
||||
verify(ecs).registerTaskDefinition(family.capture(), anyList(), isNull(), isNull(), isNull(), isNull(),
|
||||
isNull(), anyList(), eq(REGION));
|
||||
assertTrue(family.getValue().startsWith("my-stack-TaskDef-"), family.getValue());
|
||||
RegisterTaskDefinitionRequest request = registered();
|
||||
assertTrue(request.getFamily().startsWith("my-stack-TaskDef-"), request.getFamily());
|
||||
assertNull(request.getNetworkMode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void serviceIsCreatedWithTheParsedLoadBalancersAndNetwork() {
|
||||
when(ecs.createService(eq("web"), eq("front"), eq(TASK_DEF_ARN), eq(2), eq(LaunchType.FARGATE),
|
||||
anyList(), any(), eq(REGION))).thenReturn(service("front"));
|
||||
when(ecs.createService(any(CreateServiceRequest.class), eq(REGION))).thenReturn(service("front"));
|
||||
ObjectNode props = mapper.createObjectNode()
|
||||
.put("Cluster", "web").put("ServiceName", "front").put("TaskDefinition", TASK_DEF_ARN)
|
||||
.put("DesiredCount", "2").put("LaunchType", "FARGATE");
|
||||
@@ -354,20 +387,27 @@ class EcsCfnProvisionerTest {
|
||||
assertEquals("front", r.getAttributes().get("Name"));
|
||||
assertEquals(SERVICE_ARN, r.getAttributes().get("ServiceArn"));
|
||||
assertEquals(Set.of("Name", "ServiceArn"), r.getAttributes().keySet());
|
||||
@SuppressWarnings("unchecked")
|
||||
ArgumentCaptor<List<EcsLoadBalancer>> lbs = ArgumentCaptor.forClass(List.class);
|
||||
ArgumentCaptor<NetworkConfiguration> net = ArgumentCaptor.forClass(NetworkConfiguration.class);
|
||||
verify(ecs).createService(eq("web"), eq("front"), eq(TASK_DEF_ARN), eq(2), eq(LaunchType.FARGATE),
|
||||
lbs.capture(), net.capture(), eq(REGION));
|
||||
assertEquals("app", lbs.getValue().get(0).getContainerName());
|
||||
assertEquals(80, lbs.getValue().get(0).getContainerPort());
|
||||
assertEquals(List.of("subnet-1", "subnet-2"), net.getValue().getAwsvpcConfiguration().getSubnets());
|
||||
assertEquals("ENABLED", net.getValue().getAwsvpcConfiguration().getAssignPublicIp());
|
||||
ArgumentCaptor<CreateServiceRequest> request = ArgumentCaptor.forClass(CreateServiceRequest.class);
|
||||
verify(ecs).createService(request.capture(), eq(REGION));
|
||||
assertEquals("web", request.getValue().getCluster());
|
||||
assertEquals("front", request.getValue().getServiceName());
|
||||
assertEquals(TASK_DEF_ARN, request.getValue().getTaskDefinition());
|
||||
assertEquals(2, request.getValue().getDesiredCount());
|
||||
assertEquals(LaunchType.FARGATE, request.getValue().getLaunchType());
|
||||
assertNull(request.getValue().getServiceRegistries());
|
||||
assertNull(request.getValue().getDeploymentConfiguration());
|
||||
assertNull(request.getValue().getCapacityProviderStrategy());
|
||||
List<EcsLoadBalancer> lbs = request.getValue().getLoadBalancers();
|
||||
assertEquals("app", lbs.get(0).getContainerName());
|
||||
assertEquals(80, lbs.get(0).getContainerPort());
|
||||
NetworkConfiguration net = request.getValue().getNetworkConfiguration();
|
||||
assertEquals(List.of("subnet-1", "subnet-2"), net.getAwsvpcConfiguration().getSubnets());
|
||||
assertEquals("ENABLED", net.getAwsvpcConfiguration().getAssignPublicIp());
|
||||
}
|
||||
|
||||
@Test
|
||||
void anUnchangedServiceIsUpdatedInPlaceOnTheSecondPass() {
|
||||
when(ecs.updateService(eq("web"), eq("front"), eq(TASK_DEF_ARN), eq(3), isNull(), eq(REGION)))
|
||||
when(ecs.updateService(updating("web", "front", TASK_DEF_ARN, 3), eq(REGION)))
|
||||
.thenReturn(service("front"));
|
||||
StackResource r = resource("AWS::ECS::Service", "Service");
|
||||
r.getAttributes().put("Name", "front");
|
||||
@@ -378,14 +418,13 @@ class EcsCfnProvisionerTest {
|
||||
provisioner.provision(r, props, ctx(SERVICE_ARN));
|
||||
|
||||
assertEquals(SERVICE_ARN, r.getPhysicalId());
|
||||
verify(ecs).updateService("web", "front", TASK_DEF_ARN, 3, null, REGION);
|
||||
verify(ecs, never()).createService(anyString(), anyString(), anyString(), anyInt(), any(), anyList(),
|
||||
any(), anyString());
|
||||
verify(ecs).updateService(updating("web", "front", TASK_DEF_ARN, 3), eq(REGION));
|
||||
verify(ecs, never()).createService(any(CreateServiceRequest.class), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void anUnnamedServiceKeepsTheNameItGotAtCreateTime() {
|
||||
when(ecs.updateService(eq("web"), eq("my-stack-Service-abc"), eq(TASK_DEF_ARN), eq(1), isNull(), eq(REGION)))
|
||||
when(ecs.updateService(updating("web", "my-stack-Service-abc", TASK_DEF_ARN, 1), eq(REGION)))
|
||||
.thenReturn(service("my-stack-Service-abc"));
|
||||
StackResource r = resource("AWS::ECS::Service", "Service");
|
||||
r.getAttributes().put("Name", "my-stack-Service-abc");
|
||||
@@ -393,13 +432,12 @@ class EcsCfnProvisionerTest {
|
||||
provisioner.provision(r, mapper.createObjectNode().put("Cluster", "web").put("TaskDefinition", TASK_DEF_ARN),
|
||||
ctx("arn:aws:ecs:us-east-1:000000000000:service/web/my-stack-Service-abc"));
|
||||
|
||||
verify(ecs).updateService("web", "my-stack-Service-abc", TASK_DEF_ARN, 1, null, REGION);
|
||||
verify(ecs).updateService(updating("web", "my-stack-Service-abc", TASK_DEF_ARN, 1), eq(REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aRenamedServiceIsCreatedAsAReplacement() {
|
||||
when(ecs.createService(eq("web"), eq("front-v2"), eq(TASK_DEF_ARN), eq(1), isNull(), anyList(), isNull(),
|
||||
eq(REGION))).thenReturn(service("front-v2"));
|
||||
when(ecs.createService(creating("web", "front-v2"), eq(REGION))).thenReturn(service("front-v2"));
|
||||
StackResource r = resource("AWS::ECS::Service", "Service");
|
||||
r.getAttributes().put("Name", "front");
|
||||
|
||||
@@ -409,15 +447,14 @@ class EcsCfnProvisionerTest {
|
||||
|
||||
assertNotEquals(SERVICE_ARN, r.getPhysicalId());
|
||||
assertEquals("front-v2", r.getAttributes().get("Name"));
|
||||
verify(ecs, never()).updateService(anyString(), anyString(), anyString(), anyInt(), any(), anyString());
|
||||
verify(ecs, never()).updateService(any(UpdateServiceRequest.class), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aServiceMovedToAnotherClusterIsCreatedAsAReplacementAndTheOldOneCleanedUpAfterCommit() {
|
||||
EcsServiceModel moved = service("front");
|
||||
moved.setServiceArn("arn:aws:ecs:us-east-1:000000000000:service/batch/front");
|
||||
when(ecs.createService(eq("batch"), eq("front"), eq(TASK_DEF_ARN), eq(1), isNull(), anyList(), isNull(),
|
||||
eq(REGION))).thenReturn(moved);
|
||||
when(ecs.createService(creating("batch", "front"), eq(REGION))).thenReturn(moved);
|
||||
StackResource r = resource("AWS::ECS::Service", "Service");
|
||||
r.getAttributes().put("Name", "front");
|
||||
|
||||
@@ -426,7 +463,7 @@ class EcsCfnProvisionerTest {
|
||||
|
||||
// Cluster is create-only: same name, other cluster is a replacement, never an in-place update
|
||||
// against a service the new cluster may not have (or may have under another owner).
|
||||
verify(ecs, never()).updateService(anyString(), anyString(), anyString(), anyInt(), any(), anyString());
|
||||
verify(ecs, never()).updateService(any(UpdateServiceRequest.class), anyString());
|
||||
assertEquals(moved.getServiceArn(), r.getPhysicalId());
|
||||
assertTrue(provisioner.hasReplacementUpdate(r));
|
||||
assertEquals(SERVICE_ARN, provisioner.updateCleanupPhysicalId(r));
|
||||
@@ -434,8 +471,7 @@ class EcsCfnProvisionerTest {
|
||||
UpdateCleanupResult cleanup = provisioner.completeUpdate(r);
|
||||
|
||||
InOrder order = inOrder(ecs);
|
||||
order.verify(ecs).createService(eq("batch"), eq("front"), eq(TASK_DEF_ARN), eq(1), isNull(), anyList(), isNull(),
|
||||
eq(REGION));
|
||||
order.verify(ecs).createService(creating("batch", "front"), eq(REGION));
|
||||
order.verify(ecs).deleteService("web", "front", true, REGION);
|
||||
assertEquals(new UpdateCleanupResult(true, true, SERVICE_ARN, 0, null), cleanup);
|
||||
provisioner.clearUpdate(r);
|
||||
@@ -444,7 +480,7 @@ class EcsCfnProvisionerTest {
|
||||
|
||||
@Test
|
||||
void theClusterGivenAsAnArnStillCountsAsTheSameCluster() {
|
||||
when(ecs.updateService(eq(CLUSTER_ARN), eq("front"), eq(TASK_DEF_ARN), eq(1), isNull(), eq(REGION)))
|
||||
when(ecs.updateService(updating(CLUSTER_ARN, "front", TASK_DEF_ARN, 1), eq(REGION)))
|
||||
.thenReturn(service("front"));
|
||||
StackResource r = resource("AWS::ECS::Service", "Service");
|
||||
r.getAttributes().put("Name", "front");
|
||||
@@ -452,23 +488,21 @@ class EcsCfnProvisionerTest {
|
||||
provisioner.provision(r, mapper.createObjectNode()
|
||||
.put("Cluster", CLUSTER_ARN).put("ServiceName", "front").put("TaskDefinition", TASK_DEF_ARN), ctx(SERVICE_ARN));
|
||||
|
||||
verify(ecs).updateService(CLUSTER_ARN, "front", TASK_DEF_ARN, 1, null, REGION);
|
||||
verify(ecs).updateService(updating(CLUSTER_ARN, "front", TASK_DEF_ARN, 1), eq(REGION));
|
||||
assertFalse(provisioner.hasReplacementUpdate(r), "an in-place update owes no cleanup");
|
||||
}
|
||||
|
||||
@Test
|
||||
void aCreatedServiceIsAwaitedUntilStableBeforeTheResourceCompletes() {
|
||||
EcsServiceModel created = service("front");
|
||||
when(ecs.createService(eq("web"), eq("front"), eq(TASK_DEF_ARN), eq(1), isNull(), anyList(), isNull(),
|
||||
eq(REGION))).thenReturn(created);
|
||||
when(ecs.createService(creating("web", "front"), eq(REGION))).thenReturn(created);
|
||||
StackResource r = resource("AWS::ECS::Service", "Service");
|
||||
|
||||
provisioner.provision(r, mapper.createObjectNode()
|
||||
.put("Cluster", "web").put("ServiceName", "front").put("TaskDefinition", TASK_DEF_ARN), ctx());
|
||||
|
||||
InOrder order = inOrder(ecs);
|
||||
order.verify(ecs).createService(eq("web"), eq("front"), eq(TASK_DEF_ARN), eq(1), isNull(), anyList(),
|
||||
isNull(), eq(REGION));
|
||||
order.verify(ecs).createService(creating("web", "front"), eq(REGION));
|
||||
order.verify(ecs).awaitServiceStable(created);
|
||||
assertEquals(Set.of("Name", "ServiceArn"), r.getAttributes().keySet(),
|
||||
"a stable service is no longer marked for the create rollback");
|
||||
@@ -477,7 +511,7 @@ class EcsCfnProvisionerTest {
|
||||
@Test
|
||||
void anInPlaceUpdateIsAwaitedUntilStableBeforeTheResourceCompletes() {
|
||||
EcsServiceModel updated = service("front");
|
||||
when(ecs.updateService(eq("web"), eq("front"), eq(TASK_DEF_ARN), eq(3), isNull(), eq(REGION)))
|
||||
when(ecs.updateService(updating("web", "front", TASK_DEF_ARN, 3), eq(REGION)))
|
||||
.thenReturn(updated);
|
||||
StackResource r = resource("AWS::ECS::Service", "Service");
|
||||
r.getAttributes().put("Name", "front");
|
||||
@@ -487,15 +521,14 @@ class EcsCfnProvisionerTest {
|
||||
.put("DesiredCount", "3"), ctx(SERVICE_ARN));
|
||||
|
||||
InOrder order = inOrder(ecs);
|
||||
order.verify(ecs).updateService("web", "front", TASK_DEF_ARN, 3, null, REGION);
|
||||
order.verify(ecs).updateService(updating("web", "front", TASK_DEF_ARN, 3), eq(REGION));
|
||||
order.verify(ecs).awaitServiceStable(updated);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aCreatedServiceThatDoesNotStabilizeFailsAndStaysOwnedForTheCreateRollback() {
|
||||
EcsServiceModel created = service("front");
|
||||
when(ecs.createService(eq("web"), eq("front"), eq(TASK_DEF_ARN), eq(1), isNull(), anyList(), isNull(),
|
||||
eq(REGION))).thenReturn(created);
|
||||
when(ecs.createService(creating("web", "front"), eq(REGION))).thenReturn(created);
|
||||
doThrow(new AwsException("NotStabilized", "Service " + SERVICE_ARN + " did not stabilize.", 500))
|
||||
.when(ecs).awaitServiceStable(created);
|
||||
StackResource r = resource("AWS::ECS::Service", "Service");
|
||||
@@ -513,8 +546,7 @@ class EcsCfnProvisionerTest {
|
||||
@Test
|
||||
void aReplacementThatDoesNotStabilizeIsDeletedBeforeTheUpdateFails() {
|
||||
EcsServiceModel replacement = service("front-v2");
|
||||
when(ecs.createService(eq("web"), eq("front-v2"), eq(TASK_DEF_ARN), eq(1), isNull(), anyList(), isNull(),
|
||||
eq(REGION))).thenReturn(replacement);
|
||||
when(ecs.createService(creating("web", "front-v2"), eq(REGION))).thenReturn(replacement);
|
||||
doThrow(new AwsException("NotStabilized", "did not stabilize", 500))
|
||||
.when(ecs).awaitServiceStable(replacement);
|
||||
StackResource r = resource("AWS::ECS::Service", "Service");
|
||||
@@ -535,8 +567,7 @@ class EcsCfnProvisionerTest {
|
||||
@Test
|
||||
void aReplacementThatCannotBeDeletedEitherReportsTheRollbackFailure() {
|
||||
EcsServiceModel replacement = service("front-v2");
|
||||
when(ecs.createService(eq("web"), eq("front-v2"), eq(TASK_DEF_ARN), eq(1), isNull(), anyList(), isNull(),
|
||||
eq(REGION))).thenReturn(replacement);
|
||||
when(ecs.createService(creating("web", "front-v2"), eq(REGION))).thenReturn(replacement);
|
||||
AwsException notStable = new AwsException("NotStabilized", "did not stabilize", 500);
|
||||
doThrow(notStable).when(ecs).awaitServiceStable(replacement);
|
||||
doThrow(new AwsException("ServerException", "busy", 500))
|
||||
@@ -561,11 +592,11 @@ class EcsCfnProvisionerTest {
|
||||
prior.setDesiredCount(1);
|
||||
when(ecs.serviceByArn(SERVICE_ARN)).thenReturn(prior);
|
||||
EcsServiceModel updated = service("front");
|
||||
when(ecs.updateService(eq("web"), eq("front"), eq(TASK_DEF_ARN), eq(3), isNull(), eq(REGION)))
|
||||
when(ecs.updateService(updating("web", "front", TASK_DEF_ARN, 3), eq(REGION)))
|
||||
.thenReturn(updated);
|
||||
AwsException notStable = new AwsException("NotStabilized", "did not stabilize", 500);
|
||||
doThrow(notStable).when(ecs).awaitServiceStable(updated);
|
||||
when(ecs.updateService("web", "front", TASK_DEF_ARN, 1, null, REGION))
|
||||
when(ecs.updateService(updating("web", "front", TASK_DEF_ARN, 1), eq(REGION)))
|
||||
.thenThrow(new AwsException("ServerException", "busy", 500));
|
||||
StackResource r = resource("AWS::ECS::Service", "Service");
|
||||
r.getAttributes().put("Name", "front");
|
||||
@@ -576,7 +607,7 @@ class EcsCfnProvisionerTest {
|
||||
|
||||
assertEquals(notStable, e, "the stabilization failure is what fails the update");
|
||||
assertEquals("busy", e.getSuppressed()[0].getMessage());
|
||||
verify(ecs).updateService("web", "front", TASK_DEF_ARN, 1, null, REGION);
|
||||
verify(ecs).updateService(updating("web", "front", TASK_DEF_ARN, 1), eq(REGION));
|
||||
assertTrue(r.getAttributes().get(CfnRollback.UPDATE_ROLLBACK_FAILURE_ATTR).contains(SERVICE_ARN));
|
||||
}
|
||||
|
||||
@@ -587,10 +618,10 @@ class EcsCfnProvisionerTest {
|
||||
prior.setDesiredCount(1);
|
||||
when(ecs.serviceByArn(SERVICE_ARN)).thenReturn(prior);
|
||||
EcsServiceModel updated = service("front");
|
||||
when(ecs.updateService("web", "front", TASK_DEF_ARN, 3, null, REGION)).thenReturn(updated);
|
||||
when(ecs.updateService(updating("web", "front", TASK_DEF_ARN, 3), eq(REGION))).thenReturn(updated);
|
||||
doThrow(new AwsException("NotStabilized", "did not stabilize", 500)).when(ecs).awaitServiceStable(updated);
|
||||
EcsServiceModel restored = service("front");
|
||||
when(ecs.updateService("web", "front", TASK_DEF_ARN, 1, null, REGION)).thenReturn(restored);
|
||||
when(ecs.updateService(updating("web", "front", TASK_DEF_ARN, 1), eq(REGION))).thenReturn(restored);
|
||||
StackResource r = resource("AWS::ECS::Service", "Service");
|
||||
r.getAttributes().put("Name", "front");
|
||||
|
||||
@@ -599,7 +630,7 @@ class EcsCfnProvisionerTest {
|
||||
.put("DesiredCount", "3"), ctx(SERVICE_ARN)));
|
||||
|
||||
InOrder order = inOrder(ecs);
|
||||
order.verify(ecs).updateService("web", "front", TASK_DEF_ARN, 1, null, REGION);
|
||||
order.verify(ecs).updateService(updating("web", "front", TASK_DEF_ARN, 1), eq(REGION));
|
||||
order.verify(ecs).awaitServiceStable(restored);
|
||||
assertNull(r.getAttributes().get(CfnRollback.UPDATE_ROLLBACK_FAILURE_ATTR));
|
||||
}
|
||||
@@ -611,11 +642,11 @@ class EcsCfnProvisionerTest {
|
||||
prior.setDesiredCount(1);
|
||||
when(ecs.serviceByArn(SERVICE_ARN)).thenReturn(prior);
|
||||
EcsServiceModel updated = service("front");
|
||||
when(ecs.updateService("web", "front", TASK_DEF_ARN, 3, null, REGION)).thenReturn(updated);
|
||||
when(ecs.updateService(updating("web", "front", TASK_DEF_ARN, 3), eq(REGION))).thenReturn(updated);
|
||||
AwsException notStable = new AwsException("NotStabilized", "did not stabilize", 500);
|
||||
doThrow(notStable).when(ecs).awaitServiceStable(updated);
|
||||
EcsServiceModel restored = service("front");
|
||||
when(ecs.updateService("web", "front", TASK_DEF_ARN, 1, null, REGION)).thenReturn(restored);
|
||||
when(ecs.updateService(updating("web", "front", TASK_DEF_ARN, 1), eq(REGION))).thenReturn(restored);
|
||||
doThrow(new AwsException("NotStabilized", "restore did not stabilize", 500))
|
||||
.when(ecs).awaitServiceStable(restored);
|
||||
StackResource r = resource("AWS::ECS::Service", "Service");
|
||||
@@ -634,8 +665,7 @@ class EcsCfnProvisionerTest {
|
||||
void aTaskDefinitionUpdateDeregistersTheDisplacedRevisionAfterCommit() {
|
||||
TaskDefinition next = new TaskDefinition();
|
||||
next.setTaskDefinitionArn(TASK_DEF_ARN.replace(":3", ":4"));
|
||||
when(ecs.registerTaskDefinition(eq("web"), anyList(), isNull(), isNull(), isNull(), isNull(), isNull(), anyList(),
|
||||
eq(REGION))).thenReturn(next);
|
||||
when(ecs.registerTaskDefinition(any(RegisterTaskDefinitionRequest.class), eq(REGION))).thenReturn(next);
|
||||
StackResource r = resource("AWS::ECS::TaskDefinition", "TaskDef");
|
||||
|
||||
provisioner.provision(r, mapper.createObjectNode().put("Family", "web"), ctx(TASK_DEF_ARN));
|
||||
@@ -650,8 +680,7 @@ class EcsCfnProvisionerTest {
|
||||
void aRetainedDisplacedEntityIsNotDeletedAndAFailingDeleteIsRetriedThreeTimes() {
|
||||
TaskDefinition next = new TaskDefinition();
|
||||
next.setTaskDefinitionArn(TASK_DEF_ARN.replace(":3", ":4"));
|
||||
when(ecs.registerTaskDefinition(eq("web"), anyList(), isNull(), isNull(), isNull(), isNull(), isNull(), anyList(),
|
||||
eq(REGION))).thenReturn(next);
|
||||
when(ecs.registerTaskDefinition(any(RegisterTaskDefinitionRequest.class), eq(REGION))).thenReturn(next);
|
||||
|
||||
StackResource retained = resource("AWS::ECS::TaskDefinition", "TaskDef");
|
||||
retained.setUpdateReplacePolicy("Retain");
|
||||
@@ -679,8 +708,7 @@ class EcsCfnProvisionerTest {
|
||||
void aFailedStackUpdateRollsAReplacementBackToThePriorServiceAndDeletesTheReplacement() {
|
||||
EcsServiceModel moved = service("front");
|
||||
moved.setServiceArn("arn:aws:ecs:us-east-1:000000000000:service/batch/front");
|
||||
when(ecs.createService(eq("batch"), eq("front"), eq(TASK_DEF_ARN), eq(1), isNull(), anyList(), isNull(),
|
||||
eq(REGION))).thenReturn(moved);
|
||||
when(ecs.createService(creating("batch", "front"), eq(REGION))).thenReturn(moved);
|
||||
StackResource r = resource("AWS::ECS::Service", "Service");
|
||||
r.getAttributes().put("Name", "front");
|
||||
r.getAttributes().put("ServiceArn", SERVICE_ARN);
|
||||
@@ -955,7 +983,7 @@ class EcsCfnProvisionerTest {
|
||||
|
||||
@Test
|
||||
void anInPlaceUpdateIsNotRolledBackHere() {
|
||||
when(ecs.updateService(eq("web"), eq("front"), eq(TASK_DEF_ARN), eq(3), isNull(), eq(REGION)))
|
||||
when(ecs.updateService(updating("web", "front", TASK_DEF_ARN, 3), eq(REGION)))
|
||||
.thenReturn(service("front"));
|
||||
StackResource r = resource("AWS::ECS::Service", "Service");
|
||||
r.getAttributes().put("Name", "front");
|
||||
@@ -972,8 +1000,7 @@ class EcsCfnProvisionerTest {
|
||||
void aRollbackWhoseDeleteFailsStillPointsTheResourceAtThePriorAndPropagates() {
|
||||
TaskDefinition next = new TaskDefinition();
|
||||
next.setTaskDefinitionArn(TASK_DEF_ARN.replace(":3", ":4"));
|
||||
when(ecs.registerTaskDefinition(eq("web"), anyList(), isNull(), isNull(), isNull(), isNull(), isNull(), anyList(),
|
||||
eq(REGION))).thenReturn(next);
|
||||
when(ecs.registerTaskDefinition(any(RegisterTaskDefinitionRequest.class), eq(REGION))).thenReturn(next);
|
||||
doThrow(new AwsException("ServerException", "busy", 500)).when(ecs).deregisterTaskDefinition(next.getTaskDefinitionArn(), REGION);
|
||||
StackResource r = resource("AWS::ECS::TaskDefinition", "TaskDef");
|
||||
r.getAttributes().put("TaskDefinitionArn", TASK_DEF_ARN);
|
||||
@@ -999,8 +1026,7 @@ class EcsCfnProvisionerTest {
|
||||
String orphan = TASK_DEF_ARN.replace(":3", ":4");
|
||||
TaskDefinition next = new TaskDefinition();
|
||||
next.setTaskDefinitionArn(orphan);
|
||||
when(ecs.registerTaskDefinition(eq("web"), anyList(), isNull(), isNull(), isNull(), isNull(), isNull(), anyList(),
|
||||
eq(REGION))).thenReturn(next);
|
||||
when(ecs.registerTaskDefinition(any(RegisterTaskDefinitionRequest.class), eq(REGION))).thenReturn(next);
|
||||
doThrow(new AwsException("ServerException", "busy", 500)).when(ecs).deregisterTaskDefinition(orphan, REGION);
|
||||
StackResource r = resource("AWS::ECS::TaskDefinition", "TaskDef");
|
||||
r.getAttributes().put("TaskDefinitionArn", TASK_DEF_ARN);
|
||||
@@ -1016,8 +1042,7 @@ class EcsCfnProvisionerTest {
|
||||
// and the committed cleanup deletes both, never the live revision.
|
||||
TaskDefinition fifth = new TaskDefinition();
|
||||
fifth.setTaskDefinitionArn(TASK_DEF_ARN.replace(":3", ":5"));
|
||||
when(ecs.registerTaskDefinition(eq("web"), anyList(), isNull(), isNull(), isNull(), isNull(), isNull(), anyList(),
|
||||
eq(REGION))).thenReturn(fifth);
|
||||
when(ecs.registerTaskDefinition(any(RegisterTaskDefinitionRequest.class), eq(REGION))).thenReturn(fifth);
|
||||
provisioner.provision(r, mapper.createObjectNode().put("Family", "web"), ctx(TASK_DEF_ARN));
|
||||
Mockito.reset(ecs);
|
||||
UpdateCleanupResult cleanup = provisioner.completeUpdate(r);
|
||||
@@ -1033,8 +1058,7 @@ class EcsCfnProvisionerTest {
|
||||
String orphan = TASK_DEF_ARN.replace(":3", ":4");
|
||||
TaskDefinition next = new TaskDefinition();
|
||||
next.setTaskDefinitionArn(orphan);
|
||||
when(ecs.registerTaskDefinition(eq("web"), anyList(), isNull(), isNull(), isNull(), isNull(), isNull(), anyList(),
|
||||
eq(REGION))).thenReturn(next);
|
||||
when(ecs.registerTaskDefinition(any(RegisterTaskDefinitionRequest.class), eq(REGION))).thenReturn(next);
|
||||
doThrow(new AwsException("ServerException", "busy", 500)).when(ecs).deregisterTaskDefinition(orphan, REGION);
|
||||
StackResource r = resource("AWS::ECS::TaskDefinition", "TaskDef");
|
||||
r.getAttributes().put("TaskDefinitionArn", TASK_DEF_ARN);
|
||||
@@ -1049,8 +1073,7 @@ class EcsCfnProvisionerTest {
|
||||
// A later replacement adds revision 3 to the list; its delete also fails at first.
|
||||
TaskDefinition fifth = new TaskDefinition();
|
||||
fifth.setTaskDefinitionArn(TASK_DEF_ARN.replace(":3", ":5"));
|
||||
when(ecs.registerTaskDefinition(eq("web"), anyList(), isNull(), isNull(), isNull(), isNull(), isNull(), anyList(),
|
||||
eq(REGION))).thenReturn(fifth);
|
||||
when(ecs.registerTaskDefinition(any(RegisterTaskDefinitionRequest.class), eq(REGION))).thenReturn(fifth);
|
||||
provisioner.provision(r, mapper.createObjectNode().put("Family", "web"), ctx(TASK_DEF_ARN));
|
||||
doThrow(new AwsException("ServerException", "busy", 500)).when(ecs).deregisterTaskDefinition(TASK_DEF_ARN, REGION);
|
||||
|
||||
@@ -1079,8 +1102,7 @@ class EcsCfnProvisionerTest {
|
||||
String orphan = TASK_DEF_ARN.replace(":3", ":4");
|
||||
TaskDefinition next = new TaskDefinition();
|
||||
next.setTaskDefinitionArn(orphan);
|
||||
when(ecs.registerTaskDefinition(eq("web"), anyList(), isNull(), isNull(), isNull(), isNull(), isNull(), anyList(),
|
||||
eq(REGION))).thenReturn(next);
|
||||
when(ecs.registerTaskDefinition(any(RegisterTaskDefinitionRequest.class), eq(REGION))).thenReturn(next);
|
||||
doThrow(new AwsException("ServerException", "busy", 500)).when(ecs).deregisterTaskDefinition(orphan, REGION);
|
||||
StackResource r = resource("AWS::ECS::TaskDefinition", "TaskDef");
|
||||
r.getAttributes().put("TaskDefinitionArn", TASK_DEF_ARN);
|
||||
@@ -1094,6 +1116,166 @@ class EcsCfnProvisionerTest {
|
||||
assertEquals(orphan, provisioner.updateCleanupPhysicalId(r));
|
||||
}
|
||||
|
||||
@Test
|
||||
void taskDefinitionForwardsTheRuntimePlatformAndEachContainersUserAndHealthCheck() {
|
||||
TaskDefinition td = new TaskDefinition();
|
||||
td.setTaskDefinitionArn(TASK_DEF_ARN);
|
||||
when(ecs.registerTaskDefinition(any(RegisterTaskDefinitionRequest.class), eq(REGION))).thenReturn(td);
|
||||
ObjectNode props = mapper.createObjectNode().put("Family", "web");
|
||||
props.putObject("RuntimePlatform").put("CpuArchitecture", "X86_64").put("OperatingSystemFamily", "LINUX");
|
||||
ObjectNode healthCheck = props.putArray("ContainerDefinitions").addObject()
|
||||
.put("Name", "app").put("Image", "nginx:1").put("User", "1000")
|
||||
.putObject("HealthCheck").put("Interval", "30").put("Timeout", 5).put("Retries", 3);
|
||||
healthCheck.putArray("Command").add("CMD-SHELL").add("true");
|
||||
|
||||
provisioner.provision(resource("AWS::ECS::TaskDefinition", "TaskDef"), props, ctx());
|
||||
|
||||
RegisterTaskDefinitionRequest request = registered();
|
||||
assertEquals(new RuntimePlatform("X86_64", "LINUX"), request.getRuntimePlatform());
|
||||
ContainerDefinition def = request.getContainerDefinitions().get(0);
|
||||
assertEquals("1000", def.getUser());
|
||||
assertEquals(new HealthCheck(List.of("CMD-SHELL", "true"), 30, 5, 3, null), def.getHealthCheck());
|
||||
}
|
||||
|
||||
@Test
|
||||
void serviceSettingsGivenAsTextAreForwardedConvertedOnCreate() {
|
||||
when(ecs.createService(any(CreateServiceRequest.class), eq(REGION))).thenReturn(service("front"));
|
||||
|
||||
provisioner.provision(resource("AWS::ECS::Service", "Service"), withServiceSettings(mapper.createObjectNode()
|
||||
.put("Cluster", "web").put("ServiceName", "front").put("TaskDefinition", TASK_DEF_ARN)), ctx());
|
||||
|
||||
ArgumentCaptor<CreateServiceRequest> request = ArgumentCaptor.forClass(CreateServiceRequest.class);
|
||||
verify(ecs).createService(request.capture(), eq(REGION));
|
||||
assertEquals(REGISTRIES, request.getValue().getServiceRegistries());
|
||||
assertEquals(DEPLOYMENT_CONFIGURATION, request.getValue().getDeploymentConfiguration());
|
||||
assertEquals(STRATEGY, request.getValue().getCapacityProviderStrategy());
|
||||
}
|
||||
|
||||
@Test
|
||||
void serviceSettingsAreForwardedOnAnInPlaceUpdate() {
|
||||
when(ecs.updateService(any(UpdateServiceRequest.class), eq(REGION))).thenReturn(service("front"));
|
||||
StackResource r = resource("AWS::ECS::Service", "Service");
|
||||
r.getAttributes().put("Name", "front");
|
||||
|
||||
provisioner.provision(r, withServiceSettings(mapper.createObjectNode()
|
||||
.put("Cluster", "web").put("ServiceName", "front").put("TaskDefinition", TASK_DEF_ARN)), ctx(SERVICE_ARN));
|
||||
|
||||
ArgumentCaptor<UpdateServiceRequest> request = ArgumentCaptor.forClass(UpdateServiceRequest.class);
|
||||
verify(ecs).updateService(request.capture(), eq(REGION));
|
||||
assertEquals(REGISTRIES, request.getValue().getServiceRegistries());
|
||||
assertEquals(DEPLOYMENT_CONFIGURATION, request.getValue().getDeploymentConfiguration());
|
||||
assertEquals(STRATEGY, request.getValue().getCapacityProviderStrategy());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aStrategyEntryResolvedToNoValueIsSkipped() {
|
||||
when(ecs.createService(any(CreateServiceRequest.class), eq(REGION))).thenReturn(service("front"));
|
||||
ObjectNode props = mapper.createObjectNode()
|
||||
.put("Cluster", "web").put("ServiceName", "front").put("TaskDefinition", TASK_DEF_ARN);
|
||||
// The empty text is what Ref AWS::NoValue resolves to inside a list.
|
||||
props.putArray("CapacityProviderStrategy").add("")
|
||||
.addObject().put("CapacityProvider", "FARGATE").put("Weight", "2");
|
||||
|
||||
provisioner.provision(resource("AWS::ECS::Service", "Service"), props, ctx());
|
||||
|
||||
ArgumentCaptor<CreateServiceRequest> request = ArgumentCaptor.forClass(CreateServiceRequest.class);
|
||||
verify(ecs).createService(request.capture(), eq(REGION));
|
||||
assertEquals(STRATEGY, request.getValue().getCapacityProviderStrategy());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aStrategyWhoseEveryEntryResolvedToNoValueIsNone() {
|
||||
when(ecs.createService(any(CreateServiceRequest.class), eq(REGION))).thenReturn(service("front"));
|
||||
ObjectNode props = mapper.createObjectNode()
|
||||
.put("Cluster", "web").put("ServiceName", "front").put("TaskDefinition", TASK_DEF_ARN);
|
||||
props.putArray("CapacityProviderStrategy").add("");
|
||||
|
||||
provisioner.provision(resource("AWS::ECS::Service", "Service"), props, ctx());
|
||||
|
||||
ArgumentCaptor<CreateServiceRequest> request = ArgumentCaptor.forClass(CreateServiceRequest.class);
|
||||
verify(ecs).createService(request.capture(), eq(REGION));
|
||||
assertNull(request.getValue().getCapacityProviderStrategy());
|
||||
}
|
||||
|
||||
@Test
|
||||
void settingsTheTemplateDoesNotDeclareAreLeftUnchangedByAnUpdateAndItsRestore() {
|
||||
EcsServiceModel prior = service("front");
|
||||
prior.setServiceRegistries(REGISTRIES);
|
||||
when(ecs.serviceByArn(SERVICE_ARN)).thenReturn(prior);
|
||||
EcsServiceModel updated = service("front");
|
||||
when(ecs.updateService(any(UpdateServiceRequest.class), eq(REGION))).thenReturn(updated);
|
||||
doThrow(new AwsException("NotStabilized", "did not stabilize", 500)).when(ecs).awaitServiceStable(updated);
|
||||
StackResource r = resource("AWS::ECS::Service", "Service");
|
||||
r.getAttributes().put("Name", "front");
|
||||
|
||||
assertThrows(AwsException.class, () -> provisioner.provision(r, mapper.createObjectNode()
|
||||
.put("Cluster", "web").put("ServiceName", "front").put("TaskDefinition", TASK_DEF_ARN), ctx(SERVICE_ARN)));
|
||||
|
||||
ArgumentCaptor<UpdateServiceRequest> requests = ArgumentCaptor.forClass(UpdateServiceRequest.class);
|
||||
verify(ecs, times(2)).updateService(requests.capture(), eq(REGION));
|
||||
for (UpdateServiceRequest request : requests.getAllValues()) {
|
||||
// An empty list would deregister the service's tasks and roll a deployment.
|
||||
assertNull(request.getServiceRegistries());
|
||||
assertNull(request.getDeploymentConfiguration());
|
||||
assertNull(request.getCapacityProviderStrategy());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void anInPlaceUpdateThatDoesNotStabilizePutsThePriorSettingsBack() {
|
||||
List<CapacityProviderStrategyItem> priorStrategy = List.of(new CapacityProviderStrategyItem("FARGATE_SPOT", 1, 0));
|
||||
EcsServiceModel prior = service("front");
|
||||
prior.setTaskDefinition(TASK_DEF_ARN);
|
||||
prior.setDesiredCount(1);
|
||||
prior.setCapacityProviderStrategy(priorStrategy);
|
||||
when(ecs.serviceByArn(SERVICE_ARN)).thenReturn(prior);
|
||||
EcsServiceModel updated = service("front");
|
||||
EcsServiceModel restored = service("front");
|
||||
when(ecs.updateService(any(UpdateServiceRequest.class), eq(REGION))).thenAnswer(inv -> {
|
||||
UpdateServiceRequest request = inv.getArgument(0);
|
||||
// UpdateService changes the very model the prior settings were read from.
|
||||
prior.setDeploymentConfiguration(request.getDeploymentConfiguration());
|
||||
prior.setCapacityProviderStrategy(request.getCapacityProviderStrategy());
|
||||
prior.setServiceRegistries(request.getServiceRegistries());
|
||||
return request.getDesiredCount() == 3 ? updated : restored;
|
||||
});
|
||||
doThrow(new AwsException("NotStabilized", "did not stabilize", 500)).when(ecs).awaitServiceStable(updated);
|
||||
StackResource r = resource("AWS::ECS::Service", "Service");
|
||||
r.getAttributes().put("Name", "front");
|
||||
|
||||
assertThrows(AwsException.class, () -> provisioner.provision(r, withServiceSettings(mapper.createObjectNode()
|
||||
.put("Cluster", "web").put("ServiceName", "front").put("TaskDefinition", TASK_DEF_ARN)
|
||||
.put("DesiredCount", "3")), ctx(SERVICE_ARN)));
|
||||
|
||||
ArgumentCaptor<UpdateServiceRequest> requests = ArgumentCaptor.forClass(UpdateServiceRequest.class);
|
||||
verify(ecs, times(2)).updateService(requests.capture(), eq(REGION));
|
||||
UpdateServiceRequest restore = requests.getAllValues().get(1);
|
||||
assertEquals(1, restore.getDesiredCount());
|
||||
assertEquals(Map.of(), restore.getDeploymentConfiguration(), "a deployment configuration the update added is removed");
|
||||
assertEquals(priorStrategy, restore.getCapacityProviderStrategy());
|
||||
assertEquals(List.of(), restore.getServiceRegistries(), "a registry the update added is deregistered");
|
||||
verify(ecs).awaitServiceStable(restored);
|
||||
assertNull(r.getAttributes().get(CfnRollback.UPDATE_ROLLBACK_FAILURE_ATTR));
|
||||
}
|
||||
|
||||
/**
|
||||
* The three service settings, every scalar the text a {@code String} parameter resolves to,
|
||||
* the booleans in each case CloudFormation's handler accepts.
|
||||
*/
|
||||
private static ObjectNode withServiceSettings(ObjectNode props) {
|
||||
props.putArray("ServiceRegistries").addObject()
|
||||
.put("RegistryArn", REGISTRY_ARN).put("ContainerName", "app").put("ContainerPort", "80");
|
||||
ObjectNode deployment = props.putObject("DeploymentConfiguration")
|
||||
.put("MaximumPercent", "150").put("MinimumHealthyPercent", "50");
|
||||
ObjectNode breaker = deployment.putObject("DeploymentCircuitBreaker")
|
||||
.put("Enable", "True").put("Rollback", "false").put("ResetOnHealthyTask", "false");
|
||||
breaker.putObject("ThresholdConfiguration").put("Type", "COUNT").put("Value", "3");
|
||||
deployment.putObject("Alarms").put("Enable", "TRUE").put("Rollback", "False")
|
||||
.putArray("AlarmNames").add("high-errors");
|
||||
props.putArray("CapacityProviderStrategy").addObject().put("CapacityProvider", "FARGATE").put("Weight", "2");
|
||||
return props;
|
||||
}
|
||||
|
||||
@Test
|
||||
void aNonIntegerDesiredCountIsAValidationError() {
|
||||
StackResource r = resource("AWS::ECS::Service", "Service");
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.floci.aws.config.EmulatorConfig;
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.services.ecs.container.EcsContainerManager;
|
||||
import io.floci.aws.services.ecs.container.HostVolumePolicy;
|
||||
import io.floci.aws.services.ecs.model.RegisterTaskDefinitionRequest;
|
||||
import io.floci.aws.services.ecs.model.TaskDefinition;
|
||||
@@ -26,7 +28,8 @@ import static org.mockito.Mockito.when;
|
||||
* Unit tests for the RegisterTaskDefinition JSON wire path in {@link EcsJsonHandler}:
|
||||
* container-level {@code healthCheck} must be parsed from the request, stored on the
|
||||
* container definition, and serialized back in the response with the AWS wire shape,
|
||||
* and must stay absent from the response when the request omitted it.
|
||||
* and must stay absent from the response when the request omitted it. A health check without
|
||||
* a command is refused by {@link EcsService}, so the refusal is checked through a real one.
|
||||
*/
|
||||
class EcsJsonHandlerHealthCheckTest {
|
||||
|
||||
@@ -167,9 +170,10 @@ class EcsJsonHandlerHealthCheckTest {
|
||||
JsonNode request = objectMapper.readTree(requestJson);
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
handler.handle("RegisterTaskDefinition", request, "us-east-1"));
|
||||
handlerOverARealService().handle("RegisterTaskDefinition", request, "us-east-1"));
|
||||
assertEquals("ClientException", ex.getErrorCode());
|
||||
assertEquals(400, ex.getHttpStatus());
|
||||
assertEquals("HealthCheck command is required.", ex.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -191,8 +195,17 @@ class EcsJsonHandlerHealthCheckTest {
|
||||
JsonNode request = objectMapper.readTree(requestJson);
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
handler.handle("RegisterTaskDefinition", request, "us-east-1"));
|
||||
handlerOverARealService().handle("RegisterTaskDefinition", request, "us-east-1"));
|
||||
assertEquals("ClientException", ex.getErrorCode());
|
||||
assertEquals(400, ex.getHttpStatus());
|
||||
assertEquals("HealthCheck command is required.", ex.getMessage());
|
||||
}
|
||||
|
||||
private EcsJsonHandler handlerOverARealService() {
|
||||
EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
|
||||
when(config.services().ecs().mock()).thenReturn(true);
|
||||
EcsService service = new EcsService(new RegionResolver("us-east-1", "000000000000"),
|
||||
mock(EcsContainerManager.class), config, mock(EcsLoadBalancerRegistrar.class), null, null);
|
||||
return new EcsJsonHandler(service, objectMapper, new HostVolumePolicy(config));
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package io.floci.aws.services.ecs;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.floci.aws.config.EmulatorConfig;
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.storage.AccountAwareStorageBackend;
|
||||
import io.floci.aws.core.storage.StorageBackend;
|
||||
@@ -34,6 +35,7 @@ import static org.awaitility.Awaitility.await;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
@@ -258,6 +260,24 @@ class EcsServiceDeploymentCircuitBreakerTest {
|
||||
assertEquals(List.of("new-alarm"), deployment.getTriggeredAlarmNames());
|
||||
}
|
||||
|
||||
@Test
|
||||
void anUpdateNamingATaskDefinitionThatDoesNotResolveChangesNothing() {
|
||||
EcsService service = newService();
|
||||
EcsServiceModel model = createService(service, "cb-unresolved", 1, null);
|
||||
UpdateServiceRequest request = new UpdateServiceRequest();
|
||||
request.setCluster("cb-unresolved-cluster");
|
||||
request.setService("cb-unresolved");
|
||||
request.setDesiredCount(3);
|
||||
request.setDeploymentConfiguration(Map.of("deploymentCircuitBreaker", breaker(true, false)));
|
||||
request.setTaskDefinition("cb-missing-fam");
|
||||
|
||||
assertThrows(AwsException.class, () -> service.updateService(request, REGION));
|
||||
|
||||
EcsServiceModel svc = service.serviceByArn(model.getServiceArn());
|
||||
assertEquals(1, svc.getDesiredCount());
|
||||
assertNull(svc.getDeploymentConfiguration());
|
||||
}
|
||||
|
||||
/** A failed initial deployment has no successful revision to roll back to. */
|
||||
@Test
|
||||
void withRollbackOnAnInitialDeploymentEndsAsRollbackFailed() {
|
||||
|
||||
@@ -262,8 +262,6 @@ AWS::ECS::Cluster DefaultCapacityProviderStrategy accepted and ignored
|
||||
AWS::ECS::Cluster ServiceConnectDefaults accepted and ignored
|
||||
AWS::ECS::Cluster Tags accepted and ignored
|
||||
AWS::ECS::Service AvailabilityZoneRebalancing accepted and ignored
|
||||
AWS::ECS::Service CapacityProviderStrategy accepted and ignored
|
||||
AWS::ECS::Service DeploymentConfiguration accepted and ignored
|
||||
AWS::ECS::Service DeploymentController accepted and ignored
|
||||
AWS::ECS::Service EnableECSManagedTags accepted and ignored
|
||||
AWS::ECS::Service EnableExecuteCommand accepted and ignored
|
||||
@@ -278,7 +276,6 @@ AWS::ECS::Service PropagateTags accepted and ignored
|
||||
AWS::ECS::Service Role accepted and ignored
|
||||
AWS::ECS::Service SchedulingStrategy accepted and ignored
|
||||
AWS::ECS::Service ServiceConnectConfiguration accepted and ignored
|
||||
AWS::ECS::Service ServiceRegistries accepted and ignored
|
||||
AWS::ECS::Service Tags accepted and ignored
|
||||
AWS::ECS::Service VolumeConfigurations accepted and ignored
|
||||
AWS::ECS::Service VpcLatticeConfigurations accepted and ignored
|
||||
@@ -288,7 +285,6 @@ AWS::ECS::TaskDefinition IpcMode accepted and ignored
|
||||
AWS::ECS::TaskDefinition PidMode accepted and ignored
|
||||
AWS::ECS::TaskDefinition PlacementConstraints accepted and ignored
|
||||
AWS::ECS::TaskDefinition ProxyConfiguration accepted and ignored
|
||||
AWS::ECS::TaskDefinition RuntimePlatform accepted and ignored
|
||||
AWS::ECS::TaskDefinition Tags accepted and ignored
|
||||
AWS::ECS::TaskDefinition Volumes accepted and ignored
|
||||
AWS::EKS::Cluster AccessConfig accepted and ignored
|
||||
|
||||
|
Reference in new issue
Block a user