2026-10-21 17:16:46 +07:00
|
|
|
"""
|
|
|
|
|
DLH Data Lakehouse - Dynamic Pipeline & Storage API
|
|
|
|
|
Modular Entrypoint with FastAPI
|
|
|
|
|
"""
|
|
|
|
|
import logging
|
|
|
|
|
from fastapi import FastAPI
|
|
|
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
|
|
|
|
|
|
from app.core.config import settings
|
|
|
|
|
from app.routers import api_v1_router, legacy_router
|
|
|
|
|
from app.schemas.pipeline import DeployRequest, DraftRequest
|
|
|
|
|
from app.schemas.connection import ConnectionTestRequest, CustomConnectionRequest
|
|
|
|
|
from app.services.pipeline_parser import parse_yaml_to_pipeline_dict
|
|
|
|
|
from app.services.metadb_service import save_connection_to_metadb
|
|
|
|
|
from app.services.dbt_service import sync_dbt_models_from_nodes
|
|
|
|
|
|
|
|
|
|
# Configure root logger
|
|
|
|
|
logging.basicConfig(
|
|
|
|
|
level=logging.INFO,
|
|
|
|
|
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s"
|
|
|
|
|
)
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
# Module-level variable exports for backward compatibility with existing scripts
|
|
|
|
|
CONFIGS_DIR = settings.CONFIGS_DIR
|
|
|
|
|
UPLOADS_DIR = settings.UPLOADS_DIR
|
|
|
|
|
DOCS_DIR = settings.DOCS_DIR
|
|
|
|
|
DBT_DIR = settings.DBT_DIR
|
|
|
|
|
|
|
|
|
|
# FastAPI Application Factory / Instance
|
|
|
|
|
app = FastAPI(
|
|
|
|
|
title=settings.PROJECT_NAME,
|
|
|
|
|
version=settings.VERSION,
|
|
|
|
|
description="Modular FastAPI Backend for MERICA Studio, Dynamic Lakehouse YAML Generation, and Airflow 3 DAG Bundles."
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# CORS Setup
|
|
|
|
|
app.add_middleware(
|
|
|
|
|
CORSMiddleware,
|
|
|
|
|
allow_origins=settings.CORS_ORIGINS,
|
|
|
|
|
allow_credentials=True,
|
|
|
|
|
allow_methods=["*"],
|
|
|
|
|
allow_headers=["*"],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Mount RESTful v1 Router and Canvas v0.1 Backward Compatibility Router
|
|
|
|
|
app.include_router(api_v1_router)
|
|
|
|
|
app.include_router(legacy_router)
|
|
|
|
|
|
|
|
|
|
|
2026-10-21 18:03:41 +07:00
|
|
|
@app.api_route("/api/v1/health", methods=["GET", "HEAD"], tags=["System"], summary="System health check probe")
|
2026-10-21 17:16:46 +07:00
|
|
|
def health_check():
|
|
|
|
|
"""Health check probe endpoint."""
|
|
|
|
|
return {
|
|
|
|
|
"status": "ok",
|
|
|
|
|
"service": settings.PROJECT_NAME,
|
|
|
|
|
"version": settings.VERSION
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Backward compatibility health check probes (hidden from OpenAPI schema)
|
2026-10-21 18:03:41 +07:00
|
|
|
@app.api_route("/health", methods=["GET", "HEAD"], include_in_schema=False)
|
|
|
|
|
@app.api_route("/api/health", methods=["GET", "HEAD"], include_in_schema=False)
|
2026-10-21 17:16:46 +07:00
|
|
|
def legacy_health_check():
|
|
|
|
|
return health_check()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Exported symbols for python imports
|
|
|
|
|
__all__ = [
|
|
|
|
|
"app",
|
|
|
|
|
"settings",
|
|
|
|
|
"CONFIGS_DIR",
|
|
|
|
|
"UPLOADS_DIR",
|
|
|
|
|
"DOCS_DIR",
|
|
|
|
|
"DBT_DIR",
|
|
|
|
|
"parse_yaml_to_pipeline_dict",
|
|
|
|
|
"save_connection_to_metadb",
|
|
|
|
|
"sync_dbt_models_from_nodes",
|
|
|
|
|
"DeployRequest",
|
|
|
|
|
"DraftRequest",
|
|
|
|
|
"ConnectionTestRequest",
|
|
|
|
|
"CustomConnectionRequest",
|
|
|
|
|
]
|