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.
|
|
|
|
from datetime import timedelta
|
2021-10-30 21:35:30 +05:30
|
|
|
|
2021-10-14 20:16:24 +05:30
|
|
|
from airflow import DAG
|
2021-12-18 16:41:38 +01:00
|
|
|
from docker.types import Mount
|
2021-10-14 20:16:24 +05:30
|
|
|
|
|
|
|
try:
|
2021-12-18 16:41:38 +01:00
|
|
|
from airflow.operators.docker_operator import DockerOperator
|
2021-10-14 20:16:24 +05:30
|
|
|
except ModuleNotFoundError:
|
2021-12-18 16:41:38 +01:00
|
|
|
from airflow.providers.docker.operators.docker import DockerOperator
|
2021-10-14 20:16:24 +05:30
|
|
|
|
2021-10-30 21:35:30 +05:30
|
|
|
from airflow.utils.dates import days_ago
|
|
|
|
|
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 = """
|
|
|
|
{
|
|
|
|
"source": {
|
|
|
|
"type": "sample-data",
|
|
|
|
"config": {
|
2021-12-18 16:41:38 +01:00
|
|
|
"sample_data_folder": "/opt/operator/sample_data"
|
2021-10-14 20:16:24 +05:30
|
|
|
}
|
|
|
|
},
|
|
|
|
"sink": {
|
|
|
|
"type": "metadata-rest",
|
|
|
|
"config": {}
|
|
|
|
},
|
|
|
|
"metadata_server": {
|
|
|
|
"type": "metadata-server",
|
|
|
|
"config": {
|
|
|
|
"api_endpoint": "http://localhost:8585/api",
|
|
|
|
"auth_provider_type": "no-auth"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
2021-10-30 21:35:30 +05:30
|
|
|
|
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),
|
|
|
|
is_paused_upon_creation=False,
|
|
|
|
catchup=False,
|
|
|
|
) as dag:
|
2021-12-18 16:41:38 +01:00
|
|
|
ingest_task = DockerOperator(
|
|
|
|
task_id="ingest_using_docker",
|
|
|
|
image="openmetadata/ingestion-connector-base",
|
|
|
|
command="python main.py",
|
|
|
|
environment={"config": config},
|
|
|
|
tty=True,
|
|
|
|
auto_remove=True,
|
|
|
|
mounts=[
|
|
|
|
Mount(
|
|
|
|
source="/tmp/openmetadata/examples/",
|
|
|
|
target="/opt/operator/",
|
|
|
|
type="bind",
|
|
|
|
),
|
|
|
|
],
|
|
|
|
mount_tmp_dir=False,
|
|
|
|
network_mode="host", # Needed to reach Docker OM
|
2021-10-30 21:35:30 +05:30
|
|
|
)
|