-
Notifications
You must be signed in to change notification settings - Fork 14.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add EMR Serverless Operators and Hooks #25324
Merged
potiuk
merged 25 commits into
apache:main
from
syedahsn:syedahsn/emr-serverless-operator
Aug 5, 2022
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
3ab377c
Hooks and Operators for EMR Serverless
syedahsn 0ee2b1d
Remove unused imports
syedahsn 9cdb462
Updated work for Dennis
syedahsn b49bd3d
Fix bugs with starting operators
syedahsn 1fb4758
Add sensor for emr jobs and applications
syedahsn 9ab620d
Linting, Added Missing Docs, and CR Fixes
ferruzzi 75637be
Fix Fake Waiter
ferruzzi 3fe842f
EMR dags and docs CR
syedahsn e8b2f0b
CR comments rev 2
syedahsn be2954d
rev 8 changes suggested by Niko
syedahsn 95caac2
Fix typos and documentation for rev 8 comments
syedahsn d92da3a
Move waiter logic to hook, improve sensor functionality to report fai…
syedahsn 014f89a
Move wait function to work only when needed
syedahsn 80d3588
Tests for emr serverless
syedahsn 9e59719
Update emr serverless release label to latest version
syedahsn 8d41f4c
Make changes suggested by Niko
syedahsn 6cace43
Mock waiter function call - improve emr serverless hook tests
syedahsn 877e79d
Add support for arbitrary parameters to StartJobOperator
syedahsn 5a522e8
Change waiter to make check_interval_seconds and countdown be passed …
syedahsn 4d86a59
Remove duplicate test variables
syedahsn 471688f
Remove service.json
syedahsn 8294870
Make changes requested by reviewers:
syedahsn 68896f4
Removed redundant try/except around calls to boto3 API
syedahsn 4281433
Forgot to remove some print statements
syedahsn c60edf1
Add template fields to EmrServerlessStartJobOperator
syedahsn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
airflow/providers/amazon/aws/example_dags/example_emr_serverless.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from datetime import datetime | ||
from os import getenv | ||
|
||
from airflow import DAG | ||
from airflow.models.baseoperator import chain | ||
from airflow.providers.amazon.aws.operators.emr import ( | ||
EmrServerlessCreateApplicationOperator, | ||
EmrServerlessDeleteApplicationOperator, | ||
EmrServerlessStartJobOperator, | ||
) | ||
from airflow.providers.amazon.aws.sensors.emr import EmrServerlessApplicationSensor, EmrServerlessJobSensor | ||
|
||
EXECUTION_ROLE_ARN = getenv('EXECUTION_ROLE_ARN', 'execution_role_arn') | ||
EMR_EXAMPLE_BUCKET = getenv('EMR_EXAMPLE_BUCKET', 'emr_example_bucket') | ||
SPARK_JOB_DRIVER = { | ||
"sparkSubmit": { | ||
"entryPoint": "s3://us-east-1.elasticmapreduce/emr-containers/samples/wordcount/scripts/wordcount.py", | ||
"entryPointArguments": [f"s3://{EMR_EXAMPLE_BUCKET}/output"], | ||
"sparkSubmitParameters": "--conf spark.executor.cores=1 --conf spark.executor.memory=4g\ | ||
--conf spark.driver.cores=1 --conf spark.driver.memory=4g --conf spark.executor.instances=1", | ||
} | ||
} | ||
|
||
SPARK_CONFIGURATION_OVERRIDES = { | ||
"monitoringConfiguration": {"s3MonitoringConfiguration": {"logUri": f"s3://{EMR_EXAMPLE_BUCKET}/logs"}} | ||
} | ||
|
||
with DAG( | ||
dag_id='example_emr_serverless', | ||
schedule_interval=None, | ||
start_date=datetime(2021, 1, 1), | ||
tags=['example'], | ||
catchup=False, | ||
) as emr_serverless_dag: | ||
|
||
# [START howto_operator_emr_serverless_create_application] | ||
emr_serverless_app = EmrServerlessCreateApplicationOperator( | ||
task_id='create_emr_serverless_task', | ||
release_label='emr-6.6.0', | ||
job_type="SPARK", | ||
config={'name': 'new_application'}, | ||
) | ||
# [END howto_operator_emr_serverless_create_application] | ||
|
||
# [START howto_sensor_emr_serverless_application] | ||
wait_for_app_creation = EmrServerlessApplicationSensor( | ||
task_id='wait_for_app_creation', | ||
application_id=emr_serverless_app.output, | ||
) | ||
# [END howto_sensor_emr_serverless_application] | ||
|
||
# [START howto_operator_emr_serverless_start_job] | ||
start_job = EmrServerlessStartJobOperator( | ||
task_id='start_emr_serverless_job', | ||
application_id=emr_serverless_app.output, | ||
execution_role_arn=EXECUTION_ROLE_ARN, | ||
job_driver=SPARK_JOB_DRIVER, | ||
configuration_overrides=SPARK_CONFIGURATION_OVERRIDES, | ||
) | ||
# [END howto_operator_emr_serverless_start_job] | ||
|
||
# [START howto_sensor_emr_serverless_job] | ||
wait_for_job = EmrServerlessJobSensor( | ||
task_id='wait_for_job', application_id=emr_serverless_app.output, job_run_id=start_job.output | ||
) | ||
# [END howto_sensor_emr_serverless_job] | ||
|
||
# [START howto_operator_emr_serverless_delete_application] | ||
delete_app = EmrServerlessDeleteApplicationOperator( | ||
task_id='delete_application', application_id=emr_serverless_app.output, trigger_rule="all_done" | ||
) | ||
# [END howto_operator_emr_serverless_delete_application] | ||
|
||
chain( | ||
emr_serverless_app, | ||
wait_for_app_creation, | ||
start_job, | ||
wait_for_job, | ||
delete_app, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new example dags should be according to AIP-47
Example: #25205
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point but the plan was to do it in two iterations since this PR is already big enough. Once this PR is merged, @syedahsn will work on converting this sample dag to system test. If you strongly disagree, I guess the two can be done in this PR but it will just make it bigger and harder to review