-
Notifications
You must be signed in to change notification settings - Fork 0
<refactor>[zstack]: Refactor extension points #3257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 5.5.6
Are you sure you want to change the base?
Changes from all commits
6b4521b
3b5bda3
80df074
a84a36e
f19223a
24d4f3b
f563992
6545350
76490a5
461e8a2
32e1e94
addec8c
26b8b1a
be53c72
e1dee9f
3bd062b
aaeaf39
f41558d
673be94
7f53f5a
72ce6ef
34bceb1
3e02188
799a84f
08aa861
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,16 @@ | |
| import org.zstack.header.errorcode.ErrorCode; | ||
|
|
||
| /** | ||
| * Created by LiangHanYu on 2022/6/9 18:30 | ||
| * 内存快照验证扩展点 | ||
| * | ||
| * <p>触发时机:创建内存快照前,验证 VM 是否符合条件</p> | ||
| * <p>调用位置:VolumeSnapshotGroupCreator.validate()</p> | ||
| * | ||
| * <h3>使用场景:</h3> | ||
| * <p>各模块通过此扩展点检查 VM 的外部设备或网络引用 | ||
| * 是否与内存快照兼容。</p> | ||
| * | ||
| * @since 5.0.0 | ||
|
Comment on lines
+6
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment from ye.zou: Acknowledged. Chinese-to-English Javadoc translation and deprecated reference cleanup will be handled in a follow-up pass. Resolving to unblock merge. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Would you like me to create a follow-up issue to track this work? I can document the need to translate Chinese Javadoc to English across the affected files in this PR. Please let me know which issue tracking platform you'd prefer:
If you'd like to proceed, I'll create an issue that references this PR and comment, and includes the list of files requiring Javadoc translation (primarily |
||
| */ | ||
| public interface MemorySnapshotValidatorExtensionPoint { | ||
| default ErrorCode checkVmWhereMemorySnapshotExistExternalDevices(String VmInstanceUuid) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,18 @@ | |
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * 内存快照资源配置归档扩展点 | ||
| * | ||
| * <p>触发时机:创建内存快照时,归档与 VM 相关的资源配置</p> | ||
| * <p>调用位置:MemorySnapshotManager.archiveResourceConfig()</p> | ||
| * | ||
| * <h3>使用场景:</h3> | ||
| * <p>当 VM 执行内存快照时,各模块通过此扩展点提供需要归档的资源配置, | ||
| * 以便恢复快照时可以同时恢复相关配置状态。</p> | ||
| * | ||
| * @since 5.0.0 | ||
| */ | ||
|
Comment on lines
+5
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment from ye.zou: Acknowledged. Chinese-to-English Javadoc translation and deprecated reference cleanup will be handled in a follow-up pass. Resolving to unblock merge. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| public interface ResourceConfigMemorySnapshotExtensionPoint { | ||
| List<ArchiveResourceConfigBundle.ResourceConfigBundle> getNeedToArchiveResourceConfig(String resourceUuid); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,10 @@ | ||
| package org.zstack.header.vm; | ||
|
|
||
| /** | ||
| * @deprecated This interface has no implementations and should be removed. | ||
| * Use {@link org.zstack.header.vm.extensions.VmInstanceAttachL3NetworkExtensionPoint} instead. | ||
| */ | ||
| @Deprecated | ||
| public interface VmInstanceAttachNicExtensionPoint { | ||
| void afterAttachNicToVm(VmNicInventory nic); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -847,7 +847,9 @@ public void setBootMode(String bootMode) { | |
|
|
||
| public long getRootDiskAllocateSize() { | ||
| if (rootDiskOffering == null) { | ||
| return this.getImageSpec().getInventory().getSize(); | ||
| long virtualSize = this.getImageSpec().getInventory().getSize(); | ||
| long actualSize = this.getImageSpec().getInventory().getActualSize(); | ||
| return Math.max(virtualSize, actualSize); | ||
| } | ||
| return rootDiskOffering.getDiskSize(); | ||
| } | ||
|
Comment on lines
848
to
855
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, let's understand the VmInstanceSpec class structure
fd -e java -p "VmInstanceSpec.java$" | head -5Repository: MatheMatrix/zstack Length of output: 191 🏁 Script executed: # Read the VmInstanceSpec.java file to understand the full context
cat -n header/src/main/java/org/zstack/header/vm/VmInstanceSpec.java | head -150Repository: MatheMatrix/zstack Length of output: 5854 🏁 Script executed: # Look for the ImageSpec class to understand inventory field
fd -e java -p "ImageSpec.java$" | head -5Repository: MatheMatrix/zstack Length of output: 44 🏁 Script executed: # Search for all calls to getRootDiskAllocateSize
rg -n "getRootDiskAllocateSize" --type java -B 3 -A 3Repository: MatheMatrix/zstack Length of output: 4266 🏁 Script executed: # Examine the context in LocalStorageDesignatedAllocateCapacityFlow around line 160
sed -n '140,180p' plugin/localstorage/src/main/java/org/zstack/storage/primary/local/LocalStorageDesignatedAllocateCapacityFlow.javaRepository: MatheMatrix/zstack Length of output: 2419 🏁 Script executed: # Examine the context in LocalStorageDefaultAllocateCapacityFlow around line 158
sed -n '140,180p' plugin/localstorage/src/main/java/org/zstack/storage/primary/local/LocalStorageDefaultAllocateCapacityFlow.javaRepository: MatheMatrix/zstack Length of output: 2248 🏁 Script executed: # Examine the context in VmAllocatePrimaryStorageFlow around line 73
sed -n '50,90p' compute/src/main/java/org/zstack/compute/vm/VmAllocatePrimaryStorageFlow.javaRepository: MatheMatrix/zstack Length of output: 2154 🏁 Script executed: # Check if there are any places where imageSpec or its inventory is set/initialized
rg -n "setInventory|imageSpec\.inventory\s*=" --type java header/src/main/java/org/zstack/header/vm/ -B 2 -A 2Repository: MatheMatrix/zstack Length of output: 45460 🏁 Script executed: # Look for null checks on inventory in related files
rg -n "getInventory().*null|inventory.*null" --type java -i | head -20Repository: MatheMatrix/zstack Length of output: 3355
当 建议添加防御性检查: 建议的修复 public long getRootDiskAllocateSize() {
if (rootDiskOffering == null) {
+ ImageInventory inventory = this.getImageSpec().getInventory();
+ if (inventory == null) {
+ return 0L;
+ }
- long virtualSize = this.getImageSpec().getInventory().getSize();
- long actualSize = this.getImageSpec().getInventory().getActualSize();
+ long virtualSize = inventory.getSize();
+ long actualSize = inventory.getActualSize();
return Math.max(virtualSize, actualSize);
}
return rootDiskOffering.getDiskSize();
}🤖 Prompt for AI Agents |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| package org.zstack.header.vm; | ||
|
|
||
| /** | ||
| * 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 | ||
|
Comment on lines
3
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 弃用引用不完整:与 同样引用了上下文类 🤖 Prompt for AI Agents
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment from ye.zou: Acknowledged. Chinese-to-English Javadoc translation and deprecated reference cleanup will be handled in a follow-up pass. Resolving to unblock merge. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| public interface VmJustAfterDeleteFromDbExtensionPoint { | ||
| void vmJustAfterDeleteFromDbExtensionPoint(VmInstanceInventory inv, String accountUuid); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| package org.zstack.header.vm; | ||
|
|
||
| /** | ||
| * Created by xing5 on 2017/6/26. | ||
| * @deprecated Use {@link org.zstack.header.vm.extensions.VmDbDeleteContext} with a single-phase extension point instead. | ||
| */ | ||
| @Deprecated | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public interface VmJustBeforeDeleteFromDbExtensionPoint { | ||
| void vmJustBeforeDeleteFromDb(VmInstanceInventory inv); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 50374
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 2188
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 1969
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 4733
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 3713
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 1377
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 868
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 2834
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 787
desensitizeUrlList(config, "mdsInfos")是无效代码,且脱敏逻辑不完整,容易导致敏感数据泄露。根据代码分析,
mdsInfos从不出现在config字段中(config 仅包含mdsUrls和logicalPoolName等),因此第 77 行的调用是死代码。更严重的问题是:
addonInfo字段包含真实的mdsInfos对象(含 username、password 等敏感字段),但当前代码完全不对 addonInfo 进行脱敏,导致返回给客户端的 API 响应中仍包含明文凭证。建议:desensitizeUrlList(config, "mdsInfos")调用。addonInfo添加脱敏逻辑,对其中的mdsInfos列表元素进行脱敏(仅脱敏字符串类型元素以保证结构一致)。🤖 Prompt for AI Agents