You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

models.go 15 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. package sch
  2. import (
  3. "gitlink.org.cn/cloudream/common/pkgs/types"
  4. schsdk "gitlink.org.cn/cloudream/common/sdks/scheduler"
  5. cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
  6. "gitlink.org.cn/cloudream/common/utils/serder"
  7. "time"
  8. )
  9. type ResourceType string
  10. const (
  11. ResourceTypeCPU ResourceType = "CPU"
  12. ResourceTypeNPU ResourceType = "NPU"
  13. ResourceTypeGPU ResourceType = "GPU"
  14. ResourceTypeMLU ResourceType = "MLU"
  15. ResourceTypeStorage ResourceType = "STORAGE"
  16. ResourceTypeMemory ResourceType = "MEMORY"
  17. ResourceTypeDCU ResourceType = "DCU"
  18. ResourceTypeGCU ResourceType = "GCU"
  19. Split = "/"
  20. CODE = "code"
  21. DATASET = "dataset"
  22. IMAGE = "image"
  23. MODEL = "model"
  24. OrderByName = "name"
  25. OrderBySize = "size"
  26. OrderByTime = "time"
  27. StorageTypeURL = "url"
  28. StorageTypeJCS = "jcs"
  29. RejectedStatus = "rejected"
  30. PendingStatus = "pending"
  31. ApprovedStatus = "approved"
  32. RevokedStatus = "revoked"
  33. CancelStatus = "cancel"
  34. ExpiredStatus = "expired"
  35. ApplyAccess = "apply"
  36. PrivateAccess = "private"
  37. PublicAccess = "public"
  38. PreferencePriority = "preference"
  39. SpecifyClusterPriority = "specify"
  40. FailedStatus = "failed"
  41. SuccessStatus = "success"
  42. Query = "query"
  43. Delete = "delete"
  44. ChildrenType = "children"
  45. ParentType = "parent"
  46. PlatformSugon = "sugon"
  47. PlatformOpenI = "openi"
  48. PlatformModelArts = "modelarts"
  49. URL = "url"
  50. ID = "id"
  51. )
  52. type TaskID int64
  53. type DataID int64
  54. type ClusterDetail struct {
  55. // 集群ID
  56. ClusterId schsdk.ClusterID `json:"clusterID"`
  57. // 集群功能类型:云算,智算,超算
  58. ClusterType string `json:"clusterType"`
  59. // 集群地区:华东地区、华南地区、华北地区、华中地区、西南地区、西北地区、东北地区
  60. Region string `json:"region"`
  61. // 资源类型
  62. Resources2 []ResourceData `json:"resources1,omitempty"`
  63. //Resources2 []ResourceData `json:"resources"`
  64. Resources []ClusterResource `json:"resources"`
  65. }
  66. type ClusterResource struct {
  67. Resource TmpResourceData `json:"resource"`
  68. BaseResources []TmpResourceData `json:"baseResources"`
  69. }
  70. type TmpResourceData struct {
  71. Type ResourceType `json:"type"`
  72. Name string `json:"name"`
  73. Total UnitValue[float64] `json:"total"`
  74. Available UnitValue[float64] `json:"available"`
  75. }
  76. type ResourceData interface {
  77. Noop()
  78. }
  79. var ResourceDataTypeUnion = types.NewTypeUnion[ResourceData](
  80. (*CPUResourceData)(nil),
  81. (*NPUResourceData)(nil),
  82. (*GPUResourceData)(nil),
  83. (*MLUResourceData)(nil),
  84. (*DCUResourceData)(nil),
  85. (*GCUResourceData)(nil),
  86. (*GPGPUResourceData)(nil),
  87. (*StorageResourceData)(nil),
  88. (*MemoryResourceData)(nil),
  89. (*BalanceResourceData)(nil),
  90. (*RateResourceData)(nil),
  91. )
  92. var _ = serder.UseTypeUnionInternallyTagged(&ResourceDataTypeUnion, "type")
  93. type ResourceDataBase struct{}
  94. func (d *ResourceDataBase) Noop() {}
  95. type UnitValue[T any] struct {
  96. Unit string `json:"unit"`
  97. Value T `json:"value"`
  98. }
  99. type CPUResourceData struct {
  100. serder.Metadata `union:"CPU"`
  101. ResourceDataBase
  102. Type string `json:"type"`
  103. Name ResourceType `json:"name"`
  104. Total UnitValue[int64] `json:"total"`
  105. Available UnitValue[int64] `json:"available"`
  106. }
  107. type NPUResourceData struct {
  108. serder.Metadata `union:"NPU"`
  109. ResourceDataBase
  110. Type string `json:"type"`
  111. Name ResourceType `json:"name"`
  112. Total UnitValue[int64] `json:"total"`
  113. Available UnitValue[int64] `json:"available"`
  114. }
  115. type GPUResourceData struct {
  116. serder.Metadata `union:"GPU"`
  117. ResourceDataBase
  118. Type string `json:"type"`
  119. Name ResourceType `json:"name"`
  120. Total UnitValue[int64] `json:"total"`
  121. Available UnitValue[int64] `json:"available"`
  122. }
  123. type MLUResourceData struct {
  124. serder.Metadata `union:"MLU"`
  125. ResourceDataBase
  126. Type string `json:"type"`
  127. Name ResourceType `json:"name"`
  128. Total UnitValue[int64] `json:"total"`
  129. Available UnitValue[int64] `json:"available"`
  130. }
  131. type DCUResourceData struct {
  132. serder.Metadata `union:"DCU"`
  133. ResourceDataBase
  134. Type string `json:"type"`
  135. Name ResourceType `json:"name"`
  136. Total UnitValue[int64] `json:"total"`
  137. Available UnitValue[int64] `json:"available"`
  138. }
  139. type GCUResourceData struct {
  140. serder.Metadata `union:"GCU"`
  141. ResourceDataBase
  142. Type string `json:"type"`
  143. Name ResourceType `json:"name"`
  144. Total UnitValue[int64] `json:"total"`
  145. Available UnitValue[int64] `json:"available"`
  146. }
  147. type GPGPUResourceData struct {
  148. serder.Metadata `union:"ILUVATAR-GPGPU"`
  149. ResourceDataBase
  150. Type string `json:"type"`
  151. Name ResourceType `json:"name"`
  152. Total UnitValue[int64] `json:"total"`
  153. Available UnitValue[int64] `json:"available"`
  154. }
  155. type StorageResourceData struct {
  156. serder.Metadata `union:"STORAGE"`
  157. ResourceDataBase
  158. Type string `json:"type"`
  159. Name ResourceType `json:"name"`
  160. Total UnitValue[float64] `json:"total"`
  161. Available UnitValue[float64] `json:"available"`
  162. }
  163. type MemoryResourceData struct {
  164. serder.Metadata `union:"MEMORY"`
  165. ResourceDataBase
  166. Type string `json:"type"`
  167. Name ResourceType `json:"name"`
  168. Total UnitValue[float64] `json:"total"`
  169. Available UnitValue[float64] `json:"available"`
  170. }
  171. type BalanceResourceData struct {
  172. serder.Metadata `union:"BALANCE"`
  173. ResourceDataBase
  174. Type string `json:"type"`
  175. Name ResourceType `json:"name"`
  176. Total UnitValue[float64] `json:"total"`
  177. Available UnitValue[float64] `json:"available"`
  178. }
  179. type RateResourceData struct {
  180. serder.Metadata `union:"RATE"`
  181. ResourceDataBase
  182. Type string `json:"type"`
  183. Name ResourceType `json:"name"`
  184. Total UnitValue[float64] `json:"total"`
  185. Available UnitValue[float64] `json:"available"`
  186. }
  187. type ResourceRange struct {
  188. UserID cdssdk.UserID `json:"userID"`
  189. Type ResourceType `json:"type"`
  190. GPU Range `json:"gpu"`
  191. GPUNumber int `json:"gpuNumber"`
  192. CPU Range `json:"cpu"`
  193. Memory Range `json:"memory"`
  194. Storage Range `json:"storage"`
  195. Ids []string `json:"ids"`
  196. }
  197. type Range struct {
  198. Min float64 `json:"min"`
  199. Max float64 `json:"max"`
  200. }
  201. type ResourcePriority interface {
  202. Noop()
  203. }
  204. type ResourcePriorityBase struct {
  205. }
  206. var ResourcePriorityTypeUnion = types.NewTypeUnion[ResourcePriority](
  207. (*RegionPriority)(nil),
  208. (*ChipPriority)(nil),
  209. (*BiasPriority)(nil),
  210. )
  211. var _ = serder.UseTypeUnionInternallyTagged(&ResourcePriorityTypeUnion, "type")
  212. func (d *ResourcePriorityBase) Noop() {}
  213. type RegionPriority struct {
  214. serder.Metadata `union:"region"`
  215. ResourcePriorityBase
  216. Type string `json:"type"`
  217. Options []string `json:"options"`
  218. }
  219. type ChipPriority struct {
  220. serder.Metadata `union:"chip"`
  221. ResourcePriorityBase
  222. Type string `json:"type"`
  223. Options []string `json:"options"`
  224. }
  225. type BiasPriority struct {
  226. serder.Metadata `union:"bias"`
  227. ResourcePriorityBase
  228. Type string `json:"type"`
  229. Options []string `json:"options"`
  230. }
  231. type TaskMessage struct {
  232. Status string `json:"status"`
  233. Message string `json:"message"`
  234. }
  235. type UploadParams struct {
  236. DataType string `json:"dataType"`
  237. UploadInfo UploadInfo `json:"uploadInfo"`
  238. //UploadPriority UploadPriority `json:"uploadPriority"`
  239. }
  240. type UploadInfo interface {
  241. Noop()
  242. }
  243. var UploadInfoTypeUnion = types.NewTypeUnion[UploadInfo](
  244. (*LocalUploadInfo)(nil),
  245. (*RemoteUploadInfo)(nil),
  246. )
  247. var _ = serder.UseTypeUnionInternallyTagged(&UploadInfoTypeUnion, "type")
  248. type LocalUploadInfo struct {
  249. serder.Metadata `union:"local"`
  250. UploadInfoBase
  251. Type string `json:"type"`
  252. LocalPath string `json:"localPath"`
  253. ObjectIDs []cdssdk.ObjectID `json:"objectIDs"`
  254. }
  255. type RemoteUploadInfo struct {
  256. serder.Metadata `union:"url"`
  257. UploadInfoBase
  258. Type string `json:"type"`
  259. Url string `json:"url"`
  260. Branch string `json:"branch"`
  261. DataName string `json:"dataName"`
  262. Cluster schsdk.ClusterID `json:"clusterID"`
  263. }
  264. type UploadInfoBase struct{}
  265. func (d *UploadInfoBase) Noop() {}
  266. type UploadPriority interface {
  267. Noop()
  268. }
  269. var UploadPriorityTypeUnion = types.NewTypeUnion[UploadPriority](
  270. (*Preferences)(nil),
  271. (*SpecifyCluster)(nil),
  272. )
  273. var _ = serder.UseTypeUnionInternallyTagged(&UploadPriorityTypeUnion, "type")
  274. type Preferences struct {
  275. serder.Metadata `union:"preference"`
  276. UploadPriorityBase
  277. Type string `json:"type"`
  278. ResourcePriorities []ResourcePriority `json:"priorities"`
  279. }
  280. type SpecifyCluster struct {
  281. serder.Metadata `union:"specify"`
  282. UploadPriorityBase
  283. Type string `json:"type"`
  284. Clusters []schsdk.ClusterID `json:"clusters"`
  285. }
  286. type UploadPriorityBase struct{}
  287. func (d *UploadPriorityBase) Noop() {}
  288. type QueryData struct {
  289. DataType string `json:"dataType" binding:"required"`
  290. UserID cdssdk.UserID `json:"userID" binding:"required"`
  291. Path string `json:"path"`
  292. PackageID cdssdk.PackageID `json:"packageID" binding:"required"`
  293. CurrentPage int `json:"currentPage" binding:"required"`
  294. PageSize int `json:"pageSize" binding:"required"`
  295. OrderBy string `json:"orderBy" binding:"required"`
  296. }
  297. type DataBinding interface {
  298. Noop()
  299. }
  300. var DataBindingTypeUnion = types.NewTypeUnion[DataBinding](
  301. (*DatasetBinding)(nil),
  302. (*ModelBinding)(nil),
  303. (*CodeBinding)(nil),
  304. (*ImageBinding)(nil),
  305. )
  306. var _ = serder.UseTypeUnionInternallyTagged(&DataBindingTypeUnion, "type")
  307. type DataBindingBase struct{}
  308. func (d *DataBindingBase) Noop() {}
  309. type DatasetBinding struct {
  310. serder.Metadata `union:"dataset"`
  311. DataBindingBase
  312. Type string `json:"type"`
  313. Name string `json:"name"`
  314. ClusterIDs []schsdk.ClusterID `json:"clusterIDs"`
  315. Description string `json:"description"`
  316. Category string `json:"category"`
  317. PackageID cdssdk.PackageID `json:"packageID"`
  318. }
  319. type ModelBinding struct {
  320. serder.Metadata `union:"model"`
  321. DataBindingBase
  322. Type string `json:"type"`
  323. Name string `json:"name"`
  324. ClusterIDs []schsdk.ClusterID `json:"clusterIDs"`
  325. Description string `json:"description"`
  326. Category string `json:"category"`
  327. ModelType string `json:"modelType"`
  328. Env string `json:"env"`
  329. Version string `json:"version"`
  330. PackageID cdssdk.PackageID `json:"packageID"`
  331. }
  332. type CodeBinding struct {
  333. serder.Metadata `union:"code"`
  334. DataBindingBase
  335. Type string `json:"type"`
  336. Name string `json:"name"`
  337. //ClusterIDs []schsdk.ClusterID `json:"clusterIDs"`
  338. ClusterID schsdk.ClusterID `json:"clusterID"`
  339. Description string `json:"description"`
  340. ImageID schsdk.ImageID `json:"imageID"`
  341. BootstrapObjectID cdssdk.ObjectID `json:"bootstrapObjectID"`
  342. //FilePath string `json:"filePath"`
  343. PackageID cdssdk.PackageID `json:"packageID"`
  344. }
  345. //type ImageBinding struct {
  346. // serder.Metadata `union:"image"`
  347. // DataBindingBase
  348. // Type string `json:"type"`
  349. // Name string `json:"name"`
  350. // ClusterIDs []schsdk.ClusterID `json:"clusterIDs"`
  351. // Description string `json:"description"`
  352. // Architecture string `json:"architecture"`
  353. // ResourceType string `json:"resourceType"`
  354. // Tags []string `json:"tags"`
  355. // PackageID cdssdk.PackageID `json:"packageID"`
  356. //}
  357. type ImageBinding struct {
  358. serder.Metadata `union:"image"`
  359. DataBindingBase
  360. Type string `json:"type"`
  361. ID int64 `json:"id"`
  362. Name string `json:"name"`
  363. IDType string `json:"idType"`
  364. ImageID string `json:"imageID"`
  365. ClusterID schsdk.ClusterID `json:"clusterID"`
  366. }
  367. type Image struct {
  368. ImageID schsdk.ImageID `json:"imageID" gorm:"column:ImageID;primaryKey"`
  369. Name string `json:"name" gorm:"column:Name"`
  370. CreateTime time.Time `json:"createTime" gorm:"column:CreateTime"`
  371. ClusterImage []ClusterImage `gorm:"foreignKey:image_id;references:ImageID" json:"clusterImages"`
  372. }
  373. type ClusterImage struct {
  374. ImageID schsdk.ImageID `gorm:"column:image_id" json:"imageID"`
  375. ClusterID schsdk.ClusterID `gorm:"column:cluster_id" json:"clusterID"`
  376. OriginImageType string `gorm:"column:origin_image_type" json:"originImageType"`
  377. OriginImageID string `gorm:"column:origin_image_id" json:"originImageID"`
  378. OriginImageName string `gorm:"column:origin_image_name" json:"originImageName"`
  379. ClusterImageCard []ClusterImageCard `gorm:"foreignKey:origin_image_id;references:origin_image_id" json:"cards"`
  380. }
  381. func (ClusterImage) TableName() string {
  382. return "clusterImage"
  383. }
  384. type ClusterImageCard struct {
  385. OriginImageID string `gorm:"column:origin_image_id" json:"originImageID"`
  386. Card string `gorm:"column:card" json:"card"`
  387. }
  388. func (ClusterImageCard) TableName() string {
  389. return "clusterImageCard"
  390. }
  391. type QueryBindingFilters struct {
  392. Status string `json:"status"`
  393. Name string `json:"name"`
  394. }
  395. type QueryBindingDataParam interface {
  396. Noop()
  397. }
  398. var QueryBindingDataParamTypeUnion = types.NewTypeUnion[QueryBindingDataParam](
  399. (*PrivateLevel)(nil),
  400. (*ApplyLevel)(nil),
  401. (*PublicLevel)(nil),
  402. )
  403. var _ = serder.UseTypeUnionInternallyTagged(&QueryBindingDataParamTypeUnion, "type")
  404. type QueryBindingDataParamBase struct{}
  405. func (d *QueryBindingDataParamBase) Noop() {}
  406. type PrivateLevel struct {
  407. serder.Metadata `union:"private"`
  408. QueryBindingDataParamBase
  409. Type string `json:"type" binding:"required"`
  410. UserID cdssdk.UserID `json:"userID" binding:"required"`
  411. BindingID int64 `json:"bindingID" binding:"required"`
  412. Info DataBinding `json:"info"` // 可选,用于精细筛选,功能暂未实现
  413. }
  414. type ApplyLevel struct {
  415. serder.Metadata `union:"apply"`
  416. QueryBindingDataParamBase
  417. Type string `json:"type" binding:"required"`
  418. UserID cdssdk.UserID `json:"userID" binding:"required"`
  419. Info DataBinding `json:"info"` // 可选,用于精细筛选,功能暂未实现
  420. }
  421. type PublicLevel struct {
  422. serder.Metadata `union:"public"`
  423. QueryBindingDataParamBase
  424. UserID cdssdk.UserID `json:"userID" binding:"required"`
  425. Type string `json:"type" binding:"required"`
  426. Info DataBinding `json:"info"` // 可选,用于精细筛选,功能暂未实现
  427. }