mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
feat(stepfunctions): support Scheduler DeleteSchedule (#3983)
* feat(stepfunctions): support scheduler deleteSchedule * style(stepfunctions): use explicit result types --------- Co-authored-by: Vamsi Akavarapu <16164447+vamsiak@users.noreply.github.com>
This commit is contained in:
1 parent
37ac2505e8
commit
748f71c943
4 files changed
+173
-8
No files matched your search
@@ -426,6 +426,7 @@ the wire and the task fails with `Sfn.StateMachineDoesNotExistException`.
|
||||
| `arn:aws:states:::aws-sdk:sfn:sendTaskFailure` | `{}` | `Sfn.InvalidTokenException` |
|
||||
| `arn:aws:states:::aws-sdk:scheduler:createSchedule` | `{ScheduleArn}` | `Scheduler.ConflictException` when the name is taken |
|
||||
| `arn:aws:states:::aws-sdk:scheduler:updateSchedule` | `{ScheduleArn}` | `Scheduler.ResourceNotFoundException` |
|
||||
| `arn:aws:states:::aws-sdk:scheduler:deleteSchedule` | `{}` | `Scheduler.ResourceNotFoundException` |
|
||||
| `arn:aws:states:::aws-sdk:sns:publish` | `{MessageId}` | `Sns.NotFoundException` when the topic does not exist |
|
||||
|
||||
`sendTaskSuccess` and `sendTaskFailure` resolve a token a `.waitForTaskToken` task is parked on. A
|
||||
|
||||
@@ -1373,20 +1373,24 @@ public class AslExecutor {
|
||||
}
|
||||
|
||||
/**
|
||||
* AWS SDK integrations for {@code scheduler:createSchedule} and {@code scheduler:updateSchedule}.
|
||||
* The Task {@code Arguments} are the CreateSchedule body with {@code Name} folded in, so they go
|
||||
* through the controller's parse, and both actions answer with the schedule ARN alone. The parse
|
||||
* rejects a malformed {@code Target} with the same {@code AwsException} the service raises, so it
|
||||
* belongs inside the translation that makes those failures reachable for {@code Retry} and
|
||||
* {@code Catch}.
|
||||
* AWS SDK integrations for Scheduler. Create and update parse the full schedule request and
|
||||
* return its ARN. Delete accepts only the schedule identity and returns the empty SDK response.
|
||||
* Service and parsing failures stay inside the translation that makes them reachable for
|
||||
* {@code Retry} and {@code Catch}.
|
||||
*/
|
||||
private JsonNode invokeAwsSdkScheduler(String action, JsonNode input, String region) {
|
||||
boolean deleting = "deleteSchedule".equals(action);
|
||||
boolean creating = "createSchedule".equals(action);
|
||||
if (!creating && !"updateSchedule".equals(action)) {
|
||||
if (!creating && !deleting && !"updateSchedule".equals(action)) {
|
||||
throw new FailStateException("States.TaskFailed",
|
||||
"Unsupported resource: " + AWS_SDK_SCHEDULER_PREFIX + action);
|
||||
}
|
||||
try {
|
||||
if (deleting) {
|
||||
schedulerService.deleteSchedule(input.path("Name").asText(null),
|
||||
input.path("GroupName").asText(null), region);
|
||||
return objectMapper.createObjectNode();
|
||||
}
|
||||
ScheduleRequest request = schedulerController.parseScheduleRequest(input);
|
||||
request.setName(input.path("Name").asText(null));
|
||||
Schedule schedule = creating
|
||||
|
||||
+52
@@ -129,9 +129,47 @@ class SchedulerStepFunctionsIntegrationTest {
|
||||
assertEquals(0, listExecutions(stateMachineArn).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void stepFunctionsDeleteScheduleStopsFutureOccurrence() {
|
||||
String targetStateMachineArn = createPassStateMachine();
|
||||
String scheduleName = uniqueName("sfn-delete");
|
||||
createSchedule(scheduleName, "rate(1 minute)", "ENABLED",
|
||||
targetStateMachineArn, "{\"deleted\":false}");
|
||||
Schedule schedule = schedulerService.getSchedule(scheduleName, null, REGION);
|
||||
Instant fireAt = schedule.getCreationDate().plus(61, ChronoUnit.SECONDS);
|
||||
String deleterStateMachineArn = createStateMachine(uniqueName("schedule-deleter"), """
|
||||
{
|
||||
"QueryLanguage": "JSONata",
|
||||
"StartAt": "Delete",
|
||||
"States": {
|
||||
"Delete": {
|
||||
"Type": "Task",
|
||||
"Resource": "arn:aws:states:::aws-sdk:scheduler:deleteSchedule",
|
||||
"Arguments": {"Name": "SCHEDULE_NAME"},
|
||||
"End": true
|
||||
}
|
||||
}
|
||||
}
|
||||
""".replace("SCHEDULE_NAME", scheduleName));
|
||||
|
||||
Response deletion = waitForTerminalExecution(startExecution(deleterStateMachineArn));
|
||||
assertEquals("SUCCEEDED", deletion.jsonPath().getString("status"));
|
||||
|
||||
ScheduleDispatcher dispatcher = new ScheduleDispatcher(
|
||||
schedulerService, scheduleInvoker, sqsService, config);
|
||||
testDispatchers.add(dispatcher);
|
||||
dispatcher.tick(fireAt);
|
||||
|
||||
assertEquals(0, listExecutions(targetStateMachineArn).size());
|
||||
}
|
||||
|
||||
private String createPassStateMachine() {
|
||||
String name = uniqueName("scheduled-workflow");
|
||||
String definition = "{\"StartAt\":\"Pass\",\"States\":{\"Pass\":{\"Type\":\"Pass\",\"End\":true}}}";
|
||||
return createStateMachine(name, definition);
|
||||
}
|
||||
|
||||
private String createStateMachine(String name, String definition) {
|
||||
ObjectNode request = MAPPER.createObjectNode();
|
||||
request.put("name", name);
|
||||
request.put("definition", definition);
|
||||
@@ -149,6 +187,20 @@ class SchedulerStepFunctionsIntegrationTest {
|
||||
return stateMachineArn;
|
||||
}
|
||||
|
||||
private String startExecution(String stateMachineArn) {
|
||||
ObjectNode request = MAPPER.createObjectNode();
|
||||
request.put("stateMachineArn", stateMachineArn);
|
||||
request.put("input", "{}");
|
||||
Response response = given()
|
||||
.header("X-Amz-Target", "AWSStepFunctions.StartExecution")
|
||||
.contentType(SFN_CONTENT_TYPE)
|
||||
.body(request.toString())
|
||||
.when()
|
||||
.post("/");
|
||||
response.then().statusCode(200);
|
||||
return response.jsonPath().getString("executionArn");
|
||||
}
|
||||
|
||||
private void createSchedule(String name, String expression, String state,
|
||||
String targetArn, String input) {
|
||||
ObjectNode request = MAPPER.createObjectNode();
|
||||
|
||||
+109
-1
@@ -21,7 +21,8 @@ import static org.junit.jupiter.api.Assertions.fail;
|
||||
/**
|
||||
* Integration tests for the {@code arn:aws:states:::aws-sdk:} task integrations of Step Functions
|
||||
* itself and of EventBridge Scheduler: {@code sfn:startExecution}, {@code sfn:sendTaskSuccess},
|
||||
* {@code sfn:sendTaskFailure}, {@code scheduler:createSchedule} and {@code scheduler:updateSchedule}.
|
||||
* {@code sfn:sendTaskFailure}, {@code scheduler:createSchedule}, {@code scheduler:updateSchedule}
|
||||
* and {@code scheduler:deleteSchedule}.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
@@ -483,6 +484,113 @@ class StepFunctionsAwsSdkTaskIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(16)
|
||||
void deleteScheduleReturnsAnEmptyObjectAndRemovesTheSchedule() throws Exception {
|
||||
JsonNode result = mapper.readTree(succeedingOutputOf(
|
||||
createStateMachine("aws-sdk-delete-schedule", deleteScheduleTask(
|
||||
"payout-nightly", null)), "{}"));
|
||||
|
||||
assertTrue(result.isObject());
|
||||
assertEquals(0, result.size(), "DeleteSchedule returns an empty object");
|
||||
given().when().get("/schedules/payout-nightly").then().statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(17)
|
||||
void deleteScheduleUsesTheNamedGroup() throws Exception {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("{}")
|
||||
.when().post("/schedule-groups/payments")
|
||||
.then().statusCode(200);
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{
|
||||
"GroupName": "payments",
|
||||
"ScheduleExpression": "rate(1 day)",
|
||||
"FlexibleTimeWindow": {"Mode": "OFF"},
|
||||
"Target": {"Arn": "TARGET_ARN", "RoleArn": "ROLE"}
|
||||
}
|
||||
""".replace("TARGET_ARN", quickChildArn).replace("ROLE", ROLE_ARN))
|
||||
.when().post("/schedules/grouped-payout")
|
||||
.then().statusCode(200);
|
||||
|
||||
succeedingOutputOf(createStateMachine("aws-sdk-delete-grouped-schedule",
|
||||
deleteScheduleTask("grouped-payout", "payments")), "{}");
|
||||
|
||||
given().queryParam("groupName", "payments")
|
||||
.when().get("/schedules/grouped-payout")
|
||||
.then().statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(18)
|
||||
void deleteMissingScheduleIsCatchableAsResourceNotFound() throws Exception {
|
||||
JsonNode result = mapper.readTree(succeedingOutputOf(
|
||||
createStateMachine("aws-sdk-delete-missing-schedule", catchingDeleteScheduleTask(
|
||||
"no-such-schedule", "Scheduler.ResourceNotFoundException")), "{}"));
|
||||
|
||||
assertEquals("Scheduler.ResourceNotFoundException", result.path("caughtError").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(19)
|
||||
void deleteScheduleWithoutANameIsCatchableAsValidationException() throws Exception {
|
||||
JsonNode result = mapper.readTree(succeedingOutputOf(
|
||||
createStateMachine("aws-sdk-delete-schedule-without-name", catchingDeleteScheduleTask(
|
||||
null, "Scheduler.ValidationException")), "{}"));
|
||||
|
||||
assertEquals("Scheduler.ValidationException", result.path("caughtError").asText());
|
||||
}
|
||||
|
||||
private static String deleteScheduleTask(String scheduleName, String groupName) {
|
||||
String groupArgument = groupName == null ? "" : ", \"GroupName\": \"" + groupName + "\"";
|
||||
return """
|
||||
{
|
||||
"QueryLanguage": "JSONata",
|
||||
"StartAt": "Delete",
|
||||
"States": {
|
||||
"Delete": {
|
||||
"Type": "Task",
|
||||
"Resource": "arn:aws:states:::aws-sdk:scheduler:deleteSchedule",
|
||||
"Arguments": {"Name": "SCHEDULE_NAME"GROUP_ARGUMENT},
|
||||
"End": true
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
.replace("SCHEDULE_NAME", scheduleName)
|
||||
.replace("GROUP_ARGUMENT", groupArgument);
|
||||
}
|
||||
|
||||
private static String catchingDeleteScheduleTask(String scheduleName, String errorName) {
|
||||
String nameArgument = scheduleName == null ? "" : "\"Name\": \"" + scheduleName + "\"";
|
||||
return """
|
||||
{
|
||||
"QueryLanguage": "JSONata",
|
||||
"StartAt": "Delete",
|
||||
"States": {
|
||||
"Delete": {
|
||||
"Type": "Task",
|
||||
"Resource": "arn:aws:states:::aws-sdk:scheduler:deleteSchedule",
|
||||
"Arguments": {NAME_ARGUMENT},
|
||||
"Catch": [{
|
||||
"ErrorEquals": ["ERROR_NAME"],
|
||||
"Next": "Recovered",
|
||||
"Output": {"caughtError": "{% $states.errorOutput.Error %}"}
|
||||
}],
|
||||
"End": true
|
||||
},
|
||||
"Recovered": {"Type": "Pass", "End": true}
|
||||
}
|
||||
}
|
||||
"""
|
||||
.replace("NAME_ARGUMENT", nameArgument)
|
||||
.replace("ERROR_NAME", errorName);
|
||||
}
|
||||
|
||||
private static String scheduleTask(String action, String scheduleName, String expression) {
|
||||
return """
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user