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

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