apache-airflow-providers-edge3 1.4.1rc2__py3-none-any.whl → 2.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. airflow/providers/edge3/__init__.py +3 -3
  2. airflow/providers/edge3/cli/api_client.py +23 -26
  3. airflow/providers/edge3/cli/worker.py +14 -29
  4. airflow/providers/edge3/example_dags/integration_test.py +1 -1
  5. airflow/providers/edge3/example_dags/win_test.py +32 -22
  6. airflow/providers/edge3/executors/edge_executor.py +7 -63
  7. airflow/providers/edge3/get_provider_info.py +7 -0
  8. airflow/providers/edge3/models/edge_worker.py +7 -3
  9. airflow/providers/edge3/plugins/edge_executor_plugin.py +26 -205
  10. airflow/providers/edge3/plugins/www/dist/main.umd.cjs +8 -100
  11. airflow/providers/edge3/plugins/www/openapi-gen/queries/common.ts +6 -1
  12. airflow/providers/edge3/plugins/www/openapi-gen/queries/ensureQueryData.ts +6 -1
  13. airflow/providers/edge3/plugins/www/openapi-gen/queries/prefetch.ts +6 -1
  14. airflow/providers/edge3/plugins/www/openapi-gen/queries/queries.ts +6 -2
  15. airflow/providers/edge3/plugins/www/openapi-gen/queries/suspense.ts +6 -1
  16. airflow/providers/edge3/plugins/www/openapi-gen/requests/schemas.gen.ts +5 -0
  17. airflow/providers/edge3/plugins/www/openapi-gen/requests/services.gen.ts +18 -3
  18. airflow/providers/edge3/plugins/www/openapi-gen/requests/types.gen.ts +24 -0
  19. airflow/providers/edge3/plugins/www/package.json +26 -24
  20. airflow/providers/edge3/plugins/www/pnpm-lock.yaml +1469 -1413
  21. airflow/providers/edge3/plugins/www/src/components/SearchBar.tsx +103 -0
  22. airflow/providers/edge3/plugins/www/src/components/ui/InputGroup.tsx +57 -0
  23. airflow/providers/edge3/plugins/www/src/components/ui/Select/Content.tsx +37 -0
  24. airflow/providers/edge3/plugins/www/src/components/ui/Select/Item.tsx +34 -0
  25. airflow/providers/edge3/plugins/www/src/components/ui/Select/Root.tsx +24 -0
  26. airflow/providers/edge3/plugins/www/src/components/ui/Select/Trigger.tsx +54 -0
  27. airflow/providers/edge3/plugins/www/src/components/ui/Select/ValueText.tsx +51 -0
  28. airflow/providers/edge3/plugins/www/src/components/ui/Select/index.ts +34 -0
  29. airflow/providers/edge3/plugins/www/src/components/ui/index.ts +3 -0
  30. airflow/providers/edge3/plugins/www/src/constants.ts +43 -0
  31. airflow/providers/edge3/plugins/www/src/pages/WorkerPage.tsx +184 -95
  32. airflow/providers/edge3/version_compat.py +0 -2
  33. airflow/providers/edge3/worker_api/auth.py +11 -35
  34. airflow/providers/edge3/worker_api/datamodels.py +3 -2
  35. airflow/providers/edge3/worker_api/routes/health.py +1 -1
  36. airflow/providers/edge3/worker_api/routes/jobs.py +10 -11
  37. airflow/providers/edge3/worker_api/routes/logs.py +5 -8
  38. airflow/providers/edge3/worker_api/routes/ui.py +14 -3
  39. airflow/providers/edge3/worker_api/routes/worker.py +19 -12
  40. airflow/providers/edge3/{openapi → worker_api}/v2-edge-generated.yaml +59 -5
  41. {apache_airflow_providers_edge3-1.4.1rc2.dist-info → apache_airflow_providers_edge3-2.0.0.dist-info}/METADATA +16 -14
  42. {apache_airflow_providers_edge3-1.4.1rc2.dist-info → apache_airflow_providers_edge3-2.0.0.dist-info}/RECORD +46 -40
  43. apache_airflow_providers_edge3-2.0.0.dist-info/licenses/NOTICE +5 -0
  44. airflow/providers/edge3/openapi/__init__.py +0 -19
  45. airflow/providers/edge3/openapi/edge_worker_api_v1.yaml +0 -808
  46. airflow/providers/edge3/worker_api/routes/_v2_compat.py +0 -136
  47. airflow/providers/edge3/worker_api/routes/_v2_routes.py +0 -237
  48. {apache_airflow_providers_edge3-1.4.1rc2.dist-info → apache_airflow_providers_edge3-2.0.0.dist-info}/WHEEL +0 -0
  49. {apache_airflow_providers_edge3-1.4.1rc2.dist-info → apache_airflow_providers_edge3-2.0.0.dist-info}/entry_points.txt +0 -0
  50. {airflow/providers/edge3 → apache_airflow_providers_edge3-2.0.0.dist-info/licenses}/LICENSE +0 -0
