mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(stepfunctions): resolve state machine alias ARNs (#3607)
* fix(stepfunctions): resolve state machine alias arns * docs(stepfunctions): list alias actions * fix(stepfunctions): paginate state machine aliases * ci: rerun compatibility checks
This commit is contained in:
1 parent
73ef15f6e2
commit
e82836348b
7 files changed
+832
-35
No files matched your search
@@ -16,6 +16,11 @@
|
||||
| `PublishStateMachineVersion` | - |
|
||||
| `ListStateMachineVersions` | - |
|
||||
| `DeleteStateMachineVersion` | - |
|
||||
| `CreateStateMachineAlias` | - |
|
||||
| `DescribeStateMachineAlias` | - |
|
||||
| `ListStateMachineAliases` | - |
|
||||
| `UpdateStateMachineAlias` | - |
|
||||
| `DeleteStateMachineAlias` | - |
|
||||
| `ValidateStateMachineDefinition` | Validate an ASL definition without creating a state machine |
|
||||
| `StartExecution` | Start a new execution |
|
||||
| `StartSyncExecution` | - |
|
||||
|
||||
+131
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.stepfunctions;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsErrorResponse;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
@@ -11,7 +12,9 @@ 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.RoutingConfiguration;
|
||||
import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine;
|
||||
import io.github.hectorvent.floci.services.stepfunctions.model.StateMachineAlias;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
@@ -45,6 +48,11 @@ public class StepFunctionsJsonHandler {
|
||||
case "PublishStateMachineVersion" -> handlePublishStateMachineVersion(request);
|
||||
case "ListStateMachineVersions" -> handleListStateMachineVersions(request);
|
||||
case "DeleteStateMachineVersion" -> handleDeleteStateMachineVersion(request);
|
||||
case "CreateStateMachineAlias" -> handleCreateStateMachineAlias(request);
|
||||
case "DescribeStateMachineAlias" -> handleDescribeStateMachineAlias(request);
|
||||
case "ListStateMachineAliases" -> handleListStateMachineAliases(request);
|
||||
case "UpdateStateMachineAlias" -> handleUpdateStateMachineAlias(request);
|
||||
case "DeleteStateMachineAlias" -> handleDeleteStateMachineAlias(request);
|
||||
case "ValidateStateMachineDefinition" -> handleValidateStateMachineDefinition(request);
|
||||
case "StartExecution" -> handleStartExecution(request, region);
|
||||
case "StartSyncExecution" -> handleStartSyncExecution(request, region);
|
||||
@@ -159,6 +167,77 @@ public class StepFunctionsJsonHandler {
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
private Response handleCreateStateMachineAlias(JsonNode request) {
|
||||
StateMachineAlias alias = service.createStateMachineAlias(
|
||||
requiredText(request, "name"),
|
||||
optionalText(request, "description"),
|
||||
parseRoutingConfiguration(request, true));
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.put("stateMachineAliasArn", alias.getStateMachineAliasArn());
|
||||
response.put("creationDate", alias.getCreationDate());
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private Response handleDescribeStateMachineAlias(JsonNode request) {
|
||||
StateMachineAlias alias = service.describeStateMachineAlias(
|
||||
requiredText(request, "stateMachineAliasArn"));
|
||||
return Response.ok(aliasResponse(alias)).build();
|
||||
}
|
||||
|
||||
private Response handleListStateMachineAliases(JsonNode request) {
|
||||
Integer maxResults = request.hasNonNull("maxResults")
|
||||
? request.path("maxResults").asInt() : null;
|
||||
PaginatedResult<StateMachineAlias> page = service.listStateMachineAliases(
|
||||
requiredText(request, "stateMachineArn"),
|
||||
maxResults,
|
||||
optionalText(request, "nextToken"));
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
ArrayNode array = response.putArray("stateMachineAliases");
|
||||
for (StateMachineAlias alias : page.items()) {
|
||||
ObjectNode item = array.addObject();
|
||||
item.put("stateMachineAliasArn", alias.getStateMachineAliasArn());
|
||||
item.put("creationDate", alias.getCreationDate());
|
||||
}
|
||||
if (page.nextToken() != null) {
|
||||
response.put("nextToken", page.nextToken());
|
||||
}
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private Response handleUpdateStateMachineAlias(JsonNode request) {
|
||||
boolean descriptionProvided = request.has("description");
|
||||
StateMachineAlias alias = service.updateStateMachineAlias(
|
||||
requiredText(request, "stateMachineAliasArn"),
|
||||
optionalText(request, "description"),
|
||||
descriptionProvided,
|
||||
parseRoutingConfiguration(request, false));
|
||||
return Response.ok(objectMapper.createObjectNode()
|
||||
.put("updateDate", alias.getUpdateDate())).build();
|
||||
}
|
||||
|
||||
private Response handleDeleteStateMachineAlias(JsonNode request) {
|
||||
service.deleteStateMachineAlias(requiredText(request, "stateMachineAliasArn"));
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
private ObjectNode aliasResponse(StateMachineAlias alias) {
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.put("stateMachineAliasArn", alias.getStateMachineAliasArn());
|
||||
response.put("name", alias.getName());
|
||||
if (alias.getDescription() != null) {
|
||||
response.put("description", alias.getDescription());
|
||||
}
|
||||
ArrayNode routing = response.putArray("routingConfiguration");
|
||||
for (RoutingConfiguration route : alias.getRoutingConfiguration()) {
|
||||
ObjectNode item = routing.addObject();
|
||||
item.put("stateMachineVersionArn", route.getStateMachineVersionArn());
|
||||
item.put("weight", route.getWeight());
|
||||
}
|
||||
response.put("creationDate", alias.getCreationDate());
|
||||
response.put("updateDate", alias.getUpdateDate());
|
||||
return response;
|
||||
}
|
||||
|
||||
private Response handleDescribeStateMachine(JsonNode request) {
|
||||
String includedData = optionalText(request, "includedData");
|
||||
if (includedData != null
|
||||
@@ -265,6 +344,12 @@ public class StepFunctionsJsonHandler {
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.put("executionArn", exec.getExecutionArn());
|
||||
response.put("stateMachineArn", exec.getStateMachineArn());
|
||||
if (exec.getStateMachineVersionArn() != null) {
|
||||
response.put("stateMachineVersionArn", exec.getStateMachineVersionArn());
|
||||
}
|
||||
if (exec.getStateMachineAliasArn() != null) {
|
||||
response.put("stateMachineAliasArn", exec.getStateMachineAliasArn());
|
||||
}
|
||||
response.put("name", exec.getName());
|
||||
response.put("status", exec.getStatus());
|
||||
response.put("startDate", exec.getStartDate());
|
||||
@@ -281,6 +366,12 @@ public class StepFunctionsJsonHandler {
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.put("executionArn", exec.getExecutionArn());
|
||||
response.put("stateMachineArn", exec.getStateMachineArn());
|
||||
if (exec.getStateMachineVersionArn() != null) {
|
||||
response.put("stateMachineVersionArn", exec.getStateMachineVersionArn());
|
||||
}
|
||||
if (exec.getStateMachineAliasArn() != null) {
|
||||
response.put("stateMachineAliasArn", exec.getStateMachineAliasArn());
|
||||
}
|
||||
response.put("name", exec.getName());
|
||||
response.put("status", exec.getStatus());
|
||||
response.put("startDate", exec.getStartDate());
|
||||
@@ -346,6 +437,12 @@ public class StepFunctionsJsonHandler {
|
||||
ObjectNode item = array.addObject();
|
||||
item.put("executionArn", e.getExecutionArn());
|
||||
item.put("stateMachineArn", e.getStateMachineArn());
|
||||
if (e.getStateMachineVersionArn() != null) {
|
||||
item.put("stateMachineVersionArn", e.getStateMachineVersionArn());
|
||||
}
|
||||
if (e.getStateMachineAliasArn() != null) {
|
||||
item.put("stateMachineAliasArn", e.getStateMachineAliasArn());
|
||||
}
|
||||
item.put("name", e.getName());
|
||||
item.put("status", e.getStatus());
|
||||
item.put("startDate", e.getStartDate());
|
||||
@@ -527,6 +624,40 @@ public class StepFunctionsJsonHandler {
|
||||
return tags;
|
||||
}
|
||||
|
||||
private List<RoutingConfiguration> parseRoutingConfiguration(
|
||||
JsonNode request, boolean required) {
|
||||
JsonNode routingNode = request.get("routingConfiguration");
|
||||
if (routingNode == null || routingNode.isNull()) {
|
||||
if (required) {
|
||||
throw new AwsException(
|
||||
"MissingRequiredParameter", "routingConfiguration is required.", 400);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (!routingNode.isArray()) {
|
||||
throw new AwsException(
|
||||
"ValidationException", "routingConfiguration must be a list.", 400);
|
||||
}
|
||||
List<RoutingConfiguration> routing = new ArrayList<>();
|
||||
for (JsonNode item : routingNode) {
|
||||
if (!item.isObject()) {
|
||||
throw new AwsException(
|
||||
"ValidationException",
|
||||
"routingConfiguration entries must be objects.", 400);
|
||||
}
|
||||
String versionArn = requiredText(item, "stateMachineVersionArn");
|
||||
JsonNode weightNode = item.get("weight");
|
||||
if (weightNode == null || weightNode.isNull()) {
|
||||
throw new AwsException("MissingRequiredParameter", "weight is required.", 400);
|
||||
}
|
||||
if (!weightNode.isIntegralNumber()) {
|
||||
throw new AwsException("ValidationException", "weight must be an integer.", 400);
|
||||
}
|
||||
routing.add(new RoutingConfiguration(versionArn, weightNode.intValue()));
|
||||
}
|
||||
return routing;
|
||||
}
|
||||
|
||||
private static String requiredText(JsonNode request, String fieldName) {
|
||||
JsonNode node = request.get(fieldName);
|
||||
if (node == null || node.isNull()) {
|
||||
|
||||
+412
-35
@@ -3,6 +3,8 @@ package io.github.hectorvent.floci.services.stepfunctions;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.AwsRegions;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.common.Pagination;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.resource.ExplorerResource;
|
||||
import io.github.hectorvent.floci.core.resource.ResourceProvider;
|
||||
@@ -19,7 +21,9 @@ 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.RoutingConfiguration;
|
||||
import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine;
|
||||
import io.github.hectorvent.floci.services.stepfunctions.model.StateMachineAlias;
|
||||
import io.github.hectorvent.floci.services.stepfunctions.model.StateMachineVersion;
|
||||
import io.github.hectorvent.floci.core.common.Resettable;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
@@ -34,6 +38,7 @@ import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -46,6 +51,7 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
|
||||
private static final int HISTORY_PERSIST_CHECKPOINT = 100;
|
||||
|
||||
private final StorageBackend<String, StateMachine> stateMachineStore;
|
||||
private final StorageBackend<String, StateMachineAlias> stateMachineAliasStore;
|
||||
// Account-aware: the startup sweep has no request context and must reach every account.
|
||||
private final AccountAwareStorageBackend<Execution> executionStore;
|
||||
private final StorageBackend<String, Activity> activityStore;
|
||||
@@ -128,6 +134,11 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
|
||||
new TypeReference<Map<String, Activity>>() {});
|
||||
this.mapRunStore = storageFactory.create("stepfunctions", "sfn-map-runs.json",
|
||||
new TypeReference<Map<String, MapRun>>() {});
|
||||
// Keep the established state-machine/execution/activity/map-run factory order stable for
|
||||
// embedders and tests that supply sequential backends. New stores are appended.
|
||||
this.stateMachineAliasStore = storageFactory.create(
|
||||
"stepfunctions", "sfn-state-machine-aliases.json",
|
||||
new TypeReference<Map<String, StateMachineAlias>>() {});
|
||||
this.regionResolver = regionResolver;
|
||||
this.aslExecutor = aslExecutor;
|
||||
this.objectMapper = objectMapper;
|
||||
@@ -419,23 +430,34 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
|
||||
return copyStateMachine(stateMachine.get());
|
||||
}
|
||||
|
||||
VersionArn parsedVersion = parseVersionArn(arn);
|
||||
if (parsedVersion != null) {
|
||||
Optional<StateMachine> baseStateMachine = stateMachineStore.get(parsedVersion.baseArn());
|
||||
if (baseStateMachine.isPresent()) {
|
||||
return baseStateMachine.get().getVersions().stream()
|
||||
.filter(version -> arn.equals(version.getStateMachineVersionArn()))
|
||||
.findFirst()
|
||||
.map(version -> stateMachineFromVersion(baseStateMachine.get(), version))
|
||||
.orElseThrow(() -> new AwsException(
|
||||
"StateMachineDoesNotExist",
|
||||
"State machine does not exist", 400));
|
||||
QualifiedStateMachineArn qualifiedArn = parseQualifiedStateMachineArn(arn);
|
||||
if (qualifiedArn != null) {
|
||||
String versionArn = qualifiedArn.isVersion()
|
||||
? arn
|
||||
: stateMachineAliasStore.get(arn)
|
||||
.map(alias -> alias.getRoutingConfiguration().get(0)
|
||||
.getStateMachineVersionArn())
|
||||
.orElse(null);
|
||||
if (versionArn != null) {
|
||||
return describeStateMachineVersion(qualifiedArn.baseArn(), versionArn);
|
||||
}
|
||||
}
|
||||
throw new AwsException(
|
||||
"StateMachineDoesNotExist", "State machine does not exist", 400);
|
||||
}
|
||||
|
||||
private StateMachine describeStateMachineVersion(String baseArn, String versionArn) {
|
||||
StateMachine baseStateMachine = stateMachineStore.get(baseArn)
|
||||
.orElseThrow(() -> new AwsException(
|
||||
"StateMachineDoesNotExist", "State machine does not exist", 400));
|
||||
return baseStateMachine.getVersions().stream()
|
||||
.filter(version -> versionArn.equals(version.getStateMachineVersionArn()))
|
||||
.findFirst()
|
||||
.map(version -> stateMachineFromVersion(baseStateMachine, version))
|
||||
.orElseThrow(() -> new AwsException(
|
||||
"StateMachineDoesNotExist", "State machine does not exist", 400));
|
||||
}
|
||||
|
||||
/**
|
||||
* Key prefix matching every Step Functions ARN in {@code region}. This store is keyed by the
|
||||
* full ARN, unlike the other services, which key by {@code region::name}, so the prefix has to
|
||||
@@ -513,12 +535,148 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
|
||||
return List.copyOf(versions);
|
||||
}
|
||||
|
||||
// ── State machine aliases ───────────────────────────────────────────────
|
||||
|
||||
public synchronized StateMachineAlias createStateMachineAlias(
|
||||
String name, String description, List<RoutingConfiguration> routingConfiguration) {
|
||||
validateStateMachineAliasName(name);
|
||||
validateAliasDescription(description);
|
||||
String stateMachineArn = validateRoutingConfiguration(routingConfiguration);
|
||||
String aliasArn = stateMachineArn + ":" + name;
|
||||
|
||||
Optional<StateMachineAlias> existing = stateMachineAliasStore.get(aliasArn);
|
||||
if (existing.isPresent()) {
|
||||
StateMachineAlias alias = existing.get();
|
||||
if (Objects.equals(description, alias.getDescription())
|
||||
&& routingConfigurationsEqual(
|
||||
routingConfiguration, alias.getRoutingConfiguration())) {
|
||||
return copyAlias(alias);
|
||||
}
|
||||
throw new AwsException(
|
||||
"ConflictException", "State machine alias already exists: " + aliasArn, 409);
|
||||
}
|
||||
|
||||
StateMachineAlias alias = new StateMachineAlias();
|
||||
alias.setStateMachineAliasArn(aliasArn);
|
||||
alias.setStateMachineArn(stateMachineArn);
|
||||
alias.setName(name);
|
||||
alias.setDescription(description);
|
||||
alias.setRoutingConfiguration(copyRoutingConfiguration(routingConfiguration));
|
||||
stateMachineAliasStore.put(aliasArn, alias);
|
||||
return copyAlias(alias);
|
||||
}
|
||||
|
||||
public StateMachineAlias describeStateMachineAlias(String aliasArn) {
|
||||
validateStateMachineAliasArn(aliasArn);
|
||||
return stateMachineAliasStore.get(aliasArn)
|
||||
.map(this::copyAlias)
|
||||
.orElseThrow(() -> new AwsException(
|
||||
"ResourceNotFound", "State machine alias does not exist: " + aliasArn, 400));
|
||||
}
|
||||
|
||||
public List<StateMachineAlias> listStateMachineAliases(String stateMachineArn) {
|
||||
return listStateMachineAliases(stateMachineArn, null, null).items();
|
||||
}
|
||||
|
||||
public PaginatedResult<StateMachineAlias> listStateMachineAliases(
|
||||
String stateMachineArn, Integer maxResults, String nextToken) {
|
||||
QualifiedStateMachineArn qualifiedArn = parseQualifiedStateMachineArn(stateMachineArn);
|
||||
String baseArn = qualifiedArn != null && qualifiedArn.isVersion()
|
||||
? qualifiedArn.baseArn() : stateMachineArn;
|
||||
validateStateMachineArn(baseArn);
|
||||
if (stateMachineStore.get(baseArn).isEmpty()) {
|
||||
throw new AwsException(
|
||||
"StateMachineDoesNotExist", "State machine does not exist: " + baseArn, 400);
|
||||
}
|
||||
|
||||
List<StateMachineAlias> aliases = stateMachineAliasStore.scan(key -> key.startsWith(baseArn + ":"));
|
||||
if (qualifiedArn != null) {
|
||||
aliases.removeIf(alias -> alias.getRoutingConfiguration().stream()
|
||||
.noneMatch(route -> stateMachineArn.equals(route.getStateMachineVersionArn())));
|
||||
}
|
||||
return Pagination.paginate(
|
||||
aliases.stream().map(this::copyAlias).toList(),
|
||||
StepFunctionsService::aliasPaginationCursor,
|
||||
maxResults,
|
||||
nextToken,
|
||||
100,
|
||||
1000,
|
||||
"ValidationException");
|
||||
}
|
||||
|
||||
private static String aliasPaginationCursor(StateMachineAlias alias) {
|
||||
// ListStateMachineAliases is newest-first. Pagination sorts cursors ascending, so invert
|
||||
// the millisecond timestamp and use the ARN to make aliases created together deterministic.
|
||||
long creationMillis = (long) (alias.getCreationDate() * 1000);
|
||||
return String.format(Locale.ROOT, "%020d:%s",
|
||||
Long.MAX_VALUE - creationMillis, alias.getStateMachineAliasArn());
|
||||
}
|
||||
|
||||
public synchronized StateMachineAlias updateStateMachineAlias(
|
||||
String aliasArn,
|
||||
String description,
|
||||
boolean descriptionProvided,
|
||||
List<RoutingConfiguration> routingConfiguration) {
|
||||
validateStateMachineAliasArn(aliasArn);
|
||||
if (!descriptionProvided && routingConfiguration == null) {
|
||||
throw new AwsException(
|
||||
"MissingRequiredParameter",
|
||||
"Either description or routingConfiguration must be specified.", 400);
|
||||
}
|
||||
if (descriptionProvided) {
|
||||
validateAliasDescription(description);
|
||||
}
|
||||
StateMachineAlias current = stateMachineAliasStore.get(aliasArn)
|
||||
.orElseThrow(() -> new AwsException(
|
||||
"ResourceNotFound", "State machine alias does not exist: " + aliasArn, 400));
|
||||
if (routingConfiguration != null) {
|
||||
String stateMachineArn = validateRoutingConfiguration(routingConfiguration);
|
||||
if (!Objects.equals(current.getStateMachineArn(), stateMachineArn)) {
|
||||
throw new AwsException(
|
||||
"ValidationException",
|
||||
"Alias routes must reference versions of the same state machine.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
StateMachineAlias updated = copyAlias(current);
|
||||
if (descriptionProvided) {
|
||||
updated.setDescription(description);
|
||||
}
|
||||
if (routingConfiguration != null) {
|
||||
updated.setRoutingConfiguration(copyRoutingConfiguration(routingConfiguration));
|
||||
}
|
||||
updated.setUpdateDate(System.currentTimeMillis() / 1000.0);
|
||||
stateMachineAliasStore.put(aliasArn, updated);
|
||||
return copyAlias(updated);
|
||||
}
|
||||
|
||||
public synchronized void deleteStateMachineAlias(String aliasArn) {
|
||||
validateStateMachineAliasArn(aliasArn);
|
||||
if (stateMachineAliasStore.get(aliasArn).isEmpty()) {
|
||||
throw new AwsException(
|
||||
"ResourceNotFound", "State machine alias does not exist: " + aliasArn, 400);
|
||||
}
|
||||
stateMachineAliasStore.delete(aliasArn);
|
||||
}
|
||||
|
||||
public synchronized void deleteStateMachineVersion(String stateMachineVersionArn) {
|
||||
VersionArn parsed = parseVersionArn(stateMachineVersionArn);
|
||||
if (parsed == null) {
|
||||
return;
|
||||
}
|
||||
String baseArn = parsed.baseArn();
|
||||
boolean referencedByAlias = stateMachineAliasStore.scan(
|
||||
key -> key.startsWith(baseArn + ":")).stream()
|
||||
.flatMap(alias -> alias.getRoutingConfiguration().stream())
|
||||
.anyMatch(route -> stateMachineVersionArn.equals(
|
||||
route.getStateMachineVersionArn()));
|
||||
if (referencedByAlias) {
|
||||
throw new AwsException(
|
||||
"ConflictException",
|
||||
"State machine version is referenced by an alias: "
|
||||
+ stateMachineVersionArn,
|
||||
409);
|
||||
}
|
||||
stateMachineStore.get(baseArn).ifPresent(current -> {
|
||||
StateMachine updated = copyStateMachine(current);
|
||||
updated.getVersions().removeIf(
|
||||
@@ -530,6 +688,7 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
|
||||
|
||||
public void deleteStateMachine(String arn) {
|
||||
stateMachineStore.delete(arn);
|
||||
deleteStateMachineAliases(arn);
|
||||
}
|
||||
|
||||
public synchronized boolean deleteStateMachineIfRevisionMatches(
|
||||
@@ -543,14 +702,23 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
|
||||
return false;
|
||||
}
|
||||
stateMachineStore.delete(arn);
|
||||
deleteStateMachineAliases(arn);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void deleteStateMachineAliases(String stateMachineArn) {
|
||||
for (StateMachineAlias alias : stateMachineAliasStore.scan(
|
||||
key -> key.startsWith(stateMachineArn + ":"))) {
|
||||
stateMachineAliasStore.delete(alias.getStateMachineAliasArn());
|
||||
}
|
||||
}
|
||||
|
||||
// ──────────────────────────── Executions ────────────────────────────
|
||||
|
||||
public Execution startExecution(String stateMachineArn, String name, String input, String region) {
|
||||
var selection = splitTestCaseSuffix(stateMachineArn);
|
||||
var sm = describeStateMachine(selection.stateMachineArn());
|
||||
var resolved = resolveStateMachineForExecution(selection.stateMachineArn());
|
||||
var sm = resolved.stateMachine();
|
||||
var mockedTestCase = resolveMockedTestCase(sm, selection);
|
||||
var execName = (name != null && !name.isBlank()) ? name : UUID.randomUUID().toString();
|
||||
boolean express = "EXPRESS".equals(sm.getType());
|
||||
@@ -583,7 +751,9 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
|
||||
|
||||
exec = new Execution();
|
||||
exec.setExecutionArn(arn);
|
||||
exec.setStateMachineArn(selection.stateMachineArn());
|
||||
exec.setStateMachineArn(resolved.baseArn());
|
||||
exec.setStateMachineVersionArn(resolved.versionArn());
|
||||
exec.setStateMachineAliasArn(resolved.aliasArn());
|
||||
exec.setName(execName);
|
||||
exec.setInput(input);
|
||||
exec.setStatus("RUNNING");
|
||||
@@ -627,7 +797,8 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
|
||||
}
|
||||
// A bare trailing '#' is not stripped on this operation: Step Functions Local looks up
|
||||
// the raw ARN and fails with StateMachineDoesNotExist, so Floci does the same.
|
||||
var sm = describeStateMachine(stateMachineArn);
|
||||
var resolved = resolveStateMachineForExecution(stateMachineArn);
|
||||
var sm = resolved.stateMachine();
|
||||
if (!"EXPRESS".equals(sm.getType())) {
|
||||
throw new AwsException("StateMachineTypeNotSupported",
|
||||
"StartSyncExecution is only supported for EXPRESS state machines", 400);
|
||||
@@ -644,7 +815,9 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
|
||||
|
||||
var exec = new Execution();
|
||||
exec.setExecutionArn(arn);
|
||||
exec.setStateMachineArn(stateMachineArn);
|
||||
exec.setStateMachineArn(resolved.baseArn());
|
||||
exec.setStateMachineVersionArn(resolved.versionArn());
|
||||
exec.setStateMachineAliasArn(resolved.aliasArn());
|
||||
exec.setName(execName);
|
||||
exec.setInput(input);
|
||||
exec.setStatus("RUNNING");
|
||||
@@ -669,6 +842,40 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
|
||||
private record TestCaseSelection(String stateMachineArn, String testCaseName) {
|
||||
}
|
||||
|
||||
private record ResolvedStateMachine(
|
||||
StateMachine stateMachine, String baseArn, String versionArn, String aliasArn) {
|
||||
}
|
||||
|
||||
private ResolvedStateMachine resolveStateMachineForExecution(String arn) {
|
||||
QualifiedStateMachineArn qualifiedArn = parseQualifiedStateMachineArn(arn);
|
||||
if (qualifiedArn == null) {
|
||||
return new ResolvedStateMachine(describeStateMachine(arn), arn, null, null);
|
||||
}
|
||||
if (qualifiedArn.isVersion()) {
|
||||
return new ResolvedStateMachine(
|
||||
describeStateMachine(arn), qualifiedArn.baseArn(), arn, null);
|
||||
}
|
||||
|
||||
StateMachineAlias alias = stateMachineAliasStore.get(arn)
|
||||
.orElseThrow(() -> new AwsException(
|
||||
"StateMachineDoesNotExist", "State machine does not exist", 400));
|
||||
int selection = ThreadLocalRandom.current().nextInt(100);
|
||||
int cumulativeWeight = 0;
|
||||
RoutingConfiguration selected = alias.getRoutingConfiguration()
|
||||
.get(alias.getRoutingConfiguration().size() - 1);
|
||||
for (RoutingConfiguration route : alias.getRoutingConfiguration()) {
|
||||
cumulativeWeight += route.getWeight();
|
||||
if (selection < cumulativeWeight) {
|
||||
selected = route;
|
||||
break;
|
||||
}
|
||||
}
|
||||
String versionArn = selected.getStateMachineVersionArn();
|
||||
return new ResolvedStateMachine(
|
||||
describeStateMachineVersion(alias.getStateMachineArn(), versionArn),
|
||||
alias.getStateMachineArn(), versionArn, arn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits the Step Functions Local mocked service integration suffix off a
|
||||
* {@code StartExecution} ARN: {@code <stateMachineArn>#<testCaseName>} selects the named
|
||||
@@ -727,8 +934,15 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
|
||||
}
|
||||
|
||||
public List<Execution> listExecutions(String stateMachineArn) {
|
||||
return executionStore.scan(k -> executionStore.get(k)
|
||||
.map(e -> e.getStateMachineArn().equals(stateMachineArn)).orElse(false));
|
||||
QualifiedStateMachineArn qualifiedArn = parseQualifiedStateMachineArn(stateMachineArn);
|
||||
return executionStore.scan(k -> executionStore.get(k).map(execution -> {
|
||||
if (qualifiedArn == null) {
|
||||
return Objects.equals(execution.getStateMachineArn(), stateMachineArn);
|
||||
}
|
||||
return qualifiedArn.isVersion()
|
||||
? Objects.equals(execution.getStateMachineVersionArn(), stateMachineArn)
|
||||
: Objects.equals(execution.getStateMachineAliasArn(), stateMachineArn);
|
||||
}).orElse(false));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1226,11 +1440,155 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
|
||||
return copy;
|
||||
}
|
||||
|
||||
private StateMachineAlias copyAlias(StateMachineAlias source) {
|
||||
StateMachineAlias copy = new StateMachineAlias();
|
||||
copy.setStateMachineAliasArn(source.getStateMachineAliasArn());
|
||||
copy.setStateMachineArn(source.getStateMachineArn());
|
||||
copy.setName(source.getName());
|
||||
copy.setDescription(source.getDescription());
|
||||
copy.setRoutingConfiguration(copyRoutingConfiguration(
|
||||
source.getRoutingConfiguration()));
|
||||
copy.setCreationDate(source.getCreationDate());
|
||||
copy.setUpdateDate(source.getUpdateDate());
|
||||
return copy;
|
||||
}
|
||||
|
||||
private static List<RoutingConfiguration> copyRoutingConfiguration(
|
||||
List<RoutingConfiguration> routingConfiguration) {
|
||||
List<RoutingConfiguration> copy = new ArrayList<>();
|
||||
for (RoutingConfiguration route : routingConfiguration) {
|
||||
copy.add(new RoutingConfiguration(
|
||||
route.getStateMachineVersionArn(), route.getWeight()));
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
private static boolean routingConfigurationsEqual(
|
||||
List<RoutingConfiguration> left, List<RoutingConfiguration> right) {
|
||||
if (left.size() != right.size()) {
|
||||
return false;
|
||||
}
|
||||
for (int index = 0; index < left.size(); index++) {
|
||||
RoutingConfiguration leftRoute = left.get(index);
|
||||
RoutingConfiguration rightRoute = right.get(index);
|
||||
if (leftRoute.getWeight() != rightRoute.getWeight()
|
||||
|| !Objects.equals(
|
||||
leftRoute.getStateMachineVersionArn(),
|
||||
rightRoute.getStateMachineVersionArn())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private String validateRoutingConfiguration(
|
||||
List<RoutingConfiguration> routingConfiguration) {
|
||||
if (routingConfiguration == null
|
||||
|| routingConfiguration.isEmpty()
|
||||
|| routingConfiguration.size() > 2) {
|
||||
throw new AwsException(
|
||||
"ValidationException",
|
||||
"routingConfiguration must contain one or two version targets.", 400);
|
||||
}
|
||||
|
||||
String baseArn = null;
|
||||
int totalWeight = 0;
|
||||
Set<String> versionArns = new HashSet<>();
|
||||
for (RoutingConfiguration route : routingConfiguration) {
|
||||
if (route == null || route.getStateMachineVersionArn() == null) {
|
||||
throw new AwsException(
|
||||
"ValidationException",
|
||||
"Each routingConfiguration entry must contain a stateMachineVersionArn.",
|
||||
400);
|
||||
}
|
||||
VersionArn versionArn = parseVersionArn(route.getStateMachineVersionArn());
|
||||
if (versionArn == null) {
|
||||
throw new AwsException(
|
||||
"InvalidArn",
|
||||
"Invalid state machine version ARN: "
|
||||
+ route.getStateMachineVersionArn(),
|
||||
400);
|
||||
}
|
||||
if (!versionArns.add(route.getStateMachineVersionArn())) {
|
||||
throw new AwsException(
|
||||
"ValidationException",
|
||||
"routingConfiguration cannot contain a version more than once.", 400);
|
||||
}
|
||||
if (baseArn == null) {
|
||||
baseArn = versionArn.baseArn();
|
||||
} else if (!baseArn.equals(versionArn.baseArn())) {
|
||||
throw new AwsException(
|
||||
"ValidationException",
|
||||
"Alias routes must reference versions of the same state machine.", 400);
|
||||
}
|
||||
if (route.getWeight() < 0 || route.getWeight() > 100) {
|
||||
throw new AwsException(
|
||||
"ValidationException", "Alias routing weights must be between 0 and 100.",
|
||||
400);
|
||||
}
|
||||
totalWeight += route.getWeight();
|
||||
StateMachine stateMachine = stateMachineStore.get(versionArn.baseArn())
|
||||
.orElseThrow(() -> new AwsException(
|
||||
"ResourceNotFound",
|
||||
"State machine version does not exist: "
|
||||
+ route.getStateMachineVersionArn(),
|
||||
400));
|
||||
boolean versionExists = stateMachine.getVersions().stream()
|
||||
.anyMatch(version -> route.getStateMachineVersionArn().equals(
|
||||
version.getStateMachineVersionArn()));
|
||||
if (!versionExists) {
|
||||
throw new AwsException(
|
||||
"ResourceNotFound",
|
||||
"State machine version does not exist: "
|
||||
+ route.getStateMachineVersionArn(),
|
||||
400);
|
||||
}
|
||||
}
|
||||
if (totalWeight != 100) {
|
||||
throw new AwsException(
|
||||
"ValidationException", "Alias routing weights must add up to 100.", 400);
|
||||
}
|
||||
return baseArn;
|
||||
}
|
||||
|
||||
private static final String STATE_MACHINE_RESOURCE = "stateMachine";
|
||||
|
||||
private record QualifiedStateMachineArn(String baseArn, String qualifier) {
|
||||
private boolean isVersion() {
|
||||
return qualifier.chars().allMatch(Character::isDigit);
|
||||
}
|
||||
}
|
||||
|
||||
private record VersionArn(String baseArn, int version) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits either a version or alias ARN into the unqualified state-machine ARN and qualifier.
|
||||
* A Distributed Map ARN uses {@code /label}, not a third colon segment, and is deliberately
|
||||
* left to the operation-specific validation that returns AWS's {@code ValidationException}.
|
||||
*/
|
||||
private static QualifiedStateMachineArn parseQualifiedStateMachineArn(String arn) {
|
||||
if (arn == null) {
|
||||
return null;
|
||||
}
|
||||
AwsArnUtils.Arn parsed;
|
||||
try {
|
||||
parsed = AwsArnUtils.parse(arn);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
String[] segments = parsed.resource().split(":", -1);
|
||||
if (!"states".equals(parsed.service())
|
||||
|| segments.length != 3
|
||||
|| !STATE_MACHINE_RESOURCE.equals(segments[0])
|
||||
|| segments[1].isEmpty()
|
||||
|| segments[2].isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return new QualifiedStateMachineArn(
|
||||
arn.substring(0, arn.length() - segments[2].length() - 1), segments[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits a state machine <em>version</em> ARN into its base ARN and version number, or returns
|
||||
* {@code null} when {@code arn} is not one.
|
||||
@@ -1243,26 +1601,13 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
|
||||
* InvalidArn: an existing state machine that could not be described.
|
||||
*/
|
||||
private static VersionArn parseVersionArn(String arn) {
|
||||
if (arn == null) {
|
||||
return null;
|
||||
}
|
||||
AwsArnUtils.Arn parsed;
|
||||
try {
|
||||
parsed = AwsArnUtils.parse(arn);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
String[] segments = parsed.resource().split(":", -1);
|
||||
if (segments.length != 3
|
||||
|| !STATE_MACHINE_RESOURCE.equals(segments[0])
|
||||
|| segments[2].isEmpty()
|
||||
|| !segments[2].chars().allMatch(Character::isDigit)) {
|
||||
QualifiedStateMachineArn qualifiedArn = parseQualifiedStateMachineArn(arn);
|
||||
if (qualifiedArn == null || !qualifiedArn.isVersion()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return new VersionArn(
|
||||
arn.substring(0, arn.length() - segments[2].length() - 1),
|
||||
Integer.parseInt(segments[2]));
|
||||
qualifiedArn.baseArn(), Integer.parseInt(qualifiedArn.qualifier()));
|
||||
} catch (NumberFormatException ignored) {
|
||||
return null;
|
||||
}
|
||||
@@ -1459,6 +1804,23 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateStateMachineAliasName(String name) {
|
||||
if (name == null
|
||||
|| name.length() > 80
|
||||
|| !name.matches("(?=.*[A-Za-z_.-])[A-Za-z0-9_.-]+")) {
|
||||
throw new AwsException(
|
||||
"InvalidName", "Invalid state machine alias name: '" + name + "'", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateAliasDescription(String description) {
|
||||
if (description != null && description.length() > 256) {
|
||||
throw new AwsException(
|
||||
"ValidationException",
|
||||
"State machine alias description must not exceed 256 characters.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateStateMachineArn(String arn) {
|
||||
if (arn == null || arn.isBlank() || arn.length() > MAX_ARN_LENGTH) {
|
||||
throw new AwsException("InvalidArn", "Invalid Arn: '" + arn + "'", 400);
|
||||
@@ -1506,9 +1868,24 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
|
||||
throw new AwsException("InvalidArn", "Invalid Arn: '" + arn + "'", 400);
|
||||
}
|
||||
|
||||
VersionArn versionArn = parseVersionArn(arn);
|
||||
QualifiedStateMachineArn qualifiedArn = parseQualifiedStateMachineArn(arn);
|
||||
validateStateMachineArn(
|
||||
versionArn != null ? versionArn.baseArn() : arn);
|
||||
qualifiedArn != null ? qualifiedArn.baseArn() : arn);
|
||||
if (qualifiedArn != null && !qualifiedArn.isVersion()) {
|
||||
validateStateMachineAliasName(qualifiedArn.qualifier());
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateStateMachineAliasArn(String arn) {
|
||||
if (arn == null || arn.isBlank() || arn.length() > MAX_ARN_LENGTH) {
|
||||
throw new AwsException("InvalidArn", "Invalid Arn: '" + arn + "'", 400);
|
||||
}
|
||||
QualifiedStateMachineArn qualifiedArn = parseQualifiedStateMachineArn(arn);
|
||||
if (qualifiedArn == null || qualifiedArn.isVersion()) {
|
||||
throw new AwsException("InvalidArn", "Invalid Arn: '" + arn + "'", 400);
|
||||
}
|
||||
validateStateMachineArn(qualifiedArn.baseArn());
|
||||
validateStateMachineAliasName(qualifiedArn.qualifier());
|
||||
}
|
||||
|
||||
private static void validateUpdateStateMachineArn(String arn) {
|
||||
|
||||
@@ -11,6 +11,8 @@ import java.util.List;
|
||||
public class Execution {
|
||||
private String executionArn;
|
||||
private String stateMachineArn;
|
||||
private String stateMachineVersionArn;
|
||||
private String stateMachineAliasArn;
|
||||
private String name;
|
||||
private String status = "RUNNING"; // RUNNING, SUCCEEDED, FAILED, TIMED_OUT, ABORTED
|
||||
private String input;
|
||||
@@ -31,6 +33,16 @@ public class Execution {
|
||||
public String getStateMachineArn() { return stateMachineArn; }
|
||||
public void setStateMachineArn(String stateMachineArn) { this.stateMachineArn = stateMachineArn; }
|
||||
|
||||
public String getStateMachineVersionArn() { return stateMachineVersionArn; }
|
||||
public void setStateMachineVersionArn(String stateMachineVersionArn) {
|
||||
this.stateMachineVersionArn = stateMachineVersionArn;
|
||||
}
|
||||
|
||||
public String getStateMachineAliasArn() { return stateMachineAliasArn; }
|
||||
public void setStateMachineAliasArn(String stateMachineAliasArn) {
|
||||
this.stateMachineAliasArn = stateMachineAliasArn;
|
||||
}
|
||||
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package io.github.hectorvent.floci.services.stepfunctions.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
/** One weighted state-machine version target in an alias routing configuration. */
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class RoutingConfiguration {
|
||||
private String stateMachineVersionArn;
|
||||
private int weight;
|
||||
|
||||
public RoutingConfiguration() {
|
||||
}
|
||||
|
||||
public RoutingConfiguration(String stateMachineVersionArn, int weight) {
|
||||
this.stateMachineVersionArn = stateMachineVersionArn;
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public String getStateMachineVersionArn() { return stateMachineVersionArn; }
|
||||
public void setStateMachineVersionArn(String stateMachineVersionArn) {
|
||||
this.stateMachineVersionArn = stateMachineVersionArn;
|
||||
}
|
||||
|
||||
public int getWeight() { return weight; }
|
||||
public void setWeight(int weight) { this.weight = weight; }
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package io.github.hectorvent.floci.services.stepfunctions.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** A named pointer to one or two published versions of a state machine. */
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class StateMachineAlias {
|
||||
private String stateMachineAliasArn;
|
||||
private String stateMachineArn;
|
||||
private String name;
|
||||
private String description;
|
||||
private List<RoutingConfiguration> routingConfiguration = new ArrayList<>();
|
||||
private double creationDate;
|
||||
private double updateDate;
|
||||
|
||||
public StateMachineAlias() {
|
||||
creationDate = System.currentTimeMillis() / 1000.0;
|
||||
updateDate = creationDate;
|
||||
}
|
||||
|
||||
public String getStateMachineAliasArn() { return stateMachineAliasArn; }
|
||||
public void setStateMachineAliasArn(String stateMachineAliasArn) {
|
||||
this.stateMachineAliasArn = stateMachineAliasArn;
|
||||
}
|
||||
|
||||
public String getStateMachineArn() { return stateMachineArn; }
|
||||
public void setStateMachineArn(String stateMachineArn) { this.stateMachineArn = stateMachineArn; }
|
||||
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
|
||||
public String getDescription() { return description; }
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
|
||||
public List<RoutingConfiguration> getRoutingConfiguration() { return routingConfiguration; }
|
||||
public void setRoutingConfiguration(List<RoutingConfiguration> routingConfiguration) {
|
||||
this.routingConfiguration = routingConfiguration != null
|
||||
? routingConfiguration : new ArrayList<>();
|
||||
}
|
||||
|
||||
public double getCreationDate() { return creationDate; }
|
||||
public void setCreationDate(double creationDate) { this.creationDate = creationDate; }
|
||||
|
||||
public double getUpdateDate() { return updateDate; }
|
||||
public void setUpdateDate(double updateDate) { this.updateDate = updateDate; }
|
||||
}
|
||||
+193
@@ -0,0 +1,193 @@
|
||||
package io.github.hectorvent.floci.services.stepfunctions;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
/** State-machine aliases resolve to their published version while preserving execution metadata. */
|
||||
@QuarkusTest
|
||||
class StepFunctionsAliasesIntegrationTest {
|
||||
|
||||
private static final String CT = "application/x-amz-json-1.0";
|
||||
private static final String DEF =
|
||||
"{\\\"StartAt\\\":\\\"D\\\",\\\"States\\\":{\\\"D\\\":{\\\"Type\\\":\\\"Pass\\\",\\\"Result\\\":1,\\\"End\\\":true}}}";
|
||||
private static final String DEF2 =
|
||||
"{\\\"StartAt\\\":\\\"D\\\",\\\"States\\\":{\\\"D\\\":{\\\"Type\\\":\\\"Pass\\\",\\\"Result\\\":2,\\\"End\\\":true}}}";
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static Response call(String target, String body) {
|
||||
return given().header("X-Amz-Target", "AWSStepFunctions." + target)
|
||||
.contentType(CT).body(body).when().post("/");
|
||||
}
|
||||
|
||||
@Test
|
||||
void aliasLifecycleResolvesDescribeAndExecutionToPublishedVersions() {
|
||||
String name = "alias-test-" + System.currentTimeMillis();
|
||||
Response created = call("CreateStateMachine", """
|
||||
{"name":"%s","definition":"%s",
|
||||
"roleArn":"arn:aws:iam::000000000000:role/r","publish":true}
|
||||
""".formatted(name, DEF));
|
||||
String stateMachineArn = created.then().statusCode(200)
|
||||
.extract().jsonPath().getString("stateMachineArn");
|
||||
String versionOneArn = created.jsonPath().getString("stateMachineVersionArn");
|
||||
|
||||
String versionTwoArn = call("UpdateStateMachine", """
|
||||
{"stateMachineArn":"%s","definition":"%s","publish":true}
|
||||
""".formatted(stateMachineArn, DEF2))
|
||||
.then().statusCode(200)
|
||||
.extract().jsonPath().getString("stateMachineVersionArn");
|
||||
|
||||
String createAliasRequest = """
|
||||
{"name":"PROD","description":"production",
|
||||
"routingConfiguration":[{"stateMachineVersionArn":"%s","weight":100}]}
|
||||
""".formatted(versionOneArn);
|
||||
String aliasArn = call("CreateStateMachineAlias", createAliasRequest)
|
||||
.then().statusCode(200)
|
||||
.body("stateMachineAliasArn", is(stateMachineArn + ":PROD"))
|
||||
.extract().jsonPath().getString("stateMachineAliasArn");
|
||||
|
||||
// CreateStateMachineAlias is idempotent for the same request.
|
||||
call("CreateStateMachineAlias", createAliasRequest)
|
||||
.then().statusCode(200)
|
||||
.body("stateMachineAliasArn", is(aliasArn));
|
||||
|
||||
call("DescribeStateMachineAlias",
|
||||
"{\"stateMachineAliasArn\":\"" + aliasArn + "\"}")
|
||||
.then().statusCode(200)
|
||||
.body("name", is("PROD"))
|
||||
.body("description", is("production"))
|
||||
.body("routingConfiguration[0].stateMachineVersionArn", is(versionOneArn))
|
||||
.body("routingConfiguration[0].weight", is(100));
|
||||
|
||||
call("ListStateMachineAliases",
|
||||
"{\"stateMachineArn\":\"" + stateMachineArn + "\"}")
|
||||
.then().statusCode(200)
|
||||
.body("stateMachineAliases[0].stateMachineAliasArn", is(aliasArn));
|
||||
call("ListStateMachineAliases",
|
||||
"{\"stateMachineArn\":\"" + versionOneArn + "\"}")
|
||||
.then().statusCode(200)
|
||||
.body("stateMachineAliases[0].stateMachineAliasArn", is(aliasArn));
|
||||
|
||||
// DescribeStateMachine accepts an alias ARN and returns the selected version snapshot.
|
||||
call("DescribeStateMachine", "{\"stateMachineArn\":\"" + aliasArn + "\"}")
|
||||
.then().statusCode(200)
|
||||
.body("stateMachineArn", is(versionOneArn))
|
||||
.body("definition", containsString("\"Result\":1"));
|
||||
|
||||
String executionArn = call("StartExecution", """
|
||||
{"stateMachineArn":"%s","name":"through-alias","input":"{}"}
|
||||
""".formatted(aliasArn))
|
||||
.then().statusCode(200)
|
||||
.extract().jsonPath().getString("executionArn");
|
||||
call("DescribeExecution", "{\"executionArn\":\"" + executionArn + "\"}")
|
||||
.then().statusCode(200)
|
||||
.body("stateMachineArn", is(stateMachineArn))
|
||||
.body("stateMachineVersionArn", is(versionOneArn))
|
||||
.body("stateMachineAliasArn", is(aliasArn));
|
||||
|
||||
call("UpdateStateMachineAlias", """
|
||||
{"stateMachineAliasArn":"%s","description":"promoted",
|
||||
"routingConfiguration":[{"stateMachineVersionArn":"%s","weight":100}]}
|
||||
""".formatted(aliasArn, versionTwoArn))
|
||||
.then().statusCode(200);
|
||||
call("DescribeStateMachine", "{\"stateMachineArn\":\"" + aliasArn + "\"}")
|
||||
.then().statusCode(200)
|
||||
.body("stateMachineArn", is(versionTwoArn))
|
||||
.body("definition", containsString("\"Result\":2"));
|
||||
|
||||
// A Distributed Map-qualified ARN is recognized but rejected, as documented by AWS.
|
||||
call("DescribeStateMachine", "{\"stateMachineArn\":\""
|
||||
+ stateMachineArn + "/map-label\"}")
|
||||
.then().statusCode(400)
|
||||
.body(containsString("ValidationException"));
|
||||
|
||||
call("DeleteStateMachineVersion",
|
||||
"{\"stateMachineVersionArn\":\"" + versionTwoArn + "\"}")
|
||||
.then().statusCode(409)
|
||||
.body(containsString("ConflictException"));
|
||||
call("DeleteStateMachineAlias",
|
||||
"{\"stateMachineAliasArn\":\"" + aliasArn + "\"}")
|
||||
.then().statusCode(200);
|
||||
call("DescribeStateMachine", "{\"stateMachineArn\":\"" + aliasArn + "\"}")
|
||||
.then().statusCode(400)
|
||||
.body(containsString("StateMachineDoesNotExist"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aliasValidationRejectsNamesAndInvalidRoutingConfiguration() {
|
||||
String name = "alias-validation-" + System.currentTimeMillis();
|
||||
Response created = call("CreateStateMachine", """
|
||||
{"name":"%s","definition":"%s",
|
||||
"roleArn":"arn:aws:iam::000000000000:role/r","publish":true}
|
||||
""".formatted(name, DEF));
|
||||
String versionArn = created.then().statusCode(200)
|
||||
.extract().jsonPath().getString("stateMachineVersionArn");
|
||||
|
||||
call("CreateStateMachineAlias", """
|
||||
{"name":"123","routingConfiguration":[
|
||||
{"stateMachineVersionArn":"%s","weight":100}]}
|
||||
""".formatted(versionArn))
|
||||
.then().statusCode(400).body(containsString("InvalidName"));
|
||||
call("CreateStateMachineAlias", """
|
||||
{"name":"TEST","routingConfiguration":[
|
||||
{"stateMachineVersionArn":"%s","weight":90}]}
|
||||
""".formatted(versionArn))
|
||||
.then().statusCode(400).body(containsString("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listAliasesPaginatesWithAnOpaqueRoundTripToken() {
|
||||
String name = "alias-pagination-" + System.currentTimeMillis();
|
||||
Response created = call("CreateStateMachine", """
|
||||
{"name":"%s","definition":"%s",
|
||||
"roleArn":"arn:aws:iam::000000000000:role/r","publish":true}
|
||||
""".formatted(name, DEF));
|
||||
String stateMachineArn = created.then().statusCode(200)
|
||||
.extract().jsonPath().getString("stateMachineArn");
|
||||
String versionArn = created.jsonPath().getString("stateMachineVersionArn");
|
||||
|
||||
for (String aliasName : new String[] {"ALPHA", "BETA"}) {
|
||||
call("CreateStateMachineAlias", """
|
||||
{"name":"%s","routingConfiguration":[
|
||||
{"stateMachineVersionArn":"%s","weight":100}]}
|
||||
""".formatted(aliasName, versionArn))
|
||||
.then().statusCode(200);
|
||||
}
|
||||
|
||||
Response firstPage = call("ListStateMachineAliases", """
|
||||
{"stateMachineArn":"%s","maxResults":1}
|
||||
""".formatted(stateMachineArn));
|
||||
firstPage.then().statusCode(200)
|
||||
.body("stateMachineAliases.size()", is(1));
|
||||
String firstArn = firstPage.jsonPath().getString("stateMachineAliases[0].stateMachineAliasArn");
|
||||
String nextToken = firstPage.jsonPath().getString("nextToken");
|
||||
assertNotNull(nextToken);
|
||||
|
||||
Response secondPage = call("ListStateMachineAliases", """
|
||||
{"stateMachineArn":"%s","maxResults":1,"nextToken":"%s"}
|
||||
""".formatted(stateMachineArn, nextToken));
|
||||
secondPage.then().statusCode(200)
|
||||
.body("stateMachineAliases.size()", is(1));
|
||||
assertNotEquals(firstArn,
|
||||
secondPage.jsonPath().getString("stateMachineAliases[0].stateMachineAliasArn"));
|
||||
assertNull(secondPage.jsonPath().getString("nextToken"));
|
||||
|
||||
call("ListStateMachineAliases", """
|
||||
{"stateMachineArn":"%s","maxResults":1001}
|
||||
""".formatted(stateMachineArn))
|
||||
.then().statusCode(400).body(containsString("ValidationException"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user