bhirsz commented on code in PR #26858: URL: https://github.com/apache/airflow/pull/26858#discussion_r1004110154
########## tests/system/providers/google/cloud/dataproc_metastore/example_dataproc_metastore_backup.py: ########## @@ -0,0 +1,135 @@ +# +# 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. +""" +Airflow System Test DAG that verifies Dataproc Metastore +operators for managing backups. +""" +from __future__ import annotations + +import datetime +import os + +from airflow import models +from airflow.providers.google.cloud.operators.dataproc_metastore import ( + DataprocMetastoreCreateBackupOperator, + DataprocMetastoreCreateServiceOperator, + DataprocMetastoreDeleteBackupOperator, + DataprocMetastoreDeleteServiceOperator, + DataprocMetastoreListBackupsOperator, + DataprocMetastoreRestoreServiceOperator, +) +from airflow.utils.trigger_rule import TriggerRule + +DAG_ID = "dataproc_metastore_backup" + +PROJECT_ID = os.environ.get("SYSTEM_TESTS_GCP_PROJECT", "") +ENV_ID = os.environ.get("SYSTEM_TESTS_ENV_ID") + +SERVICE_ID = f"{DAG_ID}-service-{ENV_ID}".replace('_', '-') +BACKUP_ID = f"{DAG_ID}-backup-{ENV_ID}".replace('_', '-') +REGION = "europe-west1" +TIMEOUT = 1200 +# Service definition +SERVICE = { + "name": "test-service", +} +# Backup definition +# [START how_to_cloud_dataproc_metastore_create_backup] +BACKUP = { + "name": "test-backup", +} +# [END how_to_cloud_dataproc_metastore_create_backup] + +with models.DAG( + DAG_ID, + start_date=datetime.datetime(2021, 1, 1), + schedule="@once", + catchup=False, + tags=["example", "dataproc", "metastore"], +) as dag: + create_service = DataprocMetastoreCreateServiceOperator( + task_id="create_service", + region=REGION, + project_id=PROJECT_ID, + service=SERVICE, + service_id=SERVICE_ID, + timeout=TIMEOUT, + ) + # [START how_to_cloud_dataproc_metastore_create_backup_operator] + backup_service = DataprocMetastoreCreateBackupOperator( + task_id="create_backup", + project_id=PROJECT_ID, + region=REGION, + service_id=SERVICE_ID, + backup=BACKUP, + backup_id=BACKUP_ID, + timeout=TIMEOUT, + ) + # [END how_to_cloud_dataproc_metastore_create_backup_operator] + # [START how_to_cloud_dataproc_metastore_list_backups_operator] + list_backups = DataprocMetastoreListBackupsOperator( + task_id="list_backups", + project_id=PROJECT_ID, + region=REGION, + service_id=SERVICE_ID, + ) + # [END how_to_cloud_dataproc_metastore_list_backups_operator] + # [START how_to_cloud_dataproc_metastore_delete_backup_operator] + delete_backup = DataprocMetastoreDeleteBackupOperator( Review Comment: I'm actually not sure.. but since it's possible to restore service from the backup, then removing the service should not remove the backup. I will add trigger rule for it. -- 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]
