Skip to content

Conversation

zstack-robot-1
Copy link
Collaborator

Add overloaded method with PrimaryStorageVO parameter
Initialize controller in activeIscsiVolume when null

Resolves: ZSTAC-77315

Change-Id: I75656f6178726675636f6d63656b666873786d62

sync from gitlab !8410

Copy link

coderabbitai bot commented Sep 12, 2025

Walkthrough

调整 BlockExternalPrimaryStorageFactory.activeIscsiVolume 方法签名:在原有参数 (String clientIqn, BaseVolumeInfo vol, boolean shareable) 基础上新增 PrimaryStorageVO vo 参数,方法返回类型保持不变。

Changes

Cohort / File(s) Summary
存储工厂方法签名调整
storage/src/main/java/org/zstack/storage/addon/primary/BlockExternalPrimaryStorageFactory.java
activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean shareable) 改为 activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean shareable, PrimaryStorageVO vo)(新增 PrimaryStorageVO 参数)。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Pre-merge checks (2 passed, 1 warning)

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed PR 标题简洁且聚焦于主要变更:明确指出在 activeIscsiVolume 为 null 时初始化 controller 的修复,这与 PR 目标和变更摘要一致,因此标题可接受并通过检查。
Description Check ✅ Passed PR 描述直接列出了新增的带 PrimaryStorageVO 参数的重载方法并说明在 activeIscsiVolume 中初始化 controller 的改动,同时包含问题单号和同步来源,描述与变更集相关,故通过检查。

Poem

我在仓库里跳一跳,耳朵竖又翘,
签名轻轻一改,参数来回跑。
VO来或去,编译器知晓,
胡萝卜做回车,合入就好。
稳稳落地,代码不乱冒.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed 标题 “[fix][storage]: Initialize controller in activeIscsiVolume when null” 明确指出此 PR 的主要修复目标:在 activeIscsiVolume 方法中当 controller 为 null 时进行初始化。该表述与变更摘要和 PR 目标一致(新增带 PrimaryStorageVO 的重载方法并在 controller 为 null 时初始化),因此与变更集高度相关且具体。标题简洁且适合在提交历史中快速识别主要改动。
Description Check ✅ Passed PR 描述说明新增了接受 PrimaryStorageVO 参数的重载方法并在 activeIscsiVolume 中初始化 controller,同时列出了解决的工单 ZSTAC-77315 和 Change-Id,内容与 raw_summary 中的变更一致。描述与变更集相关且不离题,满足宽松的描述检查标准。如果审阅者需要更多背景或回归测试信息,可以在描述中补充。
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sync/jin.shen/fix-77315@@2

📜 Recent review details

Configuration used: Path: http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml (via .coderabbit.yaml)

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5ba0b45 and bdffcb3.

📒 Files selected for processing (1)
  • storage/src/main/java/org/zstack/storage/addon/primary/BlockExternalPrimaryStorageFactory.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • storage/src/main/java/org/zstack/storage/addon/primary/BlockExternalPrimaryStorageFactory.java

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
storage/src/main/java/org/zstack/storage/addon/primary/BlockExternalPrimaryStorageFactory.java (2)

14-14: 参数命名避免缩写,提升可读性与一致性。

vo 建议命名为 primaryStorageprimaryStorageVO,符合“命名缩写不应不必要使用”的规范。

示例:

-    void activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean shareable, PrimaryStorageVO vo);
+    void activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean shareable, PrimaryStorageVO primaryStorage);

14-14: 补充 Javadoc,明确 null 约束与行为。

接口方法要求配有效 Javadoc;同时需要说明 primaryStorage 是否允许为 null,以及“当 controller 为 null 时初始化”的具体语义。

可参考上条 diff 中的注释块。

📜 Review details

Configuration used: Path: http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml (via .coderabbit.yaml)

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e41e60b and 5ba0b45.

