Skip to content

Commit

Permalink
[AIRFLOW-6109] [AIP-21] Rename GCP function operators and hooks (apac…
Browse files Browse the repository at this point in the history
  • Loading branch information
michalslowikowski00 authored and turbaszek committed Dec 31, 2019
1 parent 235a87d commit 505e5d9
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 52 deletions.
3 changes: 1 addition & 2 deletions airflow/contrib/hooks/gcp_function_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

import warnings

# pylint: disable=unused-import
from airflow.gcp.hooks.functions import CloudFunctionsHook # noqa
from airflow.gcp.hooks.functions import CloudFunctionsHook

warnings.warn(
"This module is deprecated. Please use `airflow.gcp.hooks.functions`.",
Expand Down
35 changes: 32 additions & 3 deletions airflow/contrib/operators/gcp_function_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,41 @@

import warnings

# pylint: disable=unused-import
from airflow.gcp.operators.functions import ( # # noqa
GcfFunctionDeleteOperator, GcfFunctionDeployOperator, ZipPathPreprocessor,
from airflow.gcp.operators.functions import (
CloudFunctionDeleteFunctionOperator, CloudFunctionDeployFunctionOperator,
)

warnings.warn(
"This module is deprecated. Please use `airflow.gcp.operators.functions`.",
DeprecationWarning, stacklevel=2
)


class GcfFunctionDeleteOperator(CloudFunctionDeleteFunctionOperator):
"""
This class is deprecated.
Please use `airflow.gcp.operators.function.CloudFunctionDeleteFunctionOperator`.
"""

def __init__(self, *args, **kwargs):
warnings.warn(
"""This class is deprecated.
Please use `airflow.gcp.operators.function.CloudFunctionDeleteFunctionOperator`.""",
DeprecationWarning, stacklevel=2
)
super().__init__(*args, **kwargs)


class GcfFunctionDeployOperator(CloudFunctionDeployFunctionOperator):
"""
This class is deprecated.
Please use `airflow.gcp.operators.function.CloudFunctionDeployFunctionOperator`.
"""

def __init__(self, *args, **kwargs):
warnings.warn(
"""This class is deprecated.
Please use `airflow.gcp.operators.function.CloudFunctionDeployFunctionOperator`.""",
DeprecationWarning, stacklevel=2
)
super().__init__(*args, **kwargs)
11 changes: 6 additions & 5 deletions airflow/gcp/example_dags/example_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@

from airflow import models
from airflow.gcp.operators.functions import (
GcfFunctionDeleteOperator, GcfFunctionDeployOperator, GcfFunctionInvokeOperator,
CloudFunctionDeleteFunctionOperator, CloudFunctionDeployFunctionOperator,
CloudFunctionInvokeFunctionOperator,
)
from airflow.utils import dates

Expand Down Expand Up @@ -109,7 +110,7 @@
schedule_interval=None # Override to match your needs
) as dag:
# [START howto_operator_gcf_deploy]
deploy_task = GcfFunctionDeployOperator(
deploy_task = CloudFunctionDeployFunctionOperator(
task_id="gcf_deploy_task",
project_id=GCP_PROJECT_ID,
location=GCP_LOCATION,
Expand All @@ -118,15 +119,15 @@
)
# [END howto_operator_gcf_deploy]
# [START howto_operator_gcf_deploy_no_project_id]
deploy2_task = GcfFunctionDeployOperator(
deploy2_task = CloudFunctionDeployFunctionOperator(
task_id="gcf_deploy2_task",
location=GCP_LOCATION,
body=body,
validate_body=GCP_VALIDATE_BODY
)
# [END howto_operator_gcf_deploy_no_project_id]
# [START howto_operator_gcf_invoke_function]
invoke_task = GcfFunctionInvokeOperator(
invoke_task = CloudFunctionInvokeFunctionOperator(
task_id="invoke_task",
project_id=GCP_PROJECT_ID,
location=GCP_LOCATION,
Expand All @@ -135,7 +136,7 @@
)
# [END howto_operator_gcf_invoke_function]
# [START howto_operator_gcf_delete]
delete_task = GcfFunctionDeleteOperator(
delete_task = CloudFunctionDeleteFunctionOperator(
task_id="gcf_delete_task",
name=FUNCTION_NAME
)
Expand Down
12 changes: 6 additions & 6 deletions airflow/gcp/operators/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ def _validate_max_instances(value):
] # type: List[Dict[str, Any]]


class GcfFunctionDeployOperator(BaseOperator):
class CloudFunctionDeployFunctionOperator(BaseOperator):
"""
Creates a function in Google Cloud Functions.
If a function with this name already exists, it will be updated.
.. seealso::
For more information on how to use this operator, take a look at the guide:
:ref:`howto/operator:GcfFunctionDeployOperator`
:ref:`howto/operator:CloudFunctionDeployFunctionOperator`
:param location: Google Cloud Platform region where the function should be created.
:type location: str
Expand Down Expand Up @@ -292,13 +292,13 @@ def preprocess_body(self):
FUNCTION_NAME_COMPILED_PATTERN = re.compile(FUNCTION_NAME_PATTERN)


class GcfFunctionDeleteOperator(BaseOperator):
class CloudFunctionDeleteFunctionOperator(BaseOperator):
"""
Deletes the specified function from Google Cloud Functions.
.. seealso::
For more information on how to use this operator, take a look at the guide:
:ref:`howto/operator:GcfFunctionDeleteOperator`
:ref:`howto/operator:CloudFunctionDeleteFunctionOperator`
:param name: A fully-qualified function name, matching
the pattern: `^projects/[^/]+/locations/[^/]+/functions/[^/]+$`
Expand Down Expand Up @@ -346,14 +346,14 @@ def execute(self, context):
raise e


class GcfFunctionInvokeOperator(BaseOperator):
class CloudFunctionInvokeFunctionOperator(BaseOperator):
"""
Invokes a deployed Cloud Function. To be used for testing
purposes as very limited traffic is allowed.
.. seealso::
For more information on how to use this operator, take a look at the guide:
:ref:`howto/operator:GcfFunctionDeployOperator`
:ref:`howto/operator:CloudFunctionDeployFunctionOperator`
:param function_id: ID of the function to be called
:type function_id: str
Expand Down
16 changes: 8 additions & 8 deletions docs/howto/operator/gcp/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ Prerequisite Tasks

.. include:: _partials/prerequisite_tasks.rst

.. _howto/operator:GcfFunctionDeleteOperator:
.. _howto/operator:CloudFunctionDeleteFunctionOperator:

GcfFunctionDeleteOperator
-------------------------
CloudFunctionDeleteFunctionOperator
-----------------------------------

Use the operator to delete a function from Google Cloud Functions.

For parameter definition, take a look at
:class:`~airflow.gcp.operators.functions.GcfFunctionDeleteOperator`.
:class:`~airflow.gcp.operators.functions.CloudFunctionDeleteFunctionOperator`.

Arguments
"""""""""
Expand Down Expand Up @@ -74,16 +74,16 @@ More information
See Google Cloud Functions API documentation to `delete a function
<https://cloud.google.com/functions/docs/reference/rest/v1/projects.locations.functions/delete>`_.

.. _howto/operator:GcfFunctionDeployOperator:
.. _howto/operator:CloudFunctionDeployFunctionOperator:

GcfFunctionDeployOperator
-------------------------
CloudFunctionDeployFunctionOperator
-----------------------------------

Use the operator to deploy a function to Google Cloud Functions.
If a function with this name already exists, it will be updated.

For parameter definition, take a look at
:class:`~airflow.gcp.operators.functions.GcfFunctionDeployOperator`.
:class:`~airflow.gcp.operators.functions.CloudFunctionDeployFunctionOperator`.


Arguments
Expand Down
Loading

0 comments on commit 505e5d9

Please sign in to comment.