Skip to content
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

[AIRFLOW-6258] add CloudFormation operators to AWS providers #6824

Conversation

aviemzur
Copy link
Member

@aviemzur aviemzur commented Dec 15, 2019

Make sure you have checked all steps below.

Jira

  • My PR addresses the following Airflow Jira issues and references them in the PR title. For example, "[AIRFLOW-6258] My Airflow PR"
    • https://issues.apache.org/jira/browse/AIRFLOW-6258
    • In case you are fixing a typo in the documentation you can prepend your commit with [AIRFLOW-XXX], code changes always need a Jira issue.
    • In case you are proposing a fundamental code change, you need to create an Airflow Improvement Proposal (AIP).
    • In case you are adding a dependency, check if the license complies with the ASF 3rd Party License Policy.

Description

  • Here are some details about my PR, including screenshots of any UI changes:

Add 2 new operators: CloudFormationCreateStackOperator and CloudFormationDeleteStackOperator
https://issues.apache.org/jira/browse/AIRFLOW-6258

Tests

  • My PR adds the following unit tests OR does not need testing for this extremely good reason:

TestCloudFormationCreateStackOperator and TestCloudFormationDeleteStackOperator

Commits

  • My commits all reference Jira issues in their subject lines, and I have squashed multiple commits if they address the same issue. In addition, my commits follow the guidelines from "How to write a good git commit message":
    1. Subject is separated from body by a blank line
    2. Subject is limited to 50 characters (not including Jira issue reference)
    3. Subject does not end with a period
    4. Subject uses the imperative mood ("add", not "adding")
    5. Body wraps at 72 characters
    6. Body explains "what" and "why", not "how"

Documentation

  • In case of new functionality, my PR adds documentation that describes how to use it.
    • All the public functions and the classes in the PR contain docstrings that explain what it does
    • If you implement backwards incompatible changes, please leave a note in the Updating.md so we can assign it to a appropriate release

@OmerJog
Copy link
Contributor

OmerJog commented Dec 17, 2019

@aviemzur can you please fix errors?

airflow/contrib/operators/cloudformation_create_stack_operator.py:1:0: C0111: Missing module docstring (missing-docstring)
airflow/contrib/operators/cloudformation_create_stack_operator.py:52:8: C0103: Attribute name "StackName" doesn't conform to snake_case naming style (invalid-name)
airflow/contrib/operators/cloudformation_create_stack_operator.py:53:8: C0103: Attribute name "TimeoutInMinutes" doesn't conform to snake_case naming style (invalid-name)
airflow/contrib/operators/cloudformation_create_stack_operator.py:49:57: E1101: Method '__init__' has no '__wrapped__' member (no-member)
airflow/contrib/operators/cloudformation_create_stack_operator.py:49:57: E1101: Method '__init__' has no '__wrapped__' member (no-member)
airflow/contrib/operators/cloudformation_create_stack_operator.py:49:57: E1101: Method '__init__' has no '__wrapped__' member (no-member)
************* Module airflow.contrib.operators.cloudformation_delete_stack_operator
airflow/contrib/operators/cloudformation_delete_stack_operator.py:1:0: C0111: Missing module docstring (missing-docstring)
airflow/contrib/operators/cloudformation_delete_stack_operator.py:48:8: C0103: Attribute name "StackName" doesn't conform to snake_case naming style (invalid-name)
airflow/contrib/operators/cloudformation_delete_stack_operator.py:45:57: E1101: Method '__init__' has no '__wrapped__' member (no-member)
airflow/contrib/operators/cloudformation_delete_stack_operator.py:45:57: E1101: Method '__init__' has no '__wrapped__' member (no-member)
airflow/contrib/operators/cloudformation_delete_stack_operator.py:45:57: E1101: Method '__init__' has no '__wrapped__' member (no-member)

@aviemzur aviemzur force-pushed the AIRFLOW-6258-cloudformation-create-stack-delete-stack-operators branch from 175ab03 to 42e864c Compare December 17, 2019 12:19
Copy link
Member

@turbaszek turbaszek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move those operators to airflow.providers.amazon.aws.hooks/operators.cloud_formation.py. Additionally we try to keep operators for a single service in a single file.

