2025-04-03 10:39:47 +05:30
|
|
|
# Copyright 2025 Collate
|
|
|
|
# Licensed under the Collate Community License, Version 1.0 (the "License");
|
2021-12-01 12:46:28 +05:30
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
2025-04-03 10:39:47 +05:30
|
|
|
# https://github.com/open-metadata/OpenMetadata/blob/main/ingestion/LICENSE
|
2021-10-14 20:16:24 +05:30
|
|
|
# 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-12-01 12:46:28 +05:30
|
|
|
|
2021-11-11 10:52:32 +05:30
|
|
|
import json
|
2021-10-14 20:16:24 +05:30
|
|
|
from datetime import timedelta
|
2021-11-11 10:52:32 +05:30
|
|
|
|
2021-10-14 20:16:24 +05:30
|
|
|
from airflow import DAG
|
2021-11-11 10:52:32 +05:30
|
|
|
|
2021-10-14 20:16:24 +05:30
|
|
|
try:
|
|
|
|
from airflow.operators.python import PythonOperator
|
|
|
|
except ModuleNotFoundError:
|
|
|
|
from airflow.operators.python_operator import PythonOperator
|
|
|
|
|
2021-11-11 10:52:32 +05:30
|
|
|
from airflow.utils.dates import days_ago
|
|
|
|
|
2023-08-30 15:49:42 +02:00
|
|
|
from metadata.workflow.usage import UsageWorkflow
|
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-15 09:46:39 +05:30
|
|
|
"retry_delay": timedelta(seconds=10),
|
2021-11-11 10:52:32 +05:30
|
|
|
"execution_timeout": timedelta(minutes=60),
|
2021-10-14 20:16:24 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
config = """
|
|
|
|
{
|
|
|
|
"source": {
|
2022-12-27 15:00:22 +01:00
|
|
|
"type": "custom-database",
|
|
|
|
"serviceName": "sample_data",
|
2022-04-12 02:27:18 -07:00
|
|
|
"serviceConnection": {
|
|
|
|
"config": {
|
2022-12-27 15:00:22 +01:00
|
|
|
"type": "CustomDatabase",
|
|
|
|
"sourcePythonClass": "metadata.ingestion.source.database.sample_usage.SampleUsageSource",
|
|
|
|
"connectionOptions": {
|
2023-08-30 15:49:42 +02:00
|
|
|
"sampleDataFolder": "/home/airflow/ingestion/examples/sample_data"
|
2022-12-27 15:00:22 +01:00
|
|
|
}
|
2022-04-12 02:27:18 -07:00
|
|
|
}
|
|
|
|
},
|
2022-06-21 14:54:36 +02:00
|
|
|
"sourceConfig": {
|
2022-12-27 15:00:22 +01:00
|
|
|
"config":{
|
|
|
|
"type": "DatabaseUsage"
|
2022-06-21 14:54:36 +02:00
|
|
|
}
|
2022-12-27 15:00:22 +01:00
|
|
|
}
|
2021-10-14 20:16:24 +05:30
|
|
|
},
|
|
|
|
"processor": {
|
|
|
|
"type": "query-parser",
|
2022-06-21 14:54:36 +02:00
|
|
|
"config": {}
|
2021-10-14 20:16:24 +05:30
|
|
|
},
|
|
|
|
"stage": {
|
|
|
|
"type": "table-usage",
|
|
|
|
"config": {
|
|
|
|
"filename": "/tmp/sample_usage"
|
|
|
|
}
|
|
|
|
},
|
2022-04-12 02:27:18 -07:00
|
|
|
"bulkSink": {
|
2021-10-14 20:16:24 +05:30
|
|
|
"type": "metadata-usage",
|
|
|
|
"config": {
|
2022-01-04 17:12:10 +05:30
|
|
|
"filename": "/tmp/sample_usage"
|
2021-10-14 20:16:24 +05:30
|
|
|
}
|
|
|
|
},
|
2022-04-12 02:27:18 -07:00
|
|
|
"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-11-11 10:52:32 +05:30
|
|
|
|
2021-10-14 20:16:24 +05:30
|
|
|
def metadata_ingestion_workflow():
|
|
|
|
workflow_config = json.loads(config)
|
2023-08-30 15:49:42 +02:00
|
|
|
workflow = UsageWorkflow.create(workflow_config)
|
2021-10-14 20:16:24 +05:30
|
|
|
workflow.execute()
|
|
|
|
workflow.raise_from_status()
|
2024-07-29 09:20:34 +02:00
|
|
|
workflow.print_status()
|
2021-10-14 20:16:24 +05:30
|
|
|
workflow.stop()
|
|
|
|
|
|
|
|
|
|
|
|
with DAG(
|
|
|
|
"sample_usage",
|
|
|
|
default_args=default_args,
|
|
|
|
description="An example DAG which runs a OpenMetadata ingestion workflow",
|
|
|
|
schedule_interval=timedelta(days=1),
|
|
|
|
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:
|
|
|
|
ingest_task = PythonOperator(
|
|
|
|
task_id="ingest_using_recipe",
|
|
|
|
python_callable=metadata_ingestion_workflow,
|
2021-11-11 10:52:32 +05:30
|
|
|
)
|