Skip to content

Conversation

@zstack-robot-2
Copy link
Collaborator

Change-Id: I7a7678786d6e657369657a746170716775746f63

sync from gitlab !9077

Change-Id: I7a7678786d6e657369657a746170716775746f63
@coderabbitai
Copy link

coderabbitai bot commented Jan 28, 2026

Walkthrough

该变更引入了新的虚拟机和卷扩展点架构,并弃用了旧的扩展接口。新增了多个上下文数据类和统一的扩展点定义,同时用@deprecated注解标记了大量旧接口,指向新的扩展包中的替代方案。

Changes

Cohort / File(s) 变更摘要
弃用虚拟机扩展点(旧包)
header/src/main/java/org/zstack/header/vm/VmAfterAttachL3NetworkExtensionPoint.java, VmAfterAttachNicExtensionPoint.java, VmAfterExpungeExtensionPoint.java, VmBeforeAttachL3NetworkExtensionPoint.java, VmBeforeExpungeExtensionPoint.java, VmDetachNicExtensionPoint.java, VmFailToAttachL3NetworkExtensionPoint.java, VmInstanceAttachNicExtensionPoint.java, VmInstanceDestroyExtensionPoint.java, VmJustAfterDeleteFromDbExtensionPoint.java, VmJustBeforeDeleteFromDbExtensionPoint.java, VmPreAttachL3NetworkExtensionPoint.java, DetachNicExtensionPoint.java
添加@deprecated注解并更新Javadoc,指向extensions子包中的新实现;无行为变更
弃用卷扩展点(旧包)
header/src/main/java/org/zstack/header/volume/VolumeBeforeExpungeExtensionPoint.java, VolumeDeletionExtensionPoint.java
添加@deprecated注解并更新Javadoc,指向extensions子包中的新实现;无行为变更
虚拟机扩展文档更新
header/src/main/java/org/zstack/header/vm/MemorySnapshotValidatorExtensionPoint.java, ResourceConfigMemorySnapshotExtensionPoint.java
扩展Javadoc文档,添加详细的触发时机、调用位置和使用场景说明;无代码行为变更
虚拟机上下文数据类(新增)
header/src/main/java/org/zstack/header/vm/extensions/VmAttachL3NetworkContext.java, VmDbDeleteContext.java, VmDestroyContext.java, VmDetachNicContext.java, VmExpungeContext.java
新增数据容器类,包含VM实例/账户信息、错误代码和可扩展的additionalData映射;提供标准getter/setter及putData/getData工具方法
虚拟机扩展点接口(新增)
header/src/main/java/org/zstack/header/vm/extensions/VmDestroyExtensionPoint.java, VmExpungeExtensionPoint.java, VmInstanceAttachL3NetworkExtensionPoint.java, VmInstanceDetachNicExtensionPoint.java
新增统一的扩展点接口,定义preXxx/beforeXxx/afterXxx/failedToXxx四阶段生命周期钩子,所有方法均为default实现;支持异步处理(afterXxx接收Completion)和错误处理
卷上下文数据类(新增)
header/src/main/java/org/zstack/header/volume/extensions/VolumeDeleteContext.java, VolumeExpungeContext.java
新增数据容器类,包含卷实例/账户信息、错误代码和additionalData映射;提供标准访问器及putData/getData辅助方法
卷扩展点接口(新增)
header/src/main/java/org/zstack/header/volume/extensions/VolumeDeletionExtPoint.java, VolumeExpungeExtPoint.java
新增统一的卷扩展点接口,定义preXxx/beforeXxx/afterXxx/failedToXxx四阶段生命周期钩子,所有方法均为default实现;支持异步处理和错误处理

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 一只兔子的赞歌

旧接口渐行渐远,新架构生机勃勃,
上下文数据携手同行,跨越生命周期四重门,
弃用与新生共舞,extensions家族璀璨绽放!
🎉 ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.48% 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 标题完全符合要求的格式规范 [scope]: ,长度45字符(不超过72字符),清晰描述了变更的主要内容:重构扩展点。
Description check ✅ Passed 拉取请求描述与变更集相关,包含了Gitlab同步信息和Change-Id,虽然描述简洁但足以表达变更的意图。

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

