| 
									
										
										
										
											2021-08-14 10:18:52 -07:00
										 |  |  | #  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. | 
					
						
							| 
									
										
										
										
											2021-09-10 22:28:23 -07:00
										 |  |  | import pathlib | 
					
						
							| 
									
										
										
										
											2021-08-14 10:18:52 -07:00
										 |  |  | from datetime import timedelta | 
					
						
							| 
									
										
										
										
											2021-09-29 11:32:09 -07:00
										 |  |  | from airflow_provider_openmetadata import DAG | 
					
						
							| 
									
										
										
										
											2021-08-14 10:18:52 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | try: | 
					
						
							| 
									
										
										
										
											2021-09-29 11:32:09 -07:00
										 |  |  |     from airflow_provider_openmetadata.operators.python import PythonOperator | 
					
						
							| 
									
										
										
										
											2021-08-14 10:18:52 -07:00
										 |  |  | except ModuleNotFoundError: | 
					
						
							| 
									
										
										
										
											2021-09-29 11:32:09 -07:00
										 |  |  |     from airflow_provider_openmetadata.operators.python_operator import PythonOperator | 
					
						
							| 
									
										
										
										
											2021-08-14 10:18:52 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | from metadata.config.common import load_config_file | 
					
						
							|  |  |  | from metadata.ingestion.api.workflow import Workflow | 
					
						
							| 
									
										
										
										
											2021-09-29 11:32:09 -07:00
										 |  |  | from airflow_provider_openmetadata.utils.dates import days_ago | 
					
						
							| 
									
										
										
										
											2021-08-14 10:18:52 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | default_args = { | 
					
						
							|  |  |  |     "owner": "user_name", | 
					
						
							|  |  |  |     "email": ["username@org.com"], | 
					
						
							| 
									
										
										
										
											2021-09-10 22:28:23 -07:00
										 |  |  |     "email_on_failure": False, | 
					
						
							| 
									
										
										
										
											2021-08-14 10:18:52 -07:00
										 |  |  |     "retries": 3, | 
					
						
							|  |  |  |     "retry_delay": timedelta(minutes=5), | 
					
						
							| 
									
										
										
										
											2021-09-10 22:28:23 -07:00
										 |  |  |     "execution_timeout": timedelta(minutes=60) | 
					
						
							| 
									
										
										
										
											2021-08-14 10:18:52 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def metadata_ingestion_workflow(): | 
					
						
							| 
									
										
										
										
											2021-09-10 22:28:23 -07:00
										 |  |  |     config_file = pathlib.Path("/tmp/sample_data.json") | 
					
						
							|  |  |  |     workflow_config = load_config_file(config_file) | 
					
						
							| 
									
										
										
										
											2021-10-15 03:51:47 +05:30
										 |  |  |      | 
					
						
							| 
									
										
										
										
											2021-09-10 22:28:23 -07:00
										 |  |  |     workflow = Workflow.create(workflow_config) | 
					
						
							|  |  |  |     workflow.execute() | 
					
						
							| 
									
										
										
										
											2021-08-14 10:18:52 -07:00
										 |  |  |     workflow.raise_from_status() | 
					
						
							|  |  |  |     workflow.print_status() | 
					
						
							|  |  |  |     workflow.stop() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | with DAG( | 
					
						
							| 
									
										
										
										
											2021-09-10 22:28:23 -07:00
										 |  |  |     "sample_metadata_ingestion_workflow", | 
					
						
							| 
									
										
										
										
											2021-08-14 10:18:52 -07:00
										 |  |  |     default_args=default_args, | 
					
						
							|  |  |  |     description="An example DAG which runs a OpenMetadata ingestion workflow", | 
					
						
							|  |  |  |     schedule_interval=timedelta(days=1), | 
					
						
							|  |  |  |     start_date=days_ago(1), | 
					
						
							|  |  |  |     catchup=False, | 
					
						
							|  |  |  | ) as dag: | 
					
						
							|  |  |  |     ingest_task = PythonOperator( | 
					
						
							|  |  |  |         task_id="ingest_using_recipe", | 
					
						
							| 
									
										
										
										
											2021-09-10 22:28:23 -07:00
										 |  |  |         python_callable=metadata_ingestion_workflow, | 
					
						
							| 
									
										
										
										
											2021-08-14 10:18:52 -07:00
										 |  |  |     ) |