Skip to content

fix(ZCF-4049): split attachable L3 domain filters#4125

Closed
zstack-robot-1 wants to merge 3 commits into
5.5.22from
sync/shixin.ruan/shixin-ZCF-4049@@2
Closed

fix(ZCF-4049): split attachable L3 domain filters#4125
zstack-robot-1 wants to merge 3 commits into
5.5.22from
sync/shixin.ruan/shixin-ZCF-4049@@2

Conversation

@zstack-robot-1
Copy link
Copy Markdown
Collaborator

修复说明

修复无网卡 VM 加载网卡时 ZNS VPC L3 不可选的问题。

变更内容

  • 在 compute 中按 L3 的 SDN controller vendor 分发 domain filter
  • VPC、ZNS、OVN 作为 OR 关系,只选择对应 domain filter
  • EIP 等非 domain filter 保持 common AND 过滤

验证

  • mvn -pl compute -am -DskipTests compile
  • root@172.20.13.240: mvn -pl test-premium -Dtest=org.zstack.test.integration.premium.zns.TestZnsVmNicBasicLifeCycleCase test

sync from gitlab !10024

Split attachable L3 domain filtering by SDN vendor.
Keep non-domain filters as common AND constraints.

Resolves: ZCF-4049

Change-Id: I417ca4abbe6dfdd5cabea67edcbcace4f2681acd
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 27, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent 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: e2db1d1d-4d1a-46ae-8b11-f15e7bf8179f

📥 Commits

Reviewing files that changed from the base of the PR and between cc254e1 and 46af569.

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

Walkthrough

新增域级扩展点并在 VmInstanceBase 中实现集中过滤:先按 SDN controller vendorType 将候选 L3 分组并应用对应域过滤器,再执行其它扩展点过滤;两个相关 API 改为调用该统一入口。

Changes

L3 网络域级过滤重构

层级 / 文件 摘要
扩展点合约
header/src/main/java/org/zstack/header/vm/VmAttachableL3NetworkDomainFilterExtensionPoint.java
新增 VmAttachableL3NetworkDomainFilterExtensionPoint 接口,定义获取 SDN 控制器厂商类型与按域过滤可挂载 L3 网络的方法。
导入与常量
compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java
添加与 SDN controller、L2 system tag、Tuple 相关的 imports 并新增常量 UNRESOLVED_SDN_VENDOR
API 处理器集成
compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java
APIGetVmAttachableL3NetworkAPIGetCandidateL3NetworksForChangeVmNicNetworkMsg 中,将原逐个扩展点链式过滤替换为对 filterAttachableL3Network(VmInstanceInventory, l3Invs) 的统一调用。
过滤实现
compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java
新增私有方法 filterAttachableL3NetworkfilterAttachableL3NetworkByDomaingetSdnControllerVendorTypeByL3Uuid:按 getSdnControllerVendorType() 将域过滤器分组,按 L3 的 vendorType 将网络分组,对应分组应用域过滤器并汇总结果;未解析 vendor/空白 vendor 标记为 UNRESOLVED_SDN_VENDOR
sequenceDiagram
  participant API_GetAttachable as APIGetVmAttachableL3Network handler
  participant API_GetCandidate as APIGetCandidateL3NetworksForChangeVmNicNetworkMsg handler
  participant FilterEntry as filterAttachableL3Network
  participant DomainFilter as VmAttachableL3NetworkDomainFilterExtensionPoint
  participant VendorLookup as getSdnControllerVendorTypeByL3Uuid
  API_GetAttachable->>FilterEntry: 调用 filterAttachableL3Network(vm, l3Invs)
  API_GetCandidate->>FilterEntry: 调用 filterAttachableL3Network(vm, l3Invs)
  FilterEntry->>VendorLookup: 批量解析每个 L3 的 vendorType
  FilterEntry->>DomainFilter: 按 vendorType 将 L3 分组并调用 filterAttachableL3NetworkInDomain
  FilterEntry->>FilterEntry: 跳过实现 DomainFilter 的扩展点,继续调用其它 FilterAttachableL3NetworkExtensionPoint
  FilterEntry->>API_GetAttachable: 返回最终过滤结果
Loading

🎯 4 (Complex) | ⏱️ ~45 分钟

🐰 我在代码田野里跳跃,
将网络按厂商分群奏乐,
域中筛选轻盈如风,
两处接口共舞同歌,
小兔祝合并顺利又稳。

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% 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 PR标题遵循了指定格式 [scope]: ,长度49字符,完全符合72字符限制要求。
Description check ✅ Passed PR描述清晰地说明了修复的问题、变更内容和验证步骤,与代码改动完全相关。
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-4049@@2

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.42.3)
compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java

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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
header/src/main/java/org/zstack/header/vm/VmAttachableL3NetworkDomainFilterExtensionPoint.java (1)

8-10: ⚡ Quick win

请为接口方法补充 Javadoc 以满足规范要求。

这两个扩展点方法当前没有接口级说明,后续实现方难以统一语义边界(如入参约束、返回值是否允许 null、过滤语义是“包含/排除”)。建议在方法声明处补充简洁且可执行的 Javadoc。

As per coding guidelines: “接口方法不应有多余的修饰符(例如 public),且必须配有有效的 Javadoc 注释。”

