Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix:删除gateway主备模式的接口处理逻辑

wangxinae65d51f63a1
diff --git a/packages/jiuwenclaw-ee/gateway/extensions/manager_config_receiver/http/app.py b/packages/jiuwenclaw-ee/gateway/extensions/manager_config_receiver/http/app.py
index e36d89119f..5f53282004 100644
--- a/packages/jiuwenclaw-ee/gateway/extensions/manager_config_receiver/http/app.py
+++ b/packages/jiuwenclaw-ee/gateway/extensions/manager_config_receiver/http/app.py
@@ -2,47 +2,18 @@
from __future__ import annotations
-from fastapi import APIRouter, FastAPI, HTTPException, Request, Response
-from starlette.middleware.base import BaseHTTPMiddleware
+from fastapi import APIRouter, FastAPI
-from ..infrastructure.ha import gateway_deployment_mode, is_gateway_primary
from ..routers.application_config_routers import application_config_router
from ..routers.instance_resource_routers import instance_resource_router
from ..routers.instance_routers import instance_router
from ..routers.register_router import register_router
from ..routers.template_routers import templates_router
-_WRITE_METHODS = frozenset({"POST", "PUT", "PATCH", "DELETE"})
-# 探活路径始终放行(STANDBY 也需可被 Manager 探测)
-_WRITE_ALLOW_PATH_SUFFIXES = (
- "/api/v1/health",
- "/api/v1/ready",
- "/api/health",
- "/docs",
- "/openapi.json",
-)
-
-
-class PrimaryWriteGateMiddleware(BaseHTTPMiddleware):
- """active-standby 下 STANDBY 拒绝写请求(503),读与探活路径放行。"""
-
- async def dispatch(self, request: Request, call_next):
- if request.method.upper() in _WRITE_METHODS:
- path = request.url.path
- if not any(path.endswith(s) or path == s for s in _WRITE_ALLOW_PATH_SUFFIXES):
- if gateway_deployment_mode() == "active-standby" and not is_gateway_primary():
- return Response(
- content='{"detail":"gateway standby; write only on PRIMARY"}',
- status_code=503,
- media_type="application/json",
- )
- return await call_next(request)
-
def create_app() -> FastAPI:
- """Gateway 本机接口:无 ``/instances/{jiuwenclaw_id}``;实例 id 取自 ``JIUWENCLAW_ID``(未设则自动生成)。"""
+ """Gateway 本机接口:无路径级实例段;``JIUWENCLAW_ID`` 仅作 Manager 注册/探活身份(未设则自动生成)。"""
app = FastAPI(title="Gateway Manager Config Receiver", docs_url="/docs", redoc_url=None)
- app.add_middleware(PrimaryWriteGateMiddleware)
@app.get("/api/health", tags=["System"])
async def system_health() -> dict[str, str]:
@@ -52,11 +23,8 @@ def create_app() -> FastAPI:
@v1.get("/ready", tags=["System"])
async def ready() -> dict[str, str]:
- """K8s readiness:active-standby 仅 PRIMARY 返回 200。"""
- mode = gateway_deployment_mode()
- if mode == "active-standby" and not is_gateway_primary():
- raise HTTPException(status_code=503, detail="standby")
- return {"status": "ready", "role": "PRIMARY" if is_gateway_primary() else "ACTIVE"}
+ """K8s readiness。"""
+ return {"status": "ready"}
v1.include_router(templates_router, tags=["Templates"])
v1.include_router(register_router, tags=["Instances"])
diff --git a/packages/jiuwenclaw-ee/gateway/extensions/manager_config_receiver/infrastructure/ha.py b/packages/jiuwenclaw-ee/gateway/extensions/manager_config_receiver/infrastructure/ha.py
deleted file mode 100644
index 20d66774d0..0000000000
--- a/packages/jiuwenclaw-ee/gateway/extensions/manager_config_receiver/infrastructure/ha.py
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved.
-"""主备角色:active-standby 下仅 PRIMARY 接受写流量 / Ready。"""
-
-from __future__ import annotations
-
-import os
-
-
-def gateway_deployment_mode() -> str:
- return (os.getenv("DEPLOYMENT_MODE") or "standalone").strip().lower() or "standalone"
-
-
-def is_gateway_primary() -> bool:
- """standalone / distributed:始终视为可写;active-standby:读 LeaderElection。"""
- mode = gateway_deployment_mode()
- if mode != "active-standby":
- return True
- try:
- from jiuwenswarm.gateway.leader_election import LeaderElection
-
- le = LeaderElection.get_instance()
- return bool(le.is_primary)
- except Exception: # noqa: BLE001
- # 选主未就绪时保守:不 Ready,避免 STANDBY 抢流量
- return False