Spaces:
Configuration error
Configuration error
Baida—-
fix(registry): unterminated string literal line 692 — force re-sync [skip ci]
889ea3f verified | """ | |
| oracle_endpoints.py — Endpoint API per Gestione Nodo E (Oracle Cloud) | |
| Endpoint: | |
| GET /api/oracle/health — Health check Nodo E | |
| GET /api/oracle/metrics — Metriche Nodo E | |
| POST /api/oracle/sync — Sincronizzazione cluster | |
| POST /api/oracle/restart — Riavvio servizi | |
| GET /api/oracle/logs — Log backend remoto | |
| """ | |
| from fastapi import APIRouter, HTTPException | |
| from pydantic import BaseModel | |
| from typing import Optional | |
| import logging | |
| # Import oracle manager | |
| try: | |
| from backend.api.oracle_node_manager import ( | |
| initialize_oracle_node, | |
| get_oracle_health, | |
| sync_oracle_cluster, | |
| get_oracle_metrics, | |
| restart_oracle_services, | |
| ORACLE_NODE_E_ENABLED, | |
| ORACLE_NODE_E_IP, | |
| ) | |
| except ImportError: | |
| from oracle_node_manager import ( | |
| initialize_oracle_node, | |
| get_oracle_health, | |
| sync_oracle_cluster, | |
| get_oracle_metrics, | |
| restart_oracle_services, | |
| ORACLE_NODE_E_ENABLED, | |
| ORACLE_NODE_E_IP, | |
| ) | |
| _logger = logging.getLogger("oracle_endpoints") | |
| router = APIRouter(prefix="/api/oracle", tags=["oracle"]) | |
| # ── Modelli Pydantic ────────────────────────────────────────────────────── | |
| class OracleHealthResponse(BaseModel): | |
| ok: bool | |
| status: str | |
| metrics: Optional[dict] = None | |
| error: Optional[str] = None | |
| class OracleSyncResponse(BaseModel): | |
| ok: bool | |
| message: Optional[str] = None | |
| error: Optional[str] = None | |
| # ── Endpoint: Health Check ──────────────────────────────────────────────── | |
| async def oracle_health(): | |
| """Ritorna lo stato di salute del Nodo E.""" | |
| if not ORACLE_NODE_E_ENABLED: | |
| return OracleHealthResponse( | |
| ok=False, | |
| status="disabled", | |
| error="Oracle Node E è disabilitato", | |
| ) | |
| try: | |
| health = await get_oracle_health() | |
| return OracleHealthResponse(**health) | |
| except Exception as exc: | |
| _logger.error(f"Error getting oracle health: {exc}") | |
| raise HTTPException(500, "Error getting oracle health") | |
| # ── Endpoint: Metriche ──────────────────────────────────────────────────── | |
| async def oracle_metrics(): | |
| """Ritorna le metriche del Nodo E.""" | |
| if not ORACLE_NODE_E_ENABLED: | |
| return { | |
| "ok": False, | |
| "error": "Oracle Node E è disabilitato", | |
| } | |
| try: | |
| metrics = await get_oracle_metrics() | |
| return { | |
| "ok": True, | |
| "data": metrics, | |
| } | |
| except Exception as exc: | |
| _logger.error(f"Error getting oracle metrics: {exc}") | |
| raise HTTPException(500, "Error getting oracle metrics") | |
| # ── Endpoint: Sincronizzazione ─────────────────────────────────────────── | |
| async def oracle_sync(): | |
| """Sincronizza il Nodo E con il cluster principale.""" | |
| if not ORACLE_NODE_E_ENABLED: | |
| return OracleSyncResponse( | |
| ok=False, | |
| error="Oracle Node E è disabilitato", | |
| ) | |
| try: | |
| result = await sync_oracle_cluster() | |
| return OracleSyncResponse( | |
| ok=result.get("ok", False), | |
| message=result.get("message", result.get("output", "")), | |
| error=result.get("error"), | |
| ) | |
| except Exception as exc: | |
| _logger.error(f"Error syncing oracle cluster: {exc}") | |
| raise HTTPException(500, "Error syncing oracle cluster") | |
| # ── Endpoint: Riavvio Servizi ──────────────────────────────────────────── | |
| async def oracle_restart(): | |
| """Riavvia i servizi sul Nodo E.""" | |
| if not ORACLE_NODE_E_ENABLED: | |
| return { | |
| "ok": False, | |
| "error": "Oracle Node E è disabilitato", | |
| } | |
| try: | |
| result = await restart_oracle_services() | |
| return { | |
| "ok": result.get("ok", False), | |
| "message": result.get("message"), | |
| "health": result.get("health"), | |
| "error": result.get("error"), | |
| } | |
| except Exception as exc: | |
| _logger.error(f"Error restarting oracle services: {exc}") | |
| raise HTTPException(500, "Error restarting oracle services") | |
| # ── Endpoint: Log ──────────────────────────────────────────────────────── | |
| async def oracle_logs(lines: int = 100): | |
| """Ritorna i log del backend remoto.""" | |
| if not ORACLE_NODE_E_ENABLED: | |
| return { | |
| "ok": False, | |
| "error": "Oracle Node E è disabilitato", | |
| } | |
| try: | |
| from backend.api.oracle_node_manager import _oracle_manager | |
| logs = await _oracle_manager.get_logs(lines) | |
| return { | |
| "ok": True, | |
| "logs": logs, | |
| "lines": lines, | |
| } | |
| except Exception as exc: | |
| _logger.error(f"Error getting oracle logs: {exc}") | |
| raise HTTPException(500, "Error getting oracle logs") | |
| # ── Endpoint: Info ──────────────────────────────────────────────────────── | |
| async def oracle_info(): | |
| """Ritorna informazioni sul Nodo E.""" | |
| try: | |
| from backend.api.oracle_node_manager import ( | |
| ORACLE_NODE_E_ROLE, | |
| ORACLE_NODE_E_REGION, | |
| ORACLE_NODE_E_PORT, | |
| ) | |
| return { | |
| "enabled": ORACLE_NODE_E_ENABLED, | |
| "ip": ORACLE_NODE_E_IP, | |
| "role": ORACLE_NODE_E_ROLE, | |
| "region": ORACLE_NODE_E_REGION, | |
| "port": ORACLE_NODE_E_PORT, | |
| "node_id": "E", | |
| "type": "Oracle Cloud (OCI)", | |
| } | |
| except Exception as exc: | |
| _logger.error(f"Error getting oracle info: {exc}") | |
| raise HTTPException(500, "Error getting oracle info") | |