feat(scheduler): lifecycle 真实接线适配器(2/2) + 装配 BuildRealConfig
把 scheduler 的 stub lifecycle 换成 SQL 后端真实实现,并接入 server:
- SQLLifecycle:MySQL 后端,同时满足 detect.LifecycleService 与
orchestrate.LifecycleService(两个 thin adapter 包装共享核心)。
- TransitionStatus:乐观锁 UPDATE nodes SET status WHERE id AND status=from
→ rows affected(1=成功/0=冲突 no-op)+ 写 node_events(按状态映射 enum,
eventForStatus 纯函数已单测)+ bump directory_version,全在一个事务内。
- ListNodes/GetNode/SetWeight/BumpVersion/GetLoad(读 LoadCache)/WriteAuditLog。
- 已知限制:无历史 load 表 → GetLoadHistory 返回当前点(掉量规则安全降级);
destroy 的 cert 撤销留 TODO(provision 已拆 VM,撤销为纵深防御,待机群再接)。
- BuildRealConfig:用真实 lifecycle + provisionAdapter 装配三循环。
- main.go:SCHED_ENABLED 且有 DB 时走 BuildRealConfig(provision 无厂商凭证则
CreateNode 优雅失败、替换保持 pending),否则回退 stub。
- 全量 server 23 包测试通过;e2e(判封→drain→换机→置备)待机群+厂商凭证验证。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package scheduler
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestEventForStatus(t *testing.T) {
|
||||
cases := map[string]string{
|
||||
"up": "marked_up",
|
||||
"draining": "draining",
|
||||
"blocked_suspect": "blocked_suspect",
|
||||
"blocked_confirmed": "blocked_confirmed",
|
||||
"destroyed": "destroyed",
|
||||
"probing": "provisioned",
|
||||
"provisioning": "provisioned",
|
||||
"down": "", // no event enum → skip writing an event row
|
||||
"bogus": "",
|
||||
}
|
||||
for status, want := range cases {
|
||||
if got := eventForStatus(status); got != want {
|
||||
t.Errorf("eventForStatus(%q) = %q, want %q", status, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user