Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(glue): make DeleteJob idempotent (#3866)

Chiara Forresi992b80f8f77b
diff --git a/src/main/java/io/github/hectorvent/floci/services/glue/GlueService.java b/src/main/java/io/github/hectorvent/floci/services/glue/GlueService.java
index 16f52d8d8c..e060b74935 100644
--- a/src/main/java/io/github/hectorvent/floci/services/glue/GlueService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/glue/GlueService.java
@@ -1714,9 +1714,6 @@ public class GlueService {
validateRequired(name, "JobName");
// Jobs and crawlers skip normalizeName because AWS preserves their case
String normalizedName = name;
- if (jobStore.get(normalizedName).isEmpty()) {
- throw new AwsException("EntityNotFoundException", "Job " + name + " not found.", 400);
- }
jobStore.delete(normalizedName);
resourceGroupsTaggingService.deleteResources(List.of(jobArn(region, normalizedName)), region);
LOG.infov("Deleted Glue Job: {0}", name);
diff --git a/src/test/java/io/github/hectorvent/floci/services/glue/GlueDeleteJobIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/glue/GlueDeleteJobIntegrationTest.java
new file mode 100644
index 0000000000..883c0120d8
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/glue/GlueDeleteJobIntegrationTest.java
@@ -0,0 +1,49 @@
+package io.github.hectorvent.floci.services.glue;
+
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import java.util.UUID;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.equalTo;
+
+@QuarkusTest
+class GlueDeleteJobIntegrationTest {
+
+ private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
+ private static final String ROLE = "arn:aws:iam::000000000000:role/my-role";
+ private static final String JOB_NAME = "delete-job-" + UUID.randomUUID().toString().substring(0, 8);
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ @Test
+ void repeatedDeleteJobRequestsReturnSuccessfulResponses() {
+ given().contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWSGlue.CreateJob")
+ .body("""
+ {
+ "Name": "%s",
+ "Role": "%s",
+ "Command": {}
+ }
+ """.formatted(JOB_NAME, ROLE))
+ .when().post("/")
+ .then().statusCode(200);
+
+ for (int attempt = 0; attempt < 2; attempt++) {
+ given().contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWSGlue.DeleteJob")
+ .body("{ \"JobName\": \"" + JOB_NAME + "\" }")
+ .when().post("/")
+ .then()
+ .statusCode(200)
+ .body("JobName", equalTo(JOB_NAME));
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/io/github/hectorvent/floci/services/glue/GlueServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/glue/GlueServiceTest.java
index 261686a1b8..48a85b3a06 100644
--- a/src/test/java/io/github/hectorvent/floci/services/glue/GlueServiceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/glue/GlueServiceTest.java
@@ -1145,6 +1145,9 @@ class GlueServiceTest {
AwsException ex = assertThrows(AwsException.class, () -> glueService.getJob("my-job"));
assertEquals("EntityNotFoundException", ex.getErrorCode());
assertTrue(glueService.getJobs().isEmpty());
+
+ glueService.deleteJob("my-job", REGION);
+ assertTrue(glueService.getJobs().isEmpty());
}
@Test