Skip to content

<fix>[zns]: ZCF-3728 propagate vm system tags#4017

Open
ZStack-Robot wants to merge 2 commits into
5.5.22from
sync/shixin.ruan/shixin-ZCF-3728@@2
Open

<fix>[zns]: ZCF-3728 propagate vm system tags#4017
ZStack-Robot wants to merge 2 commits into
5.5.22from
sync/shixin.ruan/shixin-ZCF-3728@@2

Conversation

@ZStack-Robot
Copy link
Copy Markdown
Collaborator

Summary\nFix ZCF-3728 ZNS VM placement input propagation. VM API system tags are now copied to AllocateHostMsg so allocator filters can see znsNicMode.\n\n## Changes\n- Propagate API system tags into AllocateHostMsg during VM host allocation.\n\n## Testing\n- [x] mvn -pl compute -am -DskipTests install\n- [x] ./runMavenProfile premium\n- [x] mvn -pl test-premium -Dtest=TestZnsVmNicBasicLifeCycleCase -DskipJacoco=true -DfailIfNoTests=false test\n\nResolves: ZCF-3728

sync from gitlab !9911

Pass VM API system tags into AllocateHostMsg so host allocator filters can honor znsNicMode during VM placement.

Resolves: ZCF-3728

Change-Id: I4fbb522440931aad005ceb82a37a29236bd35b27
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 19, 2026

Review Change Stack

Walkthrough

新增:在宿主分配请求中转发 APIMessage 的 systemTags;将容量重算中补齐 HostUsedCpuMem 的遍历逻辑改为显式 for 循环并跳过有 VM 的宿主;为 KVM 容量上报消息设置 30 分钟超时。

Changes

Host allocation and capacity changes

Layer / File(s) Summary
System tags propagation in host allocation
compute/src/main/java/org/zstack/compute/vm/VmAllocateHostFlow.java
新增 APIMessage 导入及条件分支,在 prepareMsg 中当 spec.getMessage()APIMessage 且含 systemTags 时复制并设置到分配消息上。
Host capacity recalculation loop change
compute/src/main/java/org/zstack/compute/allocator/HostAllocatorManagerImpl.java
hostUuids 的补齐逻辑从 Stream 过滤改为显式 for 循环,遇到已有 VM 的宿主时 continue,其余宿主创建 HostUsedCpuMem 并加入列表。
KVM capacity report timeout
plugin/kvm/src/main/java/org/zstack/kvm/KVMHostCapacityExtension.java
新增 TimeUnit 导入,并在 reportCapacity 中对 CheckHostCapacityMsg 调用 setTimeout(TimeUnit.MINUTES.toMillis(30)),将超时设为 30 分钟。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

小兔在草间忙忙跑,
标签随消息跳跳到,
宿主遍历转成环,
KVM 报告三十分钟好,
我拍爪子为改动鼓掌 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Title check ✅ Passed 标题遵循规定的格式 [scope]: ,长度为45字符,未超过72字符限制。
Description check ✅ Passed 描述清晰相关,说明了修复 ZCF-3728 的目的、具体变更内容(将 VM API 系统标签传播到 AllocateHostMsg)及测试情况。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sync/shixin.ruan/shixin-ZCF-3728@@2

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

Copy link
Copy Markdown

@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.

🧹 Nitpick comments (1)
compute/src/main/java/org/zstack/compute/vm/VmAllocateHostFlow.java (1)

99-101: ⚡ Quick win

建议提取类型转换以提升可读性

当前代码对 spec.getMessage() 进行了多次类型转换为 APIMessage,建议提取到局部变量以避免重复转换并提升代码可读性。

