mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
fix(emr-serverless): retain deleted applications for waiters (#6103)
* fix(emr-serverless): retain deleted applications for waiters * fix(emr-serverless): reject tag access after application deletion
This commit is contained in:
1 parent
e5591dda32
commit
03f87285a0
4 files changed
+70
-3
No files matched your search
@@ -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.
|
||||
|
||||
+12
-1
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
+28
-2
@@ -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"));
|
||||
}
|
||||
}
|
||||
+26
@@ -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];
|
||||
|
||||
Reference in new issue
Block a user