mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(ecs): complete the operations outside the launch path (#4019)
The operations that are not part of launching a task were the ones ECS answered least like AWS: a listing returned everything at once, a describe dropped what it could not resolve, and several stored less than the request carried. Clusters. CreateCluster and UpdateCluster carry configuration and serviceConnectDefaults, UpdateCluster replaces only the members the request named, and DescribeClusters gates settings, tags, statistics, attachments and configuration on include, reporting the eight documented statistics split by launch type. DeleteCluster refuses a cluster that still has services, container instances or running tasks, with the exception AWS reports for each. Pagination. Every listing pages with maxResults and nextToken behind one shared helper: a hundred per page, ten for ListServices, ten for ListAccountSettings. ListTaskDefinitions lists only ACTIVE revisions by default and orders by family then numeric revision; ListTasks defaults to the running tasks and filters by launch type, container instance and startedBy, which has to be the only filter alongside the cluster scope. Container instances. RegisterContainerInstance keeps what the agent sent, deregistration leaves the instance describable as INACTIVE, UpdateContainerInstancesState moves only between ACTIVE and DRAINING, and DescribeContainerInstances gates tags and health on include. Account settings and attributes. A setting is validated per name, carries its principal and type, and falls back from the principal's own value to the account default to the built-in default under effectiveSettings. An attribute belongs to a cluster and must name a container instance it has. Task sets. A task set needs an EXTERNAL or CODE_DEPLOY service, computes its desired count from the service's, round-trips its networking and load balancers, and needs force to delete before it is scaled to zero. CodeDeploy's call site reports the CODE_DEPLOY startedBy ECS reports. Service deployments and revisions. A deployment is recorded with the revision it targets, the two point at each other, and the service reports the deployment and revision it is currently on. Verified against the AWS SDK for Java v2 and the AWS ECS API reference.
This commit is contained in:
1 parent
cebdc6f2bb
commit
7b29fdcf83
24 files changed
+2761
-195
No files matched your search
+3
-2
@@ -53,10 +53,11 @@ class EcsCreateClusterSettingsIntegrationTest {
|
||||
.body("cluster.settings[0].value", equalTo("enabled"));
|
||||
|
||||
// The drift the issue describes is not in the CreateCluster response but in what a later
|
||||
// read reports, which is what a client compares its configuration against.
|
||||
// read reports, which is what a client compares its configuration against. DescribeClusters
|
||||
// only reports settings when the request asks for them, which terraform-provider-aws does.
|
||||
ecs("DescribeClusters")
|
||||
.body("""
|
||||
{"clusters": ["%s"]}
|
||||
{"clusters": ["%s"], "include": ["SETTINGS"]}
|
||||
""".formatted(cluster))
|
||||
.when()
|
||||
.post("/")
|
||||
|
||||
+741
-1
@@ -449,7 +449,80 @@ class EcsFargateEdgeCaseIntegrationTest {
|
||||
.then().body("message", containsString("role parameter"));
|
||||
}
|
||||
|
||||
// ── Service updates ──────────────────────────────────────────────────────
|
||||
// ── ListTasks filters ─────────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
void listTasksDefaultsToTheRunningTasks() {
|
||||
String family = seed("edge-list-default");
|
||||
String running = call("RunTask", "{\"cluster\":\"" + CLUSTER + "\",\"taskDefinition\":\""
|
||||
+ family + "\",\"launchType\":\"FARGATE\"," + NETWORK + "}", 200)
|
||||
.jsonPath().getString("tasks[0].taskArn");
|
||||
String stopped = call("RunTask", "{\"cluster\":\"" + CLUSTER + "\",\"taskDefinition\":\""
|
||||
+ family + "\",\"launchType\":\"FARGATE\"," + NETWORK + "}", 200)
|
||||
.jsonPath().getString("tasks[0].taskArn");
|
||||
call("StopTask", "{\"cluster\":\"" + CLUSTER + "\",\"task\":\"" + stopped + "\"}", 200);
|
||||
|
||||
// Without a desiredStatus the listing is RUNNING only, which is AWS's default filter.
|
||||
List<String> byDefault = call("ListTasks", "{\"cluster\":\"" + CLUSTER + "\",\"family\":\""
|
||||
+ family + "\"}", 200).jsonPath().getList("taskArns");
|
||||
assertTrue(byDefault.contains(running), "a running task must be listed by default");
|
||||
assertFalse(byDefault.contains(stopped), "a stopped task must not be listed by default");
|
||||
|
||||
List<String> stoppedOnly = call("ListTasks", "{\"cluster\":\"" + CLUSTER + "\",\"family\":\""
|
||||
+ family + "\",\"desiredStatus\":\"STOPPED\"}", 200).jsonPath().getList("taskArns");
|
||||
assertTrue(stoppedOnly.contains(stopped), "STOPPED must list the stopped task");
|
||||
assertFalse(stoppedOnly.contains(running), "STOPPED must not list the running task");
|
||||
|
||||
// ECS never sets a desired status of PENDING, so that filter matches nothing.
|
||||
assertTrue(call("ListTasks", "{\"cluster\":\"" + CLUSTER + "\",\"family\":\"" + family
|
||||
+ "\",\"desiredStatus\":\"PENDING\"}", 200)
|
||||
.jsonPath().getList("taskArns").isEmpty(), "PENDING must match nothing");
|
||||
}
|
||||
|
||||
@Test
|
||||
void listTasksFiltersByLaunchTypeAndStartedBy() {
|
||||
String family = seed("edge-list-filters");
|
||||
String tagged = call("RunTask", "{\"cluster\":\"" + CLUSTER + "\",\"taskDefinition\":\""
|
||||
+ family + "\",\"launchType\":\"FARGATE\"," + NETWORK
|
||||
+ ",\"startedBy\":\"edge-batch-7\"}", 200)
|
||||
.jsonPath().getString("tasks[0].taskArn");
|
||||
|
||||
assertTrue(call("ListTasks", "{\"cluster\":\"" + CLUSTER + "\",\"family\":\"" + family
|
||||
+ "\",\"launchType\":\"FARGATE\"}", 200)
|
||||
.jsonPath().getList("taskArns").contains(tagged));
|
||||
assertTrue(call("ListTasks", "{\"cluster\":\"" + CLUSTER + "\",\"family\":\"" + family
|
||||
+ "\",\"launchType\":\"EC2\"}", 200)
|
||||
.jsonPath().getList("taskArns").isEmpty(), "no task here runs on EC2");
|
||||
|
||||
assertTrue(call("ListTasks", "{\"startedBy\":\"edge-batch-7\"}", 200)
|
||||
.jsonPath().getList("taskArns").contains(tagged));
|
||||
// The cluster scopes the listing rather than filtering it, so it pairs with startedBy.
|
||||
assertTrue(call("ListTasks", "{\"cluster\":\"" + CLUSTER + "\",\"startedBy\":\"edge-batch-7\"}", 200)
|
||||
.jsonPath().getList("taskArns").contains(tagged));
|
||||
// Any other filter alongside startedBy is still refused.
|
||||
call("ListTasks", "{\"cluster\":\"" + CLUSTER + "\",\"family\":\"" + family
|
||||
+ "\",\"startedBy\":\"edge-batch-7\"}", 400)
|
||||
.then().body("message", containsString("only filter"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listTasksPaginates() {
|
||||
String family = seed("edge-list-paging");
|
||||
call("RunTask", "{\"cluster\":\"" + CLUSTER + "\",\"taskDefinition\":\"" + family
|
||||
+ "\",\"count\":3,\"launchType\":\"FARGATE\"," + NETWORK + "}", 200);
|
||||
|
||||
Response first = call("ListTasks", "{\"cluster\":\"" + CLUSTER + "\",\"family\":\"" + family
|
||||
+ "\",\"maxResults\":2}", 200);
|
||||
first.then().body("taskArns", hasSize(2));
|
||||
String token = first.jsonPath().getString("nextToken");
|
||||
assertTrue(token != null && !token.isBlank(), "a truncated listing must return a token");
|
||||
|
||||
Response second = call("ListTasks", "{\"cluster\":\"" + CLUSTER + "\",\"family\":\"" + family
|
||||
+ "\",\"maxResults\":2,\"nextToken\":\"" + token + "\"}", 200);
|
||||
second.then().body("taskArns", hasSize(1));
|
||||
assertEquals(null, second.jsonPath().getString("nextToken"),
|
||||
"the last page carries no token");
|
||||
}
|
||||
|
||||
@Test
|
||||
void onlyTheDocumentedUpdatesRollTheServiceDeployment() {
|
||||
@@ -553,6 +626,127 @@ class EcsFargateEdgeCaseIntegrationTest {
|
||||
.then().body("message", containsString("being deleted"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listTaskDefinitionsDefaultsToActiveAndOrdersByRevision() {
|
||||
for (int i = 0; i < 11; i++) {
|
||||
registerSize("edge-list-td", "256", "512", 200);
|
||||
}
|
||||
call("DeregisterTaskDefinition", "{\"taskDefinition\":\"edge-list-td:1\"}", 200);
|
||||
|
||||
List<String> active = call("ListTaskDefinitions",
|
||||
"{\"familyPrefix\":\"edge-list-td\"}", 200).jsonPath().getList("taskDefinitionArns");
|
||||
assertFalse(active.stream().anyMatch(arn -> arn.endsWith("edge-list-td:1")),
|
||||
"a deregistered revision is not listed by default");
|
||||
// Ascending by revision, so revision 11 comes after revision 2 rather than before it.
|
||||
assertTrue(active.getFirst().endsWith(":2"), "the lowest active revision comes first: " + active);
|
||||
assertTrue(active.getLast().endsWith(":11"), "the newest revision comes last: " + active);
|
||||
|
||||
List<String> descending = call("ListTaskDefinitions",
|
||||
"{\"familyPrefix\":\"edge-list-td\",\"sort\":\"DESC\"}", 200)
|
||||
.jsonPath().getList("taskDefinitionArns");
|
||||
assertTrue(descending.getFirst().endsWith(":11"), "DESC lists the newest first: " + descending);
|
||||
|
||||
List<String> inactive = call("ListTaskDefinitions",
|
||||
"{\"familyPrefix\":\"edge-list-td\",\"status\":\"INACTIVE\"}", 200)
|
||||
.jsonPath().getList("taskDefinitionArns");
|
||||
assertEquals(1, inactive.size(), "only the deregistered revision is INACTIVE");
|
||||
|
||||
Response firstPage = call("ListTaskDefinitions",
|
||||
"{\"familyPrefix\":\"edge-list-td\",\"maxResults\":3}", 200);
|
||||
firstPage.then().body("taskDefinitionArns", hasSize(3));
|
||||
assertTrue(firstPage.jsonPath().getString("nextToken") != null,
|
||||
"a truncated listing returns a token");
|
||||
}
|
||||
|
||||
@Test
|
||||
void listServicesFiltersAndPagesTheWayAwsDoes() {
|
||||
String family = seed("edge-list-services");
|
||||
for (int i = 0; i < 12; i++) {
|
||||
call("CreateService", "{\"cluster\":\"" + CLUSTER + "\",\"serviceName\":\"edge-svc-" + i
|
||||
+ "\",\"taskDefinition\":\"" + family + "\",\"desiredCount\":0,"
|
||||
+ "\"launchType\":\"FARGATE\"," + NETWORK + "}", 200);
|
||||
}
|
||||
|
||||
// ListServices pages ten at a time by default, unlike the other listings.
|
||||
Response defaultPage = call("ListServices", "{\"cluster\":\"" + CLUSTER + "\"}", 200);
|
||||
defaultPage.then().body("serviceArns", hasSize(10));
|
||||
assertTrue(defaultPage.jsonPath().getString("nextToken") != null,
|
||||
"a truncated listing returns a token");
|
||||
|
||||
assertTrue(call("ListServices", "{\"cluster\":\"" + CLUSTER
|
||||
+ "\",\"launchType\":\"EC2\",\"maxResults\":100}", 200)
|
||||
.jsonPath().getList("serviceArns").isEmpty(), "no service here runs on EC2");
|
||||
assertFalse(call("ListServices", "{\"cluster\":\"" + CLUSTER
|
||||
+ "\",\"launchType\":\"FARGATE\",\"maxResults\":100}", 200)
|
||||
.jsonPath().getList("serviceArns").isEmpty(), "the Fargate services are listed");
|
||||
assertTrue(call("ListServices", "{\"cluster\":\"" + CLUSTER
|
||||
+ "\",\"schedulingStrategy\":\"DAEMON\",\"maxResults\":100}", 200)
|
||||
.jsonPath().getList("serviceArns").isEmpty(), "none of these are daemons");
|
||||
}
|
||||
|
||||
@Test
|
||||
void listTaskDefinitionFamiliesFiltersByWhetherARevisionIsActive() {
|
||||
registerSize("edge-family-active", "256", "512", 200);
|
||||
registerSize("edge-family-gone", "256", "512", 200);
|
||||
call("DeregisterTaskDefinition", "{\"taskDefinition\":\"edge-family-gone:1\"}", 200);
|
||||
|
||||
// Both are listed without a status, which is AWS's default.
|
||||
List<String> all = call("ListTaskDefinitionFamilies",
|
||||
"{\"familyPrefix\":\"edge-family-\",\"maxResults\":100}", 200)
|
||||
.jsonPath().getList("families");
|
||||
assertTrue(all.containsAll(List.of("edge-family-active", "edge-family-gone")), all.toString());
|
||||
|
||||
assertEquals(List.of("edge-family-active"), call("ListTaskDefinitionFamilies",
|
||||
"{\"familyPrefix\":\"edge-family-\",\"status\":\"ACTIVE\",\"maxResults\":100}", 200)
|
||||
.jsonPath().getList("families"));
|
||||
assertEquals(List.of("edge-family-gone"), call("ListTaskDefinitionFamilies",
|
||||
"{\"familyPrefix\":\"edge-family-\",\"status\":\"INACTIVE\",\"maxResults\":100}", 200)
|
||||
.jsonPath().getList("families"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeClustersWithholdsEverythingTheIncludeDidNotAskFor() {
|
||||
String cluster = "edge-include-cluster";
|
||||
call("CreateCluster", "{\"clusterName\":\"" + cluster + "\","
|
||||
+ "\"settings\":[{\"name\":\"containerInsights\",\"value\":\"enabled\"}],"
|
||||
+ "\"tags\":[{\"key\":\"team\",\"value\":\"platform\"}],"
|
||||
+ "\"configuration\":{\"executeCommandConfiguration\":{\"logging\":\"DEFAULT\"}}}", 200);
|
||||
|
||||
Response bare = call("DescribeClusters", "{\"clusters\":[\"" + cluster + "\"]}", 200);
|
||||
bare.then()
|
||||
.body("clusters[0].clusterName", equalTo(cluster))
|
||||
.body("clusters[0].settings", nullValue())
|
||||
.body("clusters[0].tags", nullValue())
|
||||
.body("clusters[0].statistics", nullValue())
|
||||
.body("clusters[0].attachments", nullValue())
|
||||
.body("clusters[0].configuration", nullValue());
|
||||
|
||||
call("DescribeClusters", "{\"clusters\":[\"" + cluster + "\"],"
|
||||
+ "\"include\":[\"SETTINGS\",\"TAGS\",\"STATISTICS\",\"ATTACHMENTS\",\"CONFIGURATIONS\"]}", 200)
|
||||
.then()
|
||||
.body("clusters[0].settings", hasSize(1))
|
||||
.body("clusters[0].tags", hasSize(1))
|
||||
.body("clusters[0].attachments", hasSize(0))
|
||||
.body("clusters[0].configuration.executeCommandConfiguration.logging", equalTo("DEFAULT"))
|
||||
.body("clusters[0].statistics", hasSize(8))
|
||||
.body("clusters[0].statistics.find { it.name == 'runningFargateTasksCount' }.value",
|
||||
equalTo("0"));
|
||||
|
||||
call("DescribeClusters", "{\"clusters\":[\"" + cluster + "\"],\"include\":[\"NOPE\"]}", 400);
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeClustersReportsAnUnknownClusterAsMissingRatherThanDroppingIt() {
|
||||
call("CreateCluster", "{\"clusterName\":\"" + CLUSTER + "\"}", 200);
|
||||
|
||||
call("DescribeClusters", "{\"clusters\":[\"" + CLUSTER + "\",\"edge-no-such-cluster\"]}", 200)
|
||||
.then()
|
||||
.body("clusters", hasSize(1))
|
||||
.body("failures", hasSize(1))
|
||||
.body("failures[0].reason", equalTo("MISSING"))
|
||||
.body("failures[0].arn", containsString("cluster/edge-no-such-cluster"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeTasksReportsAnUnknownTaskAsMissingRatherThanDroppingIt() {
|
||||
call("CreateCluster", "{\"clusterName\":\"" + CLUSTER + "\"}", 200);
|
||||
@@ -564,6 +758,399 @@ class EcsFargateEdgeCaseIntegrationTest {
|
||||
.body("failures[0].reason", equalTo("MISSING"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listClustersPagesTheWayAwsDoes() {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
call("CreateCluster", "{\"clusterName\":\"edge-page-cluster-" + i + "\"}", 200);
|
||||
}
|
||||
|
||||
Response first = call("ListClusters", "{\"maxResults\":1}", 200);
|
||||
first.then().body("clusterArns", hasSize(1)).body("nextToken", notNullValue());
|
||||
|
||||
String token = first.jsonPath().getString("nextToken");
|
||||
Response second = call("ListClusters", "{\"maxResults\":1,\"nextToken\":\"" + token + "\"}", 200);
|
||||
second.then().body("clusterArns", hasSize(1));
|
||||
assertNotEquals(first.jsonPath().getString("clusterArns[0]"),
|
||||
second.jsonPath().getString("clusterArns[0]"));
|
||||
|
||||
// No maxResults pages a hundred at a time, so a handful of clusters comes back whole.
|
||||
call("ListClusters", "{}", 200).then().body("nextToken", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void clusterStatisticsCountRunningFargateTasks() {
|
||||
String cluster = "edge-stats-cluster";
|
||||
call("CreateCluster", "{\"clusterName\":\"" + cluster + "\"}", 200);
|
||||
registerSize("edge-stats", "256", "512", 200);
|
||||
call("RunTask", "{\"cluster\":\"" + cluster + "\",\"taskDefinition\":\"edge-stats\","
|
||||
+ "\"launchType\":\"FARGATE\"," + NETWORK + "}", 200);
|
||||
|
||||
List<Map<String, String>> statistics = call("DescribeClusters",
|
||||
"{\"clusters\":[\"" + cluster + "\"],\"include\":[\"STATISTICS\"]}", 200)
|
||||
.jsonPath().getList("clusters[0].statistics");
|
||||
|
||||
assertEquals("1", statistics.stream()
|
||||
.filter(s -> "runningFargateTasksCount".equals(s.get("name")))
|
||||
.findFirst().orElseThrow().get("value"));
|
||||
assertEquals("0", statistics.stream()
|
||||
.filter(s -> "runningEC2TasksCount".equals(s.get("name")))
|
||||
.findFirst().orElseThrow().get("value"));
|
||||
}
|
||||
|
||||
// ── Task sets ─────────────────────────────────────────────────────────────
|
||||
|
||||
/** Creates an EXTERNAL-controller service, which is the only kind that can hold task sets. */
|
||||
private static String seedExternalService(String name) {
|
||||
String family = seed(name + "-td");
|
||||
call("CreateService", "{\"cluster\":\"" + CLUSTER + "\",\"serviceName\":\"" + name + "\","
|
||||
+ "\"taskDefinition\":\"" + family + "\",\"desiredCount\":3,"
|
||||
+ "\"deploymentController\":{\"type\":\"EXTERNAL\"},"
|
||||
+ "\"launchType\":\"FARGATE\"," + NETWORK + "}", 200);
|
||||
return family;
|
||||
}
|
||||
|
||||
@Test
|
||||
void aTaskSetNeedsAServiceThatUsesAnExternalDeploymentController() {
|
||||
String family = seed("edge-rolling-td");
|
||||
call("CreateService", "{\"cluster\":\"" + CLUSTER + "\",\"serviceName\":\"edge-rolling-svc\","
|
||||
+ "\"taskDefinition\":\"" + family + "\",\"desiredCount\":1,"
|
||||
+ "\"launchType\":\"FARGATE\"," + NETWORK + "}", 200);
|
||||
|
||||
call("CreateTaskSet", "{\"cluster\":\"" + CLUSTER + "\",\"service\":\"edge-rolling-svc\","
|
||||
+ "\"taskDefinition\":\"" + family + "\"}", 400)
|
||||
.then().body("message", containsString("EXTERNAL"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aTaskSetRoundTripsItsMembersAndComputesItsDesiredCount() {
|
||||
String family = seedExternalService("edge-taskset-svc");
|
||||
|
||||
Response created = call("CreateTaskSet", "{\"cluster\":\"" + CLUSTER
|
||||
+ "\",\"service\":\"edge-taskset-svc\",\"taskDefinition\":\"" + family + "\","
|
||||
+ "\"launchType\":\"FARGATE\",\"externalId\":\"d-EXAMPLE\","
|
||||
+ "\"scale\":{\"value\":50,\"unit\":\"PERCENT\"},"
|
||||
+ "\"networkConfiguration\":{\"awsvpcConfiguration\":{\"subnets\":"
|
||||
+ "[\"subnet-default-us-east-1-a\"]}},"
|
||||
+ "\"loadBalancers\":[{\"targetGroupArn\":\"arn:aws:elasticloadbalancing:us-east-1:"
|
||||
+ "000000000000:targetgroup/tg/1\",\"containerName\":\"app\",\"containerPort\":80}],"
|
||||
+ "\"tags\":[{\"key\":\"team\",\"value\":\"platform\"}]}", 200);
|
||||
|
||||
created.then()
|
||||
.body("taskSet.status", equalTo("ACTIVE"))
|
||||
.body("taskSet.launchType", equalTo("FARGATE"))
|
||||
.body("taskSet.platformVersion", equalTo("1.4.0"))
|
||||
.body("taskSet.platformFamily", equalTo("Linux"))
|
||||
.body("taskSet.externalId", equalTo("d-EXAMPLE"))
|
||||
.body("taskSet.scale.value", equalTo(50.0f))
|
||||
.body("taskSet.scale.unit", equalTo("PERCENT"))
|
||||
// 3 desired at 50 percent is 1.5, and AWS always rounds the computed count up.
|
||||
.body("taskSet.computedDesiredCount", equalTo(2))
|
||||
// Floci places no tasks for a task set, so it is steady rather than for ever
|
||||
// stabilising towards a count that nothing will ever reach.
|
||||
.body("taskSet.stabilityStatus", equalTo("STEADY_STATE"))
|
||||
.body("taskSet.stabilityStatusAt", notNullValue())
|
||||
.body("taskSet.networkConfiguration.awsvpcConfiguration.subnets", hasSize(1))
|
||||
.body("taskSet.loadBalancers[0].containerPort", equalTo(80));
|
||||
|
||||
String id = created.jsonPath().getString("taskSet.id");
|
||||
|
||||
// Tags come back from DescribeTaskSets only when the request asks for them.
|
||||
call("DescribeTaskSets", "{\"cluster\":\"" + CLUSTER + "\",\"service\":\"edge-taskset-svc\"}", 200)
|
||||
.then()
|
||||
.body("taskSets[0].tags", nullValue())
|
||||
.body("taskSets[0].stabilityStatus", equalTo("STEADY_STATE"));
|
||||
call("DescribeTaskSets", "{\"cluster\":\"" + CLUSTER + "\",\"service\":\"edge-taskset-svc\","
|
||||
+ "\"include\":[\"TAGS\"]}", 200)
|
||||
.then().body("taskSets[0].tags", hasSize(1));
|
||||
|
||||
// A scale change recomputes the desired count.
|
||||
call("UpdateTaskSet", "{\"cluster\":\"" + CLUSTER + "\",\"service\":\"edge-taskset-svc\","
|
||||
+ "\"taskSet\":\"" + id + "\",\"scale\":{\"value\":100,\"unit\":\"PERCENT\"}}", 200)
|
||||
.then()
|
||||
.body("taskSet.computedDesiredCount", equalTo(3))
|
||||
.body("taskSet.stabilityStatus", equalTo("STEADY_STATE"));
|
||||
|
||||
// Deleting a task set that has not been scaled to zero needs force.
|
||||
call("DeleteTaskSet", "{\"cluster\":\"" + CLUSTER + "\",\"service\":\"edge-taskset-svc\","
|
||||
+ "\"taskSet\":\"" + id + "\"}", 400)
|
||||
.then().body("message", containsString("scaled down to zero"));
|
||||
call("DeleteTaskSet", "{\"cluster\":\"" + CLUSTER + "\",\"service\":\"edge-taskset-svc\","
|
||||
+ "\"taskSet\":\"" + id + "\",\"force\":true}", 200)
|
||||
.then().body("taskSet.status", equalTo("DRAINING"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeTaskSetsReportsAnUnknownTaskSetAsMissing() {
|
||||
seedExternalService("edge-taskset-missing");
|
||||
|
||||
call("DescribeTaskSets", "{\"cluster\":\"" + CLUSTER + "\","
|
||||
+ "\"service\":\"edge-taskset-missing\",\"taskSets\":[\"ecs-svc/nope\"]}", 200)
|
||||
.then()
|
||||
.body("taskSets", hasSize(0))
|
||||
.body("failures", hasSize(1))
|
||||
.body("failures[0].reason", equalTo("MISSING"));
|
||||
|
||||
call("UpdateTaskSet", "{\"cluster\":\"" + CLUSTER + "\",\"service\":\"edge-taskset-missing\","
|
||||
+ "\"taskSet\":\"ecs-svc/nope\",\"scale\":{\"value\":100,\"unit\":\"PERCENT\"}}", 400)
|
||||
.then().body("__type", containsString("TaskSetNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aTaskSetCannotNameBothALaunchTypeAndACapacityProviderStrategy() {
|
||||
String family = seedExternalService("edge-taskset-both");
|
||||
|
||||
call("CreateTaskSet", "{\"cluster\":\"" + CLUSTER + "\",\"service\":\"edge-taskset-both\","
|
||||
+ "\"taskDefinition\":\"" + family + "\",\"launchType\":\"FARGATE\","
|
||||
+ "\"capacityProviderStrategy\":[{\"capacityProvider\":\"FARGATE_SPOT\",\"weight\":1}]}", 400)
|
||||
.then().body("message", containsString("capacity provider strategy"));
|
||||
}
|
||||
|
||||
// ── Account settings and attributes ───────────────────────────────────────
|
||||
|
||||
@Test
|
||||
void accountSettingsAreValidatedPerName() {
|
||||
call("PutAccountSetting", "{\"name\":\"nonsenseSetting\",\"value\":\"enabled\"}", 400)
|
||||
.then().body("message", containsString("Invalid account setting name"));
|
||||
call("PutAccountSetting", "{\"name\":\"containerInsights\",\"value\":\"maybe\"}", 400)
|
||||
.then().body("message", containsString("Invalid value"));
|
||||
|
||||
// Two settings are not opt-in flags: a wait period in days and a log delivery mode.
|
||||
call("PutAccountSetting", "{\"name\":\"fargateTaskRetirementWaitPeriod\",\"value\":\"14\"}", 200);
|
||||
call("PutAccountSetting", "{\"name\":\"fargateTaskRetirementWaitPeriod\",\"value\":\"3\"}", 400);
|
||||
call("PutAccountSetting", "{\"name\":\"defaultLogDriverMode\",\"value\":\"blocking\"}", 200);
|
||||
call("PutAccountSetting", "{\"name\":\"defaultLogDriverMode\",\"value\":\"enabled\"}", 400);
|
||||
// enhanced is a containerInsights value only.
|
||||
call("PutAccountSetting", "{\"name\":\"containerInsights\",\"value\":\"enhanced\"}", 200);
|
||||
call("PutAccountSetting", "{\"name\":\"awsvpcTrunking\",\"value\":\"enhanced\"}", 400);
|
||||
}
|
||||
|
||||
@Test
|
||||
void anAccountSettingReportsItsPrincipalAndType() {
|
||||
call("PutAccountSetting", "{\"name\":\"awsvpcTrunking\",\"value\":\"enabled\","
|
||||
+ "\"principalArn\":\"arn:aws:iam::000000000000:user/edge\"}", 200)
|
||||
.then()
|
||||
.body("setting.name", equalTo("awsvpcTrunking"))
|
||||
.body("setting.value", equalTo("enabled"))
|
||||
.body("setting.principalArn", equalTo("arn:aws:iam::000000000000:user/edge"))
|
||||
.body("setting.type", equalTo("user"));
|
||||
|
||||
// A principal sees only what it set; effectiveSettings fills in the rest.
|
||||
call("ListAccountSettings", "{\"principalArn\":\"arn:aws:iam::000000000000:user/edge\","
|
||||
+ "\"name\":\"containerInsights\"}", 200)
|
||||
.then().body("settings", hasSize(0));
|
||||
call("ListAccountSettings", "{\"principalArn\":\"arn:aws:iam::000000000000:user/edge\","
|
||||
+ "\"name\":\"containerInsights\",\"effectiveSettings\":true}", 200)
|
||||
.then().body("settings", hasSize(1));
|
||||
|
||||
// GuardDuty owns its setting on the account's behalf.
|
||||
call("ListAccountSettings", "{\"name\":\"guardDutyActivate\",\"effectiveSettings\":true}", 200)
|
||||
.then().body("settings[0].type", equalTo("aws_managed"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void effectiveAccountSettingsFallBackToTheAccountDefaultThenTheBuiltIn() {
|
||||
String principal = "arn:aws:iam::000000000000:user/edge-fallback";
|
||||
|
||||
// Untouched, the built-in default applies.
|
||||
call("ListAccountSettings", "{\"principalArn\":\"" + principal + "\","
|
||||
+ "\"name\":\"awsvpcTrunking\",\"effectiveSettings\":true}", 200)
|
||||
.then().body("settings[0].value", equalTo("disabled"));
|
||||
|
||||
// The account default lives on the root user, which is where AWS keeps it too.
|
||||
call("PutAccountSettingDefault", "{\"name\":\"awsvpcTrunking\",\"value\":\"enabled\"}", 200)
|
||||
.then().body("setting.principalArn", containsString(":root"));
|
||||
call("ListAccountSettings", "{\"principalArn\":\"" + principal + "\","
|
||||
+ "\"name\":\"awsvpcTrunking\",\"effectiveSettings\":true}", 200)
|
||||
.then().body("settings[0].value", equalTo("enabled"));
|
||||
|
||||
// The principal's own setting wins over the account default.
|
||||
call("PutAccountSetting", "{\"name\":\"awsvpcTrunking\",\"value\":\"disabled\","
|
||||
+ "\"principalArn\":\"" + principal + "\"}", 200);
|
||||
call("ListAccountSettings", "{\"principalArn\":\"" + principal + "\","
|
||||
+ "\"name\":\"awsvpcTrunking\",\"effectiveSettings\":true}", 200)
|
||||
.then().body("settings[0].value", equalTo("disabled"));
|
||||
|
||||
// Deleting it falls back to the account default again.
|
||||
call("DeleteAccountSetting", "{\"name\":\"awsvpcTrunking\",\"principalArn\":\""
|
||||
+ principal + "\"}", 200)
|
||||
.then().body("setting.value", equalTo("disabled"));
|
||||
call("ListAccountSettings", "{\"principalArn\":\"" + principal + "\","
|
||||
+ "\"name\":\"awsvpcTrunking\",\"effectiveSettings\":true}", 200)
|
||||
.then().body("settings[0].value", equalTo("enabled"));
|
||||
|
||||
// The full effective listing is eleven settings, which pages ten at a time.
|
||||
Response page = call("ListAccountSettings",
|
||||
"{\"principalArn\":\"" + principal + "\",\"effectiveSettings\":true}", 200);
|
||||
page.then().body("settings", hasSize(10)).body("nextToken", notNullValue());
|
||||
call("ListAccountSettings", "{\"principalArn\":\"" + principal + "\","
|
||||
+ "\"effectiveSettings\":true,\"nextToken\":\"" + page.jsonPath().getString("nextToken")
|
||||
+ "\"}", 200)
|
||||
.then().body("settings", hasSize(1)).body("nextToken", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void attributesAreScopedToTheirClusterAndNeedARegisteredTarget() {
|
||||
String cluster = "edge-attr-cluster";
|
||||
String other = "edge-attr-other";
|
||||
call("CreateCluster", "{\"clusterName\":\"" + cluster + "\"}", 200);
|
||||
call("CreateCluster", "{\"clusterName\":\"" + other + "\"}", 200);
|
||||
|
||||
String instance = call("RegisterContainerInstance", "{\"cluster\":\"" + cluster + "\"}", 200)
|
||||
.jsonPath().getString("containerInstance.containerInstanceArn");
|
||||
|
||||
// An attribute on a target the cluster does not have is a TargetNotFoundException.
|
||||
call("PutAttributes", "{\"cluster\":\"" + cluster + "\",\"attributes\":"
|
||||
+ "[{\"name\":\"stack\",\"value\":\"prod\",\"targetType\":\"container-instance\","
|
||||
+ "\"targetId\":\"nope\"}]}", 400)
|
||||
.then().body("__type", containsString("TargetNotFoundException"));
|
||||
|
||||
call("PutAttributes", "{\"cluster\":\"" + cluster + "\",\"attributes\":"
|
||||
+ "[{\"name\":\"stack\",\"value\":\"prod\",\"targetType\":\"container-instance\","
|
||||
+ "\"targetId\":\"" + instance + "\"}]}", 200)
|
||||
.then().body("attributes", hasSize(1));
|
||||
|
||||
// targetType is required, and container-instance is its only value.
|
||||
call("ListAttributes", "{\"cluster\":\"" + cluster + "\"}", 400)
|
||||
.then().body("message", containsString("targetType"));
|
||||
call("ListAttributes", "{\"cluster\":\"" + cluster + "\",\"targetType\":\"task\"}", 400);
|
||||
|
||||
call("ListAttributes", "{\"cluster\":\"" + cluster + "\","
|
||||
+ "\"targetType\":\"container-instance\"}", 200)
|
||||
.then().body("attributes.find { it.name == 'stack' }.value", equalTo("prod"));
|
||||
|
||||
// The other cluster never sees it.
|
||||
call("ListAttributes", "{\"cluster\":\"" + other + "\","
|
||||
+ "\"targetType\":\"container-instance\"}", 200)
|
||||
.then().body("attributes.findAll { it.name == 'stack' }", hasSize(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aTargetTakesAtMostTenCustomAttributes() {
|
||||
String cluster = "edge-attr-limit";
|
||||
call("CreateCluster", "{\"clusterName\":\"" + cluster + "\"}", 200);
|
||||
String instance = call("RegisterContainerInstance", "{\"cluster\":\"" + cluster + "\"}", 200)
|
||||
.jsonPath().getString("containerInstance.containerInstanceArn");
|
||||
|
||||
StringBuilder ten = new StringBuilder();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (i > 0) { ten.append(','); }
|
||||
ten.append("{\"name\":\"a").append(i).append("\",\"value\":\"v\",")
|
||||
.append("\"targetType\":\"container-instance\",\"targetId\":\"")
|
||||
.append(instance).append("\"}");
|
||||
}
|
||||
call("PutAttributes", "{\"cluster\":\"" + cluster + "\",\"attributes\":[" + ten + "]}", 200);
|
||||
|
||||
call("PutAttributes", "{\"cluster\":\"" + cluster + "\",\"attributes\":"
|
||||
+ "[{\"name\":\"a10\",\"value\":\"v\",\"targetType\":\"container-instance\","
|
||||
+ "\"targetId\":\"" + instance + "\"}]}", 400)
|
||||
.then().body("__type", containsString("AttributeLimitExceededException"));
|
||||
}
|
||||
|
||||
// ── Container instances ───────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
void aRegisteredContainerInstanceReportsWhatTheAgentSent() {
|
||||
String cluster = "edge-ci-register";
|
||||
call("CreateCluster", "{\"clusterName\":\"" + cluster + "\"}", 200);
|
||||
|
||||
call("RegisterContainerInstance", "{\"cluster\":\"" + cluster + "\","
|
||||
+ "\"versionInfo\":{\"agentVersion\":\"1.79.0\",\"agentHash\":\"abc1234\","
|
||||
+ "\"dockerVersion\":\"DockerVersion: 24.0.5\"},"
|
||||
+ "\"totalResources\":[{\"name\":\"CPU\",\"type\":\"INTEGER\",\"integerValue\":4096},"
|
||||
+ "{\"name\":\"MEMORY\",\"type\":\"INTEGER\",\"integerValue\":7482}],"
|
||||
+ "\"tags\":[{\"key\":\"fleet\",\"value\":\"batch\"}]}", 200)
|
||||
.then()
|
||||
.body("containerInstance.status", equalTo("ACTIVE"))
|
||||
.body("containerInstance.registeredAt", notNullValue())
|
||||
.body("containerInstance.version", equalTo(1))
|
||||
// versionInfo is where the agent version lives; there is no top-level agentVersion.
|
||||
.body("containerInstance.agentVersion", nullValue())
|
||||
.body("containerInstance.versionInfo.agentVersion", equalTo("1.79.0"))
|
||||
.body("containerInstance.versionInfo.dockerVersion", equalTo("DockerVersion: 24.0.5"))
|
||||
.body("containerInstance.registeredResources", hasSize(2))
|
||||
.body("containerInstance.remainingResources", hasSize(2))
|
||||
.body("containerInstance.tags", hasSize(1));
|
||||
|
||||
call("DescribeClusters", "{\"clusters\":[\"" + cluster + "\"]}", 200)
|
||||
.then().body("clusters[0].registeredContainerInstancesCount", equalTo(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aDeregisteredContainerInstanceStaysDescribableAsInactive() {
|
||||
String cluster = "edge-ci-deregister";
|
||||
call("CreateCluster", "{\"clusterName\":\"" + cluster + "\"}", 200);
|
||||
String instance = call("RegisterContainerInstance", "{\"cluster\":\"" + cluster + "\"}", 200)
|
||||
.jsonPath().getString("containerInstance.containerInstanceArn");
|
||||
|
||||
call("DeregisterContainerInstance", "{\"cluster\":\"" + cluster + "\","
|
||||
+ "\"containerInstance\":\"" + instance + "\"}", 200)
|
||||
.then().body("containerInstance.status", equalTo("INACTIVE"));
|
||||
|
||||
// AWS keeps answering a describe for a deregistered instance.
|
||||
call("DescribeContainerInstances", "{\"cluster\":\"" + cluster + "\","
|
||||
+ "\"containerInstances\":[\"" + instance + "\"]}", 200)
|
||||
.then()
|
||||
.body("containerInstances", hasSize(1))
|
||||
.body("containerInstances[0].status", equalTo("INACTIVE"));
|
||||
|
||||
// The default listing excludes it, and only ACTIVE and DRAINING instances are registered.
|
||||
call("ListContainerInstances", "{\"cluster\":\"" + cluster + "\"}", 200)
|
||||
.then().body("containerInstanceArns", hasSize(0));
|
||||
call("DescribeClusters", "{\"clusters\":[\"" + cluster + "\"]}", 200)
|
||||
.then().body("clusters[0].registeredContainerInstancesCount", equalTo(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void containerInstanceStateOnlyMovesBetweenActiveAndDraining() {
|
||||
String cluster = "edge-ci-state";
|
||||
call("CreateCluster", "{\"clusterName\":\"" + cluster + "\"}", 200);
|
||||
String instance = call("RegisterContainerInstance", "{\"cluster\":\"" + cluster + "\"}", 200)
|
||||
.jsonPath().getString("containerInstance.containerInstanceArn");
|
||||
|
||||
call("UpdateContainerInstancesState", "{\"cluster\":\"" + cluster + "\","
|
||||
+ "\"containerInstances\":[\"" + instance + "\"],\"status\":\"REGISTERING\"}", 400)
|
||||
.then().body("message", containsString("ACTIVE and DRAINING"));
|
||||
|
||||
call("UpdateContainerInstancesState", "{\"cluster\":\"" + cluster + "\","
|
||||
+ "\"containerInstances\":[\"" + instance + "\"],\"status\":\"DRAINING\"}", 200)
|
||||
.then().body("containerInstances[0].status", equalTo("DRAINING"));
|
||||
|
||||
// A DRAINING instance is not ACTIVE, so it cannot be set to DRAINING again.
|
||||
call("UpdateContainerInstancesState", "{\"cluster\":\"" + cluster + "\","
|
||||
+ "\"containerInstances\":[\"" + instance + "\"],\"status\":\"DRAINING\"}", 400)
|
||||
.then().body("message", containsString("must be ACTIVE"));
|
||||
|
||||
// A DRAINING instance still counts as registered and still lists by default.
|
||||
call("ListContainerInstances", "{\"cluster\":\"" + cluster + "\"}", 200)
|
||||
.then().body("containerInstanceArns", hasSize(1));
|
||||
call("ListContainerInstances", "{\"cluster\":\"" + cluster + "\",\"status\":\"ACTIVE\"}", 200)
|
||||
.then().body("containerInstanceArns", hasSize(0));
|
||||
call("ListContainerInstances", "{\"cluster\":\"" + cluster + "\",\"status\":\"nonsense\"}", 400);
|
||||
|
||||
call("UpdateContainerInstancesState", "{\"cluster\":\"" + cluster + "\","
|
||||
+ "\"containerInstances\":[\"" + instance + "\"],\"status\":\"ACTIVE\"}", 200)
|
||||
.then().body("containerInstances[0].status", equalTo("ACTIVE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anUnknownContainerInstanceIsAFailureNotAnError() {
|
||||
String cluster = "edge-ci-missing";
|
||||
call("CreateCluster", "{\"clusterName\":\"" + cluster + "\"}", 200);
|
||||
|
||||
call("DescribeContainerInstances", "{\"cluster\":\"" + cluster + "\","
|
||||
+ "\"containerInstances\":[\"no-such-instance\"]}", 200)
|
||||
.then()
|
||||
.body("containerInstances", hasSize(0))
|
||||
.body("failures", hasSize(1))
|
||||
.body("failures[0].reason", equalTo("MISSING"));
|
||||
|
||||
call("UpdateContainerInstancesState", "{\"cluster\":\"" + cluster + "\","
|
||||
+ "\"containerInstances\":[\"no-such-instance\"],\"status\":\"DRAINING\"}", 200)
|
||||
.then()
|
||||
.body("containerInstances", hasSize(0))
|
||||
.body("failures[0].reason", equalTo("MISSING"));
|
||||
}
|
||||
|
||||
// ── Derived compatibilities and requiresAttributes ────────────────────────
|
||||
|
||||
@Test
|
||||
@@ -619,6 +1206,65 @@ class EcsFargateEdgeCaseIntegrationTest {
|
||||
.then().body("message", containsString("containerInstances"));
|
||||
}
|
||||
|
||||
// ── The Service shape's own members ──────────────────────────────────────
|
||||
|
||||
@Test
|
||||
void aServiceReportsItsEventsAndTaskSetsAndWhatItsDeploymentRunsOn() {
|
||||
String family = seed("edge-svc-shape-td");
|
||||
call("CreateService", "{\"cluster\":\"" + CLUSTER + "\",\"serviceName\":\"edge-svc-shape\","
|
||||
+ "\"taskDefinition\":\"" + family + "\",\"desiredCount\":0,"
|
||||
+ "\"launchType\":\"FARGATE\"," + NETWORK + "}", 200);
|
||||
|
||||
call("DescribeServices", "{\"cluster\":\"" + CLUSTER
|
||||
+ "\",\"services\":[\"edge-svc-shape\"]}", 200)
|
||||
.then()
|
||||
// Both members are always present, so a client can tell an empty answer from one
|
||||
// the emulator never wrote.
|
||||
.body("services[0].taskSets", hasSize(0))
|
||||
.body("services[0].events", hasSize(1))
|
||||
.body("services[0].events[0].message",
|
||||
containsString("(service edge-svc-shape) has reached a steady state."))
|
||||
.body("services[0].events[0].id", notNullValue())
|
||||
.body("services[0].events[0].createdAt", notNullValue())
|
||||
// The deployment carries the placement the service runs under, not just its id.
|
||||
.body("services[0].deployments[0].launchType", equalTo("FARGATE"))
|
||||
.body("services[0].deployments[0].platformVersion", equalTo("1.4.0"))
|
||||
.body("services[0].deployments[0].platformFamily", equalTo("Linux"))
|
||||
.body("services[0].deployments[0].networkConfiguration.awsvpcConfiguration.subnets",
|
||||
hasSize(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aServicesTaskSetsAreVisibleOnTheServiceItself() {
|
||||
String family = seedExternalService("edge-svc-tasksets");
|
||||
call("CreateTaskSet", "{\"cluster\":\"" + CLUSTER + "\",\"service\":\"edge-svc-tasksets\","
|
||||
+ "\"taskDefinition\":\"" + family + "\",\"launchType\":\"FARGATE\"}", 200);
|
||||
|
||||
call("DescribeServices", "{\"cluster\":\"" + CLUSTER
|
||||
+ "\",\"services\":[\"edge-svc-tasksets\"]}", 200)
|
||||
.then()
|
||||
.body("services[0].taskSets", hasSize(1))
|
||||
.body("services[0].taskSets[0].status", equalTo("ACTIVE"));
|
||||
}
|
||||
|
||||
// ── Cluster deletion ─────────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
void aClusterWithRegisteredContainerInstancesCannotBeDeleted() {
|
||||
String cluster = "edge-delete-with-instances";
|
||||
call("CreateCluster", "{\"clusterName\":\"" + cluster + "\"}", 200);
|
||||
String instance = call("RegisterContainerInstance", "{\"cluster\":\"" + cluster + "\"}", 200)
|
||||
.jsonPath().getString("containerInstance.containerInstanceArn");
|
||||
|
||||
call("DeleteCluster", "{\"cluster\":\"" + cluster + "\"}", 400)
|
||||
.then().body("__type", containsString("ClusterContainsContainerInstancesException"));
|
||||
|
||||
call("DeregisterContainerInstance", "{\"cluster\":\"" + cluster + "\","
|
||||
+ "\"containerInstance\":\"" + instance + "\"}", 200);
|
||||
call("DeleteCluster", "{\"cluster\":\"" + cluster + "\"}", 200)
|
||||
.then().body("cluster.status", equalTo("INACTIVE"));
|
||||
}
|
||||
|
||||
// ── Capacity providers ───────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
@@ -775,6 +1421,9 @@ class EcsFargateEdgeCaseIntegrationTest {
|
||||
+ "\"networkMode\":\"AWSVPC\","
|
||||
+ "\"containerDefinitions\":[{\"name\":\"app\",\"image\":\"nginx:latest\"}]}", 400)
|
||||
.then().body("message", containsString("networkMode"));
|
||||
|
||||
call("ListContainerInstances", "{\"cluster\":\"" + CLUSTER + "\",\"status\":\"BOGUS\"}", 400)
|
||||
.then().body("message", containsString("status"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -791,4 +1440,95 @@ class EcsFargateEdgeCaseIntegrationTest {
|
||||
+ "\"tags\":[{\"key\":\"\",\"value\":\"v\"}]}", 400)
|
||||
.then().body("message", containsString("Tag keys"));
|
||||
}
|
||||
|
||||
// ── Container instance health ────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
void containerInstanceHealthIsWithheldUntilTheRequestAsksForIt() {
|
||||
String cluster = "edge-ci-health";
|
||||
call("CreateCluster", "{\"clusterName\":\"" + cluster + "\"}", 200);
|
||||
String instance = call("RegisterContainerInstance", "{\"cluster\":\"" + cluster + "\"}", 200)
|
||||
.jsonPath().getString("containerInstance.containerInstanceArn");
|
||||
String describe = "{\"cluster\":\"" + cluster + "\",\"containerInstances\":[\""
|
||||
+ instance + "\"]";
|
||||
|
||||
call("DescribeContainerInstances", describe + "}", 200)
|
||||
.then().body("containerInstances[0].healthStatus", nullValue());
|
||||
|
||||
call("DescribeContainerInstances", describe + ",\"include\":[\"CONTAINER_INSTANCE_HEALTH\"]}", 200)
|
||||
.then()
|
||||
.body("containerInstances[0].healthStatus.overallStatus", equalTo("OK"))
|
||||
.body("containerInstances[0].healthStatus.details[0].type",
|
||||
equalTo("AGENT_CONNECTIVITY"));
|
||||
|
||||
call("DescribeContainerInstances", describe + ",\"include\":[\"NOPE\"]}", 400)
|
||||
.then().body("message", containsString("include"));
|
||||
}
|
||||
|
||||
// ── Service deployments and revisions ────────────────────────────────────
|
||||
|
||||
@Test
|
||||
void aServiceDeploymentPointsAtTheRevisionItDeployed() {
|
||||
String family = seed("edge-deployment-td");
|
||||
call("CreateService", "{\"cluster\":\"" + CLUSTER + "\",\"serviceName\":\"edge-deployment-svc\","
|
||||
+ "\"taskDefinition\":\"" + family + "\",\"desiredCount\":0,"
|
||||
+ "\"launchType\":\"FARGATE\"," + NETWORK + "}", 200);
|
||||
|
||||
Response listed = call("ListServiceDeployments", "{\"cluster\":\"" + CLUSTER
|
||||
+ "\",\"service\":\"edge-deployment-svc\"}", 200);
|
||||
listed.then()
|
||||
.body("serviceDeployments", hasSize(1))
|
||||
.body("serviceDeployments[0].targetServiceRevisionArn",
|
||||
containsString("service-revision/"))
|
||||
.body("serviceDeployments[0].startedAt", notNullValue())
|
||||
.body("serviceDeployments[0].finishedAt", notNullValue());
|
||||
|
||||
String deploymentArn = listed.jsonPath().getString("serviceDeployments[0].serviceDeploymentArn");
|
||||
String revisionArn = listed.jsonPath().getString("serviceDeployments[0].targetServiceRevisionArn");
|
||||
|
||||
call("DescribeServiceDeployments", "{\"serviceDeploymentArns\":[\"" + deploymentArn + "\"]}", 200)
|
||||
.then()
|
||||
.body("serviceDeployments[0].status", equalTo("SUCCESSFUL"))
|
||||
.body("serviceDeployments[0].targetServiceRevision.arn", equalTo(revisionArn))
|
||||
.body("serviceDeployments[0].targetServiceRevision.requestedTaskCount", equalTo(0))
|
||||
// AWS's ServiceDeployment shape has no taskDefinition; the revision carries it.
|
||||
.body("serviceDeployments[0].taskDefinition", nullValue());
|
||||
|
||||
// The service points back at both, so a caller never has to list first.
|
||||
call("DescribeServices", "{\"cluster\":\"" + CLUSTER
|
||||
+ "\",\"services\":[\"edge-deployment-svc\"]}", 200)
|
||||
.then()
|
||||
.body("services[0].currentServiceDeployment", equalTo(deploymentArn))
|
||||
.body("services[0].currentServiceRevisions[0].arn", equalTo(revisionArn));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aServiceRevisionSnapshotsTheConfigurationItWasCreatedWith() {
|
||||
String family = seed("edge-revision-td");
|
||||
call("CreateService", "{\"cluster\":\"" + CLUSTER + "\",\"serviceName\":\"edge-revision-svc\","
|
||||
+ "\"taskDefinition\":\"" + family + "\",\"desiredCount\":0,"
|
||||
+ "\"launchType\":\"FARGATE\"," + NETWORK + "}", 200);
|
||||
|
||||
String revisionArn = call("ListServiceDeployments", "{\"cluster\":\"" + CLUSTER
|
||||
+ "\",\"service\":\"edge-revision-svc\"}", 200)
|
||||
.jsonPath().getString("serviceDeployments[0].targetServiceRevisionArn");
|
||||
|
||||
call("DescribeServiceRevisions", "{\"serviceRevisionArns\":[\"" + revisionArn + "\"]}", 200)
|
||||
.then()
|
||||
.body("serviceRevisions[0].taskDefinition", containsString(family))
|
||||
.body("serviceRevisions[0].launchType", equalTo("FARGATE"))
|
||||
.body("serviceRevisions[0].platformVersion", equalTo("1.4.0"))
|
||||
.body("serviceRevisions[0].platformFamily", equalTo("Linux"))
|
||||
.body("serviceRevisions[0].networkConfiguration.awsvpcConfiguration.subnets",
|
||||
hasSize(1))
|
||||
.body("serviceRevisions[0].containerImages[0].containerName", equalTo("app"))
|
||||
.body("serviceRevisions[0].containerImages[0].image", equalTo("nginx:latest"))
|
||||
.body("serviceRevisions[0].guardDutyEnabled", equalTo(false));
|
||||
|
||||
call("DescribeServiceRevisions", "{\"serviceRevisionArns\":[\"arn:aws:ecs:us-east-1:"
|
||||
+ "000000000000:service-revision/nope\"]}", 200)
|
||||
.then()
|
||||
.body("serviceRevisions", hasSize(0))
|
||||
.body("failures[0].reason", equalTo("MISSING"));
|
||||
}
|
||||
}
|
||||
@@ -420,8 +420,10 @@ class EcsIntegrationTest {
|
||||
@Test
|
||||
@Order(18)
|
||||
void listTaskDefinitions() {
|
||||
// Scoped by family: the unfiltered listing pages a hundred at a time, as it does on AWS,
|
||||
// and the rest of the suite registers more families than fit on one page.
|
||||
ecs("ListTaskDefinitions")
|
||||
.body("{}")
|
||||
.body("{\"familyPrefix\":\"" + TASK_DEF_FAMILY + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
@@ -432,8 +434,9 @@ class EcsIntegrationTest {
|
||||
@Test
|
||||
@Order(19)
|
||||
void listTaskDefinitionFamilies() {
|
||||
// Scoped for the same reason as listTaskDefinitions: this listing pages too.
|
||||
ecs("ListTaskDefinitionFamilies")
|
||||
.body("{}")
|
||||
.body("{\"familyPrefix\":\"" + TASK_DEF_FAMILY + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
@@ -1011,7 +1014,32 @@ class EcsIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Order(53)
|
||||
void deleteClusterRejectsAClusterThatStillHasServices() {
|
||||
ecs("DeleteCluster")
|
||||
.body("""
|
||||
{"cluster": "%s"}
|
||||
""".formatted(CLUSTER_NAME))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", containsString("ClusterContainsServicesException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(54)
|
||||
void deleteCluster() {
|
||||
// zero-count-svc outlives the service tests and keeps the cluster non-empty, which is
|
||||
// exactly what AWS refuses to delete over.
|
||||
ecs("DeleteService")
|
||||
.body("""
|
||||
{"cluster": "%s", "service": "zero-count-svc"}
|
||||
""".formatted(CLUSTER_NAME))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
ecs("DeleteCluster")
|
||||
.body("""
|
||||
{"cluster": "%s"}
|
||||
@@ -1025,7 +1053,7 @@ class EcsIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(54)
|
||||
@Order(55)
|
||||
void deleteClusterNotFound() {
|
||||
ecs("DeleteCluster")
|
||||
.body("""
|
||||
|
||||
+4
-1
@@ -92,7 +92,10 @@ class EcsServiceDaemonSchedulingTest {
|
||||
assertEquals(0, runningTasks(service).size());
|
||||
|
||||
service.reconcileServices();
|
||||
long attempts = service.describeTasks(null, service.listTasks(null, null, null, null, REGION), REGION).size();
|
||||
// Both attempts died on launch, so they are the STOPPED tasks: ListTasks only returns the
|
||||
// running ones unless a desired status is asked for, as on AWS.
|
||||
long attempts = service.describeTasks(null,
|
||||
service.listTasks(null, null, "STOPPED", null, REGION), REGION).size();
|
||||
assertEquals(2, attempts, "the uncovered instance is retried on the next tick");
|
||||
}
|
||||
|
||||
|
||||
+15
-9
@@ -51,9 +51,12 @@ class EcsServicePersistenceTest {
|
||||
Map.of("tier", "web"), REGION);
|
||||
EcsServiceModel svc = first.createService("app-cluster", "web-svc", td.getTaskDefinitionArn(),
|
||||
0, LaunchType.FARGATE, List.of(), awsvpcConfiguration(), Map.of("team", "payments"), REGION);
|
||||
// An attribute names a container instance of the cluster, as it must on AWS.
|
||||
String instanceArn = first.registerContainerInstance("app-cluster", null, List.of(), REGION)
|
||||
.getContainerInstanceArn();
|
||||
first.putAttributes("app-cluster",
|
||||
List.of(new Attribute("stack", "prod", "container-instance", "ci-1")), REGION);
|
||||
first.putAccountSetting("containerInsights", "enabled");
|
||||
List.of(new Attribute("stack", "prod", "container-instance", instanceArn)), REGION);
|
||||
first.putAccountSetting("containerInsights", "enabled", null);
|
||||
|
||||
// Simulate restart: a fresh instance reloading from the same shared store.
|
||||
EcsService reloaded = serviceWithStorage(storage);
|
||||
@@ -70,10 +73,10 @@ class EcsServicePersistenceTest {
|
||||
List.of(svc.getServiceArn()), REGION).getFirst();
|
||||
assertEquals("payments", reloadedSvc.getTags().get("team"));
|
||||
|
||||
assertEquals("prod", reloaded.listAttributes("app-cluster", null, "stack", null, REGION)
|
||||
.getFirst().value());
|
||||
assertEquals("enabled", reloaded.listAccountSettings("containerInsights", null)
|
||||
.getFirst().getValue());
|
||||
assertEquals("prod", reloaded.listAttributes("app-cluster", "container-instance", "stack",
|
||||
null, null, null, REGION).attributes().getFirst().value());
|
||||
assertEquals("enabled", reloaded.listAccountSettings("containerInsights", null, null,
|
||||
false, null, null).settings().getFirst().value());
|
||||
|
||||
// latestRevisions persisted: registering the same family again yields the next revision.
|
||||
assertEquals(2, reloaded.registerTaskDefinition("web", List.of(container("app", "nginx:latest")),
|
||||
@@ -88,15 +91,18 @@ class EcsServicePersistenceTest {
|
||||
EcsCluster cluster = first.createCluster("c1", Map.of(), REGION);
|
||||
first.tagResource(cluster.getClusterArn(), Map.of("env", "test", "owner", "qa"));
|
||||
first.untagResource(cluster.getClusterArn(), List.of("owner"));
|
||||
first.putAttributes("c1", List.of(new Attribute("a", "1", "container-instance", "t1")), REGION);
|
||||
first.deleteAttributes("c1", List.of(new Attribute("a", "1", "container-instance", "t1")), REGION);
|
||||
String instanceArn = first.registerContainerInstance("c1", null, List.of(), REGION)
|
||||
.getContainerInstanceArn();
|
||||
first.putAttributes("c1", List.of(new Attribute("a", "1", "container-instance", instanceArn)), REGION);
|
||||
first.deleteAttributes("c1", List.of(new Attribute("a", "1", "container-instance", instanceArn)), REGION);
|
||||
|
||||
EcsService reloaded = serviceWithStorage(storage);
|
||||
|
||||
Map<String, String> tags = reloaded.listTagsForResource(cluster.getClusterArn());
|
||||
assertEquals("test", tags.get("env"));
|
||||
assertFalse(tags.containsKey("owner"), "untagged key must not reappear after restart");
|
||||
assertTrue(reloaded.listAttributes("c1", null, "a", null, REGION).isEmpty(),
|
||||
assertTrue(reloaded.listAttributes("c1", "container-instance", "a", null, null, null, REGION)
|
||||
.attributes().isEmpty(),
|
||||
"deleted attribute must not reappear after restart");
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user