apache-airflow-providers-edge3 1.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.
- airflow/providers/edge3/LICENSE +201 -0
- airflow/providers/edge3/__init__.py +39 -0
- airflow/providers/edge3/cli/__init__.py +16 -0
- airflow/providers/edge3/cli/api_client.py +206 -0
- airflow/providers/edge3/cli/dataclasses.py +95 -0
- airflow/providers/edge3/cli/edge_command.py +689 -0
- airflow/providers/edge3/example_dags/__init__.py +16 -0
- airflow/providers/edge3/example_dags/integration_test.py +164 -0
- airflow/providers/edge3/example_dags/win_notepad.py +83 -0
- airflow/providers/edge3/example_dags/win_test.py +342 -0
- airflow/providers/edge3/executors/__init__.py +22 -0
- airflow/providers/edge3/executors/edge_executor.py +367 -0
- airflow/providers/edge3/get_provider_info.py +99 -0
- airflow/providers/edge3/models/__init__.py +16 -0
- airflow/providers/edge3/models/edge_job.py +94 -0
- airflow/providers/edge3/models/edge_logs.py +73 -0
- airflow/providers/edge3/models/edge_worker.py +230 -0
- airflow/providers/edge3/openapi/__init__.py +19 -0
- airflow/providers/edge3/openapi/edge_worker_api_v1.yaml +808 -0
- airflow/providers/edge3/plugins/__init__.py +16 -0
- airflow/providers/edge3/plugins/edge_executor_plugin.py +229 -0
- airflow/providers/edge3/plugins/templates/edge_worker_hosts.html +175 -0
- airflow/providers/edge3/plugins/templates/edge_worker_jobs.html +69 -0
- airflow/providers/edge3/version_compat.py +36 -0
- airflow/providers/edge3/worker_api/__init__.py +17 -0
- airflow/providers/edge3/worker_api/app.py +43 -0
- airflow/providers/edge3/worker_api/auth.py +135 -0
- airflow/providers/edge3/worker_api/datamodels.py +190 -0
- airflow/providers/edge3/worker_api/routes/__init__.py +16 -0
- airflow/providers/edge3/worker_api/routes/_v2_compat.py +135 -0
- airflow/providers/edge3/worker_api/routes/_v2_routes.py +237 -0
- airflow/providers/edge3/worker_api/routes/health.py +28 -0
- airflow/providers/edge3/worker_api/routes/jobs.py +162 -0
- airflow/providers/edge3/worker_api/routes/logs.py +133 -0
- airflow/providers/edge3/worker_api/routes/worker.py +224 -0
- apache_airflow_providers_edge3-1.0.0.dist-info/METADATA +117 -0
- apache_airflow_providers_edge3-1.0.0.dist-info/RECORD +39 -0
- apache_airflow_providers_edge3-1.0.0.dist-info/WHEEL +4 -0
- apache_airflow_providers_edge3-1.0.0.dist-info/entry_points.txt +6 -0
@@ -0,0 +1,230 @@
|
|
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
|
+
from __future__ import annotations
|
18
|
+
|
19
|
+
import ast
|
20
|
+
import json
|
21
|
+
from datetime import datetime
|
22
|
+
from enum import Enum
|
23
|
+
from typing import TYPE_CHECKING
|
24
|
+
|
25
|
+
from sqlalchemy import Column, Integer, String, delete, select
|
26
|
+
|
27
|
+
from airflow.exceptions import AirflowException
|
28
|
+
from airflow.models.base import Base
|
29
|
+
from airflow.stats import Stats
|
30
|
+
from airflow.utils import timezone
|
31
|
+
from airflow.utils.log.logging_mixin import LoggingMixin
|
32
|
+
from airflow.utils.session import NEW_SESSION, provide_session
|
33
|
+
from airflow.utils.sqlalchemy import UtcDateTime
|
34
|
+
|
35
|
+
if TYPE_CHECKING:
|
36
|
+
from sqlalchemy.orm import Session
|
37
|
+
|
38
|
+
|
39
|
+
class EdgeWorkerVersionException(AirflowException):
|
40
|
+
"""Signal a version mismatch between core and Edge Site."""
|
41
|
+
|
42
|
+
pass
|
43
|
+
|
44
|
+
|
45
|
+
class EdgeWorkerState(str, Enum):
|
46
|
+
"""Status of a Edge Worker instance."""
|
47
|
+
|
48
|
+
STARTING = "starting"
|
49
|
+
"""Edge Worker is in initialization."""
|
50
|
+
RUNNING = "running"
|
51
|
+
"""Edge Worker is actively running a task."""
|
52
|
+
IDLE = "idle"
|
53
|
+
"""Edge Worker is active and waiting for a task."""
|
54
|
+
TERMINATING = "terminating"
|
55
|
+
"""Edge Worker is completing work and stopping."""
|
56
|
+
OFFLINE = "offline"
|
57
|
+
"""Edge Worker was shut down."""
|
58
|
+
UNKNOWN = "unknown"
|
59
|
+
"""No heartbeat signal from worker for some time, Edge Worker probably down."""
|
60
|
+
MAINTENANCE_REQUEST = "maintenance request"
|
61
|
+
"""Worker was requested to enter maintenance mode. Once worker receives this it will pause fetching jobs."""
|
62
|
+
MAINTENANCE_PENDING = "maintenance pending"
|
63
|
+
"""Edge worker received the request for maintenance, waiting for jobs to finish. Once jobs are finished will move to 'maintenance mode'."""
|
64
|
+
MAINTENANCE_MODE = "maintenance mode"
|
65
|
+
"""Edge worker is in maintenance mode. It is online but pauses fetching jobs."""
|
66
|
+
MAINTENANCE_EXIT = "maintenance exit"
|
67
|
+
"""Request worker to exit maintenance mode. Once the worker receives this state it will un-pause and fetch new jobs."""
|
68
|
+
OFFLINE_MAINTENANCE = "offline maintenance"
|
69
|
+
"""Worker was shut down in maintenance mode. It will be in maintenance mode when restarted."""
|
70
|
+
|
71
|
+
|
72
|
+
class EdgeWorkerModel(Base, LoggingMixin):
|
73
|
+
"""A Edge Worker instance which reports the state and health."""
|
74
|
+
|
75
|
+
__tablename__ = "edge_worker"
|
76
|
+
worker_name = Column(String(64), primary_key=True, nullable=False)
|
77
|
+
state = Column(String(20))
|
78
|
+
maintenance_comment = Column(String(1024))
|
79
|
+
_queues = Column("queues", String(256))
|
80
|
+
first_online = Column(UtcDateTime)
|
81
|
+
last_update = Column(UtcDateTime)
|
82
|
+
jobs_active = Column(Integer, default=0)
|
83
|
+
jobs_taken = Column(Integer, default=0)
|
84
|
+
jobs_success = Column(Integer, default=0)
|
85
|
+
jobs_failed = Column(Integer, default=0)
|
86
|
+
sysinfo = Column(String(256))
|
87
|
+
|
88
|
+
def __init__(
|
89
|
+
self,
|
90
|
+
worker_name: str,
|
91
|
+
state: str,
|
92
|
+
queues: list[str] | None,
|
93
|
+
first_online: datetime | None = None,
|
94
|
+
last_update: datetime | None = None,
|
95
|
+
maintenance_comment: str | None = None,
|
96
|
+
):
|
97
|
+
self.worker_name = worker_name
|
98
|
+
self.state = state
|
99
|
+
self.queues = queues
|
100
|
+
self.first_online = first_online or timezone.utcnow()
|
101
|
+
self.last_update = last_update
|
102
|
+
self.maintenance_comment = maintenance_comment
|
103
|
+
super().__init__()
|
104
|
+
|
105
|
+
@property
|
106
|
+
def sysinfo_json(self) -> dict:
|
107
|
+
return json.loads(self.sysinfo) if self.sysinfo else None
|
108
|
+
|
109
|
+
@property
|
110
|
+
def queues(self) -> list[str] | None:
|
111
|
+
"""Return list of queues which are stored in queues field."""
|
112
|
+
if self._queues:
|
113
|
+
return ast.literal_eval(self._queues)
|
114
|
+
return None
|
115
|
+
|
116
|
+
@queues.setter
|
117
|
+
def queues(self, queues: list[str] | None) -> None:
|
118
|
+
"""Set all queues of list into queues field."""
|
119
|
+
self._queues = str(queues) if queues else None
|
120
|
+
|
121
|
+
def add_queues(self, new_queues: list[str]) -> None:
|
122
|
+
"""Add new queue to the queues field."""
|
123
|
+
queues = self.queues if self.queues else []
|
124
|
+
queues.extend(new_queues)
|
125
|
+
# remove duplicated items
|
126
|
+
self.queues = list(set(queues))
|
127
|
+
|
128
|
+
def remove_queues(self, remove_queues: list[str]) -> None:
|
129
|
+
"""Remove queue from queues field."""
|
130
|
+
queues = self.queues if self.queues else []
|
131
|
+
for queue_name in remove_queues:
|
132
|
+
if queue_name in queues:
|
133
|
+
queues.remove(queue_name)
|
134
|
+
self.queues = queues
|
135
|
+
|
136
|
+
def update_state(self, state: str) -> None:
|
137
|
+
"""Update state field."""
|
138
|
+
self.state = state
|
139
|
+
|
140
|
+
|
141
|
+
def set_metrics(
|
142
|
+
worker_name: str,
|
143
|
+
state: EdgeWorkerState,
|
144
|
+
jobs_active: int,
|
145
|
+
concurrency: int,
|
146
|
+
free_concurrency: int,
|
147
|
+
queues: list[str] | None,
|
148
|
+
) -> None:
|
149
|
+
"""Set metric of edge worker."""
|
150
|
+
queues = queues if queues else []
|
151
|
+
connected = state not in (
|
152
|
+
EdgeWorkerState.UNKNOWN,
|
153
|
+
EdgeWorkerState.OFFLINE,
|
154
|
+
EdgeWorkerState.OFFLINE_MAINTENANCE,
|
155
|
+
)
|
156
|
+
maintenance = state in (
|
157
|
+
EdgeWorkerState.MAINTENANCE_MODE,
|
158
|
+
EdgeWorkerState.MAINTENANCE_EXIT,
|
159
|
+
EdgeWorkerState.OFFLINE_MAINTENANCE,
|
160
|
+
)
|
161
|
+
|
162
|
+
Stats.gauge(f"edge_worker.connected.{worker_name}", int(connected))
|
163
|
+
Stats.gauge("edge_worker.connected", int(connected), tags={"worker_name": worker_name})
|
164
|
+
|
165
|
+
Stats.gauge(f"edge_worker.maintenance.{worker_name}", int(maintenance))
|
166
|
+
Stats.gauge("edge_worker.maintenance", int(maintenance), tags={"worker_name": worker_name})
|
167
|
+
|
168
|
+
Stats.gauge(f"edge_worker.jobs_active.{worker_name}", jobs_active)
|
169
|
+
Stats.gauge("edge_worker.jobs_active", jobs_active, tags={"worker_name": worker_name})
|
170
|
+
|
171
|
+
Stats.gauge(f"edge_worker.concurrency.{worker_name}", concurrency)
|
172
|
+
Stats.gauge("edge_worker.concurrency", concurrency, tags={"worker_name": worker_name})
|
173
|
+
|
174
|
+
Stats.gauge(f"edge_worker.free_concurrency.{worker_name}", free_concurrency)
|
175
|
+
Stats.gauge("edge_worker.free_concurrency", free_concurrency, tags={"worker_name": worker_name})
|
176
|
+
|
177
|
+
Stats.gauge(f"edge_worker.num_queues.{worker_name}", len(queues))
|
178
|
+
Stats.gauge(
|
179
|
+
"edge_worker.num_queues",
|
180
|
+
len(queues),
|
181
|
+
tags={"worker_name": worker_name, "queues": ",".join(queues)},
|
182
|
+
)
|
183
|
+
|
184
|
+
|
185
|
+
def reset_metrics(worker_name: str) -> None:
|
186
|
+
"""Reset metrics of worker."""
|
187
|
+
set_metrics(
|
188
|
+
worker_name=worker_name,
|
189
|
+
state=EdgeWorkerState.UNKNOWN,
|
190
|
+
jobs_active=0,
|
191
|
+
concurrency=0,
|
192
|
+
free_concurrency=-1,
|
193
|
+
queues=None,
|
194
|
+
)
|
195
|
+
|
196
|
+
|
197
|
+
@provide_session
|
198
|
+
def request_maintenance(
|
199
|
+
worker_name: str, maintenance_comment: str | None, session: Session = NEW_SESSION
|
200
|
+
) -> None:
|
201
|
+
"""Write maintenance request to the db."""
|
202
|
+
query = select(EdgeWorkerModel).where(EdgeWorkerModel.worker_name == worker_name)
|
203
|
+
worker: EdgeWorkerModel = session.scalar(query)
|
204
|
+
worker.state = EdgeWorkerState.MAINTENANCE_REQUEST
|
205
|
+
worker.maintenance_comment = maintenance_comment
|
206
|
+
|
207
|
+
|
208
|
+
@provide_session
|
209
|
+
def exit_maintenance(worker_name: str, session: Session = NEW_SESSION) -> None:
|
210
|
+
"""Write maintenance exit to the db."""
|
211
|
+
query = select(EdgeWorkerModel).where(EdgeWorkerModel.worker_name == worker_name)
|
212
|
+
worker: EdgeWorkerModel = session.scalar(query)
|
213
|
+
worker.state = EdgeWorkerState.MAINTENANCE_EXIT
|
214
|
+
worker.maintenance_comment = None
|
215
|
+
|
216
|
+
|
217
|
+
@provide_session
|
218
|
+
def remove_worker(worker_name: str, session: Session = NEW_SESSION) -> None:
|
219
|
+
"""Remove a worker that is offline or just gone from DB."""
|
220
|
+
session.execute(delete(EdgeWorkerModel).where(EdgeWorkerModel.worker_name == worker_name))
|
221
|
+
|
222
|
+
|
223
|
+
@provide_session
|
224
|
+
def change_maintenance_comment(
|
225
|
+
worker_name: str, maintenance_comment: str | None, session: Session = NEW_SESSION
|
226
|
+
) -> None:
|
227
|
+
"""Write maintenance comment in the db."""
|
228
|
+
query = select(EdgeWorkerModel).where(EdgeWorkerModel.worker_name == worker_name)
|
229
|
+
worker: EdgeWorkerModel = session.scalar(query)
|
230
|
+
worker.maintenance_comment = maintenance_comment
|
@@ -0,0 +1,19 @@
|
|
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
|
+
"""OpenAPI Specs for Connexion API in Airflow 2.10.x."""
|
18
|
+
|
19
|
+
# Note: This module folder is to be removed once Airflow 2.10.x support is removed.
|