o-nikolas commented on code in PR #27227: URL: https://github.com/apache/airflow/pull/27227#discussion_r1005199854
########## airflow/providers/google/cloud/sensors/cloud_composer.py: ########## @@ -0,0 +1,99 @@ +# +# 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. +"""This module contains a Cloud Composer sensor.""" + +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Sequence + +from airflow.exceptions import AirflowException +from airflow.providers.google.cloud.triggers.cloud_composer import CloudComposerExecutionTrigger +from airflow.sensors.base import BaseSensorOperator + +if TYPE_CHECKING: + from airflow.utils.context import Context + + +class CloudComposerEnvironmentSensor(BaseSensorOperator): Review Comment: I would have expected to see this new Sensor in one of the system tests? ########## tests/system/providers/google/cloud/composer/example_cloud_composer.py: ########## @@ -115,48 +121,14 @@ chain(image_versions, create_env, list_envs, get_env, update_env, delete_env) Review Comment: You'll need to add a `TriggerRule.ALL_DONE` to the delete_env cleanup task (outside of the howto block though to keep the docs clean). ########## tests/system/providers/google/cloud/composer/example_cloud_composer_deferrable.py: ########## @@ -0,0 +1,115 @@ +# +# 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 __future__ import annotations + +import os +from datetime import datetime + +from airflow import models +from airflow.models.baseoperator import chain +from airflow.providers.google.cloud.operators.cloud_composer import ( + CloudComposerCreateEnvironmentOperator, + CloudComposerDeleteEnvironmentOperator, + CloudComposerUpdateEnvironmentOperator, +) +from airflow.utils.trigger_rule import TriggerRule + +ENV_ID = os.environ.get("SYSTEM_TESTS_ENV_ID") +PROJECT_ID = os.environ.get("SYSTEM_TESTS_GCP_PROJECT") + +DAG_ID = "example_composer_deferrable" + +REGION = "us-central1" + +ENVIRONMENT_ID = f"test-{DAG_ID}-{ENV_ID}" +# [START howto_operator_composer_simple_environment] +ENVIRONMENT = { + "config": { + "software_config": {"image_version": "composer-2.0.28-airflow-2.2.5"}, + } +} +# [END howto_operator_composer_simple_environment] + +# [START howto_operator_composer_update_environment] +UPDATED_ENVIRONMENT = { + "labels": { + "label2": "testing", + } +} +UPDATE_MASK = {"paths": ["labels.label2"]} +# [END howto_operator_composer_update_environment] + + +with models.DAG( + DAG_ID, + schedule="@once", + start_date=datetime(2021, 1, 1), + catchup=False, + tags=["example", "composer"], +) as dag: + # [START howto_operator_create_composer_environment_deferrable_mode] + defer_create_env = CloudComposerCreateEnvironmentOperator( + task_id="defer_create_env", + project_id=PROJECT_ID, + region=REGION, + environment_id=ENVIRONMENT_ID, + environment=ENVIRONMENT, + deferrable=True, + ) + # [END howto_operator_create_composer_environment_deferrable_mode] + + # [START howto_operator_update_composer_environment_deferrable_mode] + defer_update_env = CloudComposerUpdateEnvironmentOperator( + task_id="defer_update_env", + project_id=PROJECT_ID, + region=REGION, + environment_id=ENVIRONMENT_ID, + update_mask=UPDATE_MASK, + environment=UPDATED_ENVIRONMENT, + deferrable=True, + ) + # [END howto_operator_update_composer_environment_deferrable_mode] + + # [START howto_operator_delete_composer_environment_deferrable_mode] + defer_delete_env = CloudComposerDeleteEnvironmentOperator( + task_id="defer_delete_env", + project_id=PROJECT_ID, + region=REGION, + environment_id=ENVIRONMENT_ID, + deferrable=True, + trigger_rule=TriggerRule.ALL_DONE, Review Comment: So far we've been adding these outside of the howto block to keep the docs clean. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
