Skip to content

<fix>[sugonSdn]: sync tf ports after ping#4033

Open
zstack-robot-2 wants to merge 2 commits into
5.5.22from
sync/shixin.ruan/shixin-ZSTAC-85281
Open

<fix>[sugonSdn]: sync tf ports after ping#4033
zstack-robot-2 wants to merge 2 commits into
5.5.22from
sync/shixin.ruan/shixin-ZSTAC-85281

Conversation

@zstack-robot-2
Copy link
Copy Markdown
Collaborator

Root cause:
TfZstackPortSync was started from MN ready even when no TF controller exists. The task then built TfPortClient without a controller and getPortToDelete returned null after the fetch failure, leading to a secondary NPE.

Fix:
Trigger TF port sync from TF controller ping success, keep the original one day interval and existing cleanup algorithm, and scope sync/delete operations to the current controller uuid.

Verification:

  • mvn -pl plugin/sugonSdnController -am -DskipTests compile
  • git diff --check

Note:
Focused SugonSdnControllerCase was attempted locally before branch isolation, but the local test DB already existed during deploydb, so the case did not start.

sync from gitlab !9929

Trigger TF port sync from TF controller ping success instead of MN startup. Keep the original one day interval and port cleanup algorithm, while scoping sync to the current controller.

Resolves: ZSTAC-85281

Change-Id: I84a88a34135cd47fc79b3019d2f0fc2953f06ac9
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

Review Change Stack

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • conf/springConfigXml/sugonSdnController.xml is excluded by !**/*.xml

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

⚙️ 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: b57f43f0-2dfb-4622-92d4-90e3a1d31eed

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

总体概述

该 PR 实现了 SDN 控制器的 ping 消息驱动端口同步机制。当控制器收到 ping 消息时,验证连接有效性后触发端口同步,同时新增 per-controller 的速率限制和并发防护,将之前的周期性后台同步改为按需触发。

变更内容

Ping 消息驱动端口同步

层级 / 文件 摘要
Ping 消息处理
plugin/sugonSdnController/src/main/java/org/zstack/sugonSdnController/controller/SugonSdnController.java
handleMessage 新增 SdnControllerPingMsg 分支路由;新增 handMessage(SdnControllerPingMsg) 方法通过 TfHttpClient 验证 Domain 可访问性,成功则触发 tfZstackPortSync.triggerSyncIfDue();新增相关 import 和 @Autowired 字段注入。
按控制器 UUID 作用域的端口操作
plugin/sugonSdnController/src/main/java/org/zstack/sugonSdnController/controller/neutronClient/TfPortClient.java, plugin/sugonSdnController/src/main/java/org/zstack/sugonSdnController/network/TfPortService.java
TfPortClient 新增 TfPortClient(String sdnControllerUuid) 构造方法,按 UUID 初始化并校验 vendorType。TfPortService 新增 getTfPortsDetail(String sdnControllerUuid)deleteTfPort(String sdnControllerUuid, String portUUid) 重载方法,实现 controller-scoped 的端口查询和删除。
按需触发的同步流程与速率限制
plugin/sugonSdnController/src/main/java/org/zstack/sugonSdnController/network/TfZstackPortSync.java
ManagementNodeReadyExtensionPoint 周期性任务重构为按需触发:移除 managementNodeReady() 和定期线程,新增 triggerSyncIfDue(String sdnControllerUuid) 实现 per-controller 速率限制和并发防护(lastSyncTimerunningSyncs 状态);内部 SyncPort 任务改用 Task<Void> 接口的 call() 方法;端口删除逻辑改为 controller-scoped 调用;getPortToDelete() 异常时返回空集合而非 null;finally 块保证清理运行中的同步标记。
集成测试
test/src/test/groovy/org/zstack/test/integration/network/sdnController/SugonSdnControllerCase.groovy
新增 testTfPortSyncTriggeredByPingSuccess()sendTfPing(String sdnControllerUuid) 方法,验证 ping 消息触发的端口同步流程,模拟 TF VMI 端点返回空列表,通过 AtomicInteger 计数同步触发次数,断言触发仅一次且速率限制生效。

🎯 3 (中等) | ⏱️ ~25 分钟

🐰 通过 ping 的魔法,唤醒沉睡的同步
控制器闻声而来,按需而作
不再周期困扰,智能速率守护
一条消息,一次同步,完美和谐~ 🌟

🚥 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 PR标题清晰准确地描述了主要变更:从MN就绪时触发改为从TF控制器ping成功后触发端口同步,完全对应changeset的核心目标。
Description check ✅ Passed PR描述明确阐述了根本原因、修复方案和验证步骤,与changeset的所有变更高度相关且逻辑一致。
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sync/shixin.ruan/shixin-ZSTAC-85281

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

Change-Id: If07dce918c4d7d9f62445184ff5984e30b83ce64
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