Skip to content

Commit e0824ea

Browse files
author
zhong.xian
committed
<feature>[kvm]: support model mount
Resolves: ZSTAC-83157 Change-Id: Ifc0f1fab5634ef4387c6cbe8daf1a20af00664fa
1 parent f15be32 commit e0824ea

12 files changed

Lines changed: 619 additions & 10 deletions

conf/db/upgrade/V5.5.12__schema.sql

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,26 @@ END $$
177177
DELIMITER ;
178178

179179
CALL ModifyUsedIpVOForeignKey();
180-
DROP PROCEDURE IF EXISTS ModifyUsedIpVOForeignKey;
180+
DROP PROCEDURE IF EXISTS ModifyUsedIpVOForeignKey;
181+
182+
-- ZSTAC-83157: Add VM model mount feature
183+
CREATE TABLE IF NOT EXISTS `zstack`.`VmModelMountVO` (
184+
`uuid` VARCHAR(32) NOT NULL,
185+
`vmInstanceUuid` VARCHAR(32) NOT NULL,
186+
`modelUuid` VARCHAR(32) NOT NULL,
187+
`modelName` VARCHAR(256) NOT NULL,
188+
`juicefsSubdir` VARCHAR(512) NOT NULL,
189+
`mountPath` VARCHAR(512) NOT NULL,
190+
`status` VARCHAR(32) NOT NULL,
191+
`createDate` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
192+
`lastOpDate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
193+
PRIMARY KEY (`uuid`),
194+
UNIQUE KEY `uk_vm_model_mountpoint` (`vmInstanceUuid`, `mountPath`),
195+
KEY `idx_vm` (`vmInstanceUuid`),
196+
KEY `idx_model` (`modelUuid`),
197+
KEY `idx_status` (`status`),
198+
CONSTRAINT `fk_VmModelMount_vm` FOREIGN KEY (`vmInstanceUuid`)
199+
REFERENCES `VmInstanceEO`(`uuid`) ON DELETE CASCADE,
200+
CONSTRAINT `fk_VmModelMount_model` FOREIGN KEY (`modelUuid`)
201+
REFERENCES `ModelVO`(`uuid`) ON DELETE CASCADE
202+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

plugin/kvm/src/main/java/org/zstack/kvm/KVMAgentCommands.java

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5205,4 +5205,96 @@ public void setMemoryUsage(long memoryUsage) {
52055205
}
52065206
}
52075207

5208+
public static class KvmAttachModelCmd extends AgentCommand {
5209+
@GrayVersion(value = "5.5.12")
5210+
private String vmInstanceUuid;
5211+
@GrayVersion(value = "5.5.12")
5212+
private String zdfsUrl;
5213+
@GrayVersion(value = "5.5.12")
5214+
private String juicefsSubdir;
5215+
@GrayVersion(value = "5.5.12")
5216+
private String mountPath;
5217+
5218+
public String getVmInstanceUuid() {
5219+
return vmInstanceUuid;
5220+
}
5221+
5222+
public void setVmInstanceUuid(String vmInstanceUuid) {
5223+
this.vmInstanceUuid = vmInstanceUuid;
5224+
}
5225+
5226+
public String getZdfsUrl() {
5227+
return zdfsUrl;
5228+
}
5229+
5230+
public void setZdfsUrl(String zdfsUrl) {
5231+
this.zdfsUrl = zdfsUrl;
5232+
}
5233+
5234+
public String getJuicefsSubdir() {
5235+
return juicefsSubdir;
5236+
}
5237+
5238+
public void setJuicefsSubdir(String juicefsSubdir) {
5239+
this.juicefsSubdir = juicefsSubdir;
5240+
}
5241+
5242+
public String getMountPath() {
5243+
return mountPath;
5244+
}
5245+
5246+
public void setMountPath(String mountPath) {
5247+
this.mountPath = mountPath;
5248+
}
5249+
}
5250+
5251+
public static class KvmAttachModelResponse extends AgentResponse {
5252+
@GrayVersion(value = "5.5.12")
5253+
private String status;
5254+
5255+
public String getStatus() {
5256+
return status;
5257+
}
5258+
5259+
public void setStatus(String status) {
5260+
this.status = status;
5261+
}
5262+
}
5263+
5264+
public static class KvmDetachModelCmd extends AgentCommand {
5265+
@GrayVersion(value = "5.5.12")
5266+
private String vmInstanceUuid;
5267+
@GrayVersion(value = "5.5.12")
5268+
private String mountPath;
5269+
5270+
public String getVmInstanceUuid() {
5271+
return vmInstanceUuid;
5272+
}
5273+
5274+
public void setVmInstanceUuid(String vmInstanceUuid) {
5275+
this.vmInstanceUuid = vmInstanceUuid;
5276+
}
5277+
5278+
public String getMountPath() {
5279+
return mountPath;
5280+
}
5281+
5282+
public void setMountPath(String mountPath) {
5283+
this.mountPath = mountPath;
5284+
}
5285+
}
5286+
5287+
public static class KvmDetachModelResponse extends AgentResponse {
5288+
@GrayVersion(value = "5.5.12")
5289+
private String status;
5290+
5291+
public String getStatus() {
5292+
return status;
5293+
}
5294+
5295+
public void setStatus(String status) {
5296+
this.status = status;
5297+
}
5298+
}
5299+
52085300
}

plugin/kvm/src/main/java/org/zstack/kvm/KVMConstant.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ public interface KVMConstant {
9595
String KVM_REGISTER_PRIMARY_VM_HEARTBEAT = "/register/primary/vm/heartbeat";
9696
String CLEAN_FIRMWARE_FLASH = "/clean/firmware/flash";
9797
String FSTRIM_VM_PATH = "/vm/fstrim";
98+
String KVM_ATTACH_AI_MODEL_PATH = "/aimodel/attach";
99+
String KVM_DETACH_AI_MODEL_PATH = "/aimodel/detach";
98100

99101
String ISO_TO = "kvm.isoto";
100102
String ANSIBLE_PLAYBOOK_NAME = "kvm.py";

sdk/src/main/java/SourceClassMap.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class SourceClassMap {
2525
put("org.zstack.ai.entity.ModelServiceRefInventory", "org.zstack.sdk.ModelServiceRefInventory");
2626
put("org.zstack.ai.entity.ModelServiceTemplateInventory", "org.zstack.sdk.ModelServiceTemplateInventory");
2727
put("org.zstack.ai.entity.TrainedModelRecordInventory", "org.zstack.sdk.TrainedModelRecordInventory");
28+
put("org.zstack.ai.entity.VmModelMountInventory", "org.zstack.sdk.VmModelMountInventory");
2829
put("org.zstack.ai.message.ArchitectureImageMapping", "org.zstack.sdk.ArchitectureImageMapping");
2930
put("org.zstack.ai.message.MaaSUsage", "org.zstack.sdk.MaaSUsage");
3031
put("org.zstack.ai.message.ModelCenterServiceInventory", "org.zstack.sdk.ModelCenterServiceInventory");
@@ -1549,6 +1550,7 @@ public class SourceClassMap {
15491550
put("org.zstack.sdk.VmInstancePciDeviceSpecRefInventory", "org.zstack.pciDevice.specification.pci.VmInstancePciDeviceSpecRefInventory");
15501551
put("org.zstack.sdk.VmMemoryBillingInventory", "org.zstack.billing.generator.vm.memory.VmMemoryBillingInventory");
15511552
put("org.zstack.sdk.VmMemorySpendingDetails", "org.zstack.billing.spendingcalculator.vm.VmMemorySpendingDetails");
1553+
put("org.zstack.sdk.VmModelMountInventory", "org.zstack.ai.entity.VmModelMountInventory");
15521554
put("org.zstack.sdk.VmNicBandwidthSpendingDetails", "org.zstack.billing.spendingcalculator.vmnic.VmNicBandwidthSpendingDetails");
15531555
put("org.zstack.sdk.VmNicInventory", "org.zstack.header.vm.VmNicInventory");
15541556
put("org.zstack.sdk.VmNicSecurityGroupRefInventory", "org.zstack.network.securitygroup.VmNicSecurityGroupRefInventory");
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package org.zstack.sdk;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
import org.zstack.sdk.*;
6+
7+
public class MountModelToVmInstanceAction extends AbstractAction {
8+
9+
private static final HashMap<String, Parameter> parameterMap = new HashMap<>();
10+
11+
private static final HashMap<String, Parameter> nonAPIParameterMap = new HashMap<>();
12+
13+
public static class Result {
14+
public ErrorCode error;
15+
public org.zstack.sdk.MountModelToVmInstanceResult value;
16+
17+
public Result throwExceptionIfError() {
18+
if (error != null) {
19+
throw new ApiException(
20+
String.format("error[code: %s, description: %s, details: %s, globalErrorCode: %s]", error.code, error.description, error.details, error.globalErrorCode)
21+
);
22+
}
23+
24+
return this;
25+
}
26+
}
27+
28+
@Param(required = true, nonempty = false, nullElements = false, emptyString = true, noTrim = false)
29+
public java.lang.String vmInstanceUuid;
30+
31+
@Param(required = true, nonempty = false, nullElements = false, emptyString = true, noTrim = false)
32+
public java.lang.String modelUuid;
33+
34+
@Param(required = false, maxLength = 512, nonempty = false, nullElements = false, emptyString = true, noTrim = false)
35+
public java.lang.String mountPath;
36+
37+
@Param(required = false)
38+
public java.util.List systemTags;
39+
40+
@Param(required = false)
41+
public java.util.List userTags;
42+
43+
@Param(required = false)
44+
public String sessionId;
45+
46+
@Param(required = false)
47+
public String accessKeyId;
48+
49+
@Param(required = false)
50+
public String accessKeySecret;
51+
52+
@Param(required = false)
53+
public String requestIp;
54+
55+
@NonAPIParam
56+
public long timeout = -1;
57+
58+
@NonAPIParam
59+
public long pollingInterval = -1;
60+
61+
62+
private Result makeResult(ApiResult res) {
63+
Result ret = new Result();
64+
if (res.error != null) {
65+
ret.error = res.error;
66+
return ret;
67+
}
68+
69+
org.zstack.sdk.MountModelToVmInstanceResult value = res.getResult(org.zstack.sdk.MountModelToVmInstanceResult.class);
70+
ret.value = value == null ? new org.zstack.sdk.MountModelToVmInstanceResult() : value;
71+
72+
return ret;
73+
}
74+
75+
public Result call() {
76+
ApiResult res = ZSClient.call(this);
77+
return makeResult(res);
78+
}
79+
80+
public void call(final Completion<Result> completion) {
81+
ZSClient.call(this, new InternalCompletion() {
82+
@Override
83+
public void complete(ApiResult res) {
84+
completion.complete(makeResult(res));
85+
}
86+
});
87+
}
88+
89+
protected Map<String, Parameter> getParameterMap() {
90+
return parameterMap;
91+
}
92+
93+
protected Map<String, Parameter> getNonAPIParameterMap() {
94+
return nonAPIParameterMap;
95+
}
96+
97+
protected RestInfo getRestInfo() {
98+
RestInfo info = new RestInfo();
99+
info.httpMethod = "PUT";
100+
info.path = "/ai/models/{modelUuid}/vm-instances/{vmInstanceUuid}/actions";
101+
info.needSession = true;
102+
info.needPoll = true;
103+
info.parameterName = "mountModelToVmInstance";
104+
return info;
105+
}
106+
107+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.zstack.sdk;
2+
3+
import org.zstack.sdk.VmModelMountInventory;
4+
5+
public class MountModelToVmInstanceResult {
6+
public VmModelMountInventory inventory;
7+
public void setInventory(VmModelMountInventory inventory) {
8+
this.inventory = inventory;
9+
}
10+
public VmModelMountInventory getInventory() {
11+
return this.inventory;
12+
}
13+
14+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package org.zstack.sdk;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
import org.zstack.sdk.*;
6+
7+
public class QueryVmModelMountAction extends QueryAction {
8+
9+
private static final HashMap<String, Parameter> parameterMap = new HashMap<>();
10+
11+
private static final HashMap<String, Parameter> nonAPIParameterMap = new HashMap<>();
12+
13+
public static class Result {
14+
public ErrorCode error;
15+
public org.zstack.sdk.QueryVmModelMountResult value;
16+
17+
public Result throwExceptionIfError() {
18+
if (error != null) {
19+
throw new ApiException(
20+
String.format("error[code: %s, description: %s, details: %s, globalErrorCode: %s]", error.code, error.description, error.details, error.globalErrorCode)
21+
);
22+
}
23+
24+
return this;
25+
}
26+
}
27+
28+
29+
30+
private Result makeResult(ApiResult res) {
31+
Result ret = new Result();
32+
if (res.error != null) {
33+
ret.error = res.error;
34+
return ret;
35+
}
36+
37+
org.zstack.sdk.QueryVmModelMountResult value = res.getResult(org.zstack.sdk.QueryVmModelMountResult.class);
38+
ret.value = value == null ? new org.zstack.sdk.QueryVmModelMountResult() : value;
39+
40+
return ret;
41+
}
42+
43+
public Result call() {
44+
ApiResult res = ZSClient.call(this);
45+
return makeResult(res);
46+
}
47+
48+
public void call(final Completion<Result> completion) {
49+
ZSClient.call(this, new InternalCompletion() {
50+
@Override
51+
public void complete(ApiResult res) {
52+
completion.complete(makeResult(res));
53+
}
54+
});
55+
}
56+
57+
protected Map<String, Parameter> getParameterMap() {
58+
return parameterMap;
59+
}
60+
61+
protected Map<String, Parameter> getNonAPIParameterMap() {
62+
return nonAPIParameterMap;
63+
}
64+
65+
protected RestInfo getRestInfo() {
66+
RestInfo info = new RestInfo();
67+
info.httpMethod = "GET";
68+
info.path = "/ai/vm-model-mounts";
69+
info.needSession = true;
70+
info.needPoll = false;
71+
info.parameterName = "";
72+
return info;
73+
}
74+
75+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.zstack.sdk;
2+
3+
4+
5+
public class QueryVmModelMountResult {
6+
public java.util.List inventories;
7+
public void setInventories(java.util.List inventories) {
8+
this.inventories = inventories;
9+
}
10+
public java.util.List getInventories() {
11+
return this.inventories;
12+
}
13+
14+
public java.lang.Long total;
15+
public void setTotal(java.lang.Long total) {
16+
this.total = total;
17+
}
18+
public java.lang.Long getTotal() {
19+
return this.total;
20+
}
21+
22+
}

0 commit comments

Comments
 (0)