Source code for tests.system.providers.google.cloud.datafusion.example_datafusion_async
# 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 shows how to use DataFusion."""from__future__importannotationsimportosfromdatetimeimportdatetimefromairflowimportmodelsfromairflow.providers.google.cloud.operators.datafusionimport(CloudDataFusionCreateInstanceOperator,CloudDataFusionCreatePipelineOperator,CloudDataFusionDeleteInstanceOperator,CloudDataFusionDeletePipelineOperator,CloudDataFusionGetInstanceOperator,CloudDataFusionListPipelinesOperator,CloudDataFusionRestartInstanceOperator,CloudDataFusionStartPipelineOperator,CloudDataFusionStopPipelineOperator,CloudDataFusionUpdateInstanceOperator,)fromairflow.providers.google.cloud.operators.gcsimportGCSCreateBucketOperator,GCSDeleteBucketOperatorfromairflow.utils.trigger_ruleimportTriggerRule# [START howto_data_fusion_env_variables]
create_bucket2=GCSCreateBucketOperator(task_id="create_bucket2",bucket_name=BUCKET_NAME_2,project_id=PROJECT_ID,)# [START howto_cloud_data_fusion_create_instance_operator]create_instance=CloudDataFusionCreateInstanceOperator(location=LOCATION,instance_name=INSTANCE_NAME,instance=INSTANCE,task_id="create_instance",)# [END howto_cloud_data_fusion_create_instance_operator]# [START howto_cloud_data_fusion_get_instance_operator]get_instance=CloudDataFusionGetInstanceOperator(location=LOCATION,instance_name=INSTANCE_NAME,task_id="get_instance")# [END howto_cloud_data_fusion_get_instance_operator]# [START howto_cloud_data_fusion_restart_instance_operator]restart_instance=CloudDataFusionRestartInstanceOperator(location=LOCATION,instance_name=INSTANCE_NAME,task_id="restart_instance")# [END howto_cloud_data_fusion_restart_instance_operator]# [START howto_cloud_data_fusion_update_instance_operator]update_instance=CloudDataFusionUpdateInstanceOperator(location=LOCATION,instance_name=INSTANCE_NAME,instance=INSTANCE,update_mask="",task_id="update_instance",)# [END howto_cloud_data_fusion_update_instance_operator]# [START howto_cloud_data_fusion_create_pipeline]create_pipeline=CloudDataFusionCreatePipelineOperator(location=LOCATION,pipeline_name=PIPELINE_NAME,pipeline=PIPELINE,instance_name=INSTANCE_NAME,task_id="create_pipeline",)# [END howto_cloud_data_fusion_create_pipeline]# [START howto_cloud_data_fusion_list_pipelines]list_pipelines=CloudDataFusionListPipelinesOperator(location=LOCATION,instance_name=INSTANCE_NAME,task_id="list_pipelines")# [END howto_cloud_data_fusion_list_pipelines]# [START howto_cloud_data_fusion_start_pipeline_def]start_pipeline_def=CloudDataFusionStartPipelineOperator(location=LOCATION,pipeline_name=PIPELINE_NAME,instance_name=INSTANCE_NAME,deferrable=True,task_id="start_pipeline_def",)# [END howto_cloud_data_fusion_start_pipeline_def]# [START howto_cloud_data_fusion_stop_pipeline]stop_pipeline=CloudDataFusionStopPipelineOperator(location=LOCATION,pipeline_name=PIPELINE_NAME,instance_name=INSTANCE_NAME,task_id="stop_pipeline",)# [END howto_cloud_data_fusion_stop_pipeline]# [START howto_cloud_data_fusion_delete_pipeline]delete_pipeline=CloudDataFusionDeletePipelineOperator(location=LOCATION,pipeline_name=PIPELINE_NAME,instance_name=INSTANCE_NAME,task_id="delete_pipeline",trigger_rule=TriggerRule.ALL_DONE,)# [END howto_cloud_data_fusion_delete_pipeline]# [START howto_cloud_data_fusion_delete_instance_operator]delete_instance=CloudDataFusionDeleteInstanceOperator(location=LOCATION,instance_name=INSTANCE_NAME,task_id="delete_instance",trigger_rule=TriggerRule.ALL_DONE,)# [END howto_cloud_data_fusion_delete_instance_operator]delete_bucket1=GCSDeleteBucketOperator(task_id="delete_bucket1",bucket_name=BUCKET_NAME_1,trigger_rule=TriggerRule.ALL_DONE)delete_bucket2=GCSDeleteBucketOperator(task_id="delete_bucket2",bucket_name=BUCKET_NAME_1,trigger_rule=TriggerRule.ALL_DONE)(# TEST SETUP[create_bucket1,create_bucket2]# TEST BODY>>create_instance>>get_instance>>restart_instance>>update_instance>>create_pipeline>>list_pipelines>>start_pipeline_def>>stop_pipeline>>delete_pipeline>>delete_instance# TEST TEARDOWN>>[delete_bucket1,delete_bucket2])fromtests.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)