Phase 1 abgeschlossen: Node-Identitaet in Control Core verkabelt (§3.6, §6.3)
- NodeIdentity/NodeRole in hms_domain: persistente node_id aus userdata/identity, Rollen RENDER_NODE/COORDINATOR/CONTROL_DESK, plausible Kombinationen validiert, keine Auto-Leader-Wahl (§6.3) - Control Core: create_app(identity) injizierbar; Dev-Modus ephemeral; Registry registriert eigene Node; neue Endpunkte /system/identity (ohne Secrets, §27.1) und /cluster/nodes (UI-Kategorien §6.3) - 16 neue/aktualisierte Integrationstests; Gesamtsuite 199 gruen
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
"""FastAPI-Anwendung des Control Core (Phase-0-Minimalversion).
|
||||
"""FastAPI-Anwendung des Control Core.
|
||||
|
||||
Endpunkte:
|
||||
- GET /api/v1/system/health
|
||||
- GET /api/v1/system/identity (node_id, display_name, roles; nicht vertraulich)
|
||||
- GET /api/v1/system/capabilities
|
||||
- GET /api/v1/parameters
|
||||
- POST /api/v1/commands (parameter.set mit Revision-Prüfung und Idempotenz)
|
||||
- POST /api/v1/commands/{command_id}/release
|
||||
- GET /api/v1/diagnostics
|
||||
- GET /api/v1/cluster/nodes
|
||||
- WS /ws (State-Snapshot + Updates)
|
||||
|
||||
Commands folgen §23.2: command_id, type, expected_revision, actor, payload.
|
||||
Node-Identität: persistente node_id aus userdata/identity (§3.6, §6.3);
|
||||
im Dev-Modus ohne App-Root wird eine ephemeral-Identität erzeugt.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -19,6 +23,8 @@ import uuid
|
||||
|
||||
from fastapi import FastAPI, HTTPException, WebSocket, WebSocketDisconnect
|
||||
from hms_capabilities.probe import CapabilityReport
|
||||
from hms_cluster.registry import NodeRegistry
|
||||
from hms_domain.identity import NodeIdentity, NodeRole
|
||||
from hms_parameter.engine import (
|
||||
ControlSource,
|
||||
ParameterEngine,
|
||||
@@ -43,16 +49,34 @@ class ReleaseCommand(BaseModel):
|
||||
|
||||
|
||||
class _State:
|
||||
def __init__(self) -> None:
|
||||
def __init__(self, identity: NodeIdentity) -> None:
|
||||
self.identity = identity
|
||||
self.engine = ParameterEngine()
|
||||
self.registry = IdempotencyRegistry()
|
||||
self.report = CapabilityReport()
|
||||
self.nodes = NodeRegistry()
|
||||
self.subscribers: list[asyncio.Queue] = []
|
||||
|
||||
|
||||
def create_app() -> FastAPI:
|
||||
def create_app(identity: NodeIdentity | None = None) -> FastAPI:
|
||||
"""Erzeugt die Control-Core-App.
|
||||
|
||||
identity: produktiv vom Launcher geladene persistente Identität
|
||||
(userdata/identity). Ohne Angabe gilt Dev-Modus mit ephemeral-Identität
|
||||
(jede App-Instanz erhält eine eigene ID; für Showbetrieb unzulässig).
|
||||
"""
|
||||
if identity is None:
|
||||
identity = NodeIdentity.ephemeral(
|
||||
"Dev Node", frozenset({NodeRole.RENDER_NODE, NodeRole.COORDINATOR})
|
||||
)
|
||||
app = FastAPI(title="HMS MediaEngine Control Core", version="0.1.0")
|
||||
state = _State()
|
||||
state = _State(identity)
|
||||
# Eigene Node in die Registry eintragen (§6.3)
|
||||
state.nodes.register(
|
||||
node_id=identity.node_id,
|
||||
display_name=identity.display_name,
|
||||
roles=tuple(r.value for r in identity.roles),
|
||||
)
|
||||
|
||||
def _broadcast(event: dict) -> None:
|
||||
for queue in list(state.subscribers):
|
||||
@@ -60,7 +84,23 @@ def create_app() -> FastAPI:
|
||||
|
||||
@app.get("/api/v1/system/health")
|
||||
async def health() -> dict:
|
||||
return {"status": "ok", "phase": 0, "revision": state.engine.revision}
|
||||
return {
|
||||
"status": "ok",
|
||||
"phase": 1,
|
||||
"node_id": state.identity.node_id,
|
||||
"revision": state.engine.revision,
|
||||
}
|
||||
|
||||
@app.get("/api/v1/system/identity")
|
||||
async def system_identity() -> dict:
|
||||
"""Nicht vertrauliche Selbstauskunft (§27.1: keine Tokens/Secrets)."""
|
||||
return {
|
||||
"node_id": state.identity.node_id,
|
||||
"display_name": state.identity.display_name,
|
||||
"roles": sorted(r.value for r in state.identity.roles),
|
||||
"renders_locally": state.identity.renders_locally,
|
||||
"is_coordinator": state.identity.is_coordinator,
|
||||
}
|
||||
|
||||
@app.get("/api/v1/system/capabilities")
|
||||
async def capabilities() -> dict:
|
||||
@@ -127,11 +167,29 @@ def create_app() -> FastAPI:
|
||||
@app.get("/api/v1/diagnostics")
|
||||
async def diagnostics() -> dict:
|
||||
return {
|
||||
"renderer": "not_connected", # IPC-Handshake folgt in Phase 1 (ADR-0003)
|
||||
"renderer": "not_connected", # IPC-Handshake folgt (ADR-0003)
|
||||
"artnet": "not_started",
|
||||
"revision": state.engine.revision,
|
||||
"node_id": state.identity.node_id,
|
||||
}
|
||||
|
||||
@app.get("/api/v1/cluster/nodes")
|
||||
async def cluster_nodes() -> dict:
|
||||
"""Node-Übersicht nach UI-Kategorien (§6.3): getrennt aufgeführt."""
|
||||
nodes = []
|
||||
for entry in state.nodes.all():
|
||||
state.nodes.evaluate_health(entry.node_id)
|
||||
nodes.append(
|
||||
{
|
||||
"node_id": entry.node_id,
|
||||
"display_name": entry.display_name,
|
||||
"roles": list(entry.roles),
|
||||
"health": entry.health.value,
|
||||
"category": entry.category.value,
|
||||
}
|
||||
)
|
||||
return {"self": state.identity.node_id, "nodes": nodes}
|
||||
|
||||
@app.websocket("/ws")
|
||||
async def websocket_endpoint(ws: WebSocket) -> None:
|
||||
await ws.accept()
|
||||
|
||||
Reference in New Issue
Block a user