Source code for tests.system.providers.google.cloud.vision.example_vision_explicit
# 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__importannotationsimportosfromdatetimeimportdatetimefromairflowimportmodelsfromairflow.models.baseoperatorimportchainfromairflow.providers.google.cloud.operators.gcsimportGCSCreateBucketOperator,GCSDeleteBucketOperatorfromairflow.providers.google.cloud.operators.visionimport(CloudVisionAddProductToProductSetOperator,CloudVisionCreateProductOperator,CloudVisionCreateProductSetOperator,CloudVisionCreateReferenceImageOperator,CloudVisionDeleteProductOperator,CloudVisionDeleteProductSetOperator,CloudVisionDeleteReferenceImageOperator,CloudVisionGetProductOperator,CloudVisionGetProductSetOperator,CloudVisionRemoveProductFromProductSetOperator,CloudVisionUpdateProductOperator,CloudVisionUpdateProductSetOperator,)fromairflow.providers.google.cloud.transfers.gcs_to_gcsimportGCSToGCSOperatorfromairflow.utils.trigger_ruleimportTriggerRule# [START howto_operator_vision_retry_import]fromgoogle.api_core.retryimportRetry# isort:skip# [END howto_operator_vision_retry_import]# [START howto_operator_vision_product_set_import_2]fromgoogle.cloud.vision_v1.typesimportProductSet# isort:skip# [END howto_operator_vision_product_set_import_2]# [START howto_operator_vision_product_import_2]fromgoogle.cloud.vision_v1.typesimportProduct# isort:skip# [END howto_operator_vision_product_import_2]# [START howto_operator_vision_reference_image_import_2]fromgoogle.cloud.vision_v1.typesimportReferenceImage# isort:skip# [END howto_operator_vision_reference_image_import_2]
)copy_single_file=GCSToGCSOperator(task_id="copy_single_gcs_file",source_bucket=BUCKET_NAME_SRC,source_object=PATH_SRC,destination_bucket=BUCKET_NAME,destination_object=FILE_NAME,)# [START howto_operator_vision_product_set_create_2]product_set_create_2=CloudVisionCreateProductSetOperator(product_set_id=GCP_VISION_PRODUCT_SET_ID,location=LOCATION,product_set=product_set,retry=Retry(maximum=10.0),timeout=5,task_id="product_set_create_2",)# [END howto_operator_vision_product_set_create_2]# Second 'create' task with the same product_set_id to demonstrate idempotenceproduct_set_create_2_idempotence=CloudVisionCreateProductSetOperator(product_set_id=GCP_VISION_PRODUCT_SET_ID,location=LOCATION,product_set=product_set,retry=Retry(maximum=10.0),timeout=5,task_id="product_set_create_2_idempotence",)# [START howto_operator_vision_product_set_get_2]product_set_get_2=CloudVisionGetProductSetOperator(location=LOCATION,product_set_id=GCP_VISION_PRODUCT_SET_ID,task_id="product_set_get_2")# [END howto_operator_vision_product_set_get_2]# [START howto_operator_vision_product_set_update_2]product_set_update_2=CloudVisionUpdateProductSetOperator(location=LOCATION,product_set_id=GCP_VISION_PRODUCT_SET_ID,product_set=ProductSet(display_name="My Product Set 2"),task_id="product_set_update_2",)# [END howto_operator_vision_product_set_update_2]# [START howto_operator_vision_product_set_delete_2]product_set_delete_2=CloudVisionDeleteProductSetOperator(location=LOCATION,product_set_id=GCP_VISION_PRODUCT_SET_ID,task_id="product_set_delete_2")# [END howto_operator_vision_product_set_delete_2]# [START howto_operator_vision_product_create_2]product_create_2=CloudVisionCreateProductOperator(product_id=GCP_VISION_PRODUCT_ID,location=LOCATION,product=product,retry=Retry(maximum=10.0),timeout=5,task_id="product_create_2",)# [END howto_operator_vision_product_create_2]# Second 'create' task with the same product_id to demonstrate idempotenceproduct_create_2_idempotence=CloudVisionCreateProductOperator(product_id=GCP_VISION_PRODUCT_ID,location=LOCATION,product=product,retry=Retry(maximum=10.0),timeout=5,task_id="product_create_2_idempotence",)# [START howto_operator_vision_product_get_2]product_get_2=CloudVisionGetProductOperator(location=LOCATION,product_id=GCP_VISION_PRODUCT_ID,task_id="product_get_2")# [END howto_operator_vision_product_get_2]# [START howto_operator_vision_product_update_2]product_update_2=CloudVisionUpdateProductOperator(location=LOCATION,product_id=GCP_VISION_PRODUCT_ID,product=Product(display_name="My Product 2",description="My updated description"),task_id="product_update_2",)# [END howto_operator_vision_product_update_2]# [START howto_operator_vision_product_delete_2]product_delete_2=CloudVisionDeleteProductOperator(location=LOCATION,product_id=GCP_VISION_PRODUCT_ID,task_id="product_delete_2")# [END howto_operator_vision_product_delete_2]# [START howto_operator_vision_reference_image_create_2]reference_image_create_2=CloudVisionCreateReferenceImageOperator(location=LOCATION,reference_image=reference_image,product_id=GCP_VISION_PRODUCT_ID,reference_image_id=GCP_VISION_REFERENCE_IMAGE_ID,retry=Retry(maximum=10.0),timeout=5,task_id="reference_image_create_2",)# [END howto_operator_vision_reference_image_create_2]# [START howto_operator_vision_reference_image_delete_2]reference_image_delete_2=CloudVisionDeleteReferenceImageOperator(location=LOCATION,reference_image_id=GCP_VISION_REFERENCE_IMAGE_ID,product_id=GCP_VISION_PRODUCT_ID,retry=Retry(maximum=10.0),timeout=5,task_id="reference_image_delete_2",)# [END howto_operator_vision_reference_image_delete_2]# Second 'create' task with the same product_id to demonstrate idempotencereference_image_create_2_idempotence=CloudVisionCreateReferenceImageOperator(location=LOCATION,reference_image=reference_image,product_id=GCP_VISION_PRODUCT_ID,reference_image_id=GCP_VISION_REFERENCE_IMAGE_ID,retry=Retry(maximum=10.0),timeout=5,task_id="reference_image_create_2_idempotence",)# [START howto_operator_vision_add_product_to_product_set_2]add_product_to_product_set_2=CloudVisionAddProductToProductSetOperator(location=LOCATION,product_set_id=GCP_VISION_PRODUCT_SET_ID,product_id=GCP_VISION_PRODUCT_ID,retry=Retry(maximum=10.0),timeout=5,task_id="add_product_to_product_set_2",)# [END howto_operator_vision_add_product_to_product_set_2]# [START howto_operator_vision_remove_product_from_product_set_2]remove_product_from_product_set_2=CloudVisionRemoveProductFromProductSetOperator(location=LOCATION,product_set_id=GCP_VISION_PRODUCT_SET_ID,product_id=GCP_VISION_PRODUCT_ID,retry=Retry(maximum=10.0),timeout=5,task_id="remove_product_from_product_set_2",)# [END howto_operator_vision_remove_product_from_product_set_2]delete_bucket=GCSDeleteBucketOperator(task_id="delete_bucket",bucket_name=BUCKET_NAME,trigger_rule=TriggerRule.ALL_DONE)chain(product_set_create_2,product_set_get_2,product_set_update_2,product_create_2,product_create_2_idempotence,product_get_2,product_update_2,reference_image_create_2,reference_image_create_2_idempotence,add_product_to_product_set_2,remove_product_from_product_set_2,reference_image_delete_2,product_delete_2,product_set_delete_2,delete_bucket,)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)