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

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