Skip to content

Add EmrServerlessTerminateSessionOperator to Amazon provider - #73999

Closed
o-nikolas wants to merge 1 commit into
apache:mainfrom
aws-mwaa:onikolas/emr-serverless-stop-session
Closed

o-nikolas wants to merge 1 commit into
apache:mainfrom
aws-mwaa:onikolas/emr-serverless-stop-session

Conversation

@o-nikolas

Copy link
Copy Markdown
Contributor

Why

EMR Serverless rejects StopApplication while any of the application's sessions is still active, and the provider has no way to terminate a session. EmrServerlessStopApplicationOperator cannot cover the gap — its force_stop argument only calls cancel_running_jobs, which cancels job runs and leaves sessions untouched.

As a result example_emr_serverless_session, added in #70763, can never finish. Its teardown goes straight from start_session to stop_app, so the session is still IDLE and AWS fails the call:

ValidationException: An error occurred (ValidationException) when calling the StopApplication operation:
Application 00g966g6g91vau0l cannot be STOPPED. All sessions for the Application need to be in one of
the following states: [TERMINATED, FAILED]

stop_app fails, delete_app fails with it, and the application is left running and billing.

What

Adds EmrServerlessTerminateSessionOperator, the counterpart to EmrServerlessStartSessionOperator:

  • EmrServerlessHook.terminate_session() wrapping the TerminateSession API, gated on botocore at runtime by the existing _check_interactive_session_support() so users who do not touch sessions keep the provider's lower botocore floor.
  • A serverless_session_terminated waiter. It accepts both TERMINATED and FAILED as success, because either state is enough for the application to stop — that is exactly the condition StopApplication enforces.
  • EmrServerlessTerminateSessionTrigger for deferrable mode.
  • The system test now terminates the session before stopping the application.
  • Docs note that force_stop does not cover sessions, so dag authors know they need this operator.

force_stop is deliberately left alone: it is documented as being about job runs, and making it terminate sessions as well would change the behaviour of the existing operator. Happy to extend it in a follow-up if maintainers prefer that instead.

Testing

  • providers/amazon/tests/unit/amazon/aws/{operators/test_emr_serverless_session,hooks/test_emr_serverless,triggers/test_emr}.py — 51 passed, covering the sync wait, wait_for_completion=False, the deferrable path, execute_complete success/failure, the hook call and its botocore gate, and trigger serialization.
  • Ran the system test against a real AWS account before and after the change.
    • Before: stop_app failed with the ValidationException above, delete_app failed, application left STARTED.
    • After: all 6 tasks succeeded, DagRun ... state=success, and the application was deleted by the dag's own teardown (list_applications shows no session-systest left behind).

EMR Serverless rejects StopApplication while any of the application's
sessions is still active, and the provider had no way to terminate a
session. EmrServerlessStopApplicationOperator cannot cover the gap: its
force_stop argument only calls cancel_running_jobs, which cancels job
runs and leaves sessions untouched.

As a result example_emr_serverless_session could never finish. Its
teardown went straight from start_session to stop_app, so the session was
still IDLE and AWS failed the call:

  ValidationException: Application ... cannot be STOPPED. All sessions for
  the Application need to be in one of the following states:
  [TERMINATED, FAILED]

This adds the counterpart to EmrServerlessStartSessionOperator. The
terminated waiter accepts both TERMINATED and FAILED, since either state
lets the application stop, and the session APIs stay gated on botocore at
runtime so users who do not touch sessions keep the provider's lower
floor. The system test now terminates the session before stopping the
application.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant