Skip to content

<feature>[dpu-bm2]: support dpu baremetal2 instance#3482

Open
zstack-robot-1 wants to merge 1 commit into5.5.12from
sync/shan.wu/feature-dpu-baremetal@@2
Open

<feature>[dpu-bm2]: support dpu baremetal2 instance#3482
zstack-robot-1 wants to merge 1 commit into5.5.12from
sync/shan.wu/feature-dpu-baremetal@@2

Conversation

@zstack-robot-1
Copy link
Collaborator

support dpu baremetal2 instance

Resolves/Related: ZSTAC-12345

Change-Id: I626d637a7168656a6c726c6769777a726e616973
[dpu-bm2]: support dpu baremetal2 instance

support dpu baremetal2 instance

Resolves/Related: ZSTAC-80830

Change-Id: I626d637a7168656a6c726c6769777a726e616973

sync from gitlab !9341

@coderabbitai
Copy link

coderabbitai bot commented Mar 13, 2026

Walkthrough

将裸金属2型扩展为支持 DPU(baremetal2Dpu):更新主机管理器的架构检查条件以基于集群类型,新增 DPU 相关数据库表,注册新的集群 hypervisor 类型,扩展测试辅助方法并添加多项错误码常量。

Changes

Cohort / File(s) Summary
主机管理器逻辑调整
compute/src/main/java/org/zstack/compute/host/HostManagerImpl.java
新增静态列表 SKIP_ARCH_CHECK_HYPERVISOR_TYPES 并将跳过架构校验的判定从主机 hypervisorType 改为基于集群 cluster.getHypervisorType(),包含 baremetal2baremetal2Dpu
数据库模式扩展
conf/db/upgrade/V5.5.12__schema.sql
新增表 BareMetal2DpuChassisVOBareMetal2DpuHostVO(含主键、字段、外键与删除策略);调整 BareMetal2InstanceVO 的外键约束,gatewayUuid/lastGatewayUuid 指向 HostEO(uuid) 且 ON DELETE SET NULL。
API/文档更新
header/src/main/java/org/zstack/header/cluster/APICreateClusterMsg.java, header/src/main/java/org/zstack/header/cluster/APICreateClusterMsgDoc_zh_cn.groovy
APICreateClusterMsghypervisorType 有效值集中添加 baremetal2Dpu,并同步更新中文文档示例/说明。
测试库工具增强
testlib/src/main/java/org/zstack/testlib/ApiHelper.groovy
新增多条 API 辅助方法(多处新增,遵循统一调用/追踪模式),覆盖安全组、VPC、VPN 等操作,统一设置 session、delegate、apipath 跟踪与错误包装。
错误码常量扩展
utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java
新增多项公有静态错误码常量,包含 BareMetal2 DPU/网关、存储、网络等模块的标识常量。

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant HostMgr as HostManagerImpl
    participant ClusterSvc as Cluster (DB/Service)
    participant ArchCheck as ArchValidator

    Client->>HostMgr: 请求添加/连接主机
    HostMgr->>ClusterSvc: 查询 cluster.getHypervisorType()
    ClusterSvc-->>HostMgr: 返回 hypervisorType
    HostMgr->>ArchCheck: 基于 cluster hypervisorType 决定是否跳过架构校验
    alt cluster in SKIP list
        ArchCheck-->>HostMgr: 跳过校验
    else
        ArchCheck-->>HostMgr: 执行校验
    end
    HostMgr-->>Client: 返回结果
Loading

代码审查工作量估计

🎯 4 (复杂) | ⏱️ ~60 分钟

庆祝诗

🐰 新簇生,DPU轻跃枝头,
主机省察从群来决定,
表格添行连桥更稳妥,
码表列新名以备检索,
我在草间为变更鼓掌 🌱

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Title check ✅ Passed PR标题遵循了必需的[scope]: 格式,51个字符在72字符限制内,清晰概括了DPU Baremetal2实例支持的核心变更。
Description check ✅ Passed PR描述与变更集相关,涵盖DPU Baremetal2实例支持的主题,包含相关问题编号和变更追溯信息。

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sync/shan.wu/feature-dpu-baremetal@@2
📝 Coding Plan
  • Generate coding plan for human review comments

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.41.1)
utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java

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

