Skip to content

Commit

Permalink
Rename CloudBuildCreateBuildOperator to CloudBuildCreateOperator (#9314)
Browse files Browse the repository at this point in the history
  • Loading branch information
mik-laj committed Jun 15, 2020
1 parent 2c18a3f commit 1459970
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 34 deletions.
2 changes: 1 addition & 1 deletion UPDATING.md
Expand Up @@ -919,7 +919,7 @@ The following table shows changes in import paths.
|airflow.contrib.operators.gcp_bigtable_operator.BigtableTableCreateOperator |airflow.providers.google.cloud.operators.bigtable.BigtableCreateTableOperator |
|airflow.contrib.operators.gcp_bigtable_operator.BigtableTableDeleteOperator |airflow.providers.google.cloud.operators.bigtable.BigtableDeleteTableOperator |
|airflow.contrib.operators.gcp_bigtable_operator.BigtableTableWaitForReplicationSensor |airflow.providers.google.cloud.sensors.bigtable.BigtableTableReplicationCompletedSensor |
|airflow.contrib.operators.gcp_cloud_build_operator.CloudBuildCreateBuildOperator |airflow.providers.google.cloud.operators.cloud_build.CloudBuildCreateOperator |
|airflow.contrib.operators.gcp_cloud_build_operator.CloudBuildCreateBuildOperator |airflow.providers.google.cloud.operators.cloud_build.CloudBuildCreateBuildOperator |
|airflow.contrib.operators.gcp_compute_operator.GceBaseOperator |airflow.providers.google.cloud.operators.compute.GceBaseOperator |
|airflow.contrib.operators.gcp_compute_operator.GceInstanceGroupManagerUpdateTemplateOperator |airflow.providers.google.cloud.operators.compute.GceInstanceGroupManagerUpdateTemplateOperator |
|airflow.contrib.operators.gcp_compute_operator.GceInstanceStartOperator |airflow.providers.google.cloud.operators.compute.GceInstanceStartOperator |
Expand Down
17 changes: 2 additions & 15 deletions airflow/contrib/operators/gcp_cloud_build_operator.py
Expand Up @@ -19,23 +19,10 @@

import warnings

from airflow.providers.google.cloud.operators.cloud_build import CloudBuildCreateOperator
# pylint: disable=unused-import
from airflow.providers.google.cloud.operators.cloud_build import CloudBuildCreateBuildOperator # noqa

warnings.warn(
"This module is deprecated. Please use `airflow.providers.google.cloud.operators.cloud_build`.",
DeprecationWarning, stacklevel=2
)


class CloudBuildCreateBuildOperator(CloudBuildCreateOperator):
"""
This class is deprecated.
Please use `airflow.providers.google.cloud.operators.cloud_build.CloudBuildCreateOperator`.
"""
def __init__(self, *args, **kwargs):
warnings.warn(
"""This class is deprecated.
Please use `airflow.providers.google.cloud.operators.cloud_build.CloudBuildCreateOperator`.""",
DeprecationWarning, stacklevel=2
)
super().__init__(*args, **kwargs)
2 changes: 1 addition & 1 deletion airflow/providers/google/README.md
Expand Up @@ -287,7 +287,7 @@ All classes in Airflow 2.0 are in `airflow.providers.google` package.
| [cloud.operators.bigtable.BigtableDeleteTableOperator](https://github.com/apache/airflow/blob/master/airflow/providers/google/cloud/operators/bigtable.py) | [contrib.operators.gcp_bigtable_operator.BigtableTableDeleteOperator](https://github.com/apache/airflow/blob/v1-10-stable/airflow/contrib/operators/gcp_bigtable_operator.py) |
| [cloud.operators.bigtable.BigtableUpdateClusterOperator](https://github.com/apache/airflow/blob/master/airflow/providers/google/cloud/operators/bigtable.py) | [contrib.operators.gcp_bigtable_operator.BigtableClusterUpdateOperator](https://github.com/apache/airflow/blob/v1-10-stable/airflow/contrib/operators/gcp_bigtable_operator.py) |
| [cloud.operators.cassandra_to_gcs.CassandraToGCSOperator](https://github.com/apache/airflow/blob/master/airflow/providers/google/cloud/operators/cassandra_to_gcs.py) | [contrib.operators.cassandra_to_gcs.CassandraToGoogleCloudStorageOperator](https://github.com/apache/airflow/blob/v1-10-stable/airflow/contrib/operators/cassandra_to_gcs.py) |
| [cloud.operators.cloud_build.CloudBuildCreateOperator](https://github.com/apache/airflow/blob/master/airflow/providers/google/cloud/operators/cloud_build.py) | [contrib.operators.gcp_cloud_build_operator.CloudBuildCreateBuildOperator](https://github.com/apache/airflow/blob/v1-10-stable/airflow/contrib/operators/gcp_cloud_build_operator.py) |
| [cloud.operators.cloud_build.CloudBuildCreateBuildOperator](https://github.com/apache/airflow/blob/master/airflow/providers/google/cloud/operators/cloud_build.py) | [contrib.operators.gcp_cloud_build_operator.CloudBuildCreateOperator](https://github.com/apache/airflow/blob/v1-10-stable/airflow/contrib/operators/gcp_cloud_build_operator.py) |
| [cloud.operators.cloud_sql.CloudSQLBaseOperator](https://github.com/apache/airflow/blob/master/airflow/providers/google/cloud/operators/cloud_sql.py) | [contrib.operators.gcp_sql_operator.CloudSqlBaseOperator](https://github.com/apache/airflow/blob/v1-10-stable/airflow/contrib/operators/gcp_sql_operator.py) |
| [cloud.operators.cloud_sql.CloudSQLCreateInstanceDatabaseOperator](https://github.com/apache/airflow/blob/master/airflow/providers/google/cloud/operators/cloud_sql.py) | [contrib.operators.gcp_sql_operator.CloudSqlInstanceDatabaseCreateOperator](https://github.com/apache/airflow/blob/v1-10-stable/airflow/contrib/operators/gcp_sql_operator.py) |
| [cloud.operators.cloud_sql.CloudSQLCreateInstanceOperator](https://github.com/apache/airflow/blob/master/airflow/providers/google/cloud/operators/cloud_sql.py) | [contrib.operators.gcp_sql_operator.CloudSqlInstanceCreateOperator](https://github.com/apache/airflow/blob/v1-10-stable/airflow/contrib/operators/gcp_sql_operator.py) |
Expand Down
Expand Up @@ -35,7 +35,7 @@

from airflow import models
from airflow.operators.bash import BashOperator
from airflow.providers.google.cloud.operators.cloud_build import CloudBuildCreateOperator
from airflow.providers.google.cloud.operators.cloud_build import CloudBuildCreateBuildOperator
from airflow.utils import dates

GCP_PROJECT_ID = os.environ.get("GCP_PROJECT_ID", "example-project")
Expand Down Expand Up @@ -81,7 +81,7 @@
tags=['example'],
) as dag:
# [START howto_operator_create_build_from_storage]
create_build_from_storage = CloudBuildCreateOperator(
create_build_from_storage = CloudBuildCreateBuildOperator(
task_id="create_build_from_storage", project_id=GCP_PROJECT_ID, body=create_build_from_storage_body
)
# [END howto_operator_create_build_from_storage]
Expand All @@ -93,7 +93,7 @@
)
# [END howto_operator_create_build_from_storage_result]

create_build_from_repo = CloudBuildCreateOperator(
create_build_from_repo = CloudBuildCreateBuildOperator(
task_id="create_build_from_repo", project_id=GCP_PROJECT_ID, body=create_build_from_repo_body
)

Expand All @@ -103,7 +103,7 @@
)

# [START howto_operator_gcp_create_build_from_yaml_body]
create_build_from_file = CloudBuildCreateOperator(
create_build_from_file = CloudBuildCreateBuildOperator(
task_id="create_build_from_file", project_id=GCP_PROJECT_ID,
body=str(CURRENT_FOLDER.joinpath('example_cloud_build.yaml')),
params={'name': 'Airflow'}
Expand Down
4 changes: 2 additions & 2 deletions airflow/providers/google/cloud/operators/cloud_build.py
Expand Up @@ -159,13 +159,13 @@ def _convert_storage_url_to_dict(storage_url: str) -> Dict[str, Any]:
return source_dict


class CloudBuildCreateOperator(BaseOperator):
class CloudBuildCreateBuildOperator(BaseOperator):
"""
Starts a build with the specified configuration.
.. seealso::
For more information on how to use this operator, take a look at the guide:
:ref:`howto/operator:CloudBuildCreateOperator`
:ref:`howto/operator:CloudBuildCreateBuildOperator`
:param body: The build config with instructions to perform with CloudBuild.
Can be a dictionary or path to a file type like YAML or JSON.
Expand Down
6 changes: 3 additions & 3 deletions docs/howto/operator/gcp/cloud_build.rst
Expand Up @@ -92,13 +92,13 @@ It is also possible to specify it using a YAML or JSON format.
Read `Build Configuration Overview <https://cloud.google.com/cloud-build/docs/build-config>`__ to understand all the fields you can include in a build config file.


.. _howto/operator:CloudBuildCreateOperator:
.. _howto/operator:CloudBuildCreateBuildOperator:

Trigger a build
^^^^^^^^^^^^^^^

Trigger a build is performed with the
:class:`~airflow.providers.google.cloud.operators.cloud_build.CloudBuildCreateOperator` operator.
:class:`~airflow.providers.google.cloud.operators.cloud_build.CloudBuildCreateBuildOperator` operator.

.. exampleinclude:: ../../../../airflow/providers/google/cloud/example_dags/example_cloud_build.py
:language: python
Expand All @@ -107,7 +107,7 @@ Trigger a build is performed with the
:end-before: [END howto_operator_create_build_from_storage]

You can use :ref:`Jinja templating <jinja-templating>` with
:template-fields:`airflow.providers.google.cloud.operators.cloud_build.CloudBuildCreateOperator`
:template-fields:`airflow.providers.google.cloud.operators.cloud_build.CloudBuildCreateBuildOperator`
parameters which allows you to dynamically determine values. The result is saved to :ref:`XCom <concepts:xcom>`, which allows it
to be used by other operators.

Expand Down
14 changes: 7 additions & 7 deletions tests/providers/google/cloud/operators/test_cloud_build.py
Expand Up @@ -27,7 +27,7 @@

from airflow.exceptions import AirflowException
from airflow.models import DAG, TaskInstance
from airflow.providers.google.cloud.operators.cloud_build import BuildProcessor, CloudBuildCreateOperator
from airflow.providers.google.cloud.operators.cloud_build import BuildProcessor, CloudBuildCreateBuildOperator

TEST_CREATE_BODY = {
"source": {"storageSource": {"bucket": "cloud-build-examples", "object": "node-docker-example.tar.gz"}},
Expand Down Expand Up @@ -114,11 +114,11 @@ def test_do_nothing(self, source_key):
self.assertEqual(body, expected_body)


class TestGcpCloudBuildCreateOperator(TestCase):
class TestGcpCloudBuildCreateBuildOperator(TestCase):
@mock.patch("airflow.providers.google.cloud.operators.cloud_build.CloudBuildHook")
def test_minimal_green_path(self, mock_hook):
mock_hook.return_value.create_build.return_value = TEST_CREATE_BODY
operator = CloudBuildCreateOperator(
operator = CloudBuildCreateBuildOperator(
body=TEST_CREATE_BODY, project_id=TEST_PROJECT_ID, task_id="task-id"
)
result = operator.execute({})
Expand All @@ -127,7 +127,7 @@ def test_minimal_green_path(self, mock_hook):
@parameterized.expand([({},), (None,)])
def test_missing_input(self, body):
with self.assertRaisesRegex(AirflowException, "The required parameter 'body' is missing"):
CloudBuildCreateOperator(body=body, project_id=TEST_PROJECT_ID, task_id="task-id")
CloudBuildCreateBuildOperator(body=body, project_id=TEST_PROJECT_ID, task_id="task-id")

@mock.patch("airflow.providers.google.cloud.operators.cloud_build.CloudBuildHook")
def test_storage_source_replace(self, hook_mock):
Expand All @@ -145,7 +145,7 @@ def test_storage_source_replace(self, hook_mock):
"images": ["gcr.io/$PROJECT_ID/docker-image"],
}

operator = CloudBuildCreateOperator(
operator = CloudBuildCreateBuildOperator(
body=current_body, project_id=TEST_PROJECT_ID, task_id="task-id"
)
operator.execute({})
Expand Down Expand Up @@ -181,7 +181,7 @@ def test_repo_source_replace(self, hook_mock):
],
"images": ["gcr.io/$PROJECT_ID/docker-image"],
}
operator = CloudBuildCreateOperator(
operator = CloudBuildCreateBuildOperator(
body=current_body, project_id=TEST_PROJECT_ID, task_id="task-id"
)

Expand Down Expand Up @@ -219,7 +219,7 @@ def test_load_templated_yaml(self):
""")
build.seek(0)
body_path = build.name
operator = CloudBuildCreateOperator(
operator = CloudBuildCreateBuildOperator(
body=body_path,
task_id="task-id", dag=dag,
params={'name': 'airflow'}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_core_to_contrib.py
Expand Up @@ -474,7 +474,7 @@
"airflow.contrib.operators.gcp_bigtable_operator.BigtableTableDeleteOperator",
),
(
"airflow.providers.google.cloud.operators.cloud_build.CloudBuildCreateOperator",
"airflow.providers.google.cloud.operators.cloud_build.CloudBuildCreateBuildOperator",
"airflow.contrib.operators.gcp_cloud_build_operator.CloudBuildCreateBuildOperator",
),
(
Expand Down

0 comments on commit 1459970

Please sign in to comment.