feat(server): API proxy routes for services and nodes (TDD)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-05 22:24:20 -06:00
parent 9af81e3001
commit f13d6151e3
5 changed files with 558 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
"""Node health endpoints for the Farm Manager API server."""
import asyncio
import httpx
from fastapi import APIRouter
from server.config import get_nodes
router = APIRouter()
async def _check_node_health(http_client: httpx.AsyncClient, node: dict) -> dict:
"""Query a single agent's /health endpoint and return a NodeStatus dict."""
url = f"http://{node['host']}:{node['agent_port']}/health"
try:
resp = await http_client.get(url, timeout=5.0)
resp.raise_for_status()
data = resp.json()
return {
"name": node["name"],
"host": node["host"],
"healthy": True,
"containers_total": data.get("containers_total", 0),
"error": None,
}
except Exception as exc:
return {
"name": node["name"],
"host": node["host"],
"healthy": False,
"containers_total": 0,
"error": str(exc),
}
@router.get("/api/nodes")
async def list_nodes():
"""Return all configured nodes with their current health status."""
nodes = get_nodes()
async with httpx.AsyncClient() as client:
tasks = [_check_node_health(client, node) for node in nodes]
results = await asyncio.gather(*tasks)
return list(results)