fix(emr-serverless): keep an application with runs going from stopping (#8038)

StopApplication stopped an application whose runs had not finished,
where the API reference says "All scheduled and running jobs must be
completed or cancelled before stopping an application."

A run that has not finished, a STREAMING or CANCELLING one included, now
refuses the stop with ValidationException, the one error the model
declares for it, carrying that sentence, as AWS's own message is not
recorded. The check holds the job runs' lock, as StartJobRun's admission
does, so no run starts between it and the stop. Step Functions'
stopApplication goes the same way.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-11 14:05:46 -06:00
1 parent 9e6f62e959
commit a0741e5011
6 files changed
+66 -4

No files matched your search

@@ -123,7 +123,7 @@ public class EmrServerlessController {
@POST
@Path("/{applicationId}/stop")
public StopApplicationResponse stopApplication(@PathParam("applicationId") String applicationId) {
service.stopApplication(applicationId);
jobRuns.stopApplication(applicationId);
StopApplicationResponse response = new StopApplicationResponse();
return response;
}
@@ -369,6 +369,25 @@ public class EmrServerlessJobRunService implements Resettable {
page.nextToken());
}
/**
* Stops the application once none of its runs is still going, as StopApplication's reference has it: "All
* scheduled and running jobs must be completed or cancelled before stopping an application." AWS's answer
* otherwise is not recorded, so the refusal is the one error the model declares for it, carrying that
* sentence. Under this service's lock, as StartJobRun's admission is, so no run starts between the two.
*/
public synchronized void stopApplication(String applicationId) {
applications.getApplication(applicationId);
for (JobRunRecord record : store.scan(key -> true)) {
JobRun run = record.getJobRun();
if (applicationId.equals(run.getApplicationId()) && inRequestRegion(run)
&& !isTerminal(settle(record).getJobRun())) {
throw new AwsException("ValidationException", "All scheduled and running jobs must be completed "
+ "or cancelled before stopping an application.", 400);
}
}
applications.stopApplication(applicationId);
}
/**
* Cancels a run that has not finished. A finished run is refused, with AWS's wording. A container
* run is CANCELLING until its driver has stopped.