Interact with AWS CloudFormation.
"""

def __init__(self, region_name=None, *args, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's worth to move region_name to methods? Then user will be able to specify this parameter using operators.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was going by the example of other AWS hooks
airflow/contrib/hooks/emr_hook.py
airflow/contrib/hooks/aws_logs_hook.py
Should I still change this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@feluelle I think you are more AWS experienced, can you take a look? 😃


:param aws_conn_id: aws connection to uses
:type aws_conn_id: str
:param kwargs: Additional arguments to be passed to CloudFormation. For possible arguments see:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not a good idea. Please use other name for the argument like params or stack.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will use params instead.

aws_conn_id='aws_default',
*args, **kwargs):
# pylint: disable=no-member
self.operator_arguments = inspect.getfullargspec(super().__init__.__wrapped__)[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was trying to use kwargs for configuration.
As you mentioned above I should change this to use param instead, and will delete this code.

@aviemzur
Copy link
Member Author

Sure, I can consolidate to one file.

I was going by the example of emr where there are 3 separate files
airflow/contrib/operators/emr_add_steps_operator.py
airflow/contrib/operators/emr_create_job_flow_operator.py
airflow/contrib/operators/emr_terminate_job_flow_operator.py

But have no problem to consolidate to one file.

@turbaszek turbaszek added the provider:amazon-aws AWS/Amazon - related issues label Dec 22, 2019
@aviemzur aviemzur force-pushed the AIRFLOW-6258-cloudformation-create-stack-delete-stack-operators branch 3 times, most recently from 661c4b3 to e0e6e99 Compare December 26, 2019 13:38
Add 2 new operators:
CloudFormationCreateStackOperator and CloudFormationDeleteStackOperator
@aviemzur aviemzur force-pushed the AIRFLOW-6258-cloudformation-create-stack-delete-stack-operators branch 2 times, most recently from 5895b59 to 9924987 Compare January 2, 2020 11:56
@aviemzur aviemzur force-pushed the AIRFLOW-6258-cloudformation-create-stack-delete-stack-operators branch from 9924987 to 51d2028 Compare January 2, 2020 12:33
@potiuk
Copy link
Member

potiuk commented Jan 2, 2020

Please move those operators to airflow.providers.amazon.aws.hooks/operators.cloud_formation.py. Additionally we try to keep operators for a single service in a single file.

Just a nice reminder to do this as well :)

@turbaszek
Copy link
Member

Please move those operators to airflow.providers.amazon.aws.hooks/operators.cloud_formation.py.

@aviemzur can you please add new operators to airflow/providers not to airflow/contrib? Contrib is going to be deprecated.

@aviemzur
Copy link
Member Author

aviemzur commented Jan 2, 2020

Sure, will move them

@aviemzur aviemzur force-pushed the AIRFLOW-6258-cloudformation-create-stack-delete-stack-operators branch from cbe77b7 to 45e68c0 Compare January 3, 2020 04:44
@aviemzur aviemzur changed the title [AIRFLOW-6258] add CloudFormation operators to contrib [AIRFLOW-6258] add CloudFormation operators to aws providers Jan 3, 2020
@aviemzur aviemzur changed the title [AIRFLOW-6258] add CloudFormation operators to aws providers [AIRFLOW-6258] add CloudFormation operators to AWS providers Jan 3, 2020
@aviemzur aviemzur force-pushed the AIRFLOW-6258-cloudformation-create-stack-delete-stack-operators branch from 45e68c0 to b92339b Compare January 3, 2020 14:22
@aviemzur
Copy link
Member Author

aviemzur commented Jan 6, 2020

@nuclearpinguin made the requested change.
Not sure about how to fix the CI error:

/opt/airflow/docs/_api/airflow/providers/amazon/aws/operators/cloud_formation/index.rst:22: WARNING: Field list ends without a blank line; unexpected unindent.
/opt/airflow/docs/_api/airflow/providers/amazon/aws/operators/cloud_formation/index.rst:67: WARNING: Field list ends without a blank line; unexpected unindent.
/opt/airflow/docs/_api/airflow/providers/amazon/aws/operators/cloud_formation/index.rst:100: WARNING: Field list ends without a blank line; unexpected unindent.

Please advise

Base operator for CloudFormation operations.

:param params: parameters to be passed to CloudFormation.
:type dict
Copy link
Member

@mik-laj mik-laj Jan 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:type dict
:type param: Dict


:param params: parameters to be passed to CloudFormation. For possible arguments see:
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cloudformation.html#CloudFormation.Client.create_stack
:type dict
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:type dict
:type params: Dict


:param params: parameters to be passed to CloudFormation. For possible arguments see:
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cloudformation.html#CloudFormation.Client.delete_stack
:type dict
Copy link
Member

@mik-laj mik-laj Jan 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:type dict
:type params: Dict

@mik-laj
Copy link
Member

mik-laj commented Jan 6, 2020

That should solve the problems.

@codecov-io
Copy link

codecov-io commented Jan 6, 2020

Codecov Report

Merging #6824 into master will increase coverage by 0.35%.
The diff coverage is 99%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #6824      +/-   ##
=========================================
+ Coverage   84.85%   85.2%   +0.35%     
=========================================
  Files         679     841     +162     
  Lines       38536   40424    +1888     
=========================================
+ Hits        32698   34445    +1747     
- Misses       5838    5979     +141
Impacted Files Coverage Δ
.../providers/amazon/aws/operators/cloud_formation.py 100% <100%> (ø)
...ow/providers/amazon/aws/sensors/cloud_formation.py 100% <100%> (ø)
...flow/providers/amazon/aws/hooks/cloud_formation.py 96.77% <96.77%> (ø)
airflow/operators/postgres_operator.py 0% <0%> (-100%) ⬇️
...rflow/contrib/sensors/sagemaker_training_sensor.py 0% <0%> (-100%) ⬇️
airflow/contrib/operators/snowflake_operator.py 0% <0%> (-95.84%) ⬇️
airflow/contrib/hooks/azure_data_lake_hook.py 0% <0%> (-93.11%) ⬇️
airflow/contrib/hooks/grpc_hook.py 0% <0%> (-91.94%) ⬇️
airflow/contrib/sensors/azure_cosmos_sensor.py 0% <0%> (-81.25%) ⬇️
airflow/contrib/hooks/snowflake_hook.py 0% <0%> (-81.14%) ⬇️
... and 481 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update be812bd...78a5d82. Read the comment docs.

@aviemzur aviemzur force-pushed the AIRFLOW-6258-cloudformation-create-stack-delete-stack-operators branch from e8d9972 to 2af82f2 Compare January 8, 2020 12:32
@aviemzur aviemzur force-pushed the AIRFLOW-6258-cloudformation-create-stack-delete-stack-operators branch from 8b6a9c4 to fcd35bc Compare January 22, 2020 08:16
@aviemzur aviemzur force-pushed the AIRFLOW-6258-cloudformation-create-stack-delete-stack-operators branch from fcd35bc to 3dce509 Compare January 22, 2020 08:39
@aviemzur
Copy link
Member Author

@nuclearpinguin made the changes you requested: Changes after CR 3

airflow/providers/amazon/aws/operators/cloud_formation.py Outdated Show resolved Hide resolved
"""
This is the main method to run CloudFormation operation.
"""
raise NotImplementedError()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with @nuclearpinguin

airflow/providers/amazon/aws/sensors/cloud_formation.py Outdated Show resolved Hide resolved
airflow/providers/amazon/aws/sensors/cloud_formation.py Outdated Show resolved Hide resolved
airflow/providers/amazon/aws/operators/cloud_formation.py Outdated Show resolved Hide resolved
airflow/providers/amazon/aws/operators/cloud_formation.py Outdated Show resolved Hide resolved
@aviemzur aviemzur force-pushed the AIRFLOW-6258-cloudformation-create-stack-delete-stack-operators branch from eb9e8c6 to d81c4fc Compare January 27, 2020 09:06
@aviemzur aviemzur force-pushed the AIRFLOW-6258-cloudformation-create-stack-delete-stack-operators branch from d81c4fc to 4147ffc Compare January 27, 2020 09:48
@aviemzur aviemzur closed this Jan 27, 2020
@aviemzur aviemzur reopened this Jan 27, 2020
aviemzur and others added 5 commits January 27, 2020 15:48
Co-Authored-By: Felix Uellendall <feluelle@users.noreply.github.com>
Co-Authored-By: Felix Uellendall <feluelle@users.noreply.github.com>
Co-Authored-By: Felix Uellendall <feluelle@users.noreply.github.com>
Co-Authored-By: Felix Uellendall <feluelle@users.noreply.github.com>
Change elif to if
@aviemzur
Copy link
Member Author

@feluelle committed all suggestions you made + made the changes you requested and all tests are passing on Travis.

@aviemzur
Copy link
Member Author

@nuclearpinguin @feluelle is anything else required prior to merging?

@kaxil kaxil merged commit 63aa3db into apache:master Feb 2, 2020
@kaxil
Copy link
Member

kaxil commented Feb 2, 2020

Good work @aviemzur 🎉

@aviemzur aviemzur deleted the AIRFLOW-6258-cloudformation-create-stack-delete-stack-operators branch February 2, 2020 11:01
galuszkak pushed a commit to FlyrInc/apache-airflow that referenced this pull request Mar 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
provider:amazon-aws AWS/Amazon - related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants