Skip to content

<feature>[storage]: register and take over sblk#3384

Open
zstack-robot-2 wants to merge 1 commit intofeature-zsv-5.0.0-vm-registrationfrom
sync/tao.gan/sblk-ZSV-10000@@3
Open

<feature>[storage]: register and take over sblk#3384
zstack-robot-2 wants to merge 1 commit intofeature-zsv-5.0.0-vm-registrationfrom
sync/tao.gan/sblk-ZSV-10000@@3

Conversation

@zstack-robot-2
Copy link
Collaborator

APIImpact

Resolves: ZSV-10000

Change-Id: I70637377776e777070676c6a6c616e74786b6667

sync from gitlab !9229

APIImpact

Resolves: ZSV-10000

Change-Id: I70637377776e777070676c6a6c616e74786b6667
@coderabbitai
Copy link

coderabbitai bot commented Feb 25, 2026

总览

引入两个新的主存储操作API(一致性检查和接管)的完整实现,包括事件类、消息类、SDK操作类及其文档,并在处理器和测试工具中添加支持。

变更

核心组件 变更摘要
主存储一致性检查API
header/src/main/java/org/zstack/header/storage/primary/APICheckPrimaryStorageConsistency*
新增事件类、消息类及其中文文档文件,支持通过PUT /primary-storage/{uuid}/consistency检查存储一致性,事件返回boolean类型的consistent字段。
主存储接管API
header/src/main/java/org/zstack/header/storage/primary/APITakeoverPrimaryStorage*
新增事件类、消息类及其中文文档文件,支持通过PUT /primary-storage/{uuid}/takeover接管主存储,事件返回PrimaryStorageInventory对象。
SDK一致性检查操作
sdk/src/main/java/org/zstack/sdk/CheckPrimaryStorageConsistency*
新增CheckPrimaryStorageConsistencyAction及CheckPrimaryStorageConsistencyResult,支持同步和异步API调用,含完整的参数映射和REST元数据。
SDK接管操作
sdk/src/main/java/org/zstack/sdk/TakeoverPrimaryStorageAction.java, sdk/src/main/java/org/zstack/sdk/TakeoverPrimaryStorageResult.java
新增TakeoverPrimaryStorageAction及TakeoverPrimaryStorageResult,支持同步和异步API调用,包含会话、轮询配置及参数映射。
共享块组LUN API
sdk/src/main/java/org/zstack/sdk/GetSharedBlockGroup*, sdk/src/main/java/org/zstack/sdk/SharedBlockGroupLunInfo.java
新增GetSharedBlockGroupLunsAction、GetSharedBlockGroupLunsResult及SharedBlockGroupLunInfo数据类,支持检索共享块组LUN信息。
处理器支持
storage/src/main/java/org/zstack/storage/primary/PrimaryStorageBase.java
在handleApiMessage流程中新增两个API消息处理方法,目前返回操作不支持异常。
SDK映射更新
sdk/src/main/java/SourceClassMap.java
为SharedBlockGroupLunInfo添加源-目标双向映射。
测试工具扩展
testlib/src/main/java/org/zstack/testlib/ApiHelper.groovy
新增81行代码,包含checkPrimaryStorageConsistency等多个API辅助方法,支持资源管理、存储操作、安全配置等多个功能模块。

诗词

🐰✨ 新的API纷纷登场,
一致性检查和接管藏,
共享块组LUN得支撑,
SDK映射成双向长,
测试工具更强梁!

评估代码审核工作量

🎯 4 (复杂) | ⏱️ ~45 分钟

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed PR标题清晰准确地反映了主要变化:添加storage模块中sblk(共享块存储)的注册和接管功能。
Description check ✅ Passed PR描述与变更集相关:提及APIImpact标记、解决ZSV-10000问题,并指出与GitLab的同步来源。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sync/tao.gan/sblk-ZSV-10000@@3

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.

♻️ Duplicate comments (2)
sdk/src/main/java/org/zstack/sdk/CheckPrimaryStorageConsistencyAction.java (2)

5-5: 冗余的自包内通配符导入(同 TakeoverPrimaryStorageAction)。

