-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmodern_stack.py
More file actions
146 lines (132 loc) · 4.9 KB
/
modern_stack.py
File metadata and controls
146 lines (132 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
"""Modern advanced orchestration stack primitives.
Implements a configurable orchestration profile that combines:
- FastAPI API layer
- Airflow/Temporal orchestrators
- Kafka eventing
- Kubernetes jobs for execution
- Ray for distributed compute
- PostgreSQL + object storage persistence
- Prometheus/Grafana/ELK observability
- JWT + RBAC + secrets manager security
"""
from __future__ import annotations
from dataclasses import dataclass
from datetime import datetime, timezone
from typing import Any, Dict, List
from uuid import uuid4
from config import settings
@dataclass
class StackComponent:
name: str
enabled: bool
config: Dict[str, Any]
class ModernOrchestrationStack:
"""Service layer for the high-end orchestration stack."""
def architecture(self) -> Dict[str, Any]:
"""Return stack topology and active configuration."""
return {
"api_layer": StackComponent(
name="FastAPI",
enabled=True,
config={"base_path": settings.API_PREFIX},
).__dict__,
"orchestration": StackComponent(
name=settings.ORCHESTRATION_ENGINE,
enabled=True,
config={
"temporal_enabled": settings.TEMPORAL_ENABLED,
"temporal_address": settings.TEMPORAL_ADDRESS,
"namespace": settings.TEMPORAL_NAMESPACE,
"task_queue": settings.TEMPORAL_TASK_QUEUE,
},
).__dict__,
"event_layer": StackComponent(
name="kafka",
enabled=settings.KAFKA_ENABLED,
config={
"bootstrap_servers": settings.KAFKA_BOOTSTRAP_SERVERS,
"topic": settings.KAFKA_EXECUTION_TOPIC,
},
).__dict__,
"execution": StackComponent(
name="kubernetes-jobs",
enabled=True,
config={
"namespace": settings.KUBERNETES_NAMESPACE,
"default_image": settings.KUBERNETES_JOB_IMAGE,
"service_account": settings.KUBERNETES_SERVICE_ACCOUNT,
},
).__dict__,
"distributed_compute": StackComponent(
name="ray",
enabled=settings.RAY_ENABLED,
config={
"dashboard_url": settings.RAY_DASHBOARD_URL,
"entrypoint": settings.RAY_JOB_ENTRYPOINT,
},
).__dict__,
"storage": {
"database": "postgresql",
"object_storage": {
"enabled": settings.OBJECT_STORAGE_ENABLED,
"bucket": settings.OBJECT_STORAGE_BUCKET,
"endpoint": settings.OBJECT_STORAGE_ENDPOINT,
},
},
"monitoring": {
"metrics": ["prometheus", "grafana"],
"logs": ["elasticsearch", "logstash", "kibana"],
},
"security": {
"auth": "jwt",
"authorization": "rbac",
"secrets_provider": settings.SECRETS_PROVIDER,
},
}
def submit_execution(self, pipeline_id: str, payload: Dict[str, Any]) -> Dict[str, Any]:
"""Create a stack-aware execution command envelope.
This API intentionally stays transport-agnostic and returns metadata that
can be consumed by workers/connectors for Airflow/Temporal/Kubernetes/Ray.
"""
execution_id = f"exec-{uuid4()}"
now = datetime.now(tz=timezone.utc).isoformat()
commands: List[Dict[str, Any]] = [
{
"layer": "orchestration",
"engine": settings.ORCHESTRATION_ENGINE,
"action": "start_workflow",
},
{
"layer": "execution",
"engine": "kubernetes-jobs",
"action": "submit_job",
"namespace": settings.KUBERNETES_NAMESPACE,
"image": settings.KUBERNETES_JOB_IMAGE,
},
]
if settings.RAY_ENABLED:
commands.append(
{
"layer": "distributed_compute",
"engine": "ray",
"action": "submit_ray_job",
"dashboard": settings.RAY_DASHBOARD_URL,
}
)
if settings.KAFKA_ENABLED:
commands.append(
{
"layer": "event_layer",
"engine": "kafka",
"action": "publish_event",
"topic": settings.KAFKA_EXECUTION_TOPIC,
}
)
return {
"execution_id": execution_id,
"pipeline_id": pipeline_id,
"submitted_at": now,
"status": "accepted",
"commands": commands,
"payload": payload,
}