support dpu baremetal2 instance

Resolves/Related: ZSTAC-12345

Change-Id: I626d637a7168656a6c726c6769777a726e616973
@MatheMatrix MatheMatrix force-pushed the sync/shan.wu/feature-dpu-baremetal@@2 branch from 5718b67 to 2318947 Compare March 13, 2026 05:53
Copy link

@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

🧹 Nitpick comments (2)
header/src/main/java/org/zstack/header/cluster/APICreateClusterMsg.java (1)

68-73: 建议同步更新 @choices 注释,避免与 validValues 不一致。

Line 73 已支持 baremetal2/baremetal2Dpu/xdragon,但上方 @choices 仍是旧列表,建议补齐以免误导。

建议修改
     /**
      * `@desc` see field 'hypervisorType' of :ref:`ClusterInventory` for details
      * `@choices` - KVM
      * - Simulator
      * - baremetal
+     * - baremetal2
+     * - xdragon
+     * - baremetal2Dpu
      */
     `@APIParam`(validValues = {"KVM", "Simulator", "baremetal", "baremetal2", "xdragon", "baremetal2Dpu"})
     private String hypervisorType;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@header/src/main/java/org/zstack/header/cluster/APICreateClusterMsg.java`
around lines 68 - 73, Update the `@choices` Javadoc above APICreateClusterMsg to
match the `@APIParam` validValues by adding the missing entries "baremetal2",
"baremetal2Dpu", and "xdragon" so the documentation and choices list for the
ClusterInventory hypervisorType remain consistent with the validValues
declaration in APICreateClusterMsg.
conf/db/upgrade/V5.5.12__schema.sql (1)

6-6: PRIMARY KEY 已保证唯一性,UNIQUE 约束可去重

Line 6 与 Line 15 的 uuid 同时声明 PRIMARY KEYUNIQUEUNIQUE 在这里是冗余约束,建议移除以减少无效定义。

建议修复(示例)
-`uuid` varchar(32) NOT NULL UNIQUE,
+`uuid` varchar(32) NOT NULL,
@@
-`uuid` varchar(32) NOT NULL UNIQUE,
+`uuid` varchar(32) NOT NULL,

Also applies to: 15-15

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@conf/db/upgrade/V5.5.12__schema.sql` at line 6, 在迁移脚本中找到同时将 uuid 声明为 PRIMARY
KEY 和 UNIQUE 的列定义(例如出现的片段 "uuid varchar(32) NOT NULL UNIQUE"),删除冗余的 UNIQUE 约束只保留
NOT NULL/PRIMARY KEY(即将 "uuid varchar(32) NOT NULL UNIQUE" 改为 "uuid varchar(32)
NOT NULL" 或直接用 "uuid varchar(32) PRIMARY KEY"),在脚本中对所有出现该重复约束的 uuid
定义都做相同修改以去掉无效 UNIQUE。
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@conf/db/upgrade/V5.5.12__schema.sql`:
- Around line 10-11: The foreign key REFERENCES in the CONSTRAINTs
fkBareMetal2DpuChassisVOChassisVO and fkBareMetal2DpuChassisVOHostEO currently
use unqualified table names; update them to fully-qualified schema references
(e.g. use zstack.`BareMetal2ChassisVO` and zstack.`HostEO`) so the SQL in
V5.5.12__schema.sql does not rely on the current default schema; apply the same
change to the other occurrences called out (around the other REFERENCES on lines
noted, e.g. any plain `TableName` in that file such as the ones near lines 20-21
and 31-35) to keep the upgrade scripts consistent.
- Around line 24-36: The ALTER statements on table BareMetal2InstanceVO drop and
re-add foreign keys fkBareMetal2InstanceVOGatewayVO and
fkBareMetal2InstanceVOGatewayVO1 without idempotency checks, which will fail if
constraints are already absent/present; modify the migration to query
information_schema.TABLE_CONSTRAINTS for BareMetal2InstanceVO and only EXECUTE
dynamic DROP FOREIGN KEY when the constraint exists and only EXECUTE ADD
CONSTRAINT when it does not exist (use the constraint names
fkBareMetal2InstanceVOGatewayVO and fkBareMetal2InstanceVOGatewayVO1 and
reference HostEO(uuid) with ON DELETE SET NULL), ensuring the script is safe to
run repeatedly and in branch states.

---

Nitpick comments:
In `@conf/db/upgrade/V5.5.12__schema.sql`:
- Line 6: 在迁移脚本中找到同时将 uuid 声明为 PRIMARY KEY 和 UNIQUE 的列定义(例如出现的片段 "uuid
varchar(32) NOT NULL UNIQUE"),删除冗余的 UNIQUE 约束只保留 NOT NULL/PRIMARY KEY(即将 "uuid
varchar(32) NOT NULL UNIQUE" 改为 "uuid varchar(32) NOT NULL" 或直接用 "uuid
varchar(32) PRIMARY KEY"),在脚本中对所有出现该重复约束的 uuid 定义都做相同修改以去掉无效 UNIQUE。

In `@header/src/main/java/org/zstack/header/cluster/APICreateClusterMsg.java`:
- Around line 68-73: Update the `@choices` Javadoc above APICreateClusterMsg to
match the `@APIParam` validValues by adding the missing entries "baremetal2",
"baremetal2Dpu", and "xdragon" so the documentation and choices list for the
ClusterInventory hypervisorType remain consistent with the validValues
declaration in APICreateClusterMsg.

ℹ️ 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: 562e6ff3-9483-4afd-acdf-6c9c83e0adb2

📥 Commits

Reviewing files that changed from the base of the PR and between 44c191f and 5718b67.

⛔ Files ignored due to path filters (7)
  • sdk/src/main/java/SourceClassMap.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/AddBareMetal2DpuChassisAction.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/BareMetal2DpuChassisInventory.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/BareMetal2DpuHostInventory.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/CreateBareMetal2InstanceAction.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/CreateClusterAction.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/StartBareMetal2InstanceAction.java is excluded by !sdk/**
📒 Files selected for processing (6)
  • compute/src/main/java/org/zstack/compute/host/HostManagerImpl.java
  • conf/db/upgrade/V5.5.12__schema.sql
  • header/src/main/java/org/zstack/header/cluster/APICreateClusterMsg.java
  • header/src/main/java/org/zstack/header/cluster/APICreateClusterMsgDoc_zh_cn.groovy
  • testlib/src/main/java/org/zstack/testlib/ApiHelper.groovy
  • utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java

Comment on lines +10 to +11
CONSTRAINT `fkBareMetal2DpuChassisVOChassisVO` FOREIGN KEY (`uuid`) REFERENCES `BareMetal2ChassisVO` (`uuid`) ON DELETE CASCADE,
CONSTRAINT `fkBareMetal2DpuChassisVOHostEO` FOREIGN KEY (`hostUuid`) REFERENCES `HostEO` (`uuid`) ON DELETE SET NULL
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

建议统一使用 zstack.表名 的 schema 全限定引用

当前外键 REFERENCES 使用了未带 schema 的表名;在 upgrade 目录建议统一为 zstack....,降低上下文 schema 依赖并保持脚本风格一致。

建议修复(示例)
-CONSTRAINT `fkBareMetal2DpuChassisVOChassisVO` FOREIGN KEY (`uuid`) REFERENCES `BareMetal2ChassisVO` (`uuid`) ON DELETE CASCADE,
-CONSTRAINT `fkBareMetal2DpuChassisVOHostEO` FOREIGN KEY (`hostUuid`) REFERENCES `HostEO` (`uuid`) ON DELETE SET NULL
+CONSTRAINT `fkBareMetal2DpuChassisVOChassisVO` FOREIGN KEY (`uuid`) REFERENCES `zstack`.`BareMetal2ChassisVO` (`uuid`) ON DELETE CASCADE,
+CONSTRAINT `fkBareMetal2DpuChassisVOHostEO` FOREIGN KEY (`hostUuid`) REFERENCES `zstack`.`HostEO` (`uuid`) ON DELETE SET NULL
@@
-CONSTRAINT `fkBareMetal2DpuHostVOHostVO` FOREIGN KEY (`uuid`) REFERENCES `HostEO` (`uuid`) ON DELETE CASCADE,
-CONSTRAINT `fkBareMetal2DpuHostVOChassisVO` FOREIGN KEY (`chassisUuid`) REFERENCES `BareMetal2DpuChassisVO` (`uuid`) ON DELETE CASCADE
+CONSTRAINT `fkBareMetal2DpuHostVOHostVO` FOREIGN KEY (`uuid`) REFERENCES `zstack`.`HostEO` (`uuid`) ON DELETE CASCADE,
+CONSTRAINT `fkBareMetal2DpuHostVOChassisVO` FOREIGN KEY (`chassisUuid`) REFERENCES `zstack`.`BareMetal2DpuChassisVO` (`uuid`) ON DELETE CASCADE
@@
-REFERENCES `HostEO` (`uuid`)
+REFERENCES `zstack`.`HostEO` (`uuid`)
@@
-REFERENCES `HostEO` (`uuid`)
+REFERENCES `zstack`.`HostEO` (`uuid`)

Based on learnings: “在 conf/db/upgrade 下继续使用 TABLE_SCHEMA = 'zstack' 并以 zstack.`Table` 方式引用表,可在该目录通用。”

Also applies to: 20-21, 31-35

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@conf/db/upgrade/V5.5.12__schema.sql` around lines 10 - 11, The foreign key
REFERENCES in the CONSTRAINTs fkBareMetal2DpuChassisVOChassisVO and
fkBareMetal2DpuChassisVOHostEO currently use unqualified table names; update
them to fully-qualified schema references (e.g. use zstack.`BareMetal2ChassisVO`
and zstack.`HostEO`) so the SQL in V5.5.12__schema.sql does not rely on the
current default schema; apply the same change to the other occurrences called
out (around the other REFERENCES on lines noted, e.g. any plain `TableName` in
that file such as the ones near lines 20-21 and 31-35) to keep the upgrade
scripts consistent.

Comment on lines +24 to +36
ALTER TABLE `zstack`.`BareMetal2InstanceVO`
DROP FOREIGN KEY `fkBareMetal2InstanceVOGatewayVO`,
DROP FOREIGN KEY `fkBareMetal2InstanceVOGatewayVO1`;

ALTER TABLE `zstack`.`BareMetal2InstanceVO`
ADD CONSTRAINT `fkBareMetal2InstanceVOGatewayVO`
FOREIGN KEY (`gatewayUuid`)
REFERENCES `HostEO` (`uuid`)
ON DELETE SET NULL,
ADD CONSTRAINT `fkBareMetal2InstanceVOGatewayVO1`
FOREIGN KEY (`lastGatewayUuid`)
REFERENCES `HostEO` (`uuid`)
ON DELETE SET NULL;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

外键变更缺少幂等保护,升级脚本在分支库状态下可能中断

Line 24-36 直接 DROP FOREIGN KEY / ADD CONSTRAINT,当约束不存在或已存在时会报错,升级流程会被中断。建议基于 information_schema.TABLE_CONSTRAINTS 先判断再执行动态 SQL。

建议修复(示例)
-ALTER TABLE `zstack`.`BareMetal2InstanceVO`
-DROP FOREIGN KEY `fkBareMetal2InstanceVOGatewayVO`,
-DROP FOREIGN KEY `fkBareMetal2InstanceVOGatewayVO1`;
-
-ALTER TABLE `zstack`.`BareMetal2InstanceVO`
-    ADD CONSTRAINT `fkBareMetal2InstanceVOGatewayVO`
-        FOREIGN KEY (`gatewayUuid`)
-        REFERENCES `HostEO` (`uuid`)
-        ON DELETE SET NULL,
-    ADD CONSTRAINT `fkBareMetal2InstanceVOGatewayVO1`
-        FOREIGN KEY (`lastGatewayUuid`)
-        REFERENCES `HostEO` (`uuid`)
-        ON DELETE SET NULL;
+SET `@schema` := 'zstack';
+SET `@tbl` := 'BareMetal2InstanceVO';
+
+SELECT COUNT(1) INTO `@fk1_exists`
+FROM information_schema.TABLE_CONSTRAINTS
+WHERE CONSTRAINT_SCHEMA = `@schema`
+  AND TABLE_NAME = `@tbl`
+  AND CONSTRAINT_NAME = 'fkBareMetal2InstanceVOGatewayVO'
+  AND CONSTRAINT_TYPE = 'FOREIGN KEY';
+SET `@sql` := IF(`@fk1_exists` > 0,
+  'ALTER TABLE `zstack`.`BareMetal2InstanceVO` DROP FOREIGN KEY `fkBareMetal2InstanceVOGatewayVO`',
+  'SELECT 1');
+PREPARE stmt FROM `@sql`; EXECUTE stmt; DEALLOCATE PREPARE stmt;
+
+SELECT COUNT(1) INTO `@fk2_exists`
+FROM information_schema.TABLE_CONSTRAINTS
+WHERE CONSTRAINT_SCHEMA = `@schema`
+  AND TABLE_NAME = `@tbl`
+  AND CONSTRAINT_NAME = 'fkBareMetal2InstanceVOGatewayVO1'
+  AND CONSTRAINT_TYPE = 'FOREIGN KEY';
+SET `@sql` := IF(`@fk2_exists` > 0,
+  'ALTER TABLE `zstack`.`BareMetal2InstanceVO` DROP FOREIGN KEY `fkBareMetal2InstanceVOGatewayVO1`',
+  'SELECT 1');
+PREPARE stmt FROM `@sql`; EXECUTE stmt; DEALLOCATE PREPARE stmt;
+
+SELECT COUNT(1) INTO `@fk1_new_exists`
+FROM information_schema.TABLE_CONSTRAINTS
+WHERE CONSTRAINT_SCHEMA = `@schema`
+  AND TABLE_NAME = `@tbl`
+  AND CONSTRAINT_NAME = 'fkBareMetal2InstanceVOGatewayVO'
+  AND CONSTRAINT_TYPE = 'FOREIGN KEY';
+SET `@sql` := IF(`@fk1_new_exists` = 0,
+  'ALTER TABLE `zstack`.`BareMetal2InstanceVO`
+     ADD CONSTRAINT `fkBareMetal2InstanceVOGatewayVO`
+     FOREIGN KEY (`gatewayUuid`) REFERENCES `zstack`.`HostEO` (`uuid`) ON DELETE SET NULL',
+  'SELECT 1');
+PREPARE stmt FROM `@sql`; EXECUTE stmt; DEALLOCATE PREPARE stmt;
+
+SELECT COUNT(1) INTO `@fk2_new_exists`
+FROM information_schema.TABLE_CONSTRAINTS
+WHERE CONSTRAINT_SCHEMA = `@schema`
+  AND TABLE_NAME = `@tbl`
+  AND CONSTRAINT_NAME = 'fkBareMetal2InstanceVOGatewayVO1'
+  AND CONSTRAINT_TYPE = 'FOREIGN KEY';
+SET `@sql` := IF(`@fk2_new_exists` = 0,
+  'ALTER TABLE `zstack`.`BareMetal2InstanceVO`
+     ADD CONSTRAINT `fkBareMetal2InstanceVOGatewayVO1`
+     FOREIGN KEY (`lastGatewayUuid`) REFERENCES `zstack`.`HostEO` (`uuid`) ON DELETE SET NULL',
+  'SELECT 1');
+PREPARE stmt FROM `@sql`; EXECUTE stmt; DEALLOCATE PREPARE stmt;

Based on learnings: “ZStack 数据库升级脚本…需要通过 information_schema 检查表和约束的存在性来确保脚本可以安全重复执行。”
As per coding guidelines: “Upgrading scene has been carefully handled”.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ALTER TABLE `zstack`.`BareMetal2InstanceVO`
DROP FOREIGN KEY `fkBareMetal2InstanceVOGatewayVO`,
DROP FOREIGN KEY `fkBareMetal2InstanceVOGatewayVO1`;
ALTER TABLE `zstack`.`BareMetal2InstanceVO`
ADD CONSTRAINT `fkBareMetal2InstanceVOGatewayVO`
FOREIGN KEY (`gatewayUuid`)
REFERENCES `HostEO` (`uuid`)
ON DELETE SET NULL,
ADD CONSTRAINT `fkBareMetal2InstanceVOGatewayVO1`
FOREIGN KEY (`lastGatewayUuid`)
REFERENCES `HostEO` (`uuid`)
ON DELETE SET NULL;
SET `@schema` := 'zstack';
SET `@tbl` := 'BareMetal2InstanceVO';
SELECT COUNT(1) INTO `@fk1_exists`
FROM information_schema.TABLE_CONSTRAINTS
WHERE CONSTRAINT_SCHEMA = `@schema`
AND TABLE_NAME = `@tbl`
AND CONSTRAINT_NAME = 'fkBareMetal2InstanceVOGatewayVO'
AND CONSTRAINT_TYPE = 'FOREIGN KEY';
SET `@sql` := IF(`@fk1_exists` > 0,
'ALTER TABLE `zstack`.`BareMetal2InstanceVO` DROP FOREIGN KEY `fkBareMetal2InstanceVOGatewayVO`',
'SELECT 1');
PREPARE stmt FROM `@sql`; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SELECT COUNT(1) INTO `@fk2_exists`
FROM information_schema.TABLE_CONSTRAINTS
WHERE CONSTRAINT_SCHEMA = `@schema`
AND TABLE_NAME = `@tbl`
AND CONSTRAINT_NAME = 'fkBareMetal2InstanceVOGatewayVO1'
AND CONSTRAINT_TYPE = 'FOREIGN KEY';
SET `@sql` := IF(`@fk2_exists` > 0,
'ALTER TABLE `zstack`.`BareMetal2InstanceVO` DROP FOREIGN KEY `fkBareMetal2InstanceVOGatewayVO1`',
'SELECT 1');
PREPARE stmt FROM `@sql`; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SELECT COUNT(1) INTO `@fk1_new_exists`
FROM information_schema.TABLE_CONSTRAINTS
WHERE CONSTRAINT_SCHEMA = `@schema`
AND TABLE_NAME = `@tbl`
AND CONSTRAINT_NAME = 'fkBareMetal2InstanceVOGatewayVO'
AND CONSTRAINT_TYPE = 'FOREIGN KEY';
SET `@sql` := IF(`@fk1_new_exists` = 0,
'ALTER TABLE `zstack`.`BareMetal2InstanceVO`
ADD CONSTRAINT `fkBareMetal2InstanceVOGatewayVO`
FOREIGN KEY (`gatewayUuid`) REFERENCES `zstack`.`HostEO` (`uuid`) ON DELETE SET NULL',
'SELECT 1');
PREPARE stmt FROM `@sql`; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SELECT COUNT(1) INTO `@fk2_new_exists`
FROM information_schema.TABLE_CONSTRAINTS
WHERE CONSTRAINT_SCHEMA = `@schema`
AND TABLE_NAME = `@tbl`
AND CONSTRAINT_NAME = 'fkBareMetal2InstanceVOGatewayVO1'
AND CONSTRAINT_TYPE = 'FOREIGN KEY';
SET `@sql` := IF(`@fk2_new_exists` = 0,
'ALTER TABLE `zstack`.`BareMetal2InstanceVO`
ADD CONSTRAINT `fkBareMetal2InstanceVOGatewayVO1`
FOREIGN KEY (`lastGatewayUuid`) REFERENCES `zstack`.`HostEO` (`uuid`) ON DELETE SET NULL',
'SELECT 1');
PREPARE stmt FROM `@sql`; EXECUTE stmt; DEALLOCATE PREPARE stmt;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@conf/db/upgrade/V5.5.12__schema.sql` around lines 24 - 36, The ALTER
statements on table BareMetal2InstanceVO drop and re-add foreign keys
fkBareMetal2InstanceVOGatewayVO and fkBareMetal2InstanceVOGatewayVO1 without
idempotency checks, which will fail if constraints are already absent/present;
modify the migration to query information_schema.TABLE_CONSTRAINTS for
BareMetal2InstanceVO and only EXECUTE dynamic DROP FOREIGN KEY when the
constraint exists and only EXECUTE ADD CONSTRAINT when it does not exist (use
the constraint names fkBareMetal2InstanceVOGatewayVO and
fkBareMetal2InstanceVOGatewayVO1 and reference HostEO(uuid) with ON DELETE SET
NULL), ensuring the script is safe to run repeatedly and in branch states.

Copy link

@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)
header/src/main/java/org/zstack/header/cluster/APICreateClusterMsg.java (1)

69-73: Javadoc @choices 注释与实际 validValues 不一致

Javadoc 中的 @choices 仅列出了 KVM, Simulator, baremetal,但实际 validValues 包含了 KVM, Simulator, baremetal, baremetal2, xdragon, baremetal2Dpu。建议更新注释以保持一致。

建议修复
     /**
      * `@desc` see field 'hypervisorType' of :ref:`ClusterInventory` for details
-     * `@choices` - KVM
-     * - Simulator
-     * - baremetal
+     * `@choices` - KVM
+     * - Simulator
+     * - baremetal
+     * - baremetal2
+     * - xdragon
+     * - baremetal2Dpu
      */
     `@APIParam`(validValues = {"KVM", "Simulator", "baremetal", "baremetal2", "xdragon", "baremetal2Dpu"})
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@header/src/main/java/org/zstack/header/cluster/APICreateClusterMsg.java`
around lines 69 - 73, Update the Javadoc `@choices` on APICreateClusterMsg to
match the actual `@APIParam` validValues; replace the current "@choices - KVM -
Simulator - baremetal" with the full list "KVM, Simulator, baremetal,
baremetal2, xdragon, baremetal2Dpu" so the comment and the `@APIParam`(validValues
= {...}) remain consistent and accurate.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@header/src/main/java/org/zstack/header/cluster/APICreateClusterMsg.java`:
- Around line 69-73: Update the Javadoc `@choices` on APICreateClusterMsg to match
the actual `@APIParam` validValues; replace the current "@choices - KVM -
Simulator - baremetal" with the full list "KVM, Simulator, baremetal,
baremetal2, xdragon, baremetal2Dpu" so the comment and the `@APIParam`(validValues
= {...}) remain consistent and accurate.

ℹ️ 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: b9f94f31-6837-45f8-bbdd-c9271e50dc1a

📥 Commits

Reviewing files that changed from the base of the PR and between 5718b67 and 2318947.

⛔ Files ignored due to path filters (7)
  • sdk/src/main/java/SourceClassMap.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/AddBareMetal2DpuChassisAction.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/BareMetal2DpuChassisInventory.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/BareMetal2DpuHostInventory.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/CreateBareMetal2InstanceAction.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/CreateClusterAction.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/StartBareMetal2InstanceAction.java is excluded by !sdk/**
📒 Files selected for processing (6)
  • compute/src/main/java/org/zstack/compute/host/HostManagerImpl.java
  • conf/db/upgrade/V5.5.12__schema.sql
  • header/src/main/java/org/zstack/header/cluster/APICreateClusterMsg.java
  • header/src/main/java/org/zstack/header/cluster/APICreateClusterMsgDoc_zh_cn.groovy
  • testlib/src/main/java/org/zstack/testlib/ApiHelper.groovy
  • utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.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.

1 participant