@@ -1,136 +0,0 @@
1
- # Licensed to the Apache Software Foundation (ASF) under one
2
- # or more contributor license agreements. See the NOTICE file
3
- # distributed with this work for additional information
4
- # regarding copyright ownership. The ASF licenses this file
5
- # to you under the Apache License, Version 2.0 (the
6
- # "License"); you may not use this file except in compliance
7
- # with the License. You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing,
12
- # software distributed under the License is distributed on an
13
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
- # KIND, either express or implied. See the License for the
15
- # specific language governing permissions and limitations
16
- # under the License.
17
- """Compatibility layer for API to provide both FastAPI as well as Connexion based endpoints."""
18
-
19
- from __future__ import annotations
20
-
21
- from airflow.providers.edge3.version_compat import AIRFLOW_V_3_0_PLUS
22
-
23
- if AIRFLOW_V_3_0_PLUS:
24
- # Just re-import the types from FastAPI and Airflow Core
25
- from fastapi import Body, Depends, Header, HTTPException, Path, Request, status
26
-
27
- from airflow.api_fastapi.common.db.common import SessionDep
28
- from airflow.api_fastapi.common.router import AirflowRouter
29
- from airflow.api_fastapi.core_api.openapi.exceptions import create_openapi_http_exception_doc
30
-
31
- # In Airflow 3 with AIP-72 we get workload addressed by ExecuteTask
32
- from airflow.executors.workloads import ExecuteTask
33
-
34
- def parse_command(command: str) -> ExecuteTask:
35
- return ExecuteTask.model_validate_json(command)
36
- else:
37
- # Mock the external dependencies
38
- from collections.abc import Callable
39
-
40
- from connexion import ProblemException
41
-
42
- class Body: # type: ignore[no-redef]
43
- def __init__(self, *_, **__):
44
- pass
45
-
46
- class Depends: # type: ignore[no-redef]
47
- def __init__(self, *_, **__):
48
- pass
49
-
50
- class Header: # type: ignore[no-redef]
51
- def __init__(self, *_, **__):
52
- pass
53
-
54
- class Path: # type: ignore[no-redef]
55
- def __init__(self, *_, **__):
56
- pass
57
-
58
- class Request: # type: ignore[no-redef]
59
- pass
60
-
61
- class SessionDep: # type: ignore[no-redef]
62
- pass
63
-
64
- def create_openapi_http_exception_doc(responses_status_code: list[int]) -> dict:
65
- return {}
66
-
67
- class status: # type: ignore[no-redef]
68
- HTTP_204_NO_CONTENT = 204
69
- HTTP_400_BAD_REQUEST = 400
70
- HTTP_403_FORBIDDEN = 403
71
- HTTP_404_NOT_FOUND = 404
72
- HTTP_500_INTERNAL_SERVER_ERROR = 500
73
-
74
- class HTTPException(ProblemException): # type: ignore[no-redef]
75
- """Raise when the user does not have the required permissions."""
76
-
77
- def __init__(
78
- self,
79
- status: int,
80
- detail: str,
81
- ) -> None:
82
- from airflow.utils.docs import get_docs_url
83
-
84
- doc_link = get_docs_url("stable-rest-api-ref.html")
85
- EXCEPTIONS_LINK_MAP = {
86
- 400: f"{doc_link}#section/Errors/BadRequest",
87
- 403: f"{doc_link}#section/Errors/PermissionDenied",
88
- 500: f"{doc_link}#section/Errors/Unknown",
89
- }
90
- TITLE_MAP = {
91
- 400: "BadRequest",
92
- 403: "PermissionDenied",
93
- 500: "InternalServerError",
94
- }
95
- super().__init__(
96
- status=status,
97
- type=EXCEPTIONS_LINK_MAP[status],
98
- title=TITLE_MAP[status],
99
- detail=detail,
100
- )
101
-
102
- def to_response(self):
103
- from flask import Response
104
-
105
- return Response(response=self.detail, status=self.status)
106
-
107
- class AirflowRouter: # type: ignore[no-redef]
108
- def __init__(self, *_, **__):
109
- pass
110
-
111
- def get(self, *_, **__):
112
- def decorator(func: Callable) -> Callable:
113
- return func
114
-
115
- return decorator
116
-
117
- def post(self, *_, **__):
118
- def decorator(func: Callable) -> Callable:
119
- return func
120
-
121
- return decorator
122
-
123
- def patch(self, *_, **__):
124
- def decorator(func: Callable) -> Callable:
125
- return func
126
-
127
- return decorator
128
-
129
- # In Airflow 3 with AIP-72 we get workload addressed by ExecuteTask
130
- # But in Airflow 2.10 it is a command line array
131
- ExecuteTask = list[str] # type: ignore[assignment,misc]
132
-
133
- def parse_command(command: str) -> ExecuteTask:
134
- from ast import literal_eval
135
-
136
- return literal_eval(command)
@@ -1,237 +0,0 @@
1
- # Licensed to the Apache Software Foundation (ASF) under one
2
- # or more contributor license agreements. See the NOTICE file
3
- # distributed with this work for additional information
4
- # regarding copyright ownership. The ASF licenses this file
5
- # to you under the Apache License, Version 2.0 (the
6
- # "License"); you may not use this file except in compliance
7
- # with the License. You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing,
12
- # software distributed under the License is distributed on an
13
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
- # KIND, either express or implied. See the License for the
15
- # specific language governing permissions and limitations
16
- # under the License.
17
- """Compatibility layer for Connexion API to Airflow v2.10 API routes."""
18
-
19
- from __future__ import annotations
20
-
21
- import json
22
- import logging
23
- from typing import TYPE_CHECKING, Any
24
- from uuid import uuid4
25
-
26
- from flask import Response, request
27
-
28
- from airflow.exceptions import AirflowException
29
- from airflow.providers.edge3.worker_api.auth import (
30
- jwt_token_authorization,
31
- jwt_token_authorization_rpc,
32
- )
33
- from airflow.providers.edge3.worker_api.datamodels import (
34
- EdgeJobFetched,
35
- JsonRpcRequest,
36
- PushLogsBody,
37
- WorkerQueuesBody,
38
- WorkerStateBody,
39
- )
40
- from airflow.providers.edge3.worker_api.routes._v2_compat import HTTPException, status
41
- from airflow.providers.edge3.worker_api.routes.jobs import fetch, state as state_api
42
- from airflow.providers.edge3.worker_api.routes.logs import logfile_path, push_logs
43
- from airflow.providers.edge3.worker_api.routes.worker import register, set_state
44
- from airflow.serialization.serialized_objects import BaseSerialization
45
- from airflow.utils.session import NEW_SESSION, create_session, provide_session
46
-
47
- if TYPE_CHECKING:
48
- from airflow.api_connexion.types import APIResponse
49
- from airflow.utils.state import TaskInstanceState
50
-
51
-
52
- log = logging.getLogger(__name__)
53
-
54
-
55
- def error_response(message: str, status: int):
56
- """Log the error and return the response as JSON object."""
57
- error_id = uuid4()
58
- server_message = f"{message} error_id={error_id}"
59
- log.exception(server_message)
60
- client_message = f"{message} The server side traceback may be identified with error_id={error_id}"
61
- return HTTPException(status, client_message)
62
-
63
-
64
- def rpcapi_v2(body: dict[str, Any]) -> APIResponse:
65
- """Handle Edge Worker API `/edge_worker/v1/rpcapi` endpoint for Airflow 2.10."""
66
- # Note: Except the method map this _was_ a 100% copy of internal API module
67
- # airflow.api_internal.endpoints.rpc_api_endpoint.internal_airflow_api()
68
- # As of rework for FastAPI in Airflow 3.0, this is updated and to be removed in the future.
69
- from airflow.api_internal.endpoints.rpc_api_endpoint import (
70
- # Note: This is just for compatibility with Airflow 2.10, not working for Airflow 3 / main as removed
71
- initialize_method_map,
72
- )
73
-
74
- try:
75
- if request.headers.get("Content-Type", "") != "application/json":
76
- raise HTTPException(status.HTTP_403_FORBIDDEN, "Expected Content-Type: application/json")
77
- if request.headers.get("Accept", "") != "application/json":
78
- raise HTTPException(status.HTTP_403_FORBIDDEN, "Expected Accept: application/json")
79
- auth = request.headers.get("Authorization", "")
80
- request_obj = JsonRpcRequest(method=body["method"], jsonrpc=body["jsonrpc"], params=body["params"])
81
- jwt_token_authorization_rpc(request_obj, auth)
82
- if request_obj.jsonrpc != "2.0":
83
- raise error_response("Expected jsonrpc 2.0 request.", status.HTTP_400_BAD_REQUEST)
84
-
85
- log.debug("Got request for %s", request_obj.method)
86
- methods_map = initialize_method_map()
87
- if request_obj.method not in methods_map:
88
- raise error_response(f"Unrecognized method: {request_obj.method}.", status.HTTP_400_BAD_REQUEST)
89
-
90
- handler = methods_map[request_obj.method]
91
- params = {}
92
- try:
93
- if request_obj.params:
94
- # Note, this is Airflow 2.10 specific, as it uses Pydantic models for serialization
95
- params = BaseSerialization.deserialize(request_obj.params, use_pydantic_models=True) # type: ignore[call-arg]
96
- except Exception:
97
- raise error_response("Error deserializing parameters.", status.HTTP_400_BAD_REQUEST)
98
-
99
- log.debug("Calling method %s\nparams: %s", request_obj.method, params)
100
- try:
101
- # Session must be created there as it may be needed by serializer for lazy-loaded fields.
102
- with create_session() as session:
103
- output = handler(**params, session=session)
104
- # Note, this is Airflow 2.10 specific, as it uses Pydantic models for serialization
105
- output_json = BaseSerialization.serialize(output, use_pydantic_models=True) # type: ignore[call-arg]
106
- log.debug(
107
- "Sending response: %s", json.dumps(output_json) if output_json is not None else None
108
- )
109
- # In case of AirflowException or other selective known types, transport the exception class back to caller
110
- except (KeyError, AttributeError, AirflowException) as e:
111
- # Note, this is Airflow 2.10 specific, as it uses Pydantic models for serialization
112
- output_json = BaseSerialization.serialize(e, use_pydantic_models=True) # type: ignore[call-arg]
113
- log.debug(
114
- "Sending exception response: %s", json.dumps(output_json) if output_json is not None else None
115
- )
116
- except Exception:
117
- raise error_response(
118
- f"Error executing method '{request_obj.method}'.", status.HTTP_500_INTERNAL_SERVER_ERROR
119
- )
120
- response = json.dumps(output_json) if output_json is not None else None
121
- return Response(response=response, headers={"Content-Type": "application/json"})
122
- except HTTPException as e:
123
- return e.to_response() # type: ignore[attr-defined]
124
-
125
-
126
- def jwt_token_authorization_v2(method: str, authorization: str):
127
- """Proxy for v2 method path handling."""
128
- PREFIX = "/edge_worker/v1/"
129
- method_path = method[method.find(PREFIX) + len(PREFIX) :] if PREFIX in method else method
130
- jwt_token_authorization(method_path, authorization)
131
-
132
-
133
- @provide_session
134
- def register_v2(worker_name: str, body: dict[str, Any], session=NEW_SESSION) -> Any:
135
- """Handle Edge Worker API `/edge_worker/v1/worker/{worker_name}` endpoint for Airflow 2.10."""
136
- try:
137
- auth = request.headers.get("Authorization", "")
138
- jwt_token_authorization_v2(request.path, auth)
139
- request_obj = WorkerStateBody(
140
- state=body["state"], jobs_active=0, queues=body["queues"], sysinfo=body["sysinfo"]
141
- )
142
- return register(worker_name, request_obj, session).model_dump()
143
- except HTTPException as e:
144
- return e.to_response() # type: ignore[attr-defined]
145
-
146
-
147
- @provide_session
148
- def set_state_v2(worker_name: str, body: dict[str, Any], session=NEW_SESSION) -> Any:
149
- """Handle Edge Worker API `/edge_worker/v1/worker/{worker_name}` endpoint for Airflow 2.10."""
150
- try:
151
- auth = request.headers.get("Authorization", "")
152
- jwt_token_authorization_v2(request.path, auth)
153
- request_obj = WorkerStateBody(
154
- state=body["state"],
155
- jobs_active=body["jobs_active"],
156
- queues=body["queues"],
157
- sysinfo=body["sysinfo"],
158
- maintenance_comments=body.get("maintenance_comments"),
159
- )
160
- return set_state(worker_name, request_obj, session).model_dump()
161
- except HTTPException as e:
162
- return e.to_response() # type: ignore[attr-defined]
163
-
164
-
165
- @provide_session
166
- def job_fetch_v2(worker_name: str, body: dict[str, Any], session=NEW_SESSION) -> Any:
167
- """Handle Edge Worker API `/edge_worker/v1/jobs/fetch/{worker_name}` endpoint for Airflow 2.10."""
168
- from flask import request
169
-
170
- try:
171
- auth = request.headers.get("Authorization", "")
172
- jwt_token_authorization_v2(request.path, auth)
173
- queues = body.get("queues")
174
- free_concurrency = body.get("free_concurrency", 1)
175
- request_obj = WorkerQueuesBody(queues=queues, free_concurrency=free_concurrency)
176
- job: EdgeJobFetched | None = fetch(worker_name, request_obj, session)
177
- return job.model_dump() if job is not None else None
178
- except HTTPException as e:
179
- return e.to_response() # type: ignore[attr-defined]
180
-
181
-
182
- @provide_session
183
- def job_state_v2(
184
- dag_id: str,
185
- task_id: str,
186
- run_id: str,
187
- try_number: int,
188
- map_index: str, # Note: Connexion can not have negative numbers in path parameters, use string therefore
189
- state: TaskInstanceState,
190
- session=NEW_SESSION,
191
- ) -> Any:
192
- """Handle Edge Worker API `/jobs/state/{dag_id}/{task_id}/{run_id}/{try_number}/{map_index}/{state}` endpoint for Airflow 2.10."""
193
- from flask import request
194
-
195
- try:
196
- auth = request.headers.get("Authorization", "")
197
- jwt_token_authorization_v2(request.path, auth)
198
- state_api(dag_id, task_id, run_id, try_number, int(map_index), state, session)
199
- except HTTPException as e:
200
- return e.to_response() # type: ignore[attr-defined]
201
-
202
-
203
- def logfile_path_v2(
204
- dag_id: str,
205
- task_id: str,
206
- run_id: str,
207
- try_number: int,
208
- map_index: str, # Note: Connexion can not have negative numbers in path parameters, use string therefore
209
- ) -> str:
210
- """Handle Edge Worker API `/edge_worker/v1/logs/logfile_path/{dag_id}/{task_id}/{run_id}/{try_number}/{map_index}` endpoint for Airflow 2.10."""
211
- try:
212
- auth = request.headers.get("Authorization", "")
213
- jwt_token_authorization_v2(request.path, auth)
214
- return logfile_path(dag_id, task_id, run_id, try_number, int(map_index))
215
- except HTTPException as e:
216
- return e.to_response() # type: ignore[attr-defined]
217
-
218
-
219
- def push_logs_v2(
220
- dag_id: str,
221
- task_id: str,
222
- run_id: str,
223
- try_number: int,
224
- map_index: str, # Note: Connexion can not have negative numbers in path parameters, use string therefore
225
- body: dict[str, Any],
226
- ) -> None:
227
- """Handle Edge Worker API `/edge_worker/v1/logs/push/{dag_id}/{task_id}/{run_id}/{try_number}/{map_index}` endpoint for Airflow 2.10."""
228
- try:
229
- auth = request.headers.get("Authorization", "")
230
- jwt_token_authorization_v2(request.path, auth)
231
- request_obj = PushLogsBody(
232
- log_chunk_data=body["log_chunk_data"], log_chunk_time=body["log_chunk_time"]
233
- )
234
- with create_session() as session:
235
- push_logs(dag_id, task_id, run_id, try_number, int(map_index), request_obj, session)
236
- except HTTPException as e:
237
- return e.to_response() # type: ignore[attr-defined]