You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2022/07/19 10:46:11 UTC

[airflow] branch main updated: Migrate Google example automl_vision to new design AIP-47 (#25152)

This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 3a80b36ed9 Migrate Google example automl_vision to new design AIP-47 (#25152)
3a80b36ed9 is described below

commit 3a80b36ed98be62dd42ede0f4afab0f16a8306be
Author: Chenglong Yan <al...@gmail.com>
AuthorDate: Tue Jul 19 18:46:04 2022 +0800

    Migrate Google example automl_vision to new design AIP-47 (#25152)
    
    related: #22447, #22430
---
 .../providers/google/cloud/automl/__init__.py      | 16 +++++++++
 .../example_automl_vision_classification.py        | 42 +++++++++++++++-------
 2 files changed, 46 insertions(+), 12 deletions(-)

diff --git a/tests/system/providers/google/cloud/automl/__init__.py b/tests/system/providers/google/cloud/automl/__init__.py
new file mode 100644
index 0000000000..13a83393a9
--- /dev/null
+++ b/tests/system/providers/google/cloud/automl/__init__.py
@@ -0,0 +1,16 @@
+# 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.
diff --git a/airflow/providers/google/cloud/example_dags/example_automl_vision_classification.py b/tests/system/providers/google/cloud/automl/example_automl_vision_classification.py
similarity index 76%
rename from airflow/providers/google/cloud/example_dags/example_automl_vision_classification.py
rename to tests/system/providers/google/cloud/automl/example_automl_vision_classification.py
index 66df48f64e..8a6756223a 100644
--- a/airflow/providers/google/cloud/example_dags/example_automl_vision_classification.py
+++ b/tests/system/providers/google/cloud/automl/example_automl_vision_classification.py
@@ -31,6 +31,10 @@ from airflow.providers.google.cloud.operators.automl import (
     AutoMLImportDataOperator,
     AutoMLTrainModelOperator,
 )
+from airflow.utils.trigger_rule import TriggerRule
+
+ENV_ID = os.environ.get("SYSTEM_TESTS_ENV_ID")
+DAG_ID = "example_automl_vision"
 
 GCP_PROJECT_ID = os.environ.get("GCP_PROJECT_ID", "your-project-id")
 GCP_AUTOML_LOCATION = os.environ.get("GCP_AUTOML_LOCATION", "us-central1")
@@ -56,16 +60,15 @@ IMPORT_INPUT_CONFIG = {"gcs_source": {"input_uris": [GCP_AUTOML_VISION_BUCKET]}}
 
 extract_object_id = CloudAutoMLHook.extract_object_id
 
-
 # Example DAG for AutoML Vision Classification
 with models.DAG(
-    "example_automl_vision",
-    schedule_interval=None,  # Override to match your needs
+    DAG_ID,
+    schedule_interval="@once",  # Override to match your needs
     start_date=datetime(2021, 1, 1),
     catchup=False,
     user_defined_macros={"extract_object_id": extract_object_id},
-    tags=['example'],
-) as example_dag:
+    tags=['example', 'automl'],
+) as dag:
     create_dataset_task = AutoMLCreateDatasetOperator(
         task_id="create_dataset_task", dataset=DATASET, location=GCP_AUTOML_LOCATION
     )
@@ -90,6 +93,7 @@ with models.DAG(
         model_id=model_id,
         location=GCP_AUTOML_LOCATION,
         project_id=GCP_PROJECT_ID,
+        trigger_rule=TriggerRule.ALL_DONE,
     )
 
     delete_datasets_task = AutoMLDeleteDatasetOperator(
@@ -97,13 +101,27 @@ with models.DAG(
         dataset_id=dataset_id,
         location=GCP_AUTOML_LOCATION,
         project_id=GCP_PROJECT_ID,
+        trigger_rule=TriggerRule.ALL_DONE,
+    )
+
+    (
+        # TEST SETUP
+        create_dataset_task
+        >> import_dataset_task
+        # TEST BODY
+        >> create_model
+        # TEST TEARDOWN
+        >> delete_model_task
+        >> delete_datasets_task
     )
 
-    import_dataset_task >> create_model
-    delete_model_task >> delete_datasets_task
+    from tests.system.utils.watcher import watcher
+
+    # This test needs watcher in order to properly mark success/failure
+    # when "tearDown" task with trigger rule is part of the DAG
+    list(dag.tasks) >> watcher()
+
+from tests.system.utils import get_test_run  # noqa: E402
 
-    # Task dependencies created via `XComArgs`:
-    #   create_dataset_task >> import_dataset_task
-    #   create_dataset_task >> create_model
-    #   create_model >> delete_model_task
-    #   create_dataset_task >> delete_datasets_task
+# Needed to run the example DAG with pytest (see: tests/system/README.md#run_via_pytest)
+test_run = get_test_run(dag)