Переглянути джерело

2.15.2 算法服务随 serve 默认起: cli.services() 纳入 algorithm 组件(端口取 serve.json) + 网关路由 /algorithm→18050 + ops 兜底端口表 + offline_up.sh + registry schema; 实测直连与经网关 /algorithm/healthz 均 200, 门禁与 check 全绿

zhouyang.xie 1 тиждень тому
батько
коміт
c96bcbcbbb

+ 5 - 0
app_backEnd/app_backEnd_guanlan/cli.py

@@ -112,6 +112,11 @@ def services(c):
     P = py(c); h = c["host"]; hp = public_host(c)
     return [
         ("detail", c["detail"], [P, "scripts/windscada_serve.py", "--host", h, "--port", str(c["detail"])]),
+        # ★2026-09-29 用户令:**算法服务随 serve 默认起**(算法层 = Python + FastAPI,P10)。
+        #   端口取自 configs/serve.json 的 algorithm(缺省 18050);它只读、不改盘上产物,
+        #   是后端(各栈)与前端调用算法的统一入口。
+        ("algorithm", c.get("algorithm", 18050),
+         [P, "scripts/algorithm_service.py", "--host", h, "--port", str(c.get("algorithm", 18050))]),
         ("cms", c["cms"], [P, "scripts/windcms.py", "serve", "--farm", "rudong", "--port", str(c["cms"])]),
         ("viewer", c["viewer"], [P, "scripts/static_server.py", "--port", str(c["viewer"]), "--host", h,
                                  "--dir", str(ROOT / c["viewer_dir"]), "--comp", "viewer"]),

+ 4 - 1
app_backEnd/app_backEnd_guanlan/gateway.py

@@ -34,10 +34,13 @@ _DEFAULT_ROUTES = [
     ("/sim/sys", 18792, "/0_四系统合页.html", "/0_四系统合页.html", "仿真·四系统合页"),
     ("/sim", 18791, "/sc1_sim_demo.html", "/sc1_sim_demo.html", "仿真与回放"),
     ("/viewer", 64292, "/unit-workbench.html", "/unit-workbench.html", "三维拆装工作台"),
+    # ★2026-09-29 用户令:算法服务随 serve 默认起,并经网关可达(算法 = Python + FastAPI,P10)。
+    #   前缀 `/algorithm` → 上游 18050;前端与后端(各栈)都从这一个源站调算法,免去直连端口。
+    ("/algorithm", 18050, "/healthz", "/healthz", "算法服务 (FastAPI)"),
     ("/local-ai", OLLAMA[1], "/api/tags", "/api/tags", "本机模型 Ollama"),
 ]
 _PORT_KEY = {'/detail': 'detail', '/cms': 'cms', '/sim/sys': 'sim_sys', '/sim': 'sim',
-             '/viewer': 'viewer', '/local-ai': 'ollama'}
+             '/viewer': 'viewer', '/algorithm': 'algorithm', '/local-ai': 'ollama'}
 
 
 def _upstream_ports() -> dict:

+ 2 - 1
app_backEnd/app_backEnd_guanlan/ops.py

@@ -58,7 +58,8 @@ OFF_MANIFEST = OFF / 'manifest.json'
 PY = P.venv_python() if hasattr(P, 'venv_python') else sys.executable
 
 # 组件服务 (不含网关): 名字 → 端口。端口真源在 configs/serve.json, 这里只是网关不可用时的兜底。
-DEFAULT_PORTS = dict(detail=18033, cms=18020, sim=18791, sim_sys=18792, viewer=64292)
+DEFAULT_PORTS = dict(detail=18033, cms=18020, sim=18791, sim_sys=18792, viewer=64292,
+                     algorithm=18050)   # ★算法服务(Python+FastAPI, P10):随 serve 默认起
 GATEWAY_PORT = 28084
 KEEP_WHEN_STOPPING = 'gateway'      # 停服务默认保留网关(控制台自己在上面)
 

+ 1 - 1
configs/registry.yaml

@@ -17,7 +17,7 @@ top_level:
   - file: serve.json
     kind: 运行期单件配置
     consumers: [guanlan.py, scripts/guanlan_ops.py, scripts/page_fingerprint.py, scripts/guanlan_gateway.py, scripts/check_transferable.py]
-    schema: "{host, gateway, detail, cms, sim, sim_sys, viewer, ollama, python?, raw_dir?}"
+    schema: "{host, public_host?, gateway, detail, algorithm, cms, sim, sim_sys, viewer, ollama, python?, raw_dir?}"
   - file: models.json
     kind: 运行期单件配置
     consumers: [guanlan.py, app_ontology/app_ontology_guanlan/ontology/llm_gate.py, app_ontology/app_ontology_guanlan/ontology/fast_agent.py]

+ 2 - 0
scripts/guanlan_offline_up.sh

@@ -7,6 +7,8 @@ up(){ lsof -nP -iTCP:$1 -sTCP:LISTEN >/dev/null 2>&1; }
 start(){ local port=$1; shift; if up $port; then echo "  $port 已在运行 (复用)"; else echo "  $port 启动: $*"; (cd $R && nohup "$@" > $LOG/serve$port.log 2>&1 &); fi }
 start 18033 $PY scripts/windscada_serve.py --host 127.0.0.1 --port 18033
 start 18020 $PY scripts/windcms.py serve --farm rudong --port 18020
+# ★2026-09-29 用户令:算法服务随 serve 默认起(算法 = Python + FastAPI,P10;只读,经网关 /algorithm 可达)
+start 18050 $PY scripts/algorithm_service.py --host 127.0.0.1 --port 18050
 start 64292 python3 -m http.server 64292 --bind 127.0.0.1 --directory "$R/release/viewer"
 start 18792 python3 -u "$R/release/sim_sys_server.py"
 start 18791 python3 -m http.server 18791 --bind 127.0.0.1 --directory "$R/resources/oem_envision_sc1_rudong2014"