|
3 | 3 | from trigger_k8s_cronjob import trigger_k8s_cronjob |
4 | 4 | from airflow.providers.standard.operators.python import PythonOperator |
5 | 5 | from datetime import datetime, timedelta |
6 | | -from airflow import DAG |
| 6 | +from airflow.decorators import dag, task |
7 | 7 | import os |
8 | 8 | import sys |
9 | 9 |
|
|
28 | 28 | 'retries': 0 |
29 | 29 | } |
30 | 30 |
|
| 31 | +CIF_DEPLOY_DB_DOC = """ |
| 32 | +DAG triggering cron jobs to setup the cif database |
31 | 33 | """ |
32 | | -############################################################################### |
33 | | -# # |
34 | | -# DAG triggering cron jobs to setup the cif database # |
35 | | -# # |
36 | | -############################################################################### |
37 | | -""" |
38 | | - |
39 | 34 |
|
40 | | -deploy_db_dag = DAG(DEPLOY_DB_DAG_NAME, schedule=None, |
41 | | - default_args=default_args, is_paused_upon_creation=False) |
| 35 | +@dag( |
| 36 | + dag_id=DEPLOY_DB_DAG_NAME, |
| 37 | + schedule=None, |
| 38 | + default_args=default_args, |
| 39 | + is_paused_upon_creation=False, |
| 40 | + doc_md=CIF_DEPLOY_DB_DOC, |
| 41 | +) |
| 42 | +def cif_deploy_db(): |
| 43 | + @task |
| 44 | + def cif_db_init(): |
| 45 | + trigger_k8s_cronjob('cas-cif-db-init', cif_namespace) |
42 | 46 |
|
43 | | -cif_db_init = PythonOperator( |
44 | | - python_callable=trigger_k8s_cronjob, |
45 | | - task_id='cif_db_init', |
46 | | - op_args=['cas-cif-db-init', cif_namespace], |
47 | | - dag=deploy_db_dag) |
| 47 | + @task |
| 48 | + def cif_app_schema(): |
| 49 | + trigger_k8s_cronjob('cas-cif-deploy-data', cif_namespace) |
48 | 50 |
|
49 | | -cif_app_schema = PythonOperator( |
50 | | - python_callable=trigger_k8s_cronjob, |
51 | | - task_id='cif_app_schema', |
52 | | - op_args=['cas-cif-deploy-data', cif_namespace], |
53 | | - dag=deploy_db_dag) |
| 51 | + @task |
| 52 | + def cif_import_operator(): |
| 53 | + trigger_k8s_cronjob('cas-cif-swrs-operator-import', cif_namespace) |
54 | 54 |
|
55 | | -cif_import_operator = PythonOperator( |
56 | | - python_callable=trigger_k8s_cronjob, |
57 | | - task_id='cif_import_operator', |
58 | | - op_args=['cas-cif-swrs-operator-import', cif_namespace], |
59 | | - dag=deploy_db_dag) |
| 55 | + cif_db_init() >> cif_app_schema() >> cif_import_operator() |
60 | 56 |
|
| 57 | +cif_deploy_db() |
61 | 58 |
|
62 | | -cif_db_init >> cif_app_schema >> cif_import_operator |
63 | 59 |
|
64 | | -""" |
65 | | -############################################################################### |
66 | | -# # |
67 | | -# DAG to test database backup integrity # |
68 | | -# # |
69 | | -############################################################################### |
| 60 | +CIF_BACKUP_TEST_DOC = """ |
| 61 | +DAG to test database backup integrity |
70 | 62 | """ |
71 | 63 |
|
| 64 | +@dag( |
| 65 | + dag_id=TEST_DB_BACKUPS_DAG_NAME, |
| 66 | + schedule=None, |
| 67 | + default_args=default_backup_test_args, |
| 68 | + is_paused_upon_creation=False, |
| 69 | + doc_md=CIF_BACKUP_TEST_DOC, |
| 70 | +) |
| 71 | +def cif_backup_test(): |
| 72 | + @task |
| 73 | + def deploy_and_restore(): |
| 74 | + trigger_k8s_cronjob('deploy-database-backups', cif_namespace) |
72 | 75 |
|
73 | | -db_backup_test_dag = DAG(TEST_DB_BACKUPS_DAG_NAME, schedule='15 12 * * *', |
74 | | - default_args=default_backup_test_args , is_paused_upon_creation=False) |
| 76 | + @task |
| 77 | + def test_backups(): |
| 78 | + trigger_k8s_cronjob('test-database-backups', cif_namespace) |
75 | 79 |
|
76 | | -deploy_and_restore = PythonOperator( |
77 | | - python_callable=trigger_k8s_cronjob, |
78 | | - task_id='deploy_and_restore', |
79 | | - op_args=['deploy-database-backups', cif_namespace], |
80 | | - dag=db_backup_test_dag) |
| 80 | + deploy_and_restore() >> test_backups() |
81 | 81 |
|
82 | | -test_backups = PythonOperator( |
83 | | - python_callable=trigger_k8s_cronjob, |
84 | | - task_id='test_backups', |
85 | | - op_args=['test-database-backups', cif_namespace], |
86 | | - dag=db_backup_test_dag) |
| 82 | +cif_backup_test() |
87 | 83 |
|
88 | | -deploy_and_restore >> test_backups |
89 | 84 |
|
| 85 | +CIF_INSERT_TIMESTAMP_DOC = """ |
| 86 | +DAG to insert timestamp for backup testing |
90 | 87 | """ |
91 | | -############################################################################### |
92 | | -# # |
93 | | -# DAG to insert timestamp for backup testing # |
94 | | -# # |
95 | | -############################################################################### |
96 | | -""" |
97 | | - |
98 | | - |
99 | | -insert_timestamp_dag = DAG(INSERT_BACKUP_TIMESTAMP_DAG_NAME, schedule='0 6 * * *', |
100 | | - default_args=default_args, is_paused_upon_creation=False) |
101 | | - |
102 | | -insert_timestamp = PythonOperator( |
103 | | - python_callable=trigger_k8s_cronjob, |
104 | | - task_id='insert_timestamp', |
105 | | - op_args=['insert-backup-test-timestamp', cif_namespace], |
106 | | - dag=insert_timestamp_dag) |
107 | 88 |
|
108 | | -insert_timestamp |
| 89 | +@dag( |
| 90 | + dag_id=INSERT_BACKUP_TIMESTAMP_DAG_NAME, |
| 91 | + schedule=None, |
| 92 | + default_args=default_args, |
| 93 | + is_paused_upon_creation=False, |
| 94 | + doc_md=CIF_INSERT_TIMESTAMP_DOC, |
| 95 | +) |
| 96 | +def cif_insert_timestamp(): |
| 97 | + @task |
| 98 | + def insert_timestamp(): |
| 99 | + trigger_k8s_cronjob('insert-backup-test-timestamp', cif_namespace) |
| 100 | + |
| 101 | + insert_timestamp() |
| 102 | + |
| 103 | +cif_insert_timestamp |
0 commit comments