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

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