🤖 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
`@header/src/main/java/org/zstack/header/vm/VmAttachableL3NetworkDomainFilterExtensionPoint.java`
around lines 8 - 10, 为接口方法补充明确的 Javadoc:在
VmAttachableL3NetworkDomainFilterExtensionPoint 接口的两个方法
getSdnControllerVendorType() 和
filterAttachableL3NetworkInDomain(VmInstanceInventory vm,
List<L3NetworkInventory> l3s) 上分别添加简洁说明(方法用途/语义),对入参 vm 和 l3s 做约束说明(是否允许为
null、是否会被修改),声明返回值语义和 nullability(例如返回不可为 null 的过滤后列表,或者允许返回 null
并说明含义),明确过滤行为是“包含哪些可附加的 L3Network”还是“排除哪些不可附加的
L3Network”,并说明抛出的受检/运行时异常(若有);注意仍不要添加方法修饰符(如 public)。
🤖 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.

Inline comments:
In `@compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java`:
- Around line 5161-5194: The loop calls getSdnControllerVendorType(l3.getUuid())
for each L3 and causes N+1 DB queries; fix by precomputing a l3Uuid->vendorType
map before grouping: collect all L3 UUIDs, map each to its controller UUID via
L3NetworkHelper.getSdnControllerUuidFromL3Uuid, collect non-null controller
UUIDs, batch-query SdnControllerVO (select uuid,vendorType with
Q.New(...).in(...).list()) to build controllerUuid->vendorType, then produce
l3Uuid->vendorType by looking up each L3's controller UUID (falling back to
null), and use that map instead of calling getSdnControllerVendorType inside the
loop (or alternatively implement a method-level cache used by
getSdnControllerVendorType to avoid DB hits).

---

Nitpick comments:
In
`@header/src/main/java/org/zstack/header/vm/VmAttachableL3NetworkDomainFilterExtensionPoint.java`:
- Around line 8-10: 为接口方法补充明确的 Javadoc:在
VmAttachableL3NetworkDomainFilterExtensionPoint 接口的两个方法
getSdnControllerVendorType() 和
filterAttachableL3NetworkInDomain(VmInstanceInventory vm,
List<L3NetworkInventory> l3s) 上分别添加简洁说明(方法用途/语义),对入参 vm 和 l3s 做约束说明(是否允许为
null、是否会被修改),声明返回值语义和 nullability(例如返回不可为 null 的过滤后列表,或者允许返回 null
并说明含义),明确过滤行为是“包含哪些可附加的 L3Network”还是“排除哪些不可附加的
L3Network”,并说明抛出的受检/运行时异常(若有);注意仍不要添加方法修饰符(如 public)。
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ 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: 7f82b004-8a6f-4b1f-bf4d-2f1e7d744db5

📥 Commits

Reviewing files that changed from the base of the PR and between a621cf2 and 6496cc3.

📒 Files selected for processing (2)
  • compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java
  • header/src/main/java/org/zstack/header/vm/VmAttachableL3NetworkDomainFilterExtensionPoint.java

Comment thread compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java Outdated
Batch SDN vendor lookup for attachable L3 filters.
Document the domain filter extension contract.

Resolves: ZCF-4049

Change-Id: Iaaa3e66a1be47840999965330cc4efbb4c96f3b1
return Q.New(SdnControllerVO.class)
.select(SdnControllerVO_.vendorType)
.eq(SdnControllerVO_.uuid, controllerUuid)
.findValue();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Comment from shixin.ruan:

已处理。

  • 将 per-L3 getSdnControllerVendorType() 改为本次过滤内批量构造 l3Uuid -> vendorType:先批量查询 L3/L2,再批量读取 L2 SDN controller system tag,最后批量查询 controller vendor type。
  • 保持原有 VPC/ZNS/OVN domain OR 语义不变,EIP/common filter 仍在后续 AND 阶段执行。
  • 顺手补充了新 extension point 的接口 Javadoc。

验证:mvn -pl compute -am -DskipTests compile 通过;远端 Codex review 未发现新的 correctness issue。

Commit: cc254e16d1

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.

Actionable comments posted: 1

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

Inline comments:
In `@compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java`:
- Around line 5165-5169: The code groups L3 networks by vendor using
vendorTypeByL3Uuid.get(...) and treats a missing mapping as null, which mixes
SDN L3s with unresolved vendor into the default (non-SDN) bucket; change the
grouping logic in VmInstanceBase (the loop that builds l3sByVendor using
getSdnControllerVendorTypeByL3Uuid) to distinguish three cases: (1) non-SDN L3s
(no SdnControllerUuid tag) => keep using null/defaultFilters, (2) SDN L3s with a
resolved vendorType => use that vendorType as the key, and (3) SDN L3s with an
unresolved vendor record or empty vendorType => use an explicit sentinel key
(e.g., "UNRESOLVED_SDN_VENDOR") so they remain a separate group and are
forwarded to SDN handling; apply the same change to the similar grouping code
around the other occurrence (lines ~5249-5259) so unresolved vendorType is not
mixed into defaultFilters.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ 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: cd2345fa-0dde-4099-b134-e24c1f32a578

📥 Commits

Reviewing files that changed from the base of the PR and between 6496cc3 and cc254e1.

📒 Files selected for processing (2)
  • compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java
  • header/src/main/java/org/zstack/header/vm/VmAttachableL3NetworkDomainFilterExtensionPoint.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • header/src/main/java/org/zstack/header/vm/VmAttachableL3NetworkDomainFilterExtensionPoint.java

Comment thread compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java
Do not route unresolved SDN vendors to default filters.

Resolves: ZCF-4049

Change-Id: I257433e821925538f2a1ad0b68788a20a020bd17
@zstack-robot-1 zstack-robot-1 deleted the sync/shixin.ruan/shixin-ZCF-4049@@2 branch May 28, 2026 03:38
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.

4 participants