Skip to content

armgit / floci

Public Imported from GitHub
0

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

fix(emr-serverless): retain deleted applications for waiters (#6103)

Jimmy Liu Jia03f87285a07e
diff --git a/docs/services/emr-serverless.md b/docs/services/emr-serverless.md
index 86c90e138e..c6d72375ae 100644
--- a/docs/services/emr-serverless.md
+++ b/docs/services/emr-serverless.md
@@ -32,6 +32,10 @@ resource holds at most 50 tags, and `aws:` in any case is reserved as the prefix
Applications, creation client tokens, and application tags are scoped to the request's AWS Region.
An application created in one Region is not returned by list, get, or tag requests signed for another.
+`DeleteApplication` leaves the application in `TERMINATED` state. `GetApplication` continues to
+report that state so lifecycle waiters can observe it, while an unfiltered `ListApplications`
+omits the terminated application. A terminated application cannot be started or stopped again.
+
## Limitations and Differences from AWS
* **Jobs not implemented**: Floci supports the provisioning of the `Application` management plane (which satisfies tools like Terraform's `aws_emrserverless_application` resource). Executing actual Spark or Hive jobs against these applications via `StartJobRun` is not currently implemented.
diff --git a/src/main/java/io/github/hectorvent/floci/services/emrserverless/EmrServerlessService.java b/src/main/java/io/github/hectorvent/floci/services/emrserverless/EmrServerlessService.java
index 487d245022..0d1f4acd25 100644
--- a/src/main/java/io/github/hectorvent/floci/services/emrserverless/EmrServerlessService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/emrserverless/EmrServerlessService.java
@@ -119,6 +119,8 @@ public class EmrServerlessService {
.filter(app -> inRegion(app, region)).collect(Collectors.toList());
if (request.getStates() != null && !request.getStates().isEmpty()) {
all = all.stream().filter(app -> request.getStates().contains(app.getState())).collect(Collectors.toList());
+ } else {
+ all = all.stream().filter(app -> !"TERMINATED".equals(app.getState())).collect(Collectors.toList());
}
PaginatedResult<Application> page = Pagination.paginate(all, Application::getApplicationId, request.getMaxResults(), request.getNextToken(), 50, "ValidationException");
@@ -197,7 +199,9 @@ public class EmrServerlessService {
if (!"CREATED".equals(state) && !"STOPPED".equals(state)) {
throw new AwsException("ValidationException", "Application must be in a stopped or created state in order to be deleted.", 400);
}
- storage.delete(applicationId);
+ app.setState("TERMINATED");
+ app.setUpdatedAt(System.currentTimeMillis());
+ storage.put(applicationId, app);
}
public synchronized void startApplication(String applicationId) {
@@ -206,6 +210,9 @@ public class EmrServerlessService {
if ("STARTED".equals(state) || "STARTING".equals(state)) {
return;
}
+ if ("TERMINATED".equals(state)) {
+ throw new AwsException("ValidationException", "Application is terminated.", 400);
+ }
app.setState("STARTED");
app.setUpdatedAt(System.currentTimeMillis());
storage.put(applicationId, app);
@@ -217,6 +224,9 @@ public class EmrServerlessService {
if ("STOPPED".equals(state) || "STOPPING".equals(state)) {
return;
}
+ if ("TERMINATED".equals(state)) {
+ throw new AwsException("ValidationException", "Application is terminated.", 400);
+ }
app.setState("STOPPED");
app.setUpdatedAt(System.currentTimeMillis());
storage.put(applicationId, app);
@@ -288,6 +298,7 @@ public class EmrServerlessService {
}
return storage.get(matcher.group(1))
.filter(app -> arn.equals(app.getArn()))
+ .filter(app -> !"TERMINATED".equals(app.getState()))
.orElseThrow(() -> new AwsException("ResourceNotFoundException", "Resource " + arn + " not found", 404));
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/emrserverless/EmrServerlessIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/emrserverless/EmrServerlessIntegrationTest.java
index 11dd32b48e..ab99865c6c 100644
--- a/src/test/java/io/github/hectorvent/floci/services/emrserverless/EmrServerlessIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/emrserverless/EmrServerlessIntegrationTest.java
@@ -253,11 +253,37 @@ public class EmrServerlessIntegrationTest {
.then()
.statusCode(200);
- // Verify it's gone
givenReq()
.when()
.get("/applications/" + applicationId)
.then()
- .statusCode(404);
+ .statusCode(200)
+ .body("application.state", equalTo("TERMINATED"));
+
+ givenReq()
+ .when()
+ .get("/applications")
+ .then()
+ .statusCode(200)
+ .body("applications.find { it.id == '" + applicationId + "' }", nullValue());
+
+ givenReq()
+ .when()
+ .post("/applications/" + applicationId + "/start")
+ .then()
+ .statusCode(400);
+
+ givenReq()
+ .when()
+ .post("/applications/" + applicationId + "/stop")
+ .then()
+ .statusCode(400);
+
+ givenReq()
+ .when()
+ .get("/applications/" + applicationId)
+ .then()
+ .statusCode(200)
+ .body("application.state", equalTo("TERMINATED"));
}
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/emrserverless/EmrServerlessTagIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/emrserverless/EmrServerlessTagIntegrationTest.java
index e374980251..1fb8d799dc 100644
--- a/src/test/java/io/github/hectorvent/floci/services/emrserverless/EmrServerlessTagIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/emrserverless/EmrServerlessTagIntegrationTest.java
@@ -96,6 +96,32 @@ class EmrServerlessTagIntegrationTest {
.body("tags.team", equalTo("platform"));
}
+ @Test
+ void terminatedApplicationsCannotBeTagged() {
+ String[] app = createApplication("{ \"team\": \"data\" }");
+ String path = tagsPath(app[1]);
+
+ emr().when().delete("/applications/" + app[0])
+ .then().statusCode(200);
+
+ emr().when().get(path)
+ .then().statusCode(404)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ emr().body("{ \"tags\": { \"env\": \"dev\" } }")
+ .when().post(path)
+ .then().statusCode(404)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ emr().when().delete(path + "?tagKeys=team")
+ .then().statusCode(404)
+ .body("__type", equalTo("ResourceNotFoundException"));
+
+ emr().when().get("/applications/" + app[0])
+ .then().statusCode(200)
+ .body("application.state", equalTo("TERMINATED"))
+ .body("application.tags.team", equalTo("data"))
+ .body("application.tags", not(hasKey("env")));
+ }
+
@Test
void unknownApplicationsAndJobRunsAreNotFoundAndBadTagsAreRefused() {
String arn = createApplication("{}")[1];