Skip to content

Commit

Permalink
Migrate public get dags to fastapi (apache#42196)
Browse files Browse the repository at this point in the history
* Migrate public get dags to fastapi

* Fix CI

* Fix CI lowest dependency resolution
  • Loading branch information
pierrejeambrun authored Sep 13, 2024
1 parent ade9de1 commit 7d5f2ba
Show file tree
Hide file tree
Showing 12 changed files with 660 additions and 47 deletions.
43 changes: 43 additions & 0 deletions airflow/api_fastapi/db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 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.

from __future__ import annotations

from typing import TYPE_CHECKING

from airflow.utils.session import create_session

if TYPE_CHECKING:
from sqlalchemy.orm import Session


async def get_session() -> Session:
"""
Dependency for providing a session.
For non route function please use the :class:`airflow.utils.session.provide_session` decorator.
Example usage:
.. code:: python
@router.get("/your_path")
def your_route(session: Annotated[Session, Depends(get_session)]):
pass
"""
with create_session() as session:
yield session
259 changes: 259 additions & 0 deletions airflow/api_fastapi/openapi/v1-generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,267 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
/public/dags:
get:
tags:
- DAG
summary: Get Dags
description: Get all DAGs.
operationId: get_dags_public_dags_get
parameters:
- name: limit
in: query
required: false
schema:
type: integer
default: 100
title: Limit
- name: offset
in: query
required: false
schema:
type: integer
default: 0
title: Offset
- name: tags
in: query
required: false
schema:
anyOf:
- type: array
items:
type: string
- type: 'null'
title: Tags
- name: dag_id_pattern
in: query
required: false
schema:
anyOf:
- type: string
- type: 'null'
title: Dag Id Pattern
- name: only_active
in: query
required: false
schema:
type: boolean
default: true
title: Only Active
- name: paused
in: query
required: false
schema:
anyOf:
- type: boolean
- type: 'null'
title: Paused
- name: order_by
in: query
required: false
schema:
type: string
default: dag_id
title: Order By
responses:
'200':
description: Successful Response
content:
application/json:
schema:
$ref: '#/components/schemas/DAGCollectionResponse'
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
components:
schemas:
DAGCollectionResponse:
properties:
dags:
items:
$ref: '#/components/schemas/DAGModelResponse'
type: array
title: Dags
total_entries:
type: integer
title: Total Entries
type: object
required:
- dags
- total_entries
title: DAGCollectionResponse
description: DAG Collection serializer for responses.
DAGModelResponse:
properties:
dag_id:
type: string
title: Dag Id
dag_display_name:
type: string
title: Dag Display Name
is_paused:
type: boolean
title: Is Paused
is_active:
type: boolean
title: Is Active
last_parsed_time:
anyOf:
- type: string
format: date-time
- type: 'null'
title: Last Parsed Time
last_pickled:
anyOf:
- type: string
format: date-time
- type: 'null'
title: Last Pickled
last_expired:
anyOf:
- type: string
format: date-time
- type: 'null'
title: Last Expired
scheduler_lock:
anyOf:
- type: string
format: date-time
- type: 'null'
title: Scheduler Lock
pickle_id:
anyOf:
- type: string
format: date-time
- type: 'null'
title: Pickle Id
default_view:
anyOf:
- type: string
- type: 'null'
title: Default View
fileloc:
type: string
title: Fileloc
description:
anyOf:
- type: string
- type: 'null'
title: Description
timetable_summary:
anyOf:
- type: string
- type: 'null'
title: Timetable Summary
timetable_description:
anyOf:
- type: string
- type: 'null'
title: Timetable Description
tags:
items:
$ref: '#/components/schemas/DagTagPydantic'
type: array
title: Tags
max_active_tasks:
type: integer
title: Max Active Tasks
max_active_runs:
anyOf:
- type: integer
- type: 'null'
title: Max Active Runs
max_consecutive_failed_dag_runs:
type: integer
title: Max Consecutive Failed Dag Runs
has_task_concurrency_limits:
type: boolean
title: Has Task Concurrency Limits
has_import_errors:
type: boolean
title: Has Import Errors
next_dagrun:
anyOf:
- type: string
format: date-time
- type: 'null'
title: Next Dagrun
next_dagrun_data_interval_start:
anyOf:
- type: string
format: date-time
- type: 'null'
title: Next Dagrun Data Interval Start
next_dagrun_data_interval_end:
anyOf:
- type: string
format: date-time
- type: 'null'
title: Next Dagrun Data Interval End
next_dagrun_create_after:
anyOf:
- type: string
format: date-time
- type: 'null'
title: Next Dagrun Create After
owners:
items:
type: string
type: array
title: Owners
file_token:
type: string
title: File Token
description: Return file token.
readOnly: true
type: object
required:
- dag_id
- dag_display_name
- is_paused
- is_active
- last_parsed_time
- last_pickled
- last_expired
- scheduler_lock
- pickle_id
- default_view
- fileloc
- description
- timetable_summary
- timetable_description
- tags
- max_active_tasks
- max_active_runs
- max_consecutive_failed_dag_runs
- has_task_concurrency_limits
- has_import_errors
- next_dagrun
- next_dagrun_data_interval_start
- next_dagrun_data_interval_end
- next_dagrun_create_after
- owners
- file_token
title: DAGModelResponse
description: DAG serializer for responses.
DagTagPydantic:
properties:
name:
type: string
title: Name
dag_id:
type: string
title: Dag Id
type: object
required:
- name
- dag_id
title: DagTagPydantic
description: Serializable representation of the DagTag ORM SqlAlchemyModel used
by internal API.
HTTPValidationError:
properties:
detail:
Expand Down
16 changes: 16 additions & 0 deletions airflow/api_fastapi/serializers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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.
Loading

0 comments on commit 7d5f2ba

Please sign in to comment.