-
Notifications
You must be signed in to change notification settings - Fork 0
<feature>[dpu-bm2]: support dpu baremetal2 instance #3197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 5.5.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -476,3 +476,46 @@ CALL ADD_COLUMN('ModelServiceInstanceVO', 'architecture', 'VARCHAR(32)', 1, NULL | |
| CALL ADD_COLUMN('ModelServiceInstanceVO', 'gpuVendor', 'VARCHAR(128)', 1, NULL); | ||
|
|
||
| CALL ADD_COLUMN('ModelVO', 'dtype', 'varchar(32)', 1, NULL); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS `zstack`.`BareMetal2DpuChassisVO` ( | ||
| `uuid` varchar(32) NOT NULL UNIQUE, | ||
| `config` TEXT DEFAULT NULL, | ||
| `hostUuid` varchar(32) DEFAULT NULL, | ||
| PRIMARY KEY (`uuid`), | ||
| CONSTRAINT `fkBareMetal2DpuChassisVOChassisVO` FOREIGN KEY (`uuid`) REFERENCES `BareMetal2ChassisVO` (`uuid`) ON DELETE CASCADE, | ||
| CONSTRAINT `fkBareMetal2DpuChassisVOHostEO` FOREIGN KEY (`hostUuid`) REFERENCES `HostEO` (`uuid`) ON DELETE SET NULL | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
|
|
||
| CREATE TABLE IF NOT EXISTS `zstack`.`BareMetal2DpuHostVO` ( | ||
| `uuid` varchar(32) NOT NULL UNIQUE, | ||
| `chassisUuid` VARCHAR(32) NOT NULL, | ||
| `vendorType` VARCHAR(255) NOT NULL, | ||
| `url` VARCHAR(255) NOT NULL, | ||
| PRIMARY KEY (`uuid`), | ||
| CONSTRAINT `fkBareMetal2DpuHostVOHostVO` FOREIGN KEY (`uuid`) REFERENCES `HostEO` (`uuid`) ON DELETE CASCADE, | ||
| CONSTRAINT `fkBareMetal2DpuHostVOChassisVO` FOREIGN KEY (`chassisUuid`) REFERENCES `BareMetal2DpuChassisVO` (`uuid`) ON DELETE CASCADE | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
|
|
||
| SELECT | ||
| CONSTRAINT_NAME, | ||
| TABLE_NAME, | ||
| COLUMN_NAME, | ||
| REFERENCED_TABLE_NAME | ||
| FROM information_schema.KEY_COLUMN_USAGE | ||
| WHERE TABLE_SCHEMA = 'zstack' | ||
| AND TABLE_NAME = 'BareMetal2InstanceVO' | ||
| AND COLUMN_NAME IN ('gatewayUuid', 'lastGatewayUuid'); | ||
|
|
||
| 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; | ||
|
Comment on lines
+509
to
+521
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 外键操作缺乏幂等性保护,升级脚本重复执行将失败。 直接执行 🔧 建议使用存储过程确保幂等性-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;
+DELIMITER $$
+DROP PROCEDURE IF EXISTS UpdateBareMetal2InstanceVOForeignKeys$$
+CREATE PROCEDURE UpdateBareMetal2InstanceVOForeignKeys()
+BEGIN
+ -- Drop old FK if exists
+ IF EXISTS (
+ SELECT 1 FROM information_schema.TABLE_CONSTRAINTS
+ WHERE TABLE_SCHEMA = 'zstack'
+ AND TABLE_NAME = 'BareMetal2InstanceVO'
+ AND CONSTRAINT_NAME = 'fkBareMetal2InstanceVOGatewayVO'
+ ) THEN
+ ALTER TABLE `zstack`.`BareMetal2InstanceVO` DROP FOREIGN KEY `fkBareMetal2InstanceVOGatewayVO`;
+ END IF;
+
+ IF EXISTS (
+ SELECT 1 FROM information_schema.TABLE_CONSTRAINTS
+ WHERE TABLE_SCHEMA = 'zstack'
+ AND TABLE_NAME = 'BareMetal2InstanceVO'
+ AND CONSTRAINT_NAME = 'fkBareMetal2InstanceVOGatewayVO1'
+ ) THEN
+ ALTER TABLE `zstack`.`BareMetal2InstanceVO` DROP FOREIGN KEY `fkBareMetal2InstanceVOGatewayVO1`;
+ END IF;
+
+ -- Add new FK if not exists
+ IF NOT EXISTS (
+ SELECT 1 FROM information_schema.TABLE_CONSTRAINTS
+ WHERE TABLE_SCHEMA = 'zstack'
+ AND TABLE_NAME = 'BareMetal2InstanceVO'
+ AND CONSTRAINT_NAME = 'fkBareMetal2InstanceVOGatewayVO'
+ ) THEN
+ ALTER TABLE `zstack`.`BareMetal2InstanceVO`
+ ADD CONSTRAINT `fkBareMetal2InstanceVOGatewayVO`
+ FOREIGN KEY (`gatewayUuid`) REFERENCES `HostEO` (`uuid`) ON DELETE SET NULL;
+ END IF;
+
+ IF NOT EXISTS (
+ SELECT 1 FROM information_schema.TABLE_CONSTRAINTS
+ WHERE TABLE_SCHEMA = 'zstack'
+ AND TABLE_NAME = 'BareMetal2InstanceVO'
+ AND CONSTRAINT_NAME = 'fkBareMetal2InstanceVOGatewayVO1'
+ ) THEN
+ ALTER TABLE `zstack`.`BareMetal2InstanceVO`
+ ADD CONSTRAINT `fkBareMetal2InstanceVOGatewayVO1`
+ FOREIGN KEY (`lastGatewayUuid`) REFERENCES `HostEO` (`uuid`) ON DELETE SET NULL;
+ END IF;
+END$$
+DELIMITER ;
+
+CALL UpdateBareMetal2InstanceVOForeignKeys();
+DROP PROCEDURE IF EXISTS UpdateBareMetal2InstanceVOForeignKeys;Based on learnings,ZStack 升级脚本需要通过 information_schema 检查约束的存在性来确保脚本可以安全重复执行。 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,7 +70,7 @@ public class APICreateClusterMsg extends APICreateMessage implements CreateClust | |
| * - Simulator | ||
| * - baremetal | ||
| */ | ||
| @APIParam(validValues = {"KVM", "Simulator", "baremetal", "baremetal2", "xdragon"}) | ||
| @APIParam(validValues = {"KVM", "Simulator", "baremetal", "baremetal2", "xdragon", "baremetal2Dpu"}) | ||
| private String hypervisorType; | ||
|
Comment on lines
+73
to
74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# 搜索 baremetal2Dpu 的所有引用
echo "=== 搜索 baremetal2Dpu 引用 ==="
rg -i "baremetal2Dpu" --type java -n
echo ""
echo "=== 搜索 HypervisorType 枚举定义 ==="
fd -e java -x grep -l "enum HypervisorType" {} \;
echo ""
echo "=== 搜索 ClusterFactory 实现 ==="
fd -e java -x grep -l "ClusterFactory" {} \; | head -10
echo ""
echo "=== 搜索 baremetal 相关处理器 ==="
rg "class.*Baremetal.*Handler|class.*Baremetal.*Factory" --type java -nRepository: MatheMatrix/zstack Length of output: 1525 🏁 Script executed: #!/bin/bash
# 检查 ClusterType 定义
echo "=== ClusterType.java 内容 ==="
cat header/src/main/java/org/zstack/header/cluster/ClusterType.java
echo ""
echo "=== 搜索所有集群工厂实现 ==="
rg "implements ClusterFactory" --type java -A 5
echo ""
echo "=== 搜索 baremetal2Dpu 字符串在整个代码库 ==="
rg -i "baremetal2dpu" --type java -lRepository: MatheMatrix/zstack Length of output: 2187 🏁 Script executed: #!/bin/bash
# 搜索所有实现 ClusterFactory 的类
echo "=== 所有 ClusterFactory 实现类 ==="
fd -e java -x grep -l "implements ClusterFactory" {} \;
echo ""
echo "=== baremetal 相关的工厂/类定义 ==="
fd -e java -path "*baremetal*" | head -20
echo ""
echo "=== 搜索 baremetal2Dpu 在工厂中的注册 ==="
rg "baremetal2Dpu|baremetal2Dpu" --type java -B 3 -A 3
echo ""
echo "=== 检查 baremetal2 工厂是否存在 ==="
fd -e java -path "*baremetal2*Factory*"Repository: MatheMatrix/zstack Length of output: 148 🏁 Script executed: #!/bin/bash
# 搜索所有 Factory 实现类
echo "=== 搜索 ClusterFactory 实现 ==="
rg "implements ClusterFactory" --type java -l
echo ""
echo "=== 搜索 baremetal 相关目录 ==="
find . -type d -name "*baremetal*" 2>/dev/null | head -10
echo ""
echo "=== 检查是否存在 baremetal2Dpu 工厂类 ==="
find . -type f -name "*BareMetal2Dpu*Factory*.java" 2>/dev/nullRepository: MatheMatrix/zstack Length of output: 224 🏁 Script executed: #!/bin/bash
# 搜索 BareMetal2DpuChassisInventory 类
echo "=== 搜索 BareMetal2DpuChassisInventory 类 ==="
find . -type f -name "*BareMetal2DpuChassisInventory*" 2>/dev/null
echo ""
echo "=== 搜索 BareMetal2DpuHostInventory 类 ==="
find . -type f -name "*BareMetal2DpuHostInventory*" 2>/dev/null
echo ""
echo "=== 查看 BaseClusterFactory 完整实现 ==="
cat compute/src/main/java/org/zstack/compute/cluster/BaseClusterFactory.java
echo ""
echo "=== 搜索是否有其他模块注册 baremetal2Dpu ==="
rg "new ClusterType" --type java -B 2 -A 2Repository: MatheMatrix/zstack Length of output: 1773
新增的
需要补全相应的工厂类、类型注册、库存类定义和处理逻辑。 |
||
| /** | ||
| * @desc see field 'type' of :ref:`ClusterInventory` for details | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -56,7 +56,7 @@ doc { | |||||
| type "String" | ||||||
| optional false | ||||||
| since "0.6" | ||||||
| values ("KVM","Simulator","baremetal","baremetal2","xdragon") | ||||||
| values ("KVM","Simulator","baremetal","baremetal2","xdragon","baremetal2Dpu") | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 命名不一致:文档使用
建议修复- values ("KVM","Simulator","baremetal","baremetal2","xdragon","baremetal2Dpu")
+ values ("KVM","Simulator","baremetal","baremetal2","xdragon","dpuBaremetal2")📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| } | ||||||
| column { | ||||||
| name "type" | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| package org.zstack.sdk; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import org.zstack.sdk.*; | ||
|
|
||
| public class AddBareMetal2DpuChassisAction extends AbstractAction { | ||
|
|
||
| private static final HashMap<String, Parameter> parameterMap = new HashMap<>(); | ||
|
|
||
| private static final HashMap<String, Parameter> nonAPIParameterMap = new HashMap<>(); | ||
|
|
||
| public static class Result { | ||
| public ErrorCode error; | ||
| public org.zstack.sdk.AddBareMetal2ChassisResult value; | ||
|
|
||
| public Result throwExceptionIfError() { | ||
| if (error != null) { | ||
| throw new ApiException( | ||
| String.format("error[code: %s, description: %s, details: %s]", error.code, error.description, error.details) | ||
| ); | ||
| } | ||
|
|
||
| return this; | ||
| } | ||
| } | ||
|
|
||
| @Param(required = true, maxLength = 2048, nonempty = false, nullElements = false, emptyString = true, noTrim = false) | ||
| public java.lang.String url; | ||
|
|
||
| @Param(required = true, maxLength = 255, nonempty = false, nullElements = false, emptyString = true, noTrim = false) | ||
| public java.lang.String vendorType; | ||
|
|
||
| @Param(required = false, nonempty = false, nullElements = false, emptyString = true, noTrim = false) | ||
| public java.lang.String config; | ||
|
|
||
| @Param(required = true, maxLength = 255, nonempty = false, nullElements = false, emptyString = false, noTrim = false) | ||
| public java.lang.String name; | ||
|
|
||
| @Param(required = false, maxLength = 2048, nonempty = false, nullElements = false, emptyString = true, noTrim = false) | ||
| public java.lang.String description; | ||
|
|
||
| @Param(required = true, nonempty = false, nullElements = false, emptyString = true, noTrim = false) | ||
| public java.lang.String clusterUuid; | ||
|
|
||
| @Param(required = false, validValues = {"Remote","Local","Direct"}, nonempty = false, nullElements = false, emptyString = true, noTrim = false) | ||
| public java.lang.String provisionType = "Remote"; | ||
|
|
||
| @Param(required = false) | ||
| public java.lang.String resourceUuid; | ||
|
|
||
| @Param(required = false, nonempty = false, nullElements = false, emptyString = true, noTrim = false) | ||
| public java.util.List tagUuids; | ||
|
|
||
| @Param(required = false) | ||
| public java.util.List systemTags; | ||
|
|
||
| @Param(required = false) | ||
| public java.util.List userTags; | ||
|
|
||
| @Param(required = false) | ||
| public String sessionId; | ||
|
|
||
| @Param(required = false) | ||
| public String accessKeyId; | ||
|
|
||
| @Param(required = false) | ||
| public String accessKeySecret; | ||
|
|
||
| @Param(required = false) | ||
| public String requestIp; | ||
|
|
||
| @NonAPIParam | ||
| public long timeout = -1; | ||
|
|
||
| @NonAPIParam | ||
| public long pollingInterval = -1; | ||
|
|
||
|
|
||
| private Result makeResult(ApiResult res) { | ||
| Result ret = new Result(); | ||
| if (res.error != null) { | ||
| ret.error = res.error; | ||
| return ret; | ||
| } | ||
|
|
||
| org.zstack.sdk.AddBareMetal2ChassisResult value = res.getResult(org.zstack.sdk.AddBareMetal2ChassisResult.class); | ||
| ret.value = value == null ? new org.zstack.sdk.AddBareMetal2ChassisResult() : value; | ||
|
|
||
| return ret; | ||
| } | ||
|
|
||
| public Result call() { | ||
| ApiResult res = ZSClient.call(this); | ||
| return makeResult(res); | ||
| } | ||
|
|
||
| public void call(final Completion<Result> completion) { | ||
| ZSClient.call(this, new InternalCompletion() { | ||
| @Override | ||
| public void complete(ApiResult res) { | ||
| completion.complete(makeResult(res)); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| protected Map<String, Parameter> getParameterMap() { | ||
| return parameterMap; | ||
| } | ||
|
|
||
| protected Map<String, Parameter> getNonAPIParameterMap() { | ||
| return nonAPIParameterMap; | ||
| } | ||
|
|
||
| protected RestInfo getRestInfo() { | ||
| RestInfo info = new RestInfo(); | ||
| info.httpMethod = "POST"; | ||
| info.path = "/baremetal2/chassis/dpu"; | ||
| info.needSession = true; | ||
| info.needPoll = true; | ||
| info.parameterName = "params"; | ||
| return info; | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package org.zstack.sdk; | ||
|
|
||
|
|
||
|
|
||
| public class BareMetal2DpuChassisInventory extends org.zstack.sdk.BareMetal2ChassisInventory { | ||
|
|
||
| public java.lang.String config; | ||
| public void setConfig(java.lang.String config) { | ||
| this.config = config; | ||
| } | ||
| public java.lang.String getConfig() { | ||
| return this.config; | ||
| } | ||
|
|
||
| public java.lang.String hostUuid; | ||
| public void setHostUuid(java.lang.String hostUuid) { | ||
| this.hostUuid = hostUuid; | ||
| } | ||
| public java.lang.String getHostUuid() { | ||
| return this.hostUuid; | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package org.zstack.sdk; | ||
|
|
||
|
|
||
|
|
||
| public class BareMetal2DpuHostInventory extends org.zstack.sdk.HostInventory { | ||
|
|
||
| public java.lang.String url; | ||
| public void setUrl(java.lang.String url) { | ||
| this.url = url; | ||
| } | ||
| public java.lang.String getUrl() { | ||
| return this.url; | ||
| } | ||
|
|
||
| public java.lang.String vendorType; | ||
| public void setVendorType(java.lang.String vendorType) { | ||
| this.vendorType = vendorType; | ||
| } | ||
| public java.lang.String getVendorType() { | ||
| return this.vendorType; | ||
| } | ||
|
|
||
| public java.lang.String chassisUuid; | ||
| public void setChassisUuid(java.lang.String chassisUuid) { | ||
| this.chassisUuid = chassisUuid; | ||
| } | ||
| public java.lang.String getChassisUuid() { | ||
| return this.chassisUuid; | ||
| } | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
移除诊断性 SELECT 查询
此 SELECT 语句是调试/诊断代码,在生产环境升级脚本中执行时会输出数据但不产生任何功能性效果。建议移除,或如需检查约束存在性,应将其整合到存储过程的条件判断中。
🔧 建议修改
📝 Committable suggestion
🤖 Prompt for AI Agents