diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/StepFunctionsDescribeMapRunTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/StepFunctionsDescribeMapRunTest.java
new file mode 100644
index 0000000000..c046b7bf8d
--- /dev/null
+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/StepFunctionsDescribeMapRunTest.java
@@ -0,0 +1,200 @@
+package com.floci.test;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+import software.amazon.awssdk.services.s3.S3Client;
+import software.amazon.awssdk.services.s3.model.DeleteBucketRequest;
+import software.amazon.awssdk.services.s3.model.DeleteObjectRequest;
+import software.amazon.awssdk.services.s3.model.ListObjectsV2Response;
+import software.amazon.awssdk.services.s3.model.S3Object;
+import software.amazon.awssdk.services.sfn.SfnClient;
+import software.amazon.awssdk.services.sfn.model.DescribeExecutionResponse;
+import software.amazon.awssdk.services.sfn.model.DescribeMapRunResponse;
+import software.amazon.awssdk.services.sfn.model.ExecutionStatus;
+import software.amazon.awssdk.services.sfn.model.MapRunExecutionCounts;
+import software.amazon.awssdk.services.sfn.model.MapRunItemCounts;
+import software.amazon.awssdk.services.sfn.model.MapRunStatus;
+import software.amazon.awssdk.services.sfn.model.ResourceNotFoundException;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/**
+ * Compatibility test for DescribeMapRun through the real SFN SDK client.
+ *
+ *
StepFunctionsDescribeMapRunIntegrationTest already pins the wire shape and every field
+ * value with RestAssured. This test exists to exercise what that one cannot: the SDK's own
+ * request serialization, endpoint routing and response deserialization for
+ * {@code sfn.describeMapRun(...)}.
+ *
+ *
A distributed Map run is only describable once its {@code ResultWriter} has minted the Map
+ * run ARN and returned it in the Map result — the same way an SDK caller obtains it.
+ */
+@DisplayName("SFN DescribeMapRun")
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
+class StepFunctionsDescribeMapRunTest {
+
+ private static final String ROLE_ARN = System.getenv("SFN_ROLE_ARN") != null
+ ? System.getenv("SFN_ROLE_ARN")
+ : "arn:aws:iam::000000000000:role/service-role/test-role";
+ /** AWS reports an unbounded Map run as Integer.MAX_VALUE, not as the ASL default of 0. */
+ private static final int UNBOUNDED_CONCURRENCY = 2147483647;
+ private static final ObjectMapper MAPPER = new ObjectMapper();
+
+ private static SfnClient sfn;
+ private static S3Client s3;
+ private static String bucketName;
+ private static String stateMachineArn;
+ private static String executionArn;
+ private static String mapRunArn;
+
+ @BeforeAll
+ static void setup() throws Exception {
+ sfn = TestFixtures.sfnClient();
+ s3 = TestFixtures.s3Client();
+
+ bucketName = TestFixtures.uniqueName("describe-map-run");
+ s3.createBucket(b -> b.bucket(bucketName));
+
+ String definition = """
+ {
+ "QueryLanguage": "JSONata",
+ "StartAt": "Fan",
+ "States": {
+ "Fan": {
+ "Type": "Map",
+ "End": true,
+ "Items": [{"n": 1}, {"n": 2}, {"n": 3}],
+ "ItemProcessor": {
+ "ProcessorConfig": {"Mode": "DISTRIBUTED", "ExecutionType": "STANDARD"},
+ "StartAt": "Keep",
+ "States": {"Keep": {"Type": "Pass", "End": true}}
+ },
+ "ResultWriter": {
+ "Resource": "arn:aws:states:::s3:putObject",
+ "Arguments": {"Bucket": "%s", "Prefix": "out"}
+ }
+ }
+ }
+ }
+ """.formatted(bucketName);
+
+ stateMachineArn = sfn.createStateMachine(b -> b
+ .name(TestFixtures.uniqueName("describe-map-run-sm"))
+ .definition(definition)
+ .roleArn(ROLE_ARN)).stateMachineArn();
+
+ executionArn = sfn.startExecution(b -> b
+ .stateMachineArn(stateMachineArn)
+ .input("{}")).executionArn();
+
+ DescribeExecutionResponse execution = pollUntilDone(executionArn);
+ assertThat(execution.status())
+ .as("cause: %s", execution.cause())
+ .isEqualTo(ExecutionStatus.SUCCEEDED);
+
+ mapRunArn = MAPPER.readTree(execution.output()).path("MapRunArn").asText();
+ assertThat(mapRunArn).contains(":mapRun:");
+ }
+
+ @AfterAll
+ static void cleanup() {
+ if (sfn != null) {
+ if (stateMachineArn != null) {
+ try {
+ sfn.deleteStateMachine(b -> b.stateMachineArn(stateMachineArn));
+ } catch (Exception ignored) {
+ }
+ }
+ sfn.close();
+ }
+ if (s3 != null) {
+ try {
+ ListObjectsV2Response objects = s3.listObjectsV2(b -> b.bucket(bucketName));
+ for (S3Object object : objects.contents()) {
+ s3.deleteObject(DeleteObjectRequest.builder()
+ .bucket(bucketName).key(object.key()).build());
+ }
+ s3.deleteBucket(DeleteBucketRequest.builder().bucket(bucketName).build());
+ } catch (Exception ignored) {
+ }
+ s3.close();
+ }
+ }
+
+ @Test
+ @Order(1)
+ void describeMapRun_deserializesTheFinishedRun() {
+ DescribeMapRunResponse response = sfn.describeMapRun(b -> b.mapRunArn(mapRunArn));
+
+ assertThat(response.status()).isEqualTo(MapRunStatus.SUCCEEDED);
+ assertThat(response.executionArn()).isEqualTo(executionArn);
+ assertThat(response.maxConcurrency()).isEqualTo(UNBOUNDED_CONCURRENCY);
+ assertThat(response.toleratedFailurePercentage()).isEqualTo(0.0f);
+ assertThat(response.toleratedFailureCount()).isEqualTo(0);
+ assertThat(response.redriveCount()).isEqualTo(0);
+
+ assertItemCounts(response.itemCounts());
+ assertExecutionCounts(response.executionCounts());
+ }
+
+ @Test
+ @Order(2)
+ void describeMapRun_unknownArnRaisesResourceNotFound() {
+ String unknown = "arn:aws:states:us-east-1:000000000000:mapRun:"
+ + TestFixtures.uniqueName("no-such-map-run") + "/"
+ + "00000000-0000-0000-0000-000000000000:11111111-1111-1111-1111-111111111111";
+
+ assertThatThrownBy(() -> sfn.describeMapRun(b -> b.mapRunArn(unknown)))
+ .isInstanceOf(ResourceNotFoundException.class)
+ .hasMessageContaining("Resource not found: '" + unknown + "'");
+ }
+
+ // ──────────────────────────── helpers ────────────────────────────
+
+ /** The ten counters of a Map run all of whose three items succeeded. */
+ private static void assertItemCounts(MapRunItemCounts counts) {
+ assertThat(counts.pending()).isEqualTo(0);
+ assertThat(counts.running()).isEqualTo(0);
+ assertThat(counts.succeeded()).isEqualTo(3);
+ assertThat(counts.failed()).isEqualTo(0);
+ assertThat(counts.timedOut()).isEqualTo(0);
+ assertThat(counts.aborted()).isEqualTo(0);
+ assertThat(counts.total()).isEqualTo(3);
+ assertThat(counts.resultsWritten()).isEqualTo(3);
+ assertThat(counts.failuresNotRedrivable()).isEqualTo(0);
+ assertThat(counts.pendingRedrive()).isEqualTo(0);
+ }
+
+ /** One child execution per item: ItemBatcher is not applied, so the shape matches itemCounts. */
+ private static void assertExecutionCounts(MapRunExecutionCounts counts) {
+ assertThat(counts.pending()).isEqualTo(0);
+ assertThat(counts.running()).isEqualTo(0);
+ assertThat(counts.succeeded()).isEqualTo(3);
+ assertThat(counts.failed()).isEqualTo(0);
+ assertThat(counts.timedOut()).isEqualTo(0);
+ assertThat(counts.aborted()).isEqualTo(0);
+ assertThat(counts.total()).isEqualTo(3);
+ assertThat(counts.resultsWritten()).isEqualTo(3);
+ assertThat(counts.failuresNotRedrivable()).isEqualTo(0);
+ assertThat(counts.pendingRedrive()).isEqualTo(0);
+ }
+
+ private static DescribeExecutionResponse pollUntilDone(String execArn) throws InterruptedException {
+ for (int i = 0; i < 150; i++) {
+ DescribeExecutionResponse resp = sfn.describeExecution(b -> b.executionArn(execArn));
+ if (resp.status() != ExecutionStatus.RUNNING) {
+ return resp;
+ }
+ Thread.sleep(100);
+ }
+ throw new AssertionError("Execution did not complete within timeout: " + execArn);
+ }
+}
diff --git a/docs/services/step-functions.md b/docs/services/step-functions.md
index 1baaa580d2..df9b2b4052 100644
--- a/docs/services/step-functions.md
+++ b/docs/services/step-functions.md
@@ -23,6 +23,7 @@
| `ListExecutions` | List executions for a state machine |
| `StopExecution` | Stop a running execution |
| `GetExecutionHistory` | Get the full event history of an execution |
+| `DescribeMapRun` | Get the item and execution counters of a distributed Map run |
| `SendTaskSuccess` | Report task success (for `.waitForTaskToken` tasks) |
| `SendTaskFailure` | Report task failure |
| `SendTaskHeartbeat` | Send a heartbeat for long-running tasks |
diff --git a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java
index a4c25f9728..526c2bd713 100644
--- a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java
+++ b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java
@@ -33,6 +33,7 @@ import io.github.hectorvent.floci.services.s3.model.S3Object;
import io.github.hectorvent.floci.services.sqs.SqsJsonHandler;
import io.github.hectorvent.floci.services.stepfunctions.model.Execution;
import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent;
+import io.github.hectorvent.floci.services.stepfunctions.model.MapRun;
import io.github.hectorvent.floci.services.stepfunctions.model.MockedResponseStep;
import io.github.hectorvent.floci.services.stepfunctions.model.MockedTestCase;
import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine;
@@ -991,6 +992,7 @@ public class AslExecutor {
case "startSyncExecution" -> invokeAwsSdkSfnStartSyncExecution(input, region);
case "sendTaskSuccess" -> invokeAwsSdkSfnSendTaskSuccess(input);
case "sendTaskFailure" -> invokeAwsSdkSfnSendTaskFailure(input);
+ case "describeMapRun" -> invokeAwsSdkSfnDescribeMapRun(input);
default -> throw new FailStateException("States.TaskFailed",
"Unsupported resource: " + AWS_SDK_SFN_PREFIX + action);
};
@@ -1049,6 +1051,30 @@ public class AslExecutor {
return response;
}
+ /**
+ * AWS SDK integration for {@code sfn:describeMapRun}. The SDK names every field in PascalCase
+ * and renders both dates as ISO-8601, where the wire response of the same run carries epoch
+ * seconds. Recasing that response is what keeps the two renderings of a Map run in step.
+ */
+ private JsonNode invokeAwsSdkSfnDescribeMapRun(JsonNode input) {
+ String mapRunArn = input.path("MapRunArn").asText(null);
+ if (mapRunArn == null || mapRunArn.isBlank()) {
+ throw new FailStateException("Sfn.InvalidArnException",
+ "MapRunArn is required for DescribeMapRun");
+ }
+ MapRun mapRun;
+ try {
+ mapRun = sfnService.get().describeMapRun(mapRunArn);
+ } catch (AwsException e) {
+ throw new FailStateException(sdkExceptionName("Sfn", e.getErrorCode()), e.getMessage());
+ }
+ ObjectNode response = (ObjectNode) recaseKeys(objectMapper,
+ StepFunctionsJsonHandler.describeMapRunResponse(objectMapper, mapRun), true);
+ response.put("StartDate", sdkTimestamp(mapRun.getStartDate()));
+ response.put("StopDate", sdkTimestamp(mapRun.getStopDate()));
+ return response;
+ }
+
/**
* AWS SDK integration for {@code sfn:sendTaskSuccess}. AWS fails the calling task with
* {@code Sfn.InvalidTokenException} when the token names no waiting task, so a token that
@@ -2018,6 +2044,7 @@ public class AslExecutor {
}
mapResult = applyResultWriter(name, stateDef, mapInput, results, childInputs, childTimings,
sm, context, jsonata, variables);
+ recordMapRun(mapResult, context, childTimings, requestedConcurrency);
}
if (jsonata) {
@@ -2070,6 +2097,42 @@ public class AslExecutor {
return Math.min(itemCount, Math.min(requestedLimit, serviceLimit));
}
+ /**
+ * Retains the Map run that {@link #applyResultWriter} just exported, so {@code DescribeMapRun}
+ * can report its counters afterwards. Only an exported run is retained: the Map result is the
+ * one place an ASL author reads the Map run ARN, so a run without a {@code ResultWriter}
+ * {@code Resource} has no ARN anybody could describe.
+ *
+ *
The run starts with its first item, taken from the child timings the export record already
+ * collected, and stops here: the {@code ResultWriter} export has just returned, and AWS closes
+ * a Map run's window on the export rather than on the last item. A run over no items starts and
+ * stops at that same instant.
+ */
+ private void recordMapRun(JsonNode mapResult, JsonNode context, List childTimings,
+ int requestedConcurrency) {
+ String mapRunArn = mapResult.path("MapRunArn").asText(null);
+ if (mapRunArn == null) {
+ return;
+ }
+ long stop = System.currentTimeMillis();
+ long start = stop;
+ for (long[] timing : childTimings) {
+ start = Math.min(start, timing[0]);
+ }
+
+ MapRun mapRun = new MapRun();
+ mapRun.setMapRunArn(mapRunArn);
+ mapRun.setExecutionArn(context.path("Execution").path("Id").asText(null));
+ mapRun.setStartDate(start / 1000.0);
+ mapRun.setStopDate(stop / 1000.0);
+ mapRun.setItemCount(childTimings.size());
+ // ASL spells an unbounded Map as MaxConcurrency 0, or by omitting it; DescribeMapRun
+ // reports that same run as Integer.MAX_VALUE.
+ mapRun.setMaxConcurrency(
+ requestedConcurrency == 0 ? Integer.MAX_VALUE : requestedConcurrency);
+ sfnService.get().recordMapRun(mapRun);
+ }
+
/**
* Emulates a Distributed Map state's {@code ResultWriter}
* (AWS docs).
diff --git a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsJsonHandler.java
index c6784a64b4..c790471e0d 100644
--- a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsJsonHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsJsonHandler.java
@@ -10,6 +10,7 @@ import io.github.hectorvent.floci.services.stepfunctions.model.Activity;
import io.github.hectorvent.floci.services.stepfunctions.model.ActivityTask;
import io.github.hectorvent.floci.services.stepfunctions.model.Execution;
import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent;
+import io.github.hectorvent.floci.services.stepfunctions.model.MapRun;
import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
@@ -48,6 +49,7 @@ public class StepFunctionsJsonHandler {
case "ListExecutions" -> handleListExecutions(request);
case "StopExecution" -> handleStopExecution(request);
case "GetExecutionHistory" -> handleGetExecutionHistory(request);
+ case "DescribeMapRun" -> handleDescribeMapRun(request);
case "SendTaskSuccess" -> handleSendTaskSuccess(request);
case "SendTaskFailure" -> handleSendTaskFailure(request);
case "SendTaskHeartbeat" -> handleSendTaskHeartbeat(request);
@@ -287,6 +289,51 @@ public class StepFunctionsJsonHandler {
return Response.ok(response).build();
}
+ private Response handleDescribeMapRun(JsonNode request) {
+ MapRun mapRun = service.describeMapRun(requiredText(request, "mapRunArn"));
+ return Response.ok(describeMapRunResponse(objectMapper, mapRun)).build();
+ }
+
+ /**
+ * The wire response of {@code DescribeMapRun}, measured against us-east-1. The
+ * {@code arn:aws:states:::aws-sdk:sfn:describeMapRun} Task integration renders the same node in
+ * PascalCase, so this is the one place the response is described.
+ *
+ * A retained run is one whose every item succeeded, because a Map fails on the first item
+ * that fails. That fixes {@code status}, both zero tolerances and {@code redriveCount}:
+ * {@code redriveDate} is absent until a run is redriven, and no run here ever is.
+ */
+ static ObjectNode describeMapRunResponse(ObjectMapper objectMapper, MapRun mapRun) {
+ ObjectNode response = objectMapper.createObjectNode();
+ response.put("mapRunArn", mapRun.getMapRunArn());
+ response.put("executionArn", mapRun.getExecutionArn());
+ response.put("status", "SUCCEEDED");
+ response.put("startDate", mapRun.getStartDate());
+ response.put("stopDate", mapRun.getStopDate());
+ response.put("maxConcurrency", mapRun.getMaxConcurrency());
+ response.put("toleratedFailurePercentage", 0.0);
+ response.put("toleratedFailureCount", 0);
+ putMapRunCounts(response.putObject("itemCounts"), mapRun.getItemCount());
+ // One child execution per item: ItemBatcher is not applied, so no execution covers a batch.
+ putMapRunCounts(response.putObject("executionCounts"), mapRun.getItemCount());
+ response.put("redriveCount", 0);
+ return response;
+ }
+
+ /** The ten counters of a run whose every item succeeded and was written to the result set. */
+ private static void putMapRunCounts(ObjectNode counts, int items) {
+ counts.put("pending", 0);
+ counts.put("running", 0);
+ counts.put("succeeded", items);
+ counts.put("failed", 0);
+ counts.put("timedOut", 0);
+ counts.put("aborted", 0);
+ counts.put("total", items);
+ counts.put("resultsWritten", items);
+ counts.put("failuresNotRedrivable", 0);
+ counts.put("pendingRedrive", 0);
+ }
+
private Response handleListExecutions(JsonNode request) {
List list = service.listExecutions(request.path("stateMachineArn").asText());
ObjectNode response = objectMapper.createObjectNode();
diff --git a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsService.java b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsService.java
index b185dba2e8..fe7b03389b 100644
--- a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsService.java
@@ -16,6 +16,7 @@ import io.github.hectorvent.floci.services.stepfunctions.model.Activity;
import io.github.hectorvent.floci.services.stepfunctions.model.ActivityTask;
import io.github.hectorvent.floci.services.stepfunctions.model.Execution;
import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent;
+import io.github.hectorvent.floci.services.stepfunctions.model.MapRun;
import io.github.hectorvent.floci.services.stepfunctions.model.MockedTestCase;
import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine;
import io.github.hectorvent.floci.services.stepfunctions.model.StateMachineVersion;
@@ -44,6 +45,7 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
private final StorageBackend stateMachineStore;
private final StorageBackend executionStore;
private final StorageBackend activityStore;
+ private final StorageBackend mapRunStore;
private final Map> historyCache = new ConcurrentHashMap<>();
private final Map> activityQueues = new ConcurrentHashMap<>();
private final Map> pendingTaskTokens = new ConcurrentHashMap<>();
@@ -89,6 +91,8 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
new TypeReference