✨ Finishing touches
  • 📝 Generate docstrings

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: 4

🤖 Fix all issues with AI agents
In
`@header/src/main/java/org/zstack/header/storage/snapshot/group/MemorySnapshotValidatorExtensionPoint.java`:
- Around line 6-15: Translate the Javadoc for
MemorySnapshotValidatorExtensionPoint into clear, idiomatic English (replace the
current Chinese text) so it documents the extension point purpose, trigger
timing (before creating a memory snapshot), the invocation site
(VolumeSnapshotGroupCreator.validate()), and usage scenario (modules check VM
external devices or network references for compatibility with memory snapshots);
keep the `@since` tag and ensure no Chinese remains in the comment.

In
`@header/src/main/java/org/zstack/header/vm/ResourceConfigMemorySnapshotExtensionPoint.java`:
- Around line 5-16: Translate the Javadoc for the
ResourceConfigMemorySnapshotExtensionPoint interface from Chinese to clear,
idiomatic English while preserving the structure and tags (including the
description, trigger/call location lines, usage scenario paragraph, and the
`@since` 5.0.0 tag); update the comment text to explain that this extension point
archives VM-related resource configuration when creating memory snapshots, is
invoked by MemorySnapshotManager.archiveResourceConfig(), and that modules
should provide configuration to be restored with the snapshot. Ensure no Chinese
remains and keep formatting and annotations intact.

In
`@header/src/main/java/org/zstack/header/vm/VmJustAfterDeleteFromDbExtensionPoint.java`:
- Around line 3-6: The `@deprecated` Javadoc in
VmJustAfterDeleteFromDbExtensionPoint currently links to the context class
VmDbDeleteContext instead of the actual single-phase extension point interface;
update the `@deprecated` tag to point to the concrete replacement extension point
in org.zstack.header.vm.extensions (replace the VmDbDeleteContext reference with
the correct extension-point interface name), and apply the identical change to
VmJustBeforeDeleteFromDbExtensionPoint so both deprecation comments reference
the explicit replacement interface rather than the context class.

In
`@header/src/main/java/org/zstack/header/vm/VmJustBeforeDeleteFromDbExtensionPoint.java`:
- Around line 3-6: Update the deprecation Javadoc on
VmJustBeforeDeleteFromDbExtensionPoint to name the exact single-phase
extension-point interface developers should migrate to (in addition to the
VmDbDeleteContext). Replace the vague phrase "with a single-phase extension
point" with a concrete fully-qualified interface reference (for example:
org.zstack.header.vm.extensions.<ExactExtensionPointInterfaceName>) so the
comment clearly shows the target extension-point to use when migrating.
🧹 Nitpick comments (2)
header/src/main/java/org/zstack/header/vm/extensions/VmDestroyExtensionPoint.java (1)

5-24: LGTM! 新的统一扩展点设计良好。

接口设计符合重构规范:

  • 四阶段方法命名(pre/before/after/failedTo)遵循设计规范
  • 使用 VmDestroyContext 上下文对象传递参数,便于未来扩展
  • afterDestroy 使用 Completion 回调支持异步处理
  • 默认实现合理(preDestroy 返回 null 表示不拒绝,afterDestroy 默认调用 success)

可选改进:根据文档要求,考虑添加 @since 标签标注版本信息。

header/src/main/java/org/zstack/header/vm/extensions/VmDestroyContext.java (1)

9-25: 建议添加类级别 Javadoc 文档以保持一致性。

VmAttachL3NetworkContext 包含了完整的类级别 Javadoc 说明 Context 对象的用途和生命周期阶段,但此类缺少相应文档。建议保持统一风格:

