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

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