mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(ecs): keep task definitions and their revisions per region (#5078)
* fix(ecs): keep task definitions and their revisions per region Task definitions were keyed family:revision and revision counters by family alone, so registering a family in one region bumped its revision in every other, and ListTaskDefinitions, ListTaskDefinitionFamilies and the describe, deregister and delete lookups saw every region's definitions. Both stores now key by region (region::family:revision, region::family), as clusters already do, and every read keeps to the request region. A definition's region is read from its own ARN, so definitions persisted under the old keys still resolve; the next write re-files one under its new key, so none is listed twice. * fix(ecs): drop a task definition's old storage key only for that same definition The old family:revision key named no region, so re-filing a definition under its region's key removed whatever sat under that old key, even another region's not-yet-migrated definition. The old entry is now removed only when its ARN is the definition being written; EcsTaskDefinitionLegacyKeyTest seeds an old-key definition and covers both the re-filing and another region's registration of the same family and revision. * fix(ecs): read a task definition's region without failing on an unreadable ARN Every task definition list and lookup read each definition's region with AwsArnUtils.parse, which throws on a null or malformed ARN, so one bad stored record failed every call. The region now comes from regionOrDefault, as elsewhere in the tree: a definition whose ARN cannot be read counts as the request's region, and ListTaskDefinitions skips one with no ARN to list. * fix(ecs): keep a task definition with an unreadable ARN in the default region The fallback for a definition whose ARN cannot be read was the requesting region, so such a definition was seen from every region: its family's next revision in any region counted it, and lists and lookups everywhere included it. It now belongs to the default region, as a task with an unreadable ARN already does, so it still breaks no lookup and is seen in one region only. EcsTaskDefinitionLegacyKeyTest covers the same family registered in another region.
This commit is contained in:
1 parent
d9b2707ad4
commit
e22e24a810
4 files changed
+334
-30
No files matched your search
@@ -332,7 +332,7 @@ public class EcsJsonHandler {
|
||||
Integer maxResults = req.hasNonNull("maxResults") ? req.path("maxResults").asInt() : null;
|
||||
String nextToken = req.hasNonNull("nextToken") ? req.path("nextToken").asText() : null;
|
||||
|
||||
EcsService.ListPage page = service.listTaskDefinitions(familyPrefix, status, sort,
|
||||
EcsService.ListPage page = service.listTaskDefinitions(region, familyPrefix, status, sort,
|
||||
maxResults, nextToken);
|
||||
|
||||
ObjectNode resp = objectMapper.createObjectNode();
|
||||
@@ -351,7 +351,7 @@ public class EcsJsonHandler {
|
||||
Integer maxResults = req.hasNonNull("maxResults") ? req.path("maxResults").asInt() : null;
|
||||
String nextToken = req.hasNonNull("nextToken") ? req.path("nextToken").asText() : null;
|
||||
|
||||
EcsService.ListPage page = service.listTaskDefinitionFamilies(familyPrefix, status,
|
||||
EcsService.ListPage page = service.listTaskDefinitionFamilies(region, familyPrefix, status,
|
||||
maxResults, nextToken);
|
||||
|
||||
ObjectNode resp = objectMapper.createObjectNode();
|
||||
|
||||
@@ -129,9 +129,9 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
|
||||
// region::clusterName → EcsCluster
|
||||
private Map<String, EcsCluster> clusters = new ConcurrentHashMap<>();
|
||||
// family:revision → TaskDefinition
|
||||
// region::family:revision → TaskDefinition (entries persisted before regions were keyed: family:revision)
|
||||
private Map<String, TaskDefinition> taskDefinitions = new ConcurrentHashMap<>();
|
||||
// family → latest revision number
|
||||
// region::family → latest revision number
|
||||
private Map<String, Integer> latestRevisions = new ConcurrentHashMap<>();
|
||||
// taskArn → EcsTask
|
||||
private final Map<String, EcsTask> tasks = new ConcurrentHashMap<>();
|
||||
@@ -695,7 +695,8 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
validateFargateUnsupportedParameters(request);
|
||||
}
|
||||
String family = request.getFamily();
|
||||
int revision = latestRevisions.merge(family, 1, Integer::sum);
|
||||
int revision = latestRevisions.compute(familyKey(region, family),
|
||||
(key, latest) -> (latest != null ? latest : latestRevision(region, family)) + 1);
|
||||
|
||||
TaskDefinition td = new TaskDefinition();
|
||||
td.setFamily(family);
|
||||
@@ -726,7 +727,7 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
td.setTags(new LinkedHashMap<>(request.getTags()));
|
||||
}
|
||||
|
||||
taskDefinitions.put(family + ":" + revision, td);
|
||||
storeTaskDefinition(td);
|
||||
LOG.infov("Registered task definition: {0}:{1}", family, revision);
|
||||
return td;
|
||||
}
|
||||
@@ -1100,17 +1101,13 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
* at registration, so fields set on the returned instance need this to survive a restart.
|
||||
*/
|
||||
public void persistTaskDefinition(TaskDefinition td) {
|
||||
taskDefinitions.put(td.getFamily() + ":" + td.getRevision(), td);
|
||||
storeTaskDefinition(td);
|
||||
}
|
||||
|
||||
public TaskDefinition describeTaskDefinition(String taskDefinitionRef, String region) {
|
||||
return resolveTaskDefinitionOrThrow(taskDefinitionRef, region);
|
||||
}
|
||||
|
||||
public List<String> listTaskDefinitions(String familyPrefix, String status) {
|
||||
return listTaskDefinitions(familyPrefix, status, null, null, null).arns();
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists task definition ARNs.
|
||||
*
|
||||
@@ -1119,7 +1116,7 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
* family comes last (or first under {@code DESC}). Listing by ARN string alone would put
|
||||
* revision 10 before revision 2.
|
||||
*/
|
||||
public ListPage listTaskDefinitions(String familyPrefix, String status, String sort,
|
||||
public ListPage listTaskDefinitions(String region, String familyPrefix, String status, String sort,
|
||||
Integer maxResults, String nextToken) {
|
||||
String effectiveStatus = status != null ? status : STATUS_ACTIVE;
|
||||
Comparator<TaskDefinition> order = Comparator
|
||||
@@ -1128,7 +1125,8 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
if ("DESC".equals(sort)) {
|
||||
order = order.reversed();
|
||||
}
|
||||
List<String> arns = taskDefinitions.values().stream()
|
||||
List<String> arns = taskDefinitionsIn(region)
|
||||
.filter(td -> td.getTaskDefinitionArn() != null)
|
||||
.filter(td -> familyPrefix == null || td.getFamily().startsWith(familyPrefix))
|
||||
.filter(td -> effectiveStatus.equals(td.getStatus()))
|
||||
.sorted(order)
|
||||
@@ -1137,10 +1135,6 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
return paginate(arns, maxResults, nextToken);
|
||||
}
|
||||
|
||||
public List<String> listTaskDefinitionFamilies(String familyPrefix) {
|
||||
return listTaskDefinitionFamilies(familyPrefix, null, null, null).arns();
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists task definition family names.
|
||||
*
|
||||
@@ -1149,21 +1143,23 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
* those that have none. A family survives the deregistration of all its revisions, which is
|
||||
* why the unfiltered listing still names it.
|
||||
*/
|
||||
public ListPage listTaskDefinitionFamilies(String familyPrefix, String status,
|
||||
public ListPage listTaskDefinitionFamilies(String region, String familyPrefix, String status,
|
||||
Integer maxResults, String nextToken) {
|
||||
List<String> families = latestRevisions.keySet().stream()
|
||||
List<String> families = taskDefinitionsIn(region)
|
||||
.map(TaskDefinition::getFamily)
|
||||
.distinct()
|
||||
.filter(f -> familyPrefix == null || f.startsWith(familyPrefix))
|
||||
.filter(f -> matchesFamilyStatus(f, status))
|
||||
.filter(f -> matchesFamilyStatus(region, f, status))
|
||||
.sorted()
|
||||
.toList();
|
||||
return paginate(families, maxResults, nextToken);
|
||||
}
|
||||
|
||||
private boolean matchesFamilyStatus(String family, String status) {
|
||||
private boolean matchesFamilyStatus(String region, String family, String status) {
|
||||
if (status == null || "ALL".equals(status)) {
|
||||
return true;
|
||||
}
|
||||
boolean hasActiveRevision = taskDefinitions.values().stream()
|
||||
boolean hasActiveRevision = taskDefinitionsIn(region)
|
||||
.anyMatch(td -> family.equals(td.getFamily()) && STATUS_ACTIVE.equals(td.getStatus()));
|
||||
return STATUS_ACTIVE.equals(status) == hasActiveRevision;
|
||||
}
|
||||
@@ -1172,7 +1168,7 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
TaskDefinition td = resolveTaskDefinitionOrThrow(taskDefinitionRef, region);
|
||||
td.setStatus(STATUS_INACTIVE);
|
||||
td.setDeregisteredAt(Instant.now());
|
||||
taskDefinitions.put(td.getFamily() + ":" + td.getRevision(), td);
|
||||
storeTaskDefinition(td);
|
||||
return td;
|
||||
}
|
||||
|
||||
@@ -1202,7 +1198,7 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
}
|
||||
td.setStatus(STATUS_DELETE_IN_PROGRESS);
|
||||
td.setDeleteRequestedAt(Instant.now());
|
||||
taskDefinitions.put(td.getFamily() + ":" + td.getRevision(), td);
|
||||
storeTaskDefinition(td);
|
||||
deleted.add(td);
|
||||
}
|
||||
return deleted;
|
||||
@@ -5268,20 +5264,60 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
}
|
||||
|
||||
private TaskDefinition resolveTaskDefinitionOrThrow(String ref, String region) {
|
||||
TaskDefinition td = taskDefinitions.get(ref);
|
||||
TaskDefinition td = taskDefinitions.get(familyKey(region, ref));
|
||||
if (td != null) { return td; }
|
||||
td = taskDefinitions.values().stream()
|
||||
.filter(d -> d.getTaskDefinitionArn().equals(ref))
|
||||
td = taskDefinitionsIn(region)
|
||||
.filter(d -> d.getTaskDefinitionArn().equals(ref)
|
||||
|| (d.getFamily() + ":" + d.getRevision()).equals(ref))
|
||||
.findFirst().orElse(null);
|
||||
if (td != null) { return td; }
|
||||
Integer latest = latestRevisions.get(ref);
|
||||
if (latest != null) {
|
||||
td = taskDefinitions.get(ref + ":" + latest);
|
||||
int latest = latestRevision(region, ref);
|
||||
if (latest > 0) {
|
||||
td = taskDefinitions.get(taskDefinitionKey(region, ref, latest));
|
||||
if (td != null) { return td; }
|
||||
td = taskDefinitionsIn(region)
|
||||
.filter(d -> ref.equals(d.getFamily()) && d.getRevision() == latest)
|
||||
.findFirst().orElse(null);
|
||||
if (td != null) { return td; }
|
||||
}
|
||||
throw new AwsException("ClientException", "Unable to describe task definition: " + ref, 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores a task definition under its region's key. A definition persisted before the key
|
||||
* carried the region is re-filed on its next write, so it never appears twice. The old key
|
||||
* named no region, so it is dropped only when it holds this same definition: the same
|
||||
* family and revision in another region is a different definition.
|
||||
*/
|
||||
private void storeTaskDefinition(TaskDefinition td) {
|
||||
String legacyKey = td.getFamily() + ":" + td.getRevision();
|
||||
TaskDefinition legacy = taskDefinitions.get(legacyKey);
|
||||
if (legacy != null && Objects.equals(td.getTaskDefinitionArn(), legacy.getTaskDefinitionArn())) {
|
||||
taskDefinitions.remove(legacyKey);
|
||||
}
|
||||
taskDefinitions.put(taskDefinitionKey(regionOf(td), td.getFamily(), td.getRevision()), td);
|
||||
}
|
||||
|
||||
/** Task definitions are regional; the region is read from each one's ARN, whatever its storage key. */
|
||||
private Stream<TaskDefinition> taskDefinitionsIn(String region) {
|
||||
return taskDefinitions.values().stream().filter(td -> region.equals(regionOf(td)));
|
||||
}
|
||||
|
||||
private int latestRevision(String region, String family) {
|
||||
return taskDefinitionsIn(region)
|
||||
.filter(td -> family.equals(td.getFamily()))
|
||||
.mapToInt(TaskDefinition::getRevision)
|
||||
.max().orElse(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* The region in a definition's ARN. One whose ARN cannot be read belongs to the default region, as a
|
||||
* task does ({@link #taskRegion}): it breaks no lookup, and it is seen in one region rather than all.
|
||||
*/
|
||||
private String regionOf(TaskDefinition td) {
|
||||
return AwsArnUtils.regionOrDefault(td.getTaskDefinitionArn(), regionResolver.getDefaultRegion());
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a task definition for something that is about to run on it. A revision on its way
|
||||
* out cannot start new work: AWS refuses to run a task or create a service on a
|
||||
@@ -5383,6 +5419,14 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
return region + "::" + clusterName;
|
||||
}
|
||||
|
||||
private static String familyKey(String region, String family) {
|
||||
return region + "::" + family;
|
||||
}
|
||||
|
||||
private static String taskDefinitionKey(String region, String family, int revision) {
|
||||
return familyKey(region, family) + ":" + revision;
|
||||
}
|
||||
|
||||
private static String serviceKey(String region, String clusterName, String serviceName) {
|
||||
return region + "::" + clusterName + "/" + serviceName;
|
||||
}
|
||||
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
package io.github.hectorvent.floci.services.ecs;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.ecs.container.EcsContainerManager;
|
||||
import io.github.hectorvent.floci.services.ecs.model.ContainerDefinition;
|
||||
import io.github.hectorvent.floci.services.ecs.model.TaskDefinition;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Task definitions persisted before their storage key carried the region ({@code family:revision})
|
||||
* stay in their own region: they still resolve there, are re-filed on their next write, and are not
|
||||
* dropped when another region registers the same family and revision.
|
||||
*/
|
||||
class EcsTaskDefinitionLegacyKeyTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String OTHER = "eu-west-1";
|
||||
private static final String FAMILY = "legacy-fam";
|
||||
private static final String LEGACY_ARN =
|
||||
"arn:aws:ecs:" + REGION + ":000000000000:task-definition/" + FAMILY + ":1";
|
||||
|
||||
@Test
|
||||
void anotherRegionsRegistrationKeepsALegacyDefinition() {
|
||||
InMemoryStorageFactory storage = new InMemoryStorageFactory();
|
||||
storage.taskDefinitions().put(FAMILY + ":1", legacyDefinition());
|
||||
EcsService service = newService(storage);
|
||||
|
||||
TaskDefinition other = register(service, OTHER);
|
||||
|
||||
assertEquals(1, other.getRevision());
|
||||
assertEquals(List.of(LEGACY_ARN), arns(service, REGION));
|
||||
assertEquals(List.of(other.getTaskDefinitionArn()), arns(service, OTHER));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aLegacyDefinitionIsRefiledOnItsNextWriteAndListedOnce() {
|
||||
InMemoryStorageFactory storage = new InMemoryStorageFactory();
|
||||
storage.taskDefinitions().put(FAMILY + ":1", legacyDefinition());
|
||||
EcsService service = newService(storage);
|
||||
|
||||
service.deregisterTaskDefinition(FAMILY + ":1", REGION);
|
||||
|
||||
assertEquals(List.of(REGION + "::" + FAMILY + ":1"), List.copyOf(storage.taskDefinitions().keys()));
|
||||
assertEquals(List.of(LEGACY_ARN), service.listTaskDefinitions(REGION, FAMILY, "INACTIVE", null, null, null)
|
||||
.arns());
|
||||
assertEquals(2, register(service, REGION).getRevision());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aStoredDefinitionWithoutAnArnBreaksNoLookup() {
|
||||
InMemoryStorageFactory storage = new InMemoryStorageFactory();
|
||||
TaskDefinition unreadable = legacyDefinition();
|
||||
unreadable.setFamily(FAMILY + "-unreadable");
|
||||
unreadable.setTaskDefinitionArn(null);
|
||||
storage.taskDefinitions().put(FAMILY + "-unreadable:1", unreadable);
|
||||
EcsService service = newService(storage);
|
||||
|
||||
TaskDefinition registered = register(service, REGION);
|
||||
|
||||
assertEquals(List.of(registered.getTaskDefinitionArn()), arns(service, REGION));
|
||||
assertEquals(registered.getTaskDefinitionArn(),
|
||||
service.describeTaskDefinition(FAMILY + ":1", REGION).getTaskDefinitionArn());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aStoredDefinitionWithoutAnArnStaysInTheDefaultRegion() {
|
||||
InMemoryStorageFactory storage = new InMemoryStorageFactory();
|
||||
TaskDefinition unreadable = legacyDefinition();
|
||||
unreadable.setTaskDefinitionArn(null);
|
||||
storage.taskDefinitions().put(FAMILY + ":1", unreadable);
|
||||
EcsService service = newService(storage);
|
||||
|
||||
TaskDefinition other = register(service, OTHER);
|
||||
|
||||
assertEquals(1, other.getRevision());
|
||||
assertEquals(other.getTaskDefinitionArn(),
|
||||
service.describeTaskDefinition(FAMILY + ":1", OTHER).getTaskDefinitionArn());
|
||||
assertEquals(List.of(other.getTaskDefinitionArn()), arns(service, OTHER));
|
||||
assertEquals(2, register(service, REGION).getRevision());
|
||||
}
|
||||
|
||||
private static TaskDefinition legacyDefinition() {
|
||||
TaskDefinition td = new TaskDefinition();
|
||||
td.setFamily(FAMILY);
|
||||
td.setRevision(1);
|
||||
td.setStatus("ACTIVE");
|
||||
td.setTaskDefinitionArn(LEGACY_ARN);
|
||||
return td;
|
||||
}
|
||||
|
||||
private static TaskDefinition register(EcsService service, String region) {
|
||||
ContainerDefinition cd = new ContainerDefinition();
|
||||
cd.setName("app");
|
||||
cd.setImage("app:1");
|
||||
return service.registerTaskDefinition(FAMILY, List.of(cd), null, null, null, null, null, List.of(), region);
|
||||
}
|
||||
|
||||
private static List<String> arns(EcsService service, String region) {
|
||||
return service.listTaskDefinitions(region, FAMILY, null, null, null, null).arns();
|
||||
}
|
||||
|
||||
private static EcsService newService(StorageFactory storage) {
|
||||
EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
|
||||
when(config.services().ecs().mock()).thenReturn(true);
|
||||
when(config.effectiveBaseUrl()).thenReturn("http://localhost:4566");
|
||||
EcsService service = new EcsService(
|
||||
new RegionResolver(REGION, "000000000000"),
|
||||
mock(EcsContainerManager.class),
|
||||
config,
|
||||
mock(EcsLoadBalancerRegistrar.class),
|
||||
storage,
|
||||
null);
|
||||
service.initializeStorage();
|
||||
return service;
|
||||
}
|
||||
|
||||
private static final class InMemoryStorageFactory extends StorageFactory {
|
||||
private final Map<String, StorageBackend<String, ?>> stores = new HashMap<>();
|
||||
|
||||
private InMemoryStorageFactory() {
|
||||
super(null, null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
AccountAwareStorageBackend<TaskDefinition> taskDefinitions() {
|
||||
return (AccountAwareStorageBackend<TaskDefinition>) stores.computeIfAbsent("ecs-task-definitions.json",
|
||||
ignored -> AccountAwareStorageBackend.inMemory("000000000000"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <V> AccountAwareStorageBackend<V> create(String serviceName,
|
||||
String fileName,
|
||||
TypeReference<Map<String, V>> typeReference) {
|
||||
return (AccountAwareStorageBackend<V>) stores.computeIfAbsent(fileName,
|
||||
ignored -> AccountAwareStorageBackend.inMemory("000000000000"));
|
||||
}
|
||||
}
|
||||
}
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
package io.github.hectorvent.floci.services.ecs;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
/**
|
||||
* Task definitions are regional: a family registered in two regions has its own revisions in each,
|
||||
* and a region lists and describes only its own.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class EcsTaskDefinitionRegionIntegrationTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String TARGET_PREFIX = "AmazonEC2ContainerServiceV20141113.";
|
||||
private static final String HOME = "eu-west-1";
|
||||
private static final String OTHER = "us-west-2";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static RequestSpecification ecs(String region, String action) {
|
||||
return given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("Authorization", "AWS4-HMAC-SHA256 Credential=AKID/20260215/" + region
|
||||
+ "/ecs/aws4_request, SignedHeaders=host, Signature=abc")
|
||||
.header("X-Amz-Target", TARGET_PREFIX + action);
|
||||
}
|
||||
|
||||
private static String register(String region, String family) {
|
||||
return ecs(region, "RegisterTaskDefinition")
|
||||
.body("""
|
||||
{"family": "%s", "containerDefinitions": [{"name": "app", "image": "nginx", "memory": 128}]}
|
||||
""".formatted(family))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("taskDefinition.revision", equalTo(1))
|
||||
.body("taskDefinition.taskDefinitionArn", containsString(":" + region + ":"))
|
||||
.extract().path("taskDefinition.taskDefinitionArn");
|
||||
}
|
||||
|
||||
@Test
|
||||
void taskDefinitionsStayInTheirRegion() {
|
||||
String family = "region-td-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
String homeArn = register(HOME, family);
|
||||
String otherArn = register(OTHER, family);
|
||||
|
||||
ecs(HOME, "ListTaskDefinitions")
|
||||
.body("{\"familyPrefix\": \"" + family + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("taskDefinitionArns", contains(homeArn));
|
||||
ecs(OTHER, "ListTaskDefinitions")
|
||||
.body("{\"familyPrefix\": \"" + family + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("taskDefinitionArns", contains(otherArn));
|
||||
ecs("ap-southeast-1", "ListTaskDefinitionFamilies")
|
||||
.body("{\"familyPrefix\": \"" + family + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("families", empty());
|
||||
ecs(OTHER, "DescribeTaskDefinition")
|
||||
.body("{\"taskDefinition\": \"" + homeArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", endsWith("ClientException"));
|
||||
|
||||
for (String region : new String[] {HOME, OTHER}) {
|
||||
ecs(region, "DeregisterTaskDefinition")
|
||||
.body("{\"taskDefinition\": \"" + family + ":1\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
ecs(region, "DeleteTaskDefinitions")
|
||||
.body("{\"taskDefinitions\": [\"" + family + ":1\"]}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user