foms/app/foms.py
yumoqing e1be45e940 refactor: FOMS 单体拆分为核心 + 三独立模块
按产线规范将 FOMS 单体拆分为 4 部分:

【foms 核心(保留在本仓库)】主备切换本身
  表:clusters、nodes、switchover_logs、node_commands(新增)
  功能:集群/节点 CRUD、Agent 心跳、故障切换/切回、仪表盘、远程命令
  远程命令改用专用 node_commands 表(原借用 node_logs 的 MVP 方案,顺手修 P1 隐患)
  仪表盘跨模块只读聚合(同库松耦合 SQL)

【dbbackup 模块(独立仓库)】数据库全量备份 + 日志同步(binlog复制)管理
  表 dbbackup_replications(原 sync_databases)/jobs(备份任务)/records(备份记录)
  新建备份执行/记录/清理逻辑

【filesync 模块(独立仓库)】运行文件同步(rsync)
  表 filesync_directories(原 sync_directories)

【hostwatch 模块(独立仓库)】日志监控+日志分析+主机指标
  表 hostwatch_logs(原 node_logs)/metrics(原 node_metrics)/rules/events
  新建日志归类、规则匹配告警、聚合分析逻辑

设计(松耦合方案 A):
  · 拆出模块表加模块名前缀,cluster_id/node_id 仅存字符串不建外键
  · 拆出模块不 import foms 核心代码,可独立部署测试
  · 单 Agent 多端点:心跳→foms、指标日志→hostwatch、复制→dbbackup、rsync→filesync
  · 模块 wwwroot 软链到主 wwwroot/<模块名>(URL 前缀隔离)

Agent 端点拆分:report_health 拆为 report_db_health/report_dir_health,
metrics 上报改 /hostwatch/api/,_api_post/_api_get 支持完整路径。
2026-08-26 15:29:45 +08:00

39 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""FOMS — Failover Management System 主入口"""
import os, sys
# Add root so sibling modules are importable
root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, root_dir)
from bricks_for_python.init import load_pybricks
from ahserver.webapp import webapp
from ahserver.serverenv import ServerEnv
# Foundation modules
from rbac.init import load_rbac
from appbase.init import load_appbase
# Business modules核心 + 三个拆出的独立模块)
from foms.init import load_foms
from dbbackup.init import load_dbbackup
from filesync.init import load_filesync
from hostwatch.init import load_hostwatch
from app.global_func import set_globalvariable
def init():
set_globalvariable()
load_pybricks()
load_appbase()
load_rbac()
load_foms() # 核心:集群/节点/切换/心跳/远程命令
load_dbbackup() # 数据库备份 + 日志同步binlog 复制)
load_filesync() # 运行文件同步rsync
load_hostwatch() # 日志监控 + 日志分析 + 主机指标
if __name__ == '__main__':
webapp(init)