Skip to content

<feature>[dgpu]: update strategy API SDK#4023

Open
zstack-robot-1 wants to merge 1 commit into
feature-5.5.22-aiosfrom
sync/xinhao.huang/feature/ZSTAC-84067-dgpu-api-update@@2
Open

<feature>[dgpu]: update strategy API SDK#4023
zstack-robot-1 wants to merge 1 commit into
feature-5.5.22-aiosfrom
sync/xinhao.huang/feature/ZSTAC-84067-dgpu-api-update@@2

Conversation

@zstack-robot-1
Copy link
Copy Markdown
Collaborator

Rename SetVmDGpuStrategy SDK bindings to UpdateVmDGpuStrategy and expose the updated testlib helper.

APIImpact

Related: ZSTAC-84067

Change-Id: I7a1822b01861192c4baee5e0772354487423d5ce

sync from gitlab !9918

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: 4dca1c07-cbc4-4cf0-adb4-c6f73affa48a

📥 Commits

Reviewing files that changed from the base of the PR and between 4622440 and 907e5a5.

⛔ Files ignored due to path filters (3)
  • sdk/src/main/java/org/zstack/sdk/SetVmDGpuStrategyResult.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/UpdateVmDGpuAction.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/UpdateVmDGpuResult.java is excluded by !sdk/**
📒 Files selected for processing (4)
  • plugin/kvm/src/main/java/org/zstack/kvm/KVMHost.java
  • plugin/kvm/src/main/java/org/zstack/kvm/KVMHotPlugVmShmemMsg.java
  • plugin/kvm/src/main/java/org/zstack/kvm/KVMHotUnplugVmShmemMsg.java
  • testlib/src/main/java/org/zstack/testlib/ApiHelper.groovy

Walkthrough

拆分 KVM shmem 消息字段为 shmemName/shmemPath/shmemSize 并在 KVMHost 中新增 buildVmShmemDevice(...) 构造 cmd.shmem;同时将 testlib 中 ApiHelper 的 setVmDGpuStrategy(...) 重命名为 updateVmDGpu(...) 并切换到 UpdateVmDGpuAction

变更说明

KVM shmem 字段与构造逻辑变更

Layer / File(s) Summary
消息载荷:拆分 shmem 字段为 name/path/size
plugin/kvm/src/main/java/org/zstack/kvm/KVMHotPlugVmShmemMsg.java, plugin/kvm/src/main/java/org/zstack/kvm/KVMHotUnplugVmShmemMsg.java
删除原有 KVMAgentCommands.VmShmemDevice shmem 字段,新增 shmemName/shmemPath/shmemSize 三个字段及相应 getter/setter;新增 normalize 校验并在 size <= 0 时抛出 IllegalArgumentException
KVMHost: 基于字段构造 VmShmemDevice 并复用
plugin/kvm/src/main/java/org/zstack/kvm/KVMHost.java
在热插拔和热卸载处理处将 cmd.shmemmsg.getShmem() 改为调用 buildVmShmemDevice(name,path,size),并新增该私有构造方法以返回 KVMAgentCommands.VmShmemDevice

VM GPU 策略方法重命名

Layer / File(s) Summary
updateVmDGpu 方法签名与 action 类型更新
testlib/src/main/java/org/zstack/testlib/ApiHelper.groovy
将公开方法 setVmDGpuStrategy 重命名为 updateVmDGpu,并把 @DelegatesTovalueorg.zstack.sdk.SetVmDGpuStrategyAction.class 改为 org.zstack.sdk.UpdateVmDGpuAction.class;方法体内创建的 new org.zstack.sdk.SetVmDGpuStrategyAction() 替换为 new org.zstack.sdk.UpdateVmDGpuAction()

评估代码审查工作量

🎯 3 (Moderate) | ⏱️ ~20 minutes

可能相关的 PRs

  • MatheMatrix/zstack#4005: 与本 PR 在 shmem 热插拔消息与 KVMHost 构造链路上存在交叉改动或相同功能路径。

庆祝诗

🐰 我是一只小兔说,
字段拆分更明了,
host 用小函数造设备,
helper 名字也改好,
提交合并来跳跃.

🚥 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标题完全相关,准确概括了主要改动,即更新GPU策略相关的SDK API(SetVmDGpuStrategy重命名为UpdateVmDGpu)。
Description check ✅ Passed PR描述与变更集相关,明确说明了重命名SDK绑定和暴露testlib助手的目的,与实际代码改动保持一致。
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/xinhao.huang/feature/ZSTAC-84067-dgpu-api-update@@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.2)
plugin/kvm/src/main/java/org/zstack/kvm/KVMHost.java

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

@MatheMatrix MatheMatrix force-pushed the sync/xinhao.huang/feature/ZSTAC-84067-dgpu-api-update@@2 branch 2 times, most recently from 4011d57 to 3b38ffd Compare May 20, 2026 07:30
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: 2

🤖 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 `@plugin/kvm/src/main/java/org/zstack/kvm/KVMHotPlugVmShmemMsg.java`:
- Around line 34-35: Update the message setters to normalize and validate
inputs: in setShmemName (and the similar setter for shmemPath) call trim() on
the incoming String, treat empty/blank results as null or reject by throwing
IllegalArgumentException with a clear message, and assign the normalized value
to the field; in the setter for shmemSize validate that the incoming long is > 0
and throw IllegalArgumentException (or otherwise enforce a sane minimum) if it
is non‑positive so invalid sizes cannot be propagated. Use the existing setter
names (setShmemName, the shmemPath setter, and setShmemSize) to locate where to
apply trim/null checks and positive-value validation.

In `@plugin/kvm/src/main/java/org/zstack/kvm/KVMHotUnplugVmShmemMsg.java`:
- Around line 34-35: The setters in KVMHotUnplugVmShmemMsg lack input
normalization and validation; update setShmemName and setVmInstanceUuid to trim
incoming Strings safely (null-check before calling trim) and update setShmemSize
to validate the value is a positive number (shmemSize > 0) and throw an
appropriate IllegalArgumentException if invalid, mirroring the checks present in
the corresponding hot-plug message class so both message paths enforce the same
constraints.
🪄 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: 30e28a11-cc56-42bf-a00a-6e6a2c118a52

📥 Commits

Reviewing files that changed from the base of the PR and between 4011d57 and 3b38ffd.

⛔ Files ignored due to path filters (3)
  • sdk/src/main/java/org/zstack/sdk/SetVmDGpuStrategyResult.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/UpdateVmDGpuAction.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/UpdateVmDGpuResult.java is excluded by !sdk/**
📒 Files selected for processing (4)
  • plugin/kvm/src/main/java/org/zstack/kvm/KVMHost.java
  • plugin/kvm/src/main/java/org/zstack/kvm/KVMHotPlugVmShmemMsg.java
  • plugin/kvm/src/main/java/org/zstack/kvm/KVMHotUnplugVmShmemMsg.java
  • testlib/src/main/java/org/zstack/testlib/ApiHelper.groovy

Comment thread plugin/kvm/src/main/java/org/zstack/kvm/KVMHotPlugVmShmemMsg.java Outdated
Comment thread plugin/kvm/src/main/java/org/zstack/kvm/KVMHotUnplugVmShmemMsg.java Outdated
@MatheMatrix MatheMatrix force-pushed the sync/xinhao.huang/feature/ZSTAC-84067-dgpu-api-update@@2 branch from 3b38ffd to 4622440 Compare May 20, 2026 07:47
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.

♻️ Duplicate comments (2)
plugin/kvm/src/main/java/org/zstack/kvm/KVMHotUnplugVmShmemMsg.java (1)

34-36: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

与热插拔消息保持一致:增加 trimshmemSize > 0 约束。

Line 34、Line 42、Line 50 与对应 HotPlug 消息一致地需要输入规整和边界防护,否则两条路径会出现不一致的参数质量。

建议修改
 public void setShmemName(String shmemName) {
-    this.shmemName = shmemName;
+    this.shmemName = shmemName == null ? null : shmemName.trim();
 }

 public void setShmemPath(String shmemPath) {
-    this.shmemPath = shmemPath;
+    this.shmemPath = shmemPath == null ? null : shmemPath.trim();
 }

 public void setShmemSize(long shmemSize) {
+    if (shmemSize <= 0) {
+        throw new IllegalArgumentException("shmemSize must be greater than 0");
+    }
     this.shmemSize = shmemSize;
 }

As per coding guidelines "注意检查来自 Message 的参数是否做过 trim,用户可能在浏览器上复制粘贴的数据带有空格、换行符等"。

Also applies to: 42-44, 50-51

🤖 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/KVMHotUnplugVmShmemMsg.java` around
lines 34 - 36, In KVMHotUnplugVmShmemMsg adjust the setters to normalize and
validate inputs like the HotPlug counterpart: in setShmemName(...) and the other
message setters (e.g., setBus(...)) call trim() on incoming String parameters to
remove whitespace, and in setShmemSize(...) enforce shmemSize > 0 (throw
IllegalArgumentException or similar) to guard against non-positive sizes; update
the constructors/getters usage if any to rely on the normalized values so both
hot-plug and hot-unplug paths have consistent parameter quality.
plugin/kvm/src/main/java/org/zstack/kvm/KVMHotPlugVmShmemMsg.java (1)

34-36: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

补齐消息入参规整与 shmemSize 边界校验。

Line 34、Line 42、Line 50 目前是直接透传,建议在 setter 中统一做 trim()(含 null 安全)并拒绝 shmemSize <= 0,避免无效参数继续下游传播。

建议修改
 public void setShmemName(String shmemName) {
-    this.shmemName = shmemName;
+    this.shmemName = shmemName == null ? null : shmemName.trim();
 }

 public void setShmemPath(String shmemPath) {
-    this.shmemPath = shmemPath;
+    this.shmemPath = shmemPath == null ? null : shmemPath.trim();
 }

 public void setShmemSize(long shmemSize) {
+    if (shmemSize <= 0) {
+        throw new IllegalArgumentException("shmemSize must be greater than 0");
+    }
     this.shmemSize = shmemSize;
 }

As per coding guidelines "注意检查来自 Message 的参数是否做过 trim,用户可能在浏览器上复制粘贴的数据带有空格、换行符等"。

Also applies to: 42-44, 50-51

🤖 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/KVMHotPlugVmShmemMsg.java` around
lines 34 - 36, The setters for message parameters must normalize input and
validate bounds: update setShmemName, setShmemPath and setShmemSize to be
null-safe and trim String inputs (use something like value == null ? null :
value.trim()) and for setShmemSize reject non-positive sizes by throwing an
IllegalArgumentException (or other appropriate runtime exception) when shmemSize
<= 0 so invalid parameters aren't propagated downstream; reference the methods
setShmemName, setShmemPath and setShmemSize when making these changes.
🤖 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.

Duplicate comments:
In `@plugin/kvm/src/main/java/org/zstack/kvm/KVMHotPlugVmShmemMsg.java`:
- Around line 34-36: The setters for message parameters must normalize input and
validate bounds: update setShmemName, setShmemPath and setShmemSize to be
null-safe and trim String inputs (use something like value == null ? null :
value.trim()) and for setShmemSize reject non-positive sizes by throwing an
IllegalArgumentException (or other appropriate runtime exception) when shmemSize
<= 0 so invalid parameters aren't propagated downstream; reference the methods
setShmemName, setShmemPath and setShmemSize when making these changes.

In `@plugin/kvm/src/main/java/org/zstack/kvm/KVMHotUnplugVmShmemMsg.java`:
- Around line 34-36: In KVMHotUnplugVmShmemMsg adjust the setters to normalize
and validate inputs like the HotPlug counterpart: in setShmemName(...) and the
other message setters (e.g., setBus(...)) call trim() on incoming String
parameters to remove whitespace, and in setShmemSize(...) enforce shmemSize > 0
(throw IllegalArgumentException or similar) to guard against non-positive sizes;
update the constructors/getters usage if any to rely on the normalized values so
both hot-plug and hot-unplug paths have consistent parameter quality.

ℹ️ 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: 635d8a8e-443d-4d12-9add-e66f1f5962be

📥 Commits

Reviewing files that changed from the base of the PR and between 3b38ffd and 4622440.

⛔ Files ignored due to path filters (3)
  • sdk/src/main/java/org/zstack/sdk/SetVmDGpuStrategyResult.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/UpdateVmDGpuAction.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/UpdateVmDGpuResult.java is excluded by !sdk/**
📒 Files selected for processing (4)
  • plugin/kvm/src/main/java/org/zstack/kvm/KVMHost.java
  • plugin/kvm/src/main/java/org/zstack/kvm/KVMHotPlugVmShmemMsg.java
  • plugin/kvm/src/main/java/org/zstack/kvm/KVMHotUnplugVmShmemMsg.java
  • testlib/src/main/java/org/zstack/testlib/ApiHelper.groovy

Rename SetVmDGpuStrategy SDK bindings to UpdateVmDGpu and expose the updated testlib helper.

Carry VM shmem hotplug parameters through KVM messages as primitive fields so dGPU code does not expose agent command DTOs across modules.

APIImpact

Related: ZSTAC-84067

Change-Id: I7a1822b01861192c4baee5e0772354487423d5ce
@MatheMatrix MatheMatrix force-pushed the sync/xinhao.huang/feature/ZSTAC-84067-dgpu-api-update@@2 branch from 4622440 to 907e5a5 Compare May 20, 2026 08:29
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.

1 participant