TakeoverPrimaryStorageAction.java 中相同问题:import org.zstack.sdk.*; 在当前包内多余,可删除。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@sdk/src/main/java/org/zstack/sdk/CheckPrimaryStorageConsistencyAction.java`
at line 5, Remove the redundant package-wide wildcard import in
CheckPrimaryStorageConsistencyAction by deleting the line "import
org.zstack.sdk.*;" (same issue as in TakeoverPrimaryStorageAction); rely on
specific required imports or package-level visibility instead to avoid duplicate
self-package wildcard imports.

32-35: systemTagsuserTags 使用原始 List 类型(同 TakeoverPrimaryStorageAction)。

TakeoverPrimaryStorageAction.java 中相同,建议改为 List<String>

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@sdk/src/main/java/org/zstack/sdk/CheckPrimaryStorageConsistencyAction.java`
around lines 32 - 35, Change the raw List declarations in
CheckPrimaryStorageConsistencyAction to use a typed generic: replace the fields
"public java.util.List systemTags;" and "public java.util.List userTags;" with
"public java.util.List<String> systemTags;" and "public java.util.List<String>
userTags;" respectively (same fix as in TakeoverPrimaryStorageAction) so the
fields are List<String> rather than raw List.
🧹 Nitpick comments (6)
sdk/src/main/java/org/zstack/sdk/TakeoverPrimaryStorageAction.java (1)

5-5: 冗余的自包内通配符导入。

import org.zstack.sdk.*; 与当前类处于同一包(org.zstack.sdk)中,属于冗余导入,可以删除。

♻️ 建议修改
 import java.util.HashMap;
 import java.util.Map;
-import org.zstack.sdk.*;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@sdk/src/main/java/org/zstack/sdk/TakeoverPrimaryStorageAction.java` at line
5, 移除冗余的包内通配符导入:在 TakeoverPrimaryStorageAction
类(TakeoverPrimaryStorageAction.java)删除行 import org.zstack.sdk.*;,因为该类已处于
org.zstack.sdk 包内,保留其他必要的显式导入即可。
sdk/src/main/java/org/zstack/sdk/GetSharedBlockGroupLunsAction.java (2)

31-35: systemTagsuserTags 使用原始 List 类型

SharedBlockGroupLunInfo 中相同的问题,应参数化为 List<String>

♻️ 建议修复
-    public java.util.List systemTags;
+    public java.util.List<String> systemTags;
 
-    public java.util.List userTags;
+    public java.util.List<String> userTags;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@sdk/src/main/java/org/zstack/sdk/GetSharedBlockGroupLunsAction.java` around
lines 31 - 35, Change the raw List types for the public fields systemTags and
userTags to parameterized types to match SharedBlockGroupLunInfo; update their
declarations from "public java.util.List systemTags" and "public java.util.List
userTags" to "public java.util.List<String> systemTags" and "public
java.util.List<String> userTags" so the SDK exposes typed string tag lists (no
other logic changes required).

5-5: 冗余的通配符导入

GetSharedBlockGroupLunsAction 本身就在 org.zstack.sdk 包中,import org.zstack.sdk.*; 导入是多余的,应删除。

♻️ 建议修复
 import java.util.HashMap;
 import java.util.Map;
-import org.zstack.sdk.*;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@sdk/src/main/java/org/zstack/sdk/GetSharedBlockGroupLunsAction.java` at line
5, 在 GetSharedBlockGroupLunsAction 类文件中删除冗余的通配符导入语句 "import
org.zstack.sdk.*;"(该类已在 org.zstack.sdk 包内),保留或添加必要的显式导入项以避免
IDE/编译器报未解析类型的错误,并在保存后确认编译通过;定位标识符:类名 GetSharedBlockGroupLunsAction 和导入语句 import
org.zstack.sdk.*;。
sdk/src/main/java/org/zstack/sdk/GetSharedBlockGroupLunsResult.java (1)

6-12: lunInfos 字段使用原始 Map 类型,缺少泛型参数

根据 SharedBlockGroupLunInfo 的语义(按主机划分的 LUN 信息),lunInfos 的类型应为 Map<String, SharedBlockGroupLunInfo>,使用原始类型在反序列化(Gson)和 BeanUtils 映射时均可能产生 ClassCastException

♻️ 建议修复
-    public java.util.Map lunInfos;
-    public void setLunInfos(java.util.Map lunInfos) {
-        this.lunInfos = lunInfos;
+    public java.util.Map<String, org.zstack.sdk.SharedBlockGroupLunInfo> lunInfos;
+    public void setLunInfos(java.util.Map<String, org.zstack.sdk.SharedBlockGroupLunInfo> lunInfos) {
+        this.lunInfos = lunInfos;
     }
-    public java.util.Map getLunInfos() {
+    public java.util.Map<String, org.zstack.sdk.SharedBlockGroupLunInfo> getLunInfos() {
         return this.lunInfos;
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@sdk/src/main/java/org/zstack/sdk/GetSharedBlockGroupLunsResult.java` around
lines 6 - 12, The lunInfos field in class GetSharedBlockGroupLunsResult is
declared as a raw java.util.Map which can cause ClassCastException during Gson
deserialization and BeanUtils mapping; change the field and its accessor methods
(lunInfos, setLunInfos, getLunInfos) to use the generic type Map<String,
SharedBlockGroupLunInfo> (import SharedBlockGroupLunInfo if needed) so callers
and serializers have the correct generic information.
sdk/src/main/java/org/zstack/sdk/SharedBlockGroupLunInfo.java (2)

