Conversation
e0824ea to
12663bb
Compare
Walkthrough引入虚拟机模型挂载功能相关的基础设施:新增数据库表 Changes
Sequence Diagram(s)sequenceDiagram
participant Test as Test / API 客户端
participant Mgr as 管理节点 (API Server)
participant KVM as KVM Agent
participant DB as 数据库
Test->>Mgr: 调用 mountModelToVmInstance(action)
Mgr->>DB: 写入/更新 VmModelMountVO(uuid, vmInstanceUuid, mountPath, ...)
Mgr->>KVM: POST /aimodel/attach (KvmAttachModelCmd)
KVM-->>Mgr: KvmAttachModelResponse (status)
Mgr-->>Test: 返回 API 结果
Estimated code review effort🎯 3 (中等) | ⏱️ ~20 分钟 兔子的庆祝诗
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
Comment |
Resolves: ZSTAC-83157 Change-Id: Ifc0f1fab5634ef4387c6cbe8daf1a20af00664fa
12663bb to
a0227cf
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
plugin/kvm/src/main/java/org/zstack/kvm/KVMAgentCommands.java (1)
5208-5249: 命名建议:考虑移除 "Kvm" 前缀以保持一致性文件中其他类似的命令类如
AttachDataVolumeCmd、DetachNicCommand均未使用 "Kvm" 前缀,因为它们已经嵌套在KVMAgentCommands类中。建议将KvmAttachModelCmd重命名为AttachModelCmd,KvmDetachModelCmd重命名为DetachModelCmd,以保持命名风格一致。另外,如果
zdfsUrl可能包含嵌入式凭据(如protocol://user:password@host/path),建议添加@NoLogging注解以避免敏感信息泄露到日志中。♻️ 建议的命名修改
- public static class KvmAttachModelCmd extends AgentCommand { + public static class AttachModelCmd extends AgentCommand { `@GrayVersion`(value = "5.5.12") private String vmInstanceUuid; `@GrayVersion`(value = "5.5.12") + `@NoLogging` // 如果可能包含凭据 private String zdfsUrl;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@plugin/kvm/src/main/java/org/zstack/kvm/KVMAgentCommands.java` around lines 5208 - 5249, Rename the nested command class KvmAttachModelCmd to AttachModelCmd (and likewise KvmDetachModelCmd to DetachModelCmd) to match the naming convention used by other nested commands in KVMAgentCommands and update all references/usages accordingly; also, if zdfsUrl can contain embedded credentials, annotate the zdfsUrl field with `@NoLogging` to prevent sensitive data from being logged (ensure the import/annotation is available and add it to the field in the AttachModelCmd class).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@plugin/kvm/src/main/java/org/zstack/kvm/KVMAgentCommands.java`:
- Around line 5208-5249: Rename the nested command class KvmAttachModelCmd to
AttachModelCmd (and likewise KvmDetachModelCmd to DetachModelCmd) to match the
naming convention used by other nested commands in KVMAgentCommands and update
all references/usages accordingly; also, if zdfsUrl can contain embedded
credentials, annotate the zdfsUrl field with `@NoLogging` to prevent sensitive
data from being logged (ensure the import/annotation is available and add it to
the field in the AttachModelCmd class).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml (via .coderabbit.yaml)
Review profile: CHILL
Plan: Pro
Run ID: 559d8172-5d21-4814-ad7c-9e1d28a5fde1
⛔ Files ignored due to path filters (8)
sdk/src/main/java/SourceClassMap.javais excluded by!sdk/**sdk/src/main/java/org/zstack/sdk/MountModelToVmInstanceAction.javais excluded by!sdk/**sdk/src/main/java/org/zstack/sdk/MountModelToVmInstanceResult.javais excluded by!sdk/**sdk/src/main/java/org/zstack/sdk/QueryVmModelMountAction.javais excluded by!sdk/**sdk/src/main/java/org/zstack/sdk/QueryVmModelMountResult.javais excluded by!sdk/**sdk/src/main/java/org/zstack/sdk/UnmountModelFromVmInstanceAction.javais excluded by!sdk/**sdk/src/main/java/org/zstack/sdk/UnmountModelFromVmInstanceResult.javais excluded by!sdk/**sdk/src/main/java/org/zstack/sdk/VmModelMountInventory.javais excluded by!sdk/**
📒 Files selected for processing (4)
conf/db/upgrade/V5.5.12__schema.sqlplugin/kvm/src/main/java/org/zstack/kvm/KVMAgentCommands.javaplugin/kvm/src/main/java/org/zstack/kvm/KVMConstant.javatestlib/src/main/java/org/zstack/testlib/ApiHelper.groovy
🚧 Files skipped from review as they are similar to previous changes (2)
- plugin/kvm/src/main/java/org/zstack/kvm/KVMConstant.java
- conf/db/upgrade/V5.5.12__schema.sql
|
Comment from ye.zou: Code Review: ZSTAC-83157 — 云主机直接挂载模型仓库模型关联 MR: zstack !9404 + premium !13252 | 36 files | Verdict: CONDITIONAL 🔴 Critical1. 挂载路径未存回 normalized 值 — 重复检测可绕过
后果: 修复:interceptor 里加 2. 无 DB 唯一约束 — 并发挂载竞态
修复:SQL schema 加 🟡 Major3. 双重 dispatch — handleLocalMessage 里塞了 API 消息(死代码)
4. TOCTOU — VM 状态和 hostUuid 在 interceptor 和 agent 调用之间可变 interceptor 检查 5. CascadeExtension 是空壳
6. VM 重启后 DB 状态变脏 KVM agent 做的挂载在 VM 重启后消失,DB 仍然 7. Unmount 不处理 Stopped VM
🔵 Minor8. SQL schema 缺 modelUuid FK — JPA 有 9. 10. SQL 文件缺末尾换行 — ✅ 做得好
结论:整体设计方向正确,FlowChain + interceptor + cascade 三层符合 ZStack 惯例。路径 normalize 和唯一约束是必须修的,其他 major 建议本轮修复或加 TODO 跟踪。 — AI Code Review (Linus Mode) |
|
Comment from ye.zou: 补充:字段命名和协议设计 — 不要把实现细节烧进接口当前 DB schema 和 agent 协议里有多个字段硬编码了 JuiceFS 实现:
为什么现在必须改
建议改为
API 层( 原则:面向能力命名,不面向实现命名。 你的能力是"把模型源路径挂载到 VM 目标路径",不是"把 JuiceFS 子目录通过 ZDFS URL 挂到 VM"。 — AI Code Review (补充) |
Resolves: ZSTAC-83157
Change-Id: Ifc0f1fab5634ef4387c6cbe8daf1a20af00664fa
sync from gitlab !9404