-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AIP-72: Add support for
outlet_events
in Task Context
part of #45717 This PR adds support for `outlet_events` in Context dict within the Task SDK by adding an endpoint on the API Server which is fetched when outlet_events is accessed.
- Loading branch information
Showing
18 changed files
with
603 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# 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 airflow.api_fastapi.core_api.base import BaseModel | ||
|
||
|
||
class AssetResponse(BaseModel): | ||
"""Asset schema for responses with fields that are needed for Runtime.""" | ||
|
||
name: str | ||
uri: str | ||
group: str | ||
extra: dict | None = None | ||
|
||
|
||
class AssetAliasResponse(BaseModel): | ||
"""Asset alias schema with fields that are needed for Runtime.""" | ||
|
||
name: str | ||
group: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# 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 Annotated | ||
|
||
from fastapi import HTTPException, Query, status | ||
from sqlalchemy import select | ||
|
||
from airflow.api_fastapi.common.db.common import SessionDep | ||
from airflow.api_fastapi.common.router import AirflowRouter | ||
from airflow.api_fastapi.execution_api.datamodels.asset import AssetResponse | ||
from airflow.models.asset import AssetModel | ||
|
||
# TODO: Add dependency on JWT token | ||
router = AirflowRouter( | ||
responses={ | ||
status.HTTP_404_NOT_FOUND: {"description": "Asset not found"}, | ||
status.HTTP_401_UNAUTHORIZED: {"description": "Unauthorized"}, | ||
}, | ||
) | ||
|
||
|
||
@router.get("/by-name") | ||
def get_asset_by_name( | ||
name: Annotated[str, Query(description="The name of the Asset")], | ||
session: SessionDep, | ||
) -> AssetResponse: | ||
"""Get an Airflow Asset by `name`.""" | ||
asset = session.scalar(select(AssetModel).where(AssetModel.name == name, AssetModel.active.has())) | ||
_raise_if_not_found(asset, f"Asset with name {name} not found") | ||
|
||
return AssetResponse.model_validate(asset) | ||
|
||
|
||
@router.get("/by-uri") | ||
def get_asset_by_uri( | ||
uri: Annotated[str, Query(description="The URI of the Asset")], | ||
session: SessionDep, | ||
) -> AssetResponse: | ||
"""Get an Airflow Asset by `uri`.""" | ||
asset = session.scalar(select(AssetModel).where(AssetModel.uri == uri, AssetModel.active.has())) | ||
_raise_if_not_found(asset, f"Asset with URI {uri} not found") | ||
|
||
return AssetResponse.model_validate(asset) | ||
|
||
|
||
def _raise_if_not_found(asset, msg): | ||
if asset is None: | ||
raise HTTPException( | ||
status.HTTP_404_NOT_FOUND, | ||
detail={ | ||
"reason": "not_found", | ||
"message": msg, | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.