7-13: 使用原始类型(Raw Types)会丢失类型安全性,并可能导致 BeanUtils 映射问题

candidateLunsexistLunWwidsByHost 均使用了未参数化的原始类型,建议明确泛型类型参数。SourceClassMap 通过 commons-beanutils 进行属性拷贝,原始 Map 类型可能导致运行时类型转换异常。

♻️ 建议修复
-    public java.util.List candidateLuns;
-    public void setCandidateLuns(java.util.List candidateLuns) {
-        this.candidateLuns = candidateLuns;
+    public java.util.List<String> candidateLuns;
+    public void setCandidateLuns(java.util.List<String> candidateLuns) {
+        this.candidateLuns = candidateLuns;
     }
-    public java.util.List getCandidateLuns() {
+    public java.util.List<String> getCandidateLuns() {
         return this.candidateLuns;
     }

-    public java.util.Map existLunWwidsByHost;
-    public void setExistLunWwidsByHost(java.util.Map existLunWwidsByHost) {
-        this.existLunWwidsByHost = existLunWwidsByHost;
+    public java.util.Map<String, List<String>> existLunWwidsByHost;
+    public void setExistLunWwidsByHost(java.util.Map<String, List<String>> existLunWwidsByHost) {
+        this.existLunWwidsByHost = existLunWwidsByHost;
     }
-    public java.util.Map getExistLunWwidsByHost() {
+    public java.util.Map<String, List<String>> getExistLunWwidsByHost() {
         return this.existLunWwidsByHost;
     }

Also applies to: 23-29

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@sdk/src/main/java/org/zstack/sdk/SharedBlockGroupLunInfo.java` around lines 7
- 13, The fields and accessors in SharedBlockGroupLunInfo use raw types which
lose type-safety and break commons-beanutils mapping; change the field
declarations and their getters/setters to use concrete generic types (e.g.,
change candidateLuns from raw java.util.List to a parameterized type like
java.util.List<String> or the correct element type, and change
existLunWwidsByHost from raw java.util.Map to java.util.Map<String,
List<String>> or the appropriate key/value types), and update the signatures of
getCandidateLuns, setCandidateLuns, getExistLunWwidsByHost, and
setExistLunWwidsByHost in the SharedBlockGroupLunInfo class so BeanUtils can
correctly copy properties without runtime type conversion errors.

15-21: 考虑改进 boolean 属性的 getter 命名以遵循 JavaBean 惯例

虽然 getSharedGroupComplete() 在技术上符合 JavaBean 规范(boolean 属性的 getter 既可用 is 前缀也可用 get 前缀),但 JavaBean 规范建议原始 boolean 类型优先使用 is 前缀。为了与常见惯例保持一致并提高代码可读性,建议改用 isSharedGroupComplete() 替代。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@sdk/src/main/java/org/zstack/sdk/SharedBlockGroupLunInfo.java` around lines
15 - 21, Change the boolean getter to follow JavaBean convention: in class
SharedBlockGroupLunInfo replace or supplement the existing
getSharedGroupComplete() with an isSharedGroupComplete() method that returns the
sharedGroupComplete field; keep the existing setSharedGroupComplete(boolean)
as-is and optionally retain getSharedGroupComplete() as a deprecated passthrough
to isSharedGroupComplete() for backward compatibility.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@sdk/src/main/java/org/zstack/sdk/CheckPrimaryStorageConsistencyAction.java`:
- Line 5: Remove the redundant package-wide wildcard import in
CheckPrimaryStorageConsistencyAction by deleting the line "import
org.zstack.sdk.*;" (same issue as in TakeoverPrimaryStorageAction); rely on
specific required imports or package-level visibility instead to avoid duplicate
self-package wildcard imports.
- Around line 32-35: Change the raw List declarations in
CheckPrimaryStorageConsistencyAction to use a typed generic: replace the fields
"public java.util.List systemTags;" and "public java.util.List userTags;" with
"public java.util.List<String> systemTags;" and "public java.util.List<String>
userTags;" respectively (same fix as in TakeoverPrimaryStorageAction) so the
fields are List<String> rather than raw List.

---

Nitpick comments:
In `@sdk/src/main/java/org/zstack/sdk/GetSharedBlockGroupLunsAction.java`:
- Around line 31-35: Change the raw List types for the public fields systemTags
and userTags to parameterized types to match SharedBlockGroupLunInfo; update
their declarations from "public java.util.List systemTags" and "public
java.util.List userTags" to "public java.util.List<String> systemTags" and
"public java.util.List<String> userTags" so the SDK exposes typed string tag
lists (no other logic changes required).
- Line 5: 在 GetSharedBlockGroupLunsAction 类文件中删除冗余的通配符导入语句 "import
org.zstack.sdk.*;"(该类已在 org.zstack.sdk 包内),保留或添加必要的显式导入项以避免
IDE/编译器报未解析类型的错误,并在保存后确认编译通过;定位标识符:类名 GetSharedBlockGroupLunsAction 和导入语句 import
org.zstack.sdk.*;。

In `@sdk/src/main/java/org/zstack/sdk/GetSharedBlockGroupLunsResult.java`:
- Around line 6-12: The lunInfos field in class GetSharedBlockGroupLunsResult is
declared as a raw java.util.Map which can cause ClassCastException during Gson
deserialization and BeanUtils mapping; change the field and its accessor methods
(lunInfos, setLunInfos, getLunInfos) to use the generic type Map<String,
SharedBlockGroupLunInfo> (import SharedBlockGroupLunInfo if needed) so callers
and serializers have the correct generic information.

In `@sdk/src/main/java/org/zstack/sdk/SharedBlockGroupLunInfo.java`:
- Around line 7-13: The fields and accessors in SharedBlockGroupLunInfo use raw
types which lose type-safety and break commons-beanutils mapping; change the
field declarations and their getters/setters to use concrete generic types
(e.g., change candidateLuns from raw java.util.List to a parameterized type like
java.util.List<String> or the correct element type, and change
existLunWwidsByHost from raw java.util.Map to java.util.Map<String,
List<String>> or the appropriate key/value types), and update the signatures of
getCandidateLuns, setCandidateLuns, getExistLunWwidsByHost, and
setExistLunWwidsByHost in the SharedBlockGroupLunInfo class so BeanUtils can
correctly copy properties without runtime type conversion errors.
- Around line 15-21: Change the boolean getter to follow JavaBean convention: in
class SharedBlockGroupLunInfo replace or supplement the existing
getSharedGroupComplete() with an isSharedGroupComplete() method that returns the
sharedGroupComplete field; keep the existing setSharedGroupComplete(boolean)
as-is and optionally retain getSharedGroupComplete() as a deprecated passthrough
to isSharedGroupComplete() for backward compatibility.

In `@sdk/src/main/java/org/zstack/sdk/TakeoverPrimaryStorageAction.java`:
- Line 5: 移除冗余的包内通配符导入:在 TakeoverPrimaryStorageAction
类(TakeoverPrimaryStorageAction.java)删除行 import org.zstack.sdk.*;,因为该类已处于
org.zstack.sdk 包内,保留其他必要的显式导入即可。

ℹ️ Review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5924b9d and bbfff3c.

⛔ Files ignored due to path filters (1)
  • conf/serviceConfig/primaryStorage.xml is excluded by !**/*.xml
📒 Files selected for processing (18)
  • header/src/main/java/org/zstack/header/storage/primary/APICheckPrimaryStorageConsistencyEvent.java
  • header/src/main/java/org/zstack/header/storage/primary/APICheckPrimaryStorageConsistencyEventDoc_zh_cn.groovy
  • header/src/main/java/org/zstack/header/storage/primary/APICheckPrimaryStorageConsistencyMsg.java
  • header/src/main/java/org/zstack/header/storage/primary/APICheckPrimaryStorageConsistencyMsgDoc_zh_cn.groovy
  • header/src/main/java/org/zstack/header/storage/primary/APITakeoverPrimaryStorageEvent.java
  • header/src/main/java/org/zstack/header/storage/primary/APITakeoverPrimaryStorageEventDoc_zh_cn.groovy
  • header/src/main/java/org/zstack/header/storage/primary/APITakeoverPrimaryStorageMsg.java
  • header/src/main/java/org/zstack/header/storage/primary/APITakeoverPrimaryStorageMsgDoc_zh_cn.groovy
  • sdk/src/main/java/SourceClassMap.java
  • sdk/src/main/java/org/zstack/sdk/CheckPrimaryStorageConsistencyAction.java
  • sdk/src/main/java/org/zstack/sdk/CheckPrimaryStorageConsistencyResult.java
  • sdk/src/main/java/org/zstack/sdk/GetSharedBlockGroupLunsAction.java
  • sdk/src/main/java/org/zstack/sdk/GetSharedBlockGroupLunsResult.java
  • sdk/src/main/java/org/zstack/sdk/SharedBlockGroupLunInfo.java
  • sdk/src/main/java/org/zstack/sdk/TakeoverPrimaryStorageAction.java
  • sdk/src/main/java/org/zstack/sdk/TakeoverPrimaryStorageResult.java
  • storage/src/main/java/org/zstack/storage/primary/PrimaryStorageBase.java
  • testlib/src/main/java/org/zstack/testlib/ApiHelper.groovy

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.

2 participants