Skip to content

Commit b44a889

Browse files
AIP-84 Get Pools (#43223)
1 parent 0f38be1 commit b44a889

File tree

14 files changed

+363
-11
lines changed

14 files changed

+363
-11
lines changed

airflow/api_connexion/endpoints/pool_endpoint.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def get_pool(*, pool_name: str, session: Session = NEW_SESSION) -> APIResponse:
6666
return pool_schema.dump(obj)
6767

6868

69+
@mark_fastapi_migration_done
6970
@security.requires_access_pool("GET")
7071
@format_parameters({"limit": check_limit})
7172
@provide_session

airflow/api_fastapi/core_api/openapi/v1-generated.yaml

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,66 @@ paths:
11631163
application/json:
11641164
schema:
11651165
$ref: '#/components/schemas/HTTPValidationError'
1166+
/public/pools/:
1167+
get:
1168+
tags:
1169+
- Pool
1170+
summary: Get Pools
1171+
description: Get all pools entries.
1172+
operationId: get_pools
1173+
parameters:
1174+
- name: limit
1175+
in: query
1176+
required: false
1177+
schema:
1178+
type: integer
1179+
default: 100
1180+
title: Limit
1181+
- name: offset
1182+
in: query
1183+
required: false
1184+
schema:
1185+
type: integer
1186+
default: 0
1187+
title: Offset
1188+
- name: order_by
1189+
in: query
1190+
required: false
1191+
schema:
1192+
type: string
1193+
default: id
1194+
title: Order By
1195+
responses:
1196+
'200':
1197+
description: Successful Response
1198+
content:
1199+
application/json:
1200+
schema:
1201+
$ref: '#/components/schemas/PoolCollectionResponse'
1202+
'401':
1203+
content:
1204+
application/json:
1205+
schema:
1206+
$ref: '#/components/schemas/HTTPExceptionResponse'
1207+
description: Unauthorized
1208+
'403':
1209+
content:
1210+
application/json:
1211+
schema:
1212+
$ref: '#/components/schemas/HTTPExceptionResponse'
1213+
description: Forbidden
1214+
'404':
1215+
content:
1216+
application/json:
1217+
schema:
1218+
$ref: '#/components/schemas/HTTPExceptionResponse'
1219+
description: Not Found
1220+
'422':
1221+
description: Validation Error
1222+
content:
1223+
application/json:
1224+
schema:
1225+
$ref: '#/components/schemas/HTTPValidationError'
11661226
/public/providers/:
11671227
get:
11681228
tags:
@@ -1227,7 +1287,7 @@ components:
12271287
- connections
12281288
- total_entries
12291289
title: ConnectionCollectionResponse
1230-
description: DAG Collection serializer for responses.
1290+
description: Connection Collection serializer for responses.
12311291
ConnectionResponse:
12321292
properties:
12331293
connection_id:
@@ -1960,6 +2020,22 @@ components:
19602020
- task_instance_states
19612021
title: HistoricalMetricDataResponse
19622022
description: Historical Metric Data serializer for responses.
2023+
PoolCollectionResponse:
2024+
properties:
2025+
pools:
2026+
items:
2027+
$ref: '#/components/schemas/PoolResponse'
2028+
type: array
2029+
title: Pools
2030+
total_entries:
2031+
type: integer
2032+
title: Total Entries
2033+
type: object
2034+
required:
2035+
- pools
2036+
- total_entries
2037+
title: PoolCollectionResponse
2038+
description: Pool Collection serializer for responses.
19632039
PoolResponse:
19642040
properties:
19652041
name:

airflow/api_fastapi/core_api/routes/public/pools.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121
from sqlalchemy.orm import Session
2222
from typing_extensions import Annotated
2323

24-
from airflow.api_fastapi.common.db.common import get_session
24+
from airflow.api_fastapi.common.db.common import get_session, paginated_select
25+
from airflow.api_fastapi.common.parameters import QueryLimit, QueryOffset, SortParam
2526
from airflow.api_fastapi.common.router import AirflowRouter
2627
from airflow.api_fastapi.core_api.openapi.exceptions import create_openapi_http_exception_doc
27-
from airflow.api_fastapi.core_api.serializers.pools import PoolResponse
28+
from airflow.api_fastapi.core_api.serializers.pools import PoolCollectionResponse, PoolResponse
2829
from airflow.models.pool import Pool
2930

3031
pools_router = AirflowRouter(tags=["Pool"], prefix="/pools")
@@ -63,3 +64,34 @@ async def get_pool(
6364
raise HTTPException(404, f"The Pool with name: `{pool_name}` was not found")
6465

6566
return PoolResponse.model_validate(pool, from_attributes=True)
67+
68+
69+
@pools_router.get(
70+
"/",
71+
responses=create_openapi_http_exception_doc([401, 403, 404]),
72+
)
73+
async def get_pools(
74+
limit: QueryLimit,
75+
offset: QueryOffset,
76+
order_by: Annotated[
77+
SortParam,
78+
Depends(SortParam(["id", "name"], Pool).dynamic_depends()),
79+
],
80+
session: Annotated[Session, Depends(get_session)],
81+
) -> PoolCollectionResponse:
82+
"""Get all pools entries."""
83+
pools_select, total_entries = paginated_select(
84+
select(Pool),
85+
[],
86+
order_by=order_by,
87+
offset=offset,
88+
limit=limit,
89+
session=session,
90+
)
91+
92+
pools = session.scalars(pools_select).all()
93+
94+
return PoolCollectionResponse(
95+
pools=[PoolResponse.model_validate(pool, from_attributes=True) for pool in pools],
96+
total_entries=total_entries,
97+
)

airflow/api_fastapi/core_api/serializers/connections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def redact_extra(cls, v: str | None) -> str | None:
5151

5252

5353
class ConnectionCollectionResponse(BaseModel):
54-
"""DAG Collection serializer for responses."""
54+
"""Connection Collection serializer for responses."""
5555

5656
connections: list[ConnectionResponse]
5757
total_entries: int

airflow/api_fastapi/core_api/serializers/pools.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def _call_function(function: Callable[[], int]) -> int:
3434
class PoolResponse(BaseModel):
3535
"""Pool serializer for responses."""
3636

37-
pool: str = Field(serialization_alias="name")
37+
pool: str = Field(serialization_alias="name", validation_alias="pool")
3838
slots: int
3939
description: str | None
4040
include_deferred: bool
@@ -45,3 +45,10 @@ class PoolResponse(BaseModel):
4545
scheduled_slots: Annotated[int, BeforeValidator(_call_function)]
4646
open_slots: Annotated[int, BeforeValidator(_call_function)]
4747
deferred_slots: Annotated[int, BeforeValidator(_call_function)]
48+
49+
50+
class PoolCollectionResponse(BaseModel):
51+
"""Pool Collection serializer for responses."""
52+
53+
pools: list[PoolResponse]
54+
total_entries: int

airflow/ui/openapi-gen/queries/common.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,26 @@ export const UsePoolServiceGetPoolKeyFn = (
288288
},
289289
queryKey?: Array<unknown>,
290290
) => [usePoolServiceGetPoolKey, ...(queryKey ?? [{ poolName }])];
291+
export type PoolServiceGetPoolsDefaultResponse = Awaited<
292+
ReturnType<typeof PoolService.getPools>
293+
>;
294+
export type PoolServiceGetPoolsQueryResult<
295+
TData = PoolServiceGetPoolsDefaultResponse,
296+
TError = unknown,
297+
> = UseQueryResult<TData, TError>;
298+
export const usePoolServiceGetPoolsKey = "PoolServiceGetPools";
299+
export const UsePoolServiceGetPoolsKeyFn = (
300+
{
301+
limit,
302+
offset,
303+
orderBy,
304+
}: {
305+
limit?: number;
306+
offset?: number;
307+
orderBy?: string;
308+
} = {},
309+
queryKey?: Array<unknown>,
310+
) => [usePoolServiceGetPoolsKey, ...(queryKey ?? [{ limit, offset, orderBy }])];
291311
export type ProviderServiceGetProvidersDefaultResponse = Awaited<
292312
ReturnType<typeof ProviderService.getProviders>
293313
>;

airflow/ui/openapi-gen/queries/prefetch.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,32 @@ export const prefetchUsePoolServiceGetPool = (
357357
queryKey: Common.UsePoolServiceGetPoolKeyFn({ poolName }),
358358
queryFn: () => PoolService.getPool({ poolName }),
359359
});
360+
/**
361+
* Get Pools
362+
* Get all pools entries.
363+
* @param data The data for the request.
364+
* @param data.limit
365+
* @param data.offset
366+
* @param data.orderBy
367+
* @returns PoolCollectionResponse Successful Response
368+
* @throws ApiError
369+
*/
370+
export const prefetchUsePoolServiceGetPools = (
371+
queryClient: QueryClient,
372+
{
373+
limit,
374+
offset,
375+
orderBy,
376+
}: {
377+
limit?: number;
378+
offset?: number;
379+
orderBy?: string;
380+
} = {},
381+
) =>
382+
queryClient.prefetchQuery({
383+
queryKey: Common.UsePoolServiceGetPoolsKeyFn({ limit, offset, orderBy }),
384+
queryFn: () => PoolService.getPools({ limit, offset, orderBy }),
385+
});
360386
/**
361387
* Get Providers
362388
* Get providers.

airflow/ui/openapi-gen/queries/queries.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,41 @@ export const usePoolServiceGetPool = <
458458
queryFn: () => PoolService.getPool({ poolName }) as TData,
459459
...options,
460460
});
461+
/**
462+
* Get Pools
463+
* Get all pools entries.
464+
* @param data The data for the request.
465+
* @param data.limit
466+
* @param data.offset
467+
* @param data.orderBy
468+
* @returns PoolCollectionResponse Successful Response
469+
* @throws ApiError
470+
*/
471+
export const usePoolServiceGetPools = <
472+
TData = Common.PoolServiceGetPoolsDefaultResponse,
473+
TError = unknown,
474+
TQueryKey extends Array<unknown> = unknown[],
475+
>(
476+
{
477+
limit,
478+
offset,
479+
orderBy,
480+
}: {
481+
limit?: number;
482+
offset?: number;
483+
orderBy?: string;
484+
} = {},
485+
queryKey?: TQueryKey,
486+
options?: Omit<UseQueryOptions<TData, TError>, "queryKey" | "queryFn">,
487+
) =>
488+
useQuery<TData, TError>({
489+
queryKey: Common.UsePoolServiceGetPoolsKeyFn(
490+
{ limit, offset, orderBy },
491+
queryKey,
492+
),
493+
queryFn: () => PoolService.getPools({ limit, offset, orderBy }) as TData,
494+
...options,
495+
});
461496
/**
462497
* Get Providers
463498
* Get providers.

airflow/ui/openapi-gen/queries/suspense.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,41 @@ export const usePoolServiceGetPoolSuspense = <
453453
queryFn: () => PoolService.getPool({ poolName }) as TData,
454454
...options,
455455
});
456+
/**
457+
* Get Pools
458+
* Get all pools entries.
459+
* @param data The data for the request.
460+
* @param data.limit
461+
* @param data.offset
462+
* @param data.orderBy
463+
* @returns PoolCollectionResponse Successful Response
464+
* @throws ApiError
465+
*/
466+
export const usePoolServiceGetPoolsSuspense = <
467+
TData = Common.PoolServiceGetPoolsDefaultResponse,
468+
TError = unknown,
469+
TQueryKey extends Array<unknown> = unknown[],
470+
>(
471+
{
472+
limit,
473+
offset,
474+
orderBy,
475+
}: {
476+
limit?: number;
477+
offset?: number;
478+
orderBy?: string;
479+
} = {},
480+
queryKey?: TQueryKey,
481+
options?: Omit<UseQueryOptions<TData, TError>, "queryKey" | "queryFn">,
482+
) =>
483+
useSuspenseQuery<TData, TError>({
484+
queryKey: Common.UsePoolServiceGetPoolsKeyFn(
485+
{ limit, offset, orderBy },
486+
queryKey,
487+
),
488+
queryFn: () => PoolService.getPools({ limit, offset, orderBy }) as TData,
489+
...options,
490+
});
456491
/**
457492
* Get Providers
458493
* Get providers.

airflow/ui/openapi-gen/requests/schemas.gen.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const $ConnectionCollectionResponse = {
3737
type: "object",
3838
required: ["connections", "total_entries"],
3939
title: "ConnectionCollectionResponse",
40-
description: "DAG Collection serializer for responses.",
40+
description: "Connection Collection serializer for responses.",
4141
} as const;
4242

4343
export const $ConnectionResponse = {
@@ -1189,6 +1189,26 @@ export const $HistoricalMetricDataResponse = {
11891189
description: "Historical Metric Data serializer for responses.",
11901190
} as const;
11911191

1192+
export const $PoolCollectionResponse = {
1193+
properties: {
1194+
pools: {
1195+
items: {
1196+
$ref: "#/components/schemas/PoolResponse",
1197+
},
1198+
type: "array",
1199+
title: "Pools",
1200+
},
1201+
total_entries: {
1202+
type: "integer",
1203+
title: "Total Entries",
1204+
},
1205+
},
1206+
type: "object",
1207+
required: ["pools", "total_entries"],
1208+
title: "PoolCollectionResponse",
1209+
description: "Pool Collection serializer for responses.",
1210+
} as const;
1211+
11921212
export const $PoolResponse = {
11931213
properties: {
11941214
name: {

0 commit comments

Comments
 (0)