| 
									
										
										
										
											2021-12-01 12:46:28 +05:30
										 |  |  | #  Copyright 2021 Collate | 
					
						
							|  |  |  | #  Licensed 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 | 
					
						
							| 
									
										
										
										
											2021-10-14 20:16:24 +05:30
										 |  |  | #  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. | 
					
						
							| 
									
										
										
										
											2022-01-22 12:07:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-14 20:16:24 +05:30
										 |  |  | from datetime import timedelta | 
					
						
							| 
									
										
										
										
											2021-10-30 21:35:30 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-14 06:44:43 +02:00
										 |  |  | import yaml | 
					
						
							| 
									
										
										
										
											2021-10-14 20:16:24 +05:30
										 |  |  | from airflow import DAG | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | try: | 
					
						
							| 
									
										
										
										
											2022-01-22 12:07:56 +01:00
										 |  |  |     from airflow.operators.python import PythonOperator | 
					
						
							| 
									
										
										
										
											2021-10-14 20:16:24 +05:30
										 |  |  | except ModuleNotFoundError: | 
					
						
							| 
									
										
										
										
											2022-01-22 12:07:56 +01:00
										 |  |  |     from airflow.operators.python_operator import PythonOperator | 
					
						
							| 
									
										
										
										
											2021-10-14 20:16:24 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-30 21:35:30 +05:30
										 |  |  | from airflow.utils.dates import days_ago | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-30 15:49:42 +02:00
										 |  |  | from metadata.workflow.metadata import MetadataWorkflow | 
					
						
							| 
									
										
										
										
											2022-01-22 12:07:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-14 20:16:24 +05:30
										 |  |  | default_args = { | 
					
						
							|  |  |  |     "owner": "user_name", | 
					
						
							|  |  |  |     "email": ["username@org.com"], | 
					
						
							|  |  |  |     "email_on_failure": False, | 
					
						
							|  |  |  |     "retries": 3, | 
					
						
							| 
									
										
										
										
											2021-11-13 00:00:28 +05:30
										 |  |  |     "retry_delay": timedelta(seconds=10), | 
					
						
							| 
									
										
										
										
											2021-10-30 21:35:30 +05:30
										 |  |  |     "execution_timeout": timedelta(minutes=60), | 
					
						
							| 
									
										
										
										
											2021-10-14 20:16:24 +05:30
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | config = """
 | 
					
						
							| 
									
										
										
										
											2022-05-14 06:44:43 +02:00
										 |  |  | source: | 
					
						
							| 
									
										
										
										
											2022-12-27 15:00:22 +01:00
										 |  |  |   type: custom-database | 
					
						
							|  |  |  |   serviceName: sample_data | 
					
						
							| 
									
										
										
										
											2022-05-14 06:44:43 +02:00
										 |  |  |   serviceConnection: | 
					
						
							|  |  |  |     config: | 
					
						
							| 
									
										
										
										
											2022-12-27 15:00:22 +01:00
										 |  |  |       type: CustomDatabase | 
					
						
							|  |  |  |       sourcePythonClass: metadata.ingestion.source.database.sample_data.SampleDataSource | 
					
						
							|  |  |  |       connectionOptions: | 
					
						
							|  |  |  |         sampleDataFolder: "/home/airflow/ingestion/examples/sample_data" | 
					
						
							| 
									
										
										
										
											2022-05-14 06:44:43 +02:00
										 |  |  |   sourceConfig: {} | 
					
						
							|  |  |  | sink: | 
					
						
							|  |  |  |   type: metadata-rest | 
					
						
							|  |  |  |   config: {} | 
					
						
							|  |  |  | workflowConfig: | 
					
						
							|  |  |  |   openMetadataServerConfig: | 
					
						
							| 
									
										
										
										
											2022-08-31 21:30:24 +02:00
										 |  |  |     hostPort: http://openmetadata-server:8585/api | 
					
						
							| 
									
										
										
										
											2022-09-23 20:03:54 +05:30
										 |  |  |     authProvider: openmetadata | 
					
						
							|  |  |  |     securityConfig: | 
					
						
							|  |  |  |       jwtToken: "eyJraWQiOiJHYjM4OWEtOWY3Ni1nZGpzLWE5MmotMDI0MmJrOTQzNTYiLCJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJhZG1pbiIsImlzQm90IjpmYWxzZSwiaXNzIjoib3Blbi1tZXRhZGF0YS5vcmciLCJpYXQiOjE2NjM5Mzg0NjIsImVtYWlsIjoiYWRtaW5Ab3Blbm1ldGFkYXRhLm9yZyJ9.tS8um_5DKu7HgzGBzS1VTA5uUjKWOCU0B_j08WXBiEC0mr0zNREkqVfwFDD-d24HlNEbrqioLsBuFRiwIWKc1m_ZlVQbG7P36RUxhuv2vbSp80FKyNM-Tj93FDzq91jsyNmsQhyNv_fNr3TXfzzSPjHt8Go0FMMP66weoKMgW2PbXlhVKwEuXUHyakLLzewm9UMeQaEiRzhiTMU3UkLXcKbYEJJvfNFcLwSl9W8JCO_l0Yj3ud-qt_nQYEZwqW6u5nfdQllN133iikV4fM5QZsMCnm8Rq1mvLR0y9bmJiD7fwM1tmJ791TUWqmKaTnP49U493VanKpUAfzIiOiIbhg" | 
					
						
							| 
									
										
										
										
											2021-10-14 20:16:24 +05:30
										 |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-30 21:35:30 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-22 12:07:56 +01:00
										 |  |  | def metadata_ingestion_workflow(): | 
					
						
							| 
									
										
										
										
											2022-05-14 06:44:43 +02:00
										 |  |  |     workflow_config = yaml.safe_load(config) | 
					
						
							| 
									
										
										
										
											2023-08-30 15:49:42 +02:00
										 |  |  |     workflow = MetadataWorkflow.create(workflow_config) | 
					
						
							| 
									
										
										
										
											2022-01-22 12:07:56 +01:00
										 |  |  |     workflow.execute() | 
					
						
							|  |  |  |     workflow.raise_from_status() | 
					
						
							| 
									
										
										
										
											2024-07-29 09:20:34 +02:00
										 |  |  |     workflow.print_status() | 
					
						
							| 
									
										
										
										
											2022-01-22 12:07:56 +01:00
										 |  |  |     workflow.stop() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-14 20:16:24 +05:30
										 |  |  | with DAG( | 
					
						
							|  |  |  |     "sample_data", | 
					
						
							|  |  |  |     default_args=default_args, | 
					
						
							|  |  |  |     description="An example DAG which runs a OpenMetadata ingestion workflow", | 
					
						
							|  |  |  |     start_date=days_ago(1), | 
					
						
							| 
									
										
										
										
											2022-03-28 11:08:13 +05:30
										 |  |  |     is_paused_upon_creation=True, | 
					
						
							| 
									
										
										
										
											2021-10-14 20:16:24 +05:30
										 |  |  |     catchup=False, | 
					
						
							|  |  |  | ) as dag: | 
					
						
							| 
									
										
										
										
											2022-01-22 12:07:56 +01:00
										 |  |  |     ingest_task = PythonOperator( | 
					
						
							|  |  |  |         task_id="ingest_using_recipe", | 
					
						
							|  |  |  |         python_callable=metadata_ingestion_workflow, | 
					
						
							| 
									
										
										
										
											2021-10-30 21:35:30 +05:30
										 |  |  |     ) |