📝 建议添加文档
+/**
+ * Context object for VM destroy operations.
+ *
+ * <p>This context is passed through all lifecycle phases (pre/before/after/failedTo)
+ * allowing extensions to share state between phases.</p>
+ */
 public class VmDestroyContext {

Comment on lines +6 to +15
* 内存快照验证扩展点
*
* <p>触发时机:创建内存快照前,验证 VM 是否符合条件</p>
* <p>调用位置:VolumeSnapshotGroupCreator.validate()</p>
*
* <h3>使用场景:</h3>
* <p>各模块通过此扩展点检查 VM 的外部设备或网络引用
* 是否与内存快照兼容。</p>
*
* @since 5.0.0
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Javadoc 应使用英文编写

根据编码规范,代码中不应包含中文,包括注释和错误消息都应当使用正确的、无拼写错误的英文来编写。请将此 Javadoc 翻译为英文。

建议的英文 Javadoc
-/**
- * 内存快照验证扩展点
- *
- * <p>触发时机:创建内存快照前,验证 VM 是否符合条件</p>
- * <p>调用位置:VolumeSnapshotGroupCreator.validate()</p>
- *
- * <h3>使用场景:</h3>
- * <p>各模块通过此扩展点检查 VM 的外部设备或网络引用
- * 是否与内存快照兼容。</p>
- *
- * `@since` 5.0.0
- */
+/**
+ * Extension point for validating memory snapshot creation.
+ *
+ * <p>Trigger: Before creating a memory snapshot, validate whether the VM meets the conditions.</p>
+ * <p>Call site: VolumeSnapshotGroupCreator.validate()</p>
+ *
+ * <h3>Usage:</h3>
+ * <p>Modules use this extension point to check whether the VM's external devices
+ * or network references are compatible with memory snapshots.</p>
+ *
+ * `@since` 5.0.0
+ */

根据编码规范:代码里不应当有中文,包括报错、注释等都应当使用正确的、无拼写错误的英文来写。

🤖 Prompt for AI Agents
In
`@header/src/main/java/org/zstack/header/storage/snapshot/group/MemorySnapshotValidatorExtensionPoint.java`
around lines 6 - 15, Translate the Javadoc for
MemorySnapshotValidatorExtensionPoint into clear, idiomatic English (replace the
current Chinese text) so it documents the extension point purpose, trigger
timing (before creating a memory snapshot), the invocation site
(VolumeSnapshotGroupCreator.validate()), and usage scenario (modules check VM
external devices or network references for compatibility with memory snapshots);
keep the `@since` tag and ensure no Chinese remains in the comment.

Comment on lines +5 to +16
/**
* 内存快照资源配置归档扩展点
*
* <p>触发时机:创建内存快照时,归档与 VM 相关的资源配置</p>
* <p>调用位置:MemorySnapshotManager.archiveResourceConfig()</p>
*
* <h3>使用场景:</h3>
* <p>当 VM 执行内存快照时,各模块通过此扩展点提供需要归档的资源配置,
* 以便恢复快照时可以同时恢复相关配置状态。</p>
*
* @since 5.0.0
*/
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Javadoc 应使用英文编写

根据编码规范,代码中不应包含中文,包括注释和错误消息都应当使用正确的、无拼写错误的英文来编写。请将此 Javadoc 翻译为英文。

建议的英文 Javadoc
-/**
- * 内存快照资源配置归档扩展点
- *
- * <p>触发时机:创建内存快照时,归档与 VM 相关的资源配置</p>
- * <p>调用位置:MemorySnapshotManager.archiveResourceConfig()</p>
- *
- * <h3>使用场景:</h3>
- * <p>当 VM 执行内存快照时,各模块通过此扩展点提供需要归档的资源配置,
- * 以便恢复快照时可以同时恢复相关配置状态。</p>
- *
- * `@since` 5.0.0
- */
+/**
+ * Extension point for archiving resource configurations during memory snapshot creation.
+ *
+ * <p>Trigger: When creating a memory snapshot, archive VM-related resource configurations.</p>
+ * <p>Call site: MemorySnapshotManager.archiveResourceConfig()</p>
+ *
+ * <h3>Usage:</h3>
+ * <p>When a VM performs a memory snapshot, modules provide resource configurations
+ * to be archived via this extension point, allowing related configuration states
+ * to be restored when the snapshot is recovered.</p>
+ *
+ * `@since` 5.0.0
+ */

根据编码规范:代码里不应当有中文,包括报错、注释等都应当使用正确的、无拼写错误的英文来写。

🤖 Prompt for AI Agents
In
`@header/src/main/java/org/zstack/header/vm/ResourceConfigMemorySnapshotExtensionPoint.java`
around lines 5 - 16, Translate the Javadoc for the
ResourceConfigMemorySnapshotExtensionPoint interface from Chinese to clear,
idiomatic English while preserving the structure and tags (including the
description, trigger/call location lines, usage scenario paragraph, and the
`@since` 5.0.0 tag); update the comment text to explain that this extension point
archives VM-related resource configuration when creating memory snapshots, is
invoked by MemorySnapshotManager.archiveResourceConfig(), and that modules
should provide configuration to be restored with the snapshot. Ensure no Chinese
remains and keep formatting and annotations intact.

Comment on lines 3 to +6
/**
* Created by Qi Le on 2019-08-21
* @deprecated Use {@link org.zstack.header.vm.extensions.VmDbDeleteContext} with a single-phase extension point instead.
*/
@Deprecated
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

弃用引用不完整:与 VmJustBeforeDeleteFromDbExtensionPoint 存在相同问题。

同样引用了上下文类 VmDbDeleteContext 而非具体的扩展点接口。建议统一修复,指向明确的替代扩展点接口。

🤖 Prompt for AI Agents
In
`@header/src/main/java/org/zstack/header/vm/VmJustAfterDeleteFromDbExtensionPoint.java`
around lines 3 - 6, The `@deprecated` Javadoc in
VmJustAfterDeleteFromDbExtensionPoint currently links to the context class
VmDbDeleteContext instead of the actual single-phase extension point interface;
update the `@deprecated` tag to point to the concrete replacement extension point
in org.zstack.header.vm.extensions (replace the VmDbDeleteContext reference with
the correct extension-point interface name), and apply the identical change to
VmJustBeforeDeleteFromDbExtensionPoint so both deprecation comments reference
the explicit replacement interface rather than the context class.

Comment on lines 3 to +6
/**
* Created by xing5 on 2017/6/26.
* @deprecated Use {@link org.zstack.header.vm.extensions.VmDbDeleteContext} with a single-phase extension point instead.
*/
@Deprecated
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for VmDbDeleteContext and related extension point interfaces
echo "=== Searching for VmDbDeleteContext ==="
fd -e java . | xargs rg -l "VmDbDeleteContext" | head -20

echo -e "\n=== Searching for VmDbDelete*ExtensionPoint interfaces ==="
fd -e java . | xargs rg "interface.*VmDbDelete.*ExtensionPoint" -A 2

echo -e "\n=== Checking VmJustBeforeDeleteFromDbExtensionPoint ==="
fd -e java . -name "*VmJustBeforeDeleteFromDb*" -exec cat {} \;

echo -e "\n=== Comparing with similar deprecation patterns ==="
fd -e java . | xargs rg "@Deprecated" -B 2 | grep -A 2 "VmDeleteExtensionPoint\|VmDbDelete" | head -30

Repository: MatheMatrix/zstack

Length of output: 1558


🏁 Script executed:

#!/bin/bash
# Get the full content of VmJustBeforeDeleteFromDbExtensionPoint
echo "=== Full content of VmJustBeforeDeleteFromDbExtensionPoint ==="
cat header/src/main/java/org/zstack/header/vm/VmJustBeforeDeleteFromDbExtensionPoint.java

echo -e "\n=== Full content of VmDbDeleteContext ==="
cat header/src/main/java/org/zstack/header/vm/extensions/VmDbDeleteContext.java

echo -e "\n=== Check for all extension points related to VmDelete ==="
fd -e java . | xargs rg "interface.*ExtensionPoint" | grep -i "vmdelete\|vmdestroy\|vm.*delete" | head -20

echo -e "\n=== Check VmJustAfterDeleteFromDbExtensionPoint ==="
cat header/src/main/java/org/zstack/header/vm/VmJustAfterDeleteFromDbExtensionPoint.java

Repository: MatheMatrix/zstack

Length of output: 2425


🏁 Script executed:

#!/bin/bash
# Check VmDestroyExtensionPoint to see what it looks like
echo "=== Full content of VmDestroyExtensionPoint ==="
cat header/src/main/java/org/zstack/header/vm/extensions/VmDestroyExtensionPoint.java

echo -e "\n=== Search for VmDbDeleteExtensionPoint ==="
fd -e java . | xargs rg "VmDbDeleteExtensionPoint" 2>/dev/null || echo "Not found"

echo -e "\n=== Search for extension points that use VmDbDeleteContext ==="
fd -e java . | xargs rg "VmDbDeleteContext" -A 5 -B 5

Repository: MatheMatrix/zstack

Length of output: 4431


🏁 Script executed:

#!/bin/bash
# Search for where VmJustBeforeDeleteFromDbExtensionPoint is actually used/implemented
echo "=== Usages of VmJustBeforeDeleteFromDbExtensionPoint ==="
fd -e java . | xargs rg "VmJustBeforeDeleteFromDbExtensionPoint" | grep -v "\.java:-"

echo -e "\n=== Look for recent VM delete/destroy extension point implementations ==="
fd -e java . | xargs rg "implements.*Delete.*ExtensionPoint\|implements.*Destroy.*ExtensionPoint" | head -20

echo -e "\n=== Search for pattern: what is the actual replacement mentioned in code ==="
fd -e java . | xargs rg "single-phase extension point" -B 3 -A 3

Repository: MatheMatrix/zstack

Length of output: 3216


🏁 Script executed:

#!/bin/bash
# Check if there's any mention of what to use instead or if there's documentation
echo "=== Check for VmDbDelete* in extensions package ==="
fd -e java . header/src/main/java/org/zstack/header/vm/extensions/ | xargs ls -la

echo -e "\n=== Check VmDestroyContext to see how it differs ==="
find . -name "VmDestroyContext.java" -exec cat {} \;

echo -e "\n=== Check if there are any recent changes or comments about the replacement ==="
fd -e java . | xargs rg "VmDestroyExtensionPoint\|VmDbDelete" -B 2 -A 2 | grep -E "(TODO|FIXME|NOTE|phase)" | head -20

Repository: MatheMatrix/zstack

Length of output: 2470


🏁 Script executed:

#!/bin/bash
# Check if VmDbDeleteExtensionPoint is planned/mentioned anywhere
echo "=== Search for any TODO, FIXME, or future references to VmDbDelete ==="
fd -e java . | xargs rg "VmDbDelete" -B 3 -A 3

echo -e "\n=== Check git history or comments about when VmDbDeleteContext was added ==="
git log --oneline --all -- "header/src/main/java/org/zstack/header/vm/extensions/VmDbDeleteContext.java" | head -10

echo -e "\n=== Look for pattern in similar deprecated interfaces ==="
fd -e java . | xargs rg "@Deprecated" -B 3 | grep -E "Use.*Context.*extension" -B 3 -A 3

Repository: MatheMatrix/zstack

Length of output: 3792


🏁 Script executed:

#!/bin/bash
# Check if there's any documentation or comments about VmDbDeleteContext usage
echo "=== Search for implementations or usages of VmDbDeleteContext ==="
fd -e java . | xargs rg "VmDbDeleteContext" -A 5 | grep -v "^header/" | head -40

echo -e "\n=== Check the refactor commit message ==="
git show 1a4fa661c --stat | head -50

echo -e "\n=== Check related extension point interfaces with multiple phases ==="
cat header/src/main/java/org/zstack/header/vm/extensions/VmExpungeExtensionPoint.java

Repository: MatheMatrix/zstack

Length of output: 3974


弃用说明缺少具体的扩展点接口名称。

当前弃用注释引用了 VmDbDeleteContext(上下文类),但未指明对应的扩展点接口。注释仅说"with a single-phase extension point"而未命名具体的扩展点,这会导致开发者无法明确迁移目标。应补充具体的扩展点接口名称,使迁移路径清晰。

🤖 Prompt for AI Agents
In
`@header/src/main/java/org/zstack/header/vm/VmJustBeforeDeleteFromDbExtensionPoint.java`
around lines 3 - 6, Update the deprecation Javadoc on
VmJustBeforeDeleteFromDbExtensionPoint to name the exact single-phase
extension-point interface developers should migrate to (in addition to the
VmDbDeleteContext). Replace the vague phrase "with a single-phase extension
point" with a concrete fully-qualified interface reference (for example:
org.zstack.header.vm.extensions.<ExactExtensionPointInterfaceName>) so the
comment clearly shows the target extension-point to use when migrating.

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.

3 participants