♻️ 建议的重构
-        if (spec.getMessage() instanceof APIMessage && ((APIMessage) spec.getMessage()).getSystemTags() != null) {
-            msg.setSystemTags(new ArrayList<>(((APIMessage) spec.getMessage()).getSystemTags()));
+        if (spec.getMessage() instanceof APIMessage) {
+            APIMessage apiMessage = (APIMessage) spec.getMessage();
+            if (apiMessage.getSystemTags() != null) {
+                msg.setSystemTags(new ArrayList<>(apiMessage.getSystemTags()));
+            }
         }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@compute/src/main/java/org/zstack/compute/vm/VmAllocateHostFlow.java` around
lines 99 - 101, The code repeatedly casts spec.getMessage() to APIMessage when
checking and copying system tags; extract spec.getMessage() as a local
APIMessage variable (e.g., APIMessage apiMsg = (APIMessage) spec.getMessage())
after verifying instance-of, then use apiMsg.getSystemTags() when calling
msg.setSystemTags(new ArrayList<>(apiMsg.getSystemTags())); update the
conditional to use the local variable to improve readability and avoid duplicate
casts in VmAllocateHostFlow.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@compute/src/main/java/org/zstack/compute/vm/VmAllocateHostFlow.java`:
- Around line 99-101: The code repeatedly casts spec.getMessage() to APIMessage
when checking and copying system tags; extract spec.getMessage() as a local
APIMessage variable (e.g., APIMessage apiMsg = (APIMessage) spec.getMessage())
after verifying instance-of, then use apiMsg.getSystemTags() when calling
msg.setSystemTags(new ArrayList<>(apiMsg.getSystemTags())); update the
conditional to use the local variable to improve readability and avoid duplicate
casts in VmAllocateHostFlow.

ℹ️ 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: 4302ffa1-ded1-43fc-89aa-fdbac3761164

📥 Commits

Reviewing files that changed from the base of the PR and between f49991f and 2dcf85f.

📒 Files selected for processing (1)
  • compute/src/main/java/org/zstack/compute/vm/VmAllocateHostFlow.java

Avoid bad host allocator lambda bytecode.
Set KVM capacity sync timeout explicitly.

Test: VmwareTest passed on root@172.20.13.240.

Resolves: ZCF-3728

Change-Id: I5db26740b9fef0c0ba1b31096a8fdc3659db412b
@ZStack-Robot
Copy link
Copy Markdown
Collaborator Author

Comment from gitlab:

自上次添加REVIEWED标签(2026-05-19 08:25:09.000Z)后, 有新的COMMIT更新(2026-05-19 22:31:47.787Z), 所以移除了REVIEWED标签

Copy link
Copy Markdown

@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.

🧹 Nitpick comments (1)
plugin/kvm/src/main/java/org/zstack/kvm/KVMHostCapacityExtension.java (1)

35-35: ⚡ Quick win

将超时分钟数提取为命名常量,避免魔法值。

当前实现可用,但 30 建议抽成常量,便于统一调整和语义表达。

建议修改
 public class KVMHostCapacityExtension implements KVMHostConnectExtensionPoint, HostConnectionReestablishExtensionPoint {
+    private static final long CHECK_HOST_CAPACITY_TIMEOUT_MILLIS = TimeUnit.MINUTES.toMillis(30);
@@
-        msg.setTimeout(TimeUnit.MINUTES.toMillis(30));
+        msg.setTimeout(CHECK_HOST_CAPACITY_TIMEOUT_MILLIS);

As per coding guidelines: “避免使用魔法值(Magic Value):直接使用未经定义的数值或字符串应替换为常量或枚举。”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@plugin/kvm/src/main/java/org/zstack/kvm/KVMHostCapacityExtension.java` at
line 35, Replace the magic literal 30 in the timeout call with a named constant:
declare a private static final long (e.g. HOST_CAPACITY_TIMEOUT_MINUTES = 30L)
in the KVMHostCapacityExtension class and use it in
msg.setTimeout(TimeUnit.MINUTES.toMillis(HOST_CAPACITY_TIMEOUT_MINUTES)); this
centralizes the value, documents its meaning, and avoids the magic number.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@plugin/kvm/src/main/java/org/zstack/kvm/KVMHostCapacityExtension.java`:
- Line 35: Replace the magic literal 30 in the timeout call with a named
constant: declare a private static final long (e.g.
HOST_CAPACITY_TIMEOUT_MINUTES = 30L) in the KVMHostCapacityExtension class and
use it in
msg.setTimeout(TimeUnit.MINUTES.toMillis(HOST_CAPACITY_TIMEOUT_MINUTES)); this
centralizes the value, documents its meaning, and avoids the magic number.

ℹ️ 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: d9990735-ead3-4930-8388-b05b4a7d2f97

📥 Commits

Reviewing files that changed from the base of the PR and between 2dcf85f and dd5088c.

📒 Files selected for processing (2)
  • compute/src/main/java/org/zstack/compute/allocator/HostAllocatorManagerImpl.java
  • plugin/kvm/src/main/java/org/zstack/kvm/KVMHostCapacityExtension.java

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