Source code for tests.system.providers.google.cloud.automl.example_automl_translation
## 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."""Example Airflow DAG that uses Google AutoML services."""from__future__importannotationsimportosfromdatetimeimportdatetimefromtypingimportcastfromairflowimportmodelsfromairflow.models.xcom_argimportXComArgfromairflow.providers.google.cloud.hooks.automlimportCloudAutoMLHookfromairflow.providers.google.cloud.operators.automlimport(AutoMLCreateDatasetOperator,AutoMLDeleteDatasetOperator,AutoMLDeleteModelOperator,AutoMLImportDataOperator,AutoMLTrainModelOperator,)
# Example DAG for AutoML Translationwithmodels.DAG("example_automl_translation",start_date=datetime(2021,1,1),schedule="@once",catchup=False,user_defined_macros={"extract_object_id":extract_object_id},tags=["example"],)asdag:
dataset_id=cast(str,XComArg(create_dataset_task,key="dataset_id"))import_dataset_task=AutoMLImportDataOperator(task_id="import_dataset_task",dataset_id=dataset_id,location=GCP_AUTOML_LOCATION,input_config=IMPORT_INPUT_CONFIG,)MODEL["dataset_id"]=dataset_idcreate_model=AutoMLTrainModelOperator(task_id="create_model",model=MODEL,location=GCP_AUTOML_LOCATION)model_id=cast(str,XComArg(create_model,key="model_id"))delete_model_task=AutoMLDeleteModelOperator(task_id="delete_model_task",model_id=model_id,location=GCP_AUTOML_LOCATION,project_id=GCP_PROJECT_ID,)delete_datasets_task=AutoMLDeleteDatasetOperator(task_id="delete_datasets_task",dataset_id=dataset_id,location=GCP_AUTOML_LOCATION,project_id=GCP_PROJECT_ID,)# TEST BODYimport_dataset_task>>create_model# TEST TEARDOWNdelete_model_task>>delete_datasets_task# 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_taskfromtests.system.utils.watcherimportwatcher# This test needs watcher in order to properly mark success/failure# when "tearDown" task with trigger rule is part of the DAGlist(dag.tasks)>>watcher()fromtests.system.utilsimportget_test_run# noqa: E402# Needed to run the example DAG with pytest (see: tests/system/README.md#run_via_pytest)