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