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.
|
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
|
|
|
|
|
2021-10-14 20:16:24 +05:30
|
|
|
from metadata.ingestion.api.workflow import Workflow
|
|
|
|
|
|
|
|
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": {
|
|
|
|
"type": "sample-usage",
|
2022-08-31 21:30:24 +02:00
|
|
|
"serviceName": "sample_data_usage",
|
2022-04-12 02:27:18 -07:00
|
|
|
"serviceConnection": {
|
|
|
|
"config": {
|
|
|
|
"type": "SampleData",
|
2022-09-19 09:20:54 +05:30
|
|
|
"sampleDataFolder": "/home/airflow/ingestion/examples/sample_data"
|
2022-04-12 02:27:18 -07:00
|
|
|
}
|
|
|
|
},
|
2022-06-21 14:54:36 +02:00
|
|
|
"sourceConfig": {
|
|
|
|
"config":{
|
|
|
|
"type": "DatabaseUsage"
|
|
|
|
}
|
|
|
|
}
|
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-04-12 02:27:18 -07:00
|
|
|
"authProvider": "no-auth"
|
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)
|
|
|
|
workflow = Workflow.create(workflow_config)
|
|
|
|
workflow.execute()
|
|
|
|
workflow.raise_from_status()
|
|
|
|
workflow.print_status()
|
|
|
|
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
|
|
|
)
|