📒 Files selected for processing (1)
  • storage/src/main/java/org/zstack/storage/addon/primary/BlockExternalPrimaryStorageFactory.java (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.*

⚙️ CodeRabbit configuration file

**/*.*: - 代码里不应当有有中文,包括报错、注释等都应当使用正确的、无拼写错误的英文来写

Files:

  • storage/src/main/java/org/zstack/storage/addon/primary/BlockExternalPrimaryStorageFactory.java
**/*.java

⚙️ CodeRabbit configuration file

**/*.java: ## 1. API 设计要求

  • API 命名:
    • API 名称必须唯一,不能重复。
    • API 消息类需要继承 APIMessage;其返回类必须继承 APIReplyAPIEvent,并在注释中用 @RestResponse 进行标注。
    • API 消息上必须添加注解 @RestRequest,并满足如下规范:
      • path:
        • 针对资源使用复数形式。
        • 当 path 中引用消息类变量时,使用 {variableName} 格式。
      • HTTP 方法对应:
        • 查询操作 → HttpMethod.GET
        • 更新操作 → HttpMethod.PUT
        • 创建操作 → HttpMethod.POST
        • 删除操作 → HttpMethod.DELETE
    • API 类需要实现 __example__ 方法以便生成 API 文档,并确保生成对应的 Groovy API Template 与 API Markdown 文件。

2. 命名与格式规范

  • 类名:

    • 使用 UpperCamelCase 风格。
    • 特殊情况:
      • VO/AO/EO 类型类除外。
      • 抽象类采用 AbstractBase 前缀/后缀。
      • 异常类应以 Exception 结尾。
      • 测试类需要以 TestCase 结尾。
  • 方法名、参数名、成员变量和局部变量:

    • 使用 lowerCamelCase 风格。
  • 常量命名:

    • 全部大写,使用下划线分隔单词。
    • 要求表达清楚,避免使用含糊或不准确的名称。
  • 包名:

    • 统一使用小写,使用点分隔符,每个部分应是一个具有自然语义的英文单词(参考 Spring 框架的结构)。
  • 命名细节:

    • 避免在父子类或同一代码块中出现相同名字的成员或局部变量,防止混淆。
    • 命名缩写:
      • 不允许使用不必要的缩写,如:AbsSchedulerJobcondiFu 等。应使用完整单词提升可读性。

3. 编写自解释代码

  • 意图表达:

    • 避免使用布尔型参数造成含义不明确。例如:
      • 对于 stopAgent(boolean ignoreError),建议拆分为不同函数(如 stopAgentIgnoreError()),或使用枚举表达操作类型。
    • 命名应尽量用完整的单词组合表达意图,并在名称中体现数据类型或用途(例如在常量与变量名称中,将类型词放在末尾)。
    • 避免使用魔法值(Magic Value):
      • 直接使用未经定义的数值或字符串(如 if (status == 5))应替换为枚举或常量。

      • 示例:

      • // 错误示例:魔法值

      • if (user.getStatus() == 5) { ... }

      • // 正确示例:常量或枚举

      • public static final int STATUS_ACTIVE = 5;

      • if (user.getStatus() == STATUS_ACTIVE) { ... }

      • // 或使用枚举

      • enum UserStatus { ACTIVE, INACTIVE }

  • 注释:

    • 代码应尽量做到自解释,对少于两行的说明可以直接写在代码中。
    • 对于较长的注释,需要仔细校对并随代码更新,确保内容正确。
    • 接口方法不应有多余的修饰符(例如 public),且必须配有有效的 Javadoc 注释。

4. 流程控制和结构优化

  • if...else 的使用:

    • 应尽量减少 if...else 结构的使用,建议:
      • 限制嵌套层级最多为两层,且内层不应再出现 else 分支。
      • 尽早返回(Early Return),将条件判断中的处理逻辑提前结束或抽成独立方法。
      • 使用 Java Stream 或 Lambda 表达式代替冗长的循环与条件判断。
  • 条件判断:

    • if 条件表达不宜过长或过于复杂,必要时可以将条件抽成 boolean 变量描述。
  • 代码块长度:
    ...

Files:

  • storage/src/main/java/org/zstack/storage/addon/primary/BlockExternalPrimaryStorageFactory.java
🔇 Additional comments (1)
storage/src/main/java/org/zstack/storage/addon/primary/BlockExternalPrimaryStorageFactory.java (1)

14-14: 确认:所有实现类与调用点已迁移到 activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean shareable, PrimaryStorageVO vo)

仓库搜索未返回匹配(先前脚本输出为空),无法确认是否存在残留的旧三参调用或未更新的实现。请在仓库根目录运行并回传输出:

rg -n --hidden -S --type=java 'BlockExternalPrimaryStorageFactory|activeIscsiVolume' -C2 || true
rg -nP --type=java -U 'activeIscsiVolume\s*\([^)]{0,400}\)' -C2 || true

BlockExternalPrimaryStorageBackend getBlockExternalPrimaryStorageBackend(PrimaryStorageVO vo);

void activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean shareable);
void activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean shareable, PrimaryStorageVO vo);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

这是破坏性接口变更;请改为真正“重载”,并保持二进制兼容。

PR 说明称“新增重载方法”,但当前是直接替换签名,这会破坏所有实现类与三方插件(运行期易触发 NoSuchMethodError)。根据“向后兼容原则”,保留旧签名,并以 default 方式新增重载。

建议修改:

-    void activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean shareable, PrimaryStorageVO vo);
+    // Keep the original abstract method for ABI compatibility
+    void activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean shareable);
+
+    /**
+     * Activate an iSCSI volume so the host can access it.
+     *
+     * @param clientIqn      initiator IQN of the client host
+     * @param vol            volume to be activated
+     * @param shareable      whether the volume is shareable
+     * @param primaryStorage PrimaryStorageVO of the target primary storage; may be null
+     */
+    default void activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean shareable, PrimaryStorageVO primaryStorage) {
+        // Default to legacy behavior to avoid breaking existing implementors.
+        activeIscsiVolume(clientIqn, vol, shareable);
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
void activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean shareable, PrimaryStorageVO vo);
// Keep the original abstract method for ABI compatibility
void activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean shareable);
/**
* Activate an iSCSI volume so the host can access it.
*
* @param clientIqn initiator IQN of the client host
* @param vol volume to be activated
* @param shareable whether the volume is shareable
* @param primaryStorage PrimaryStorageVO of the target primary storage; may be null
*/
default void activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean shareable, PrimaryStorageVO primaryStorage) {
// Default to legacy behavior to avoid breaking existing implementors.
activeIscsiVolume(clientIqn, vol, shareable);
}
🤖 Prompt for AI Agents
In
storage/src/main/java/org/zstack/storage/addon/primary/BlockExternalPrimaryStorageFactory.java
around line 14, the interface method signature was changed which breaks binary
compatibility; restore the original abstract method signature void
activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean shareable,
PrimaryStorageVO vo); and add the new overloaded method as a default method
(e.g., void activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean
shareable, PrimaryStorageVO vo, /*new params*/)) that delegates to the original
method (or vice versa depending on parameter direction) so existing implementors
keep working and new callers can use the overload without breaking runtime
compatibility.

Add overloaded method with PrimaryStorageVO parameter
Initialize controller in activeIscsiVolume when null

Resolves: ZSTAC-77315

Change-Id: I75656f6178726675636f6d63656b666873786d62
@MatheMatrix MatheMatrix force-pushed the sync/jin.shen/fix-77315@@2 branch from 5ba0b45 to bdffcb3 Compare September 15, 2025 05:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant