- Implemented Pydantic models for Kubernetes cluster state representation in `cluster.py`. - Created a `Resource` class for converting JSON/dict to Python objects in `resource.py`. - Established user models and services for user management, including password hashing and JWT token generation. - Developed application orchestration services for managing Kubernetes applications, including installation and uninstallation. - Added cluster service for retrieving cluster status and health reports. - Introduced node service for fetching node resource details and health status. - Implemented user service for handling user authentication and management.
34 lines
1.0 KiB
Python
34 lines
1.0 KiB
Python
|
|
from pydantic import BaseModel
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
from ocdp.orchestration import Cluster
|
|
|
|
# 假设的依赖和 Service 函数导入路径
|
|
from ocdp.orchestration import get_cluster
|
|
from ocdp.services.orchestration import node_service
|
|
|
|
# --- Response Models for this endpoint ---
|
|
class NodeHealthStatus(BaseModel):
|
|
is_ready: bool
|
|
pressures: dict[str, bool]
|
|
|
|
HealthReportResponse = dict[str, NodeHealthStatus]
|
|
|
|
# --- Router Definition ---
|
|
router = APIRouter()
|
|
|
|
@router.get(
|
|
"/health",
|
|
response_model=HealthReportResponse,
|
|
# summary="获取集群节点健康状态"
|
|
)
|
|
def get_health(cluster: Cluster = Depends(get_cluster)):
|
|
"""
|
|
获取集群所有节点的健康状态报告。
|
|
- **is_ready**: 节点是否就绪。
|
|
- **pressures**: 节点的各项压力状态,`true` 表示存在压力。
|
|
"""
|
|
try:
|
|
return node_service.get_cluster_health_report(cluster)
|
|
except RuntimeError as e:
|
|
raise HTTPException(status_code=500, detail=str(e)) |