Light, fluffy, and always free - The AWS Local Emulator alternative
fix(ecs): accept a service ARN in ListTasks (#4859)
Mario Toffia5a8694e97a0b
diff --git a/src/main/java/io/github/hectorvent/floci/services/ecs/EcsService.java b/src/main/java/io/github/hectorvent/floci/services/ecs/EcsService.javaindex 0d35331313..b33f1bfbae 100644--- a/src/main/java/io/github/hectorvent/floci/services/ecs/EcsService.java+++ b/src/main/java/io/github/hectorvent/floci/services/ecs/EcsService.java@@ -2186,9 +2186,10 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab: (serviceName != null ? clusters.get(clusterKey(region, DEFAULT_CLUSTER)) : null);String clusterArn = clusterRef != null ? cluster.getClusterArn() : null;// A serviceName filter selects the service's own tasks, so it resolves through the- // reconciler-stamped ownership rather than the caller-supplied group.+ // reconciler-stamped ownership rather than the caller-supplied group. It may be the+ // service's name or its ARN; as on AWS, only the last path segment names the service.EcsServiceModel svc = serviceName != null && cluster != null- ? services.get(serviceKey(region, cluster.getClusterName(), serviceName))+ ? services.get(serviceKey(region, cluster.getClusterName(), extractServiceName(serviceName))): null;String family = request.getFamily();LaunchType launchType = request.getLaunchType();diff --git a/src/test/java/io/github/hectorvent/floci/services/ecs/EcsFargateEdgeCaseIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ecs/EcsFargateEdgeCaseIntegrationTest.javaindex 6b593296a0..e176d8674d 100644--- a/src/test/java/io/github/hectorvent/floci/services/ecs/EcsFargateEdgeCaseIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/ecs/EcsFargateEdgeCaseIntegrationTest.java@@ -6,10 +6,12 @@ import io.restassured.response.Response;import org.junit.jupiter.api.BeforeAll;import org.junit.jupiter.api.Test;+import java.time.Duration;import java.util.List;import java.util.Map;import static io.restassured.RestAssured.given;+import static org.awaitility.Awaitility.await;import static org.hamcrest.Matchers.containsString;import static org.hamcrest.Matchers.equalTo;import static org.hamcrest.Matchers.hasItems;@@ -524,6 +526,35 @@ class EcsFargateEdgeCaseIntegrationTest {"the last page carries no token");}+ @Test+ void listTasksTakesTheServiceNameOrItsArn() {+ String family = seed("edge-list-service");+ String serviceArn = call("CreateService", "{\"cluster\":\"" + CLUSTER+ + "\",\"serviceName\":\"edge-list-svc\",\"taskDefinition\":\"" + family+ + "\",\"desiredCount\":1,\"launchType\":\"FARGATE\"," + NETWORK + "}", 200)+ .jsonPath().getString("service.serviceArn");+ String idleArn = call("CreateService", "{\"cluster\":\"" + CLUSTER+ + "\",\"serviceName\":\"edge-list-idle-svc\",\"taskDefinition\":\"" + family+ + "\",\"desiredCount\":0,\"launchType\":\"FARGATE\"," + NETWORK + "}", 200)+ .jsonPath().getString("service.serviceArn");++ // The reconciler launches the service's task on its own schedule.+ await().atMost(Duration.ofSeconds(30)).pollInterval(Duration.ofMillis(200))+ .until(() -> listTaskArns("edge-list-svc").size() == 1);+ List<String> byName = listTaskArns("edge-list-svc");++ assertEquals(byName, listTaskArns(serviceArn), "the service ARN must select the same task");+ assertEquals(byName, listTaskArns(serviceArn.replace("service/" + CLUSTER + "/", "service/")),+ "the old service/<name> ARN format must select it too");+ assertEquals(List.of(), listTaskArns(idleArn),+ "another service's ARN must not select this service's task");+ }++ private static List<String> listTaskArns(String serviceName) {+ return call("ListTasks", "{\"cluster\":\"" + CLUSTER + "\",\"serviceName\":\"" + serviceName+ + "\"}", 200).jsonPath().getList("taskArns");+ }+@Testvoid onlyTheDocumentedUpdatesRollTheServiceDeployment() {String family = seed("edge-update-rolls");diff --git a/src/test/java/io/github/hectorvent/floci/services/ecs/EcsServiceTaskOwnershipTest.java b/src/test/java/io/github/hectorvent/floci/services/ecs/EcsServiceTaskOwnershipTest.javaindex 32a12e20c9..9c3014c41d 100644--- a/src/test/java/io/github/hectorvent/floci/services/ecs/EcsServiceTaskOwnershipTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/ecs/EcsServiceTaskOwnershipTest.java@@ -149,6 +149,29 @@ class EcsServiceTaskOwnershipTest {"a task that merely names the service as its group is not service-owned");}+ @Test+ void listTasksByServiceArnListsTheSameTasksAsByServiceName() {+ EcsService service = newMockModeService();+ service.createCluster("arn-cluster", REGION);+ registerTaskDef(service);+ String serviceArn = service.createService("arn-cluster", "svc", "own-fam", 1, LaunchType.FARGATE,+ List.of(), null, REGION).getServiceArn();+ String idleArn = service.createService("arn-cluster", "idle", "own-fam", 0, LaunchType.FARGATE,+ List.of(), null, REGION).getServiceArn();+ service.reconcileServices();++ List<String> byName = service.listTasks("arn-cluster", null, null, "svc", REGION);+ String shortArn = serviceArn.replace("service/arn-cluster/", "service/");++ assertEquals(1, byName.size(), "the service runs its one task");+ assertEquals(byName, service.listTasks("arn-cluster", null, null, serviceArn, REGION),+ "the service ARN selects the same tasks as the service name");+ assertEquals(byName, service.listTasks("arn-cluster", null, null, shortArn, REGION),+ "the old service/<name> ARN format selects them too");+ assertEquals(List.of(), service.listTasks("arn-cluster", null, null, idleArn, REGION),+ "another service's ARN does not select this service's tasks");+ }+@Testvoid aSameNamedClusterInAnotherRegionIsNotSweptIntoReconciliation() {EcsService service = newMockModeService();