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 14 kB

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