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.

cloudbrain.go 88 kB

3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
2 years ago
4 years ago
4 years ago
4 years ago
4 years ago
2 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
3 years ago
2 years ago
3 years ago
3 years ago
4 years ago
4 years ago
3 years ago
3 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
3 years ago
2 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
2 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
4 years ago
2 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
4 years ago
3 years ago
3 years ago
4 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
3 years ago
3 years ago
2 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702
  1. package models
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "path"
  7. "strconv"
  8. "strings"
  9. "time"
  10. "code.gitea.io/gitea/modules/util"
  11. "xorm.io/builder"
  12. "xorm.io/xorm"
  13. "code.gitea.io/gitea/modules/log"
  14. "code.gitea.io/gitea/modules/setting"
  15. "code.gitea.io/gitea/modules/timeutil"
  16. )
  17. type CloudbrainStatus string
  18. type JobType string
  19. type ModelArtsJobStatus string
  20. const (
  21. TypeCloudBrainOne int = iota
  22. TypeCloudBrainTwo
  23. TypeC2Net //智算网络
  24. TypeCDCenter //成都智算中心
  25. TypeCloudBrainAll = -1
  26. )
  27. const (
  28. NPUResource = "NPU"
  29. GPUResource = "CPU/GPU"
  30. AllResource = "all"
  31. //notebook storage category
  32. EVSCategory = "EVS"
  33. EFSCategory = "EFS"
  34. ManagedOwnership = "MANAGED"
  35. DetectedOwnership = "DEDICATED"
  36. NotebookFeature = "NOTEBOOK"
  37. DefaultFeature = "DEFAULT"
  38. JobWaiting CloudbrainStatus = "WAITING"
  39. JobStopped CloudbrainStatus = "STOPPED"
  40. JobSucceeded CloudbrainStatus = "SUCCEEDED"
  41. JobFailed CloudbrainStatus = "FAILED"
  42. JobRunning CloudbrainStatus = "RUNNING"
  43. ModelSafetyTesting CloudbrainStatus = "TESTING"
  44. JobTypeDebug JobType = "DEBUG"
  45. JobTypeBenchmark JobType = "BENCHMARK"
  46. JobTypeModelSafety JobType = "MODELSAFETY"
  47. JobTypeSnn4imagenet JobType = "SNN4IMAGENET"
  48. JobTypeBrainScore JobType = "BRAINSCORE"
  49. JobTypeTrain JobType = "TRAIN"
  50. JobTypeInference JobType = "INFERENCE"
  51. //notebook
  52. ModelArtsCreateQueue ModelArtsJobStatus = "CREATE_QUEUING" //免费资源创建排队中
  53. ModelArtsCreating ModelArtsJobStatus = "CREATING" //创建中
  54. ModelArtsCreateFailed ModelArtsJobStatus = "CREATE_FAILED" //创建失败
  55. ModelArtsStartQueuing ModelArtsJobStatus = "START_QUEUING" //免费资源启动排队中
  56. ModelArtsReadyToStart ModelArtsJobStatus = "READY_TO_START" //免费资源等待启动
  57. ModelArtsStarting ModelArtsJobStatus = "STARTING" //启动中
  58. ModelArtsRestarting ModelArtsJobStatus = "RESTARTING" //重启中
  59. ModelArtsStartFailed ModelArtsJobStatus = "START_FAILED" //启动失败
  60. ModelArtsRunning ModelArtsJobStatus = "RUNNING" //运行中
  61. ModelArtsStopping ModelArtsJobStatus = "STOPPING" //停止中
  62. ModelArtsStopped ModelArtsJobStatus = "STOPPED" //停止
  63. ModelArtsUnavailable ModelArtsJobStatus = "UNAVAILABLE" //故障
  64. ModelArtsDeleting ModelArtsJobStatus = "DELETING" //删除中
  65. ModelArtsDeleted ModelArtsJobStatus = "DELETED" //已删除
  66. ModelArtsResizing ModelArtsJobStatus = "RESIZING" //规格变更中
  67. ModelArtsResizFailed ModelArtsJobStatus = "RESIZE_FAILED" //规格变更失败
  68. //trainjob
  69. ModelArtsTrainJobUnknown ModelArtsJobStatus = "UNKNOWN" //作业状态未知
  70. ModelArtsTrainJobInit ModelArtsJobStatus = "INIT" //作业初始化状态
  71. ModelArtsTrainJobImageCreating ModelArtsJobStatus = "IMAGE_CREATING" //作业镜像正在创建
  72. ModelArtsTrainJobImageFailed ModelArtsJobStatus = "IMAGE_FAILED" //作业镜像创建失败
  73. ModelArtsTrainJobSubmitTrying ModelArtsJobStatus = "SUBMIT_TRYING" //作业正在提交
  74. ModelArtsTrainJobSubmitFailed ModelArtsJobStatus = "SUBMIT_FAILED" //作业提交失败
  75. ModelArtsTrainJobDeleteFailed ModelArtsJobStatus = "DELETE_FAILED" //作业删除失败
  76. ModelArtsTrainJobWaiting ModelArtsJobStatus = "WAITING" //作业正在排队中
  77. ModelArtsTrainJobRunning ModelArtsJobStatus = "RUNNING" //作业正在运行中
  78. ModelArtsTrainJobKilling ModelArtsJobStatus = "KILLING" //作业正在取消
  79. ModelArtsTrainJobCompleted ModelArtsJobStatus = "COMPLETED" //作业已经完成
  80. ModelArtsTrainJobFailed ModelArtsJobStatus = "FAILED" //作业运行失败
  81. ModelArtsTrainJobKilled ModelArtsJobStatus = "KILLED" //作业取消成功
  82. ModelArtsTrainJobCanceled ModelArtsJobStatus = "CANCELED" //作业取消
  83. ModelArtsTrainJobLost ModelArtsJobStatus = "LOST" //作业丢失
  84. ModelArtsTrainJobScaling ModelArtsJobStatus = "SCALING" //作业正在扩容
  85. ModelArtsTrainJobSubmitModelFailed ModelArtsJobStatus = "SUBMIT_MODEL_FAILED" //提交模型失败
  86. ModelArtsTrainJobDeployServiceFailed ModelArtsJobStatus = "DEPLOY_SERVICE_FAILED" //部署服务失败
  87. ModelArtsTrainJobCheckInit ModelArtsJobStatus = "CHECK_INIT" //审核作业初始化
  88. ModelArtsTrainJobCheckRunning ModelArtsJobStatus = "CHECK_RUNNING" //审核作业正在运行中
  89. ModelArtsTrainJobCheckRunningCompleted ModelArtsJobStatus = "CHECK_RUNNING_COMPLETED" //审核作业已经完成
  90. ModelArtsTrainJobCheckFailed ModelArtsJobStatus = "CHECK_FAILED" //审核作业失败
  91. DURATION_STR_ZERO = "00:00:00"
  92. CloudbrainKeyDuration = 24 * time.Hour
  93. //grampus
  94. GrampusStatusPending = "pending"
  95. GrampusStatusRunning = "RUNNING"
  96. GrampusStatusFailed = "FAILED"
  97. GrampusStatusSucceeded = "SUCCEEDED"
  98. GrampusStatusStopped = "STOPPED"
  99. GrampusStatusUnknown = "UNKNOWN"
  100. GrampusStatusWaiting = "WAITING"
  101. ModelSuffix = "models.zip"
  102. )
  103. const (
  104. //cluster
  105. OpenICluster = "OpenI"
  106. C2NetCluster = "C2Net"
  107. //AI center
  108. AICenterOfCloudBrainOne = "OpenIOne"
  109. AICenterOfCloudBrainTwo = "OpenITwo"
  110. AICenterOfChengdu = "OpenIChengdu"
  111. //ComputeResource
  112. GPU = "GPU"
  113. NPU = "NPU"
  114. )
  115. type Cloudbrain struct {
  116. ID int64 `xorm:"pk autoincr"`
  117. JobID string `xorm:"INDEX NOT NULL"`
  118. JobType string `xorm:"INDEX NOT NULL DEFAULT 'DEBUG'"`
  119. JobName string
  120. DisplayJobName string
  121. Status string
  122. UserID int64 `xorm:"INDEX NOT NULL"`
  123. RepoID int64 `xorm:"INDEX NOT NULL"`
  124. SubTaskName string
  125. ContainerID string
  126. ContainerIp string
  127. CreatedUnix timeutil.TimeStamp `xorm:"INDEX"`
  128. UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
  129. Duration int64 `xorm:"DEFAULT 0"` //运行时长 单位秒
  130. TrainJobDuration string `xorm:"DEFAULT '00:00:00'"`
  131. Image string //镜像名称
  132. GpuQueue string //GPU类型即GPU队列
  133. ResourceSpecId int //GPU规格id
  134. DeletedAt time.Time `xorm:"deleted"`
  135. CanDebug bool `xorm:"-"`
  136. CanDel bool `xorm:"-"`
  137. CanModify bool `xorm:"-"`
  138. Type int `xorm:"INDEX"`
  139. BenchmarkTypeID int
  140. BenchmarkChildTypeID int
  141. CardType string
  142. Cluster string
  143. VersionID int64 //版本id
  144. VersionName string `xorm:"INDEX"` //当前版本
  145. Uuid string //数据集id
  146. DatasetName string `xorm:"varchar(2000)"`
  147. VersionCount int //任务的当前版本数量,不包括删除的
  148. IsLatestVersion string //是否是最新版本,1是,0否
  149. CommitID string //提交的仓库代码id
  150. PreVersionName string //父版本名称
  151. ComputeResource string //计算资源,例如npu
  152. EngineID int64 //引擎id
  153. ImageID string //grampus image_id
  154. AiCenter string //grampus ai center: center_id+center_name
  155. TrainUrl string //输出模型的obs路径
  156. BranchName string //分支名称
  157. Parameters string //传给modelarts的param参数
  158. BootFile string //启动文件
  159. DataUrl string //数据集的obs路径
  160. LogUrl string //日志输出的obs路径
  161. PreVersionId int64 //父版本的版本id
  162. FlavorCode string //modelarts上的规格id
  163. Description string `xorm:"varchar(256)"` //描述
  164. WorkServerNumber int //节点数
  165. FlavorName string //规格名称
  166. EngineName string //引擎名称
  167. TotalVersionCount int //任务的所有版本数量,包括删除的
  168. LabelName string //标签名称
  169. ModelName string //模型名称
  170. ModelVersion string //模型版本
  171. CkptName string //权重文件名称
  172. PreTrainModelUrl string //预训练模型地址
  173. ResultUrl string //推理结果的obs路径
  174. ResultJson string `xorm:"varchar(4000)"`
  175. User *User `xorm:"-"`
  176. Repo *Repository `xorm:"-"`
  177. BenchmarkType string `xorm:"-"` //算法评测,模型评测
  178. BenchmarkTypeName string `xorm:"-"`
  179. BenchmarkTypeRankLink string `xorm:"-"`
  180. StartTime timeutil.TimeStamp
  181. EndTime timeutil.TimeStamp
  182. Cleared bool `xorm:"DEFAULT false"`
  183. Spec *Specification `xorm:"-"`
  184. }
  185. type CloudbrainShow struct {
  186. ID int64
  187. JobID string
  188. RepoFullName string
  189. Type int
  190. JobType string
  191. DisplayJobName string
  192. Duration string
  193. ResourceSpec *Specification
  194. ComputeResource string
  195. AiCenter string
  196. WorkServerNumber int
  197. }
  198. type CloudbrainShow4Action struct {
  199. ID int64
  200. JobID string
  201. Type int
  202. JobType string
  203. DisplayJobName string
  204. ComputeResource string
  205. }
  206. func (task *Cloudbrain) ToShow() *CloudbrainShow {
  207. n := 1
  208. if task.WorkServerNumber > 1 {
  209. n = task.WorkServerNumber
  210. }
  211. c := &CloudbrainShow{
  212. ID: task.ID,
  213. JobID: task.JobID,
  214. JobType: task.JobType,
  215. Type: task.Type,
  216. DisplayJobName: task.DisplayJobName,
  217. Duration: task.TrainJobDuration,
  218. ResourceSpec: task.Spec,
  219. ComputeResource: task.ComputeResource,
  220. WorkServerNumber: n,
  221. }
  222. if task.Repo != nil {
  223. c.RepoFullName = task.Repo.FullName()
  224. }
  225. return c
  226. }
  227. func (task *Cloudbrain) ComputeAndSetDuration() {
  228. var d int64
  229. if task.StartTime == 0 {
  230. d = 0
  231. } else if task.EndTime == 0 {
  232. if !task.IsTerminal() {
  233. d = time.Now().Unix() - task.StartTime.AsTime().Unix()
  234. }
  235. } else {
  236. d = task.EndTime.AsTime().Unix() - task.StartTime.AsTime().Unix()
  237. }
  238. if d < 0 {
  239. d = 0
  240. }
  241. task.Duration = d
  242. task.TrainJobDuration = ConvertDurationToStr(d)
  243. }
  244. func (task *Cloudbrain) CorrectCreateUnix() {
  245. if task.StartTime > 0 && task.CreatedUnix > task.StartTime {
  246. task.CreatedUnix = task.StartTime
  247. }
  248. }
  249. func (task *Cloudbrain) IsTerminal() bool {
  250. status := task.Status
  251. return status == string(ModelArtsTrainJobCompleted) || status == string(ModelArtsTrainJobFailed) ||
  252. status == string(ModelArtsTrainJobKilled) || status == string(ModelArtsStopped) ||
  253. status == string(JobStopped) || status == string(JobFailed) ||
  254. status == string(JobSucceeded) || status == GrampusStatusFailed ||
  255. status == GrampusStatusSucceeded || status == GrampusStatusStopped
  256. }
  257. func (task *Cloudbrain) IsRunning() bool {
  258. status := task.Status
  259. return status == string(ModelArtsTrainJobRunning) || status == string(ModelArtsRunning) ||
  260. status == string(JobRunning) || status == GrampusStatusRunning
  261. }
  262. func (task *Cloudbrain) IsUserHasRight(user *User) bool {
  263. if user == nil {
  264. return false
  265. }
  266. return user.IsAdmin || user.ID == task.UserID
  267. }
  268. func ConvertDurationToStr(duration int64) string {
  269. if duration <= 0 {
  270. return DURATION_STR_ZERO
  271. }
  272. return util.AddZero(duration/3600) + ":" + util.AddZero(duration%3600/60) + ":" + util.AddZero(duration%60)
  273. }
  274. func ConvertStrToDuration(trainJobDuration string) int64 {
  275. trainJobDurationList := strings.Split(trainJobDuration, ":")
  276. if len(trainJobDurationList) == 3 {
  277. i, _ := strconv.ParseInt(trainJobDurationList[0], 10, 64)
  278. j, _ := strconv.ParseInt(trainJobDurationList[1], 10, 64)
  279. k, _ := strconv.ParseInt(trainJobDurationList[2], 10, 64)
  280. return i*3600 + j*60 + k
  281. } else {
  282. return 0
  283. }
  284. }
  285. func IsTrainJobTerminal(status string) bool {
  286. return status == string(ModelArtsTrainJobCompleted) || status == string(ModelArtsTrainJobFailed) || status == string(ModelArtsTrainJobKilled) || status == GrampusStatusFailed || status == GrampusStatusStopped || status == GrampusStatusSucceeded
  287. }
  288. func IsModelArtsDebugJobTerminal(status string) bool {
  289. return status == string(ModelArtsStopped)
  290. }
  291. func IsCloudBrainOneDebugJobTerminal(status string) bool {
  292. return status == string(JobStopped) || status == string(JobFailed) || status == string(JobSucceeded)
  293. }
  294. func ParseAndSetDurationFromCloudBrainOne(result JobResultPayload, task *Cloudbrain) {
  295. isActivated := result.JobStatus.CreatedTime > 0
  296. if task.StartTime == 0 && isActivated {
  297. task.StartTime = timeutil.TimeStamp(result.JobStatus.CreatedTime / 1000)
  298. }
  299. if task.EndTime == 0 && IsCloudBrainOneDebugJobTerminal(task.Status) && isActivated {
  300. if result.JobStatus.CompletedTime > 0 {
  301. task.EndTime = timeutil.TimeStamp(result.JobStatus.CompletedTime / 1000)
  302. }
  303. }
  304. task.CorrectCreateUnix()
  305. task.ComputeAndSetDuration()
  306. }
  307. func ParseAndSetDurationFromModelArtsNotebook(result *GetNotebook2Result, job *Cloudbrain) {
  308. if job.StartTime == 0 && result.Lease.UpdateTime > 0 {
  309. job.StartTime = timeutil.TimeStamp(result.Lease.UpdateTime / 1000)
  310. }
  311. job.Status = result.Status
  312. if job.EndTime == 0 && IsModelArtsDebugJobTerminal(job.Status) {
  313. job.EndTime = timeutil.TimeStampNow()
  314. }
  315. job.CorrectCreateUnix()
  316. job.ComputeAndSetDuration()
  317. }
  318. type CloudbrainInfo struct {
  319. Cloudbrain `xorm:"extends"`
  320. User `xorm:"extends"`
  321. }
  322. type CloudBrainLoginResult struct {
  323. Code string
  324. Msg string
  325. Payload map[string]interface{}
  326. }
  327. type TaskRole struct {
  328. Name string `json:"name"`
  329. TaskNumber int `json:"taskNumber"`
  330. MinSucceededTaskCount int `json:"minSucceededTaskCount"`
  331. MinFailedTaskCount int `json:"minFailedTaskCount"`
  332. CPUNumber int `json:"cpuNumber"`
  333. GPUNumber int `json:"gpuNumber"`
  334. MemoryMB int `json:"memoryMB"`
  335. ShmMB int `json:"shmMB"`
  336. Command string `json:"command"`
  337. NeedIBDevice bool `json:"needIBDevice"`
  338. IsMainRole bool `json:"isMainRole"`
  339. UseNNI bool `json:"useNNI"`
  340. }
  341. type StHostPath struct {
  342. Path string `json:"path"`
  343. MountPath string `json:"mountPath"`
  344. ReadOnly bool `json:"readOnly"`
  345. }
  346. type Volume struct {
  347. HostPath StHostPath `json:"hostPath"`
  348. }
  349. type CreateJobParams struct {
  350. JobName string `json:"jobName"`
  351. RetryCount int8 `json:"retryCount"`
  352. GpuType string `json:"gpuType"`
  353. Image string `json:"image"`
  354. TaskRoles []TaskRole `json:"taskRoles"`
  355. Volumes []Volume `json:"volumes"`
  356. }
  357. type CreateJobResult struct {
  358. Code string `json:"code"`
  359. Msg string `json:"msg"`
  360. Payload map[string]interface{} `json:"payload"`
  361. }
  362. type QueueDetailResult struct {
  363. Code string `json:"code"`
  364. Msg string `json:"msg"`
  365. Payload map[string]QueueDetail `json:"payload"`
  366. }
  367. type QueueDetail struct {
  368. JobScheduleInfo JobScheduleInfo `json:"JobScheduleInfo"`
  369. }
  370. type JobScheduleInfo struct {
  371. Pending int `json:"Pending"`
  372. Running int `json:"Running"`
  373. MedianPendingJobDurationSec int `json:"MedianPendingJobDurationSec"`
  374. }
  375. type GetJobResult struct {
  376. Code string `json:"code"`
  377. Msg string `json:"msg"`
  378. Payload map[string]interface{} `json:"payload"`
  379. }
  380. type GetImagesResult struct {
  381. Code string `json:"code"`
  382. Msg string `json:"msg"`
  383. Payload GetImagesPayload `json:"payload"`
  384. }
  385. type GetImagesPayload struct {
  386. Count int `json:"count"`
  387. TotalPages int `json:"totalPages,omitempty"`
  388. ImageInfo []*ImageInfo `json:"rows"`
  389. }
  390. type CloudbrainsOptions struct {
  391. ListOptions
  392. RepoID int64 // include all repos if empty
  393. UserID int64
  394. JobID string
  395. SortType string
  396. CloudbrainIDs []int64
  397. JobStatus []string
  398. JobStatusNot bool
  399. Keyword string
  400. Type int
  401. JobTypes []string
  402. VersionName string
  403. IsLatestVersion string
  404. JobTypeNot bool
  405. NeedRepoInfo bool
  406. RepoIDList []int64
  407. BeginTime time.Time
  408. EndTime time.Time
  409. ComputeResource string
  410. BeginTimeUnix int64
  411. EndTimeUnix int64
  412. AiCenter string
  413. NeedDeleteInfo string
  414. Cluster string
  415. AccCardType string
  416. AccCardsNum string
  417. WorkServerNumber int
  418. }
  419. type TaskPod struct {
  420. TaskRoleStatus struct {
  421. Name string `json:"name"`
  422. } `json:"taskRoleStatus"`
  423. //TaskStatuses []struct {
  424. // TaskIndex int `json:"taskIndex"`
  425. // PodUID string `json:"podUid"`
  426. // PodIP string `json:"podIp"`
  427. // PodName string `json:"podName"`
  428. // ContainerID string `json:"containerId"`
  429. // ContainerIP string `json:"containerIp"`
  430. // ContainerGpus string `json:"containerGpus"`
  431. // State string `json:"state"`
  432. // StartAt time.Time `json:"startAt"`
  433. // FinishedAt time.Time `json:"finishedAt"`
  434. // ExitCode int `json:"exitCode"`
  435. // ExitDiagnostics string `json:"exitDiagnostics"`
  436. // RetriedCount int `json:"retriedCount"`
  437. // StartTime string
  438. // FinishedTime string
  439. //} `json:"taskStatuses"`
  440. TaskStatuses []TaskStatuses `json:"taskStatuses"`
  441. }
  442. type TaskStatuses struct {
  443. TaskIndex int `json:"taskIndex"`
  444. PodUID string `json:"podUid"`
  445. PodIP string `json:"podIp"`
  446. PodName string `json:"podName"`
  447. ContainerID string `json:"containerId"`
  448. ContainerIP string `json:"containerIp"`
  449. ContainerGpus string `json:"containerGpus"`
  450. State string `json:"state"`
  451. StartAt time.Time `json:"startAt"`
  452. FinishedAt time.Time `json:"finishedAt"`
  453. ExitCode int `json:"exitCode"`
  454. ExitDiagnostics string `json:"exitDiagnostics"`
  455. RetriedCount int `json:"retriedCount"`
  456. StartTime string
  457. FinishedTime string
  458. }
  459. type TaskInfo struct {
  460. Username string `json:"username"`
  461. TaskName string `json:"task_name"`
  462. CodeName string `json:"code_name"`
  463. BenchmarkCategory []string `json:"selected_category"`
  464. CodeLink string `json:"code_link"`
  465. GpuType string `json:"gpu_type"`
  466. }
  467. func ConvertToTaskPod(input map[string]interface{}) (TaskPod, error) {
  468. data, _ := json.Marshal(input)
  469. var taskPod TaskPod
  470. err := json.Unmarshal(data, &taskPod)
  471. taskPod.TaskStatuses[0].StartTime = time.Unix(taskPod.TaskStatuses[0].StartAt.Unix()+8*3600, 0).UTC().Format("2006-01-02 15:04:05")
  472. taskPod.TaskStatuses[0].FinishedTime = time.Unix(taskPod.TaskStatuses[0].FinishedAt.Unix()+8*3600, 0).UTC().Format("2006-01-02 15:04:05")
  473. //if the task is not finished or stopped,the cloudbrain renturns 0001-01-01 08:00:00, the finishedTime shows with -
  474. if strings.HasPrefix(taskPod.TaskStatuses[0].FinishedTime, "0001") {
  475. taskPod.TaskStatuses[0].FinishedTime = "-"
  476. }
  477. return taskPod, err
  478. }
  479. type JobResultPayload struct {
  480. ID string `json:"id"`
  481. Name string `json:"name"`
  482. Platform string `json:"platform"`
  483. JobStatus struct {
  484. Username string `json:"username"`
  485. State string `json:"state"`
  486. SubState string `json:"subState"`
  487. ExecutionType string `json:"executionType"`
  488. Retries int `json:"retries"`
  489. CreatedTime int64 `json:"createdTime"`
  490. CompletedTime int64 `json:"completedTime"`
  491. AppID string `json:"appId"`
  492. AppProgress string `json:"appProgress"`
  493. AppTrackingURL string `json:"appTrackingUrl"`
  494. AppLaunchedTime int64 `json:"appLaunchedTime"`
  495. AppCompletedTime interface{} `json:"appCompletedTime"`
  496. AppExitCode int `json:"appExitCode"`
  497. AppExitDiagnostics string `json:"appExitDiagnostics"`
  498. AppExitType interface{} `json:"appExitType"`
  499. VirtualCluster string `json:"virtualCluster"`
  500. StartTime string
  501. EndTime string
  502. } `json:"jobStatus"`
  503. TaskRoles map[string]interface{} `json:"taskRoles"`
  504. Resource struct {
  505. CPU int `json:"cpu"`
  506. Memory string `json:"memory"`
  507. NvidiaComGpu int `json:"nvidia.com/gpu"`
  508. } `json:"resource"`
  509. Config struct {
  510. Image string `json:"image"`
  511. JobID string `json:"jobId"`
  512. GpuType string `json:"gpuType"`
  513. JobName string `json:"jobName"`
  514. JobType string `json:"jobType"`
  515. TaskRoles []struct {
  516. Name string `json:"name"`
  517. ShmMB int `json:"shmMB"`
  518. Command string `json:"command"`
  519. MemoryMB int `json:"memoryMB"`
  520. CPUNumber int `json:"cpuNumber"`
  521. GpuNumber int `json:"gpuNumber"`
  522. IsMainRole bool `json:"isMainRole"`
  523. TaskNumber int `json:"taskNumber"`
  524. NeedIBDevice bool `json:"needIBDevice"`
  525. MinFailedTaskCount int `json:"minFailedTaskCount"`
  526. MinSucceededTaskCount int `json:"minSucceededTaskCount"`
  527. } `json:"taskRoles"`
  528. RetryCount int `json:"retryCount"`
  529. } `json:"config"`
  530. Userinfo struct {
  531. User string `json:"user"`
  532. OrgID string `json:"org_id"`
  533. } `json:"userinfo"`
  534. }
  535. func ConvertToJobResultPayload(input map[string]interface{}) (JobResultPayload, error) {
  536. data, _ := json.Marshal(input)
  537. var jobResultPayload JobResultPayload
  538. err := json.Unmarshal(data, &jobResultPayload)
  539. jobResultPayload.JobStatus.StartTime = time.Unix(jobResultPayload.JobStatus.CreatedTime/1000, 0).Format("2006-01-02 15:04:05")
  540. jobResultPayload.JobStatus.EndTime = time.Unix(jobResultPayload.JobStatus.CompletedTime/1000, 0).Format("2006-01-02 15:04:05")
  541. if jobResultPayload.JobStatus.State == string(JobWaiting) {
  542. jobResultPayload.JobStatus.StartTime = "-"
  543. jobResultPayload.JobStatus.EndTime = "-"
  544. }
  545. return jobResultPayload, err
  546. }
  547. type ImagesResultPayload struct {
  548. Images []struct {
  549. ID int `json:"id"`
  550. Name string `json:"name"`
  551. Place string `json:"place"`
  552. Description string `json:"description"`
  553. Provider string `json:"provider"`
  554. Createtime string `json:"createtime"`
  555. Remark string `json:"remark"`
  556. } `json:"taskStatuses"`
  557. }
  558. type ImageInfo struct {
  559. ID int `json:"id"`
  560. Name string `json:"name"`
  561. Place string `json:"place"`
  562. Description string `json:"description"`
  563. Provider string `json:"provider"`
  564. Createtime string `json:"createtime"`
  565. Remark string `json:"remark"`
  566. IsPublic int `json:"isPublic"`
  567. PlaceView string
  568. }
  569. type Categories struct {
  570. Category []*Category `json:"category"`
  571. }
  572. type Category struct {
  573. Id int `json:"id"`
  574. Value string `json:"value"`
  575. }
  576. type BenchmarkTypes struct {
  577. BenchmarkType []*BenchmarkType `json:"type"`
  578. }
  579. type BenchmarkType struct {
  580. Id int `json:"id"`
  581. RankLink string `json:"rank_link"`
  582. First string `json:"first"` //一级算法类型名称
  583. Second []*BenchmarkDataset `json:"second"`
  584. }
  585. type BenchmarkDataset struct {
  586. Id int `json:"id"`
  587. Value string `json:"value"` //二级算法类型名称
  588. Attachment string `json:"attachment"` //数据集的uuid
  589. Owner string `json:"owner"` //评估脚本所在仓库的拥有者
  590. RepoName string `json:"repo_name"` //评估脚本所在仓库的名称
  591. }
  592. type GpuInfos struct {
  593. GpuInfo []*GpuInfo `json:"gpu_type"`
  594. }
  595. type GpuInfo struct {
  596. Id int `json:"id"`
  597. Value string `json:"value"`
  598. Queue string `json:"queue"`
  599. }
  600. type ResourceSpecs struct {
  601. ResourceSpec []*ResourceSpec `json:"resorce_specs"`
  602. }
  603. type ResourceSpec struct {
  604. Id int `json:"id"`
  605. CpuNum int `json:"cpu"`
  606. GpuNum int `json:"gpu"`
  607. MemMiB int `json:"memMiB"`
  608. ShareMemMiB int `json:"shareMemMiB"`
  609. UnitPrice int64 `json:"unitPrice"`
  610. }
  611. type FlavorInfos struct {
  612. FlavorInfo []*FlavorInfo `json:"flavor_info"`
  613. }
  614. type FlavorInfo struct {
  615. Id int `json:"id"`
  616. Value string `json:"value"`
  617. Desc string `json:"desc"`
  618. UnitPrice int64 `json:"unitPrice"`
  619. }
  620. type SpecialPools struct {
  621. Pools []*SpecialPool `json:"pools"`
  622. }
  623. type SpecialPool struct {
  624. Org string `json:"org"`
  625. Type string `json:"type"`
  626. IsExclusive bool `json:"isExclusive"`
  627. Pool []*GpuInfo `json:"pool"`
  628. JobType []string `json:"jobType"`
  629. ResourceSpec []*ResourceSpec `json:"resourceSpecs"`
  630. Flavor []*setting.FlavorInfo `json:"flavor"`
  631. }
  632. type PoolInfos struct {
  633. PoolInfo []*PoolInfo `json:"pool_info"`
  634. }
  635. type PoolInfo struct {
  636. PoolId string `json:"pool_id"`
  637. PoolName string `json:"pool_name"`
  638. PoolType string `json:"pool_type"`
  639. }
  640. type CommitImageCloudBrainParams struct {
  641. Ip string `json:"ip"`
  642. TaskContainerId string `json:"taskContainerId"`
  643. ImageTag string `json:"imageTag"`
  644. ImageDescription string `json:"imageDescription"`
  645. }
  646. type CommitImageParams struct {
  647. CommitImageCloudBrainParams
  648. IsPrivate bool
  649. Topics []string
  650. CloudBrainType int
  651. UID int64
  652. Place string
  653. Type int
  654. }
  655. type CommitImageResult struct {
  656. Code string `json:"code"`
  657. Msg string `json:"msg"`
  658. Payload map[string]interface{} `json:"payload"`
  659. }
  660. type GetJobLogParams struct {
  661. Size string `json:"size"`
  662. Sort string `json:"sort"`
  663. QueryInfo QueryInfo `json:"query"`
  664. }
  665. type QueryInfo struct {
  666. MatchInfo MatchInfo `json:"match"`
  667. }
  668. type MatchInfo struct {
  669. PodName string `json:"kubernetes.pod.name"`
  670. }
  671. type GetJobLogResult struct {
  672. ScrollID string `json:"_scroll_id"`
  673. Took int `json:"took"`
  674. TimedOut bool `json:"timed_out"`
  675. Shards struct {
  676. Total int `json:"total"`
  677. Successful int `json:"successful"`
  678. Skipped int `json:"skipped"`
  679. Failed int `json:"failed"`
  680. } `json:"_shards"`
  681. Hits struct {
  682. Hits []Hits `json:"hits"`
  683. } `json:"hits"`
  684. }
  685. type Hits struct {
  686. Index string `json:"_index"`
  687. Type string `json:"_type"`
  688. ID string `json:"_id"`
  689. Source struct {
  690. Message string `json:"message"`
  691. } `json:"_source"`
  692. Sort []int `json:"sort"`
  693. }
  694. type GetAllJobLogParams struct {
  695. Scroll string `json:"scroll"`
  696. ScrollID string `json:"scroll_id"`
  697. }
  698. type DeleteJobLogTokenParams struct {
  699. ScrollID string `json:"scroll_id"`
  700. }
  701. type DeleteJobLogTokenResult struct {
  702. Succeeded bool `json:"succeeded"`
  703. NumFreed int `json:"num_freed"`
  704. }
  705. type CloudBrainResult struct {
  706. Code string `json:"code"`
  707. Msg string `json:"msg"`
  708. }
  709. type CreateNotebook2Params struct {
  710. JobName string `json:"name"`
  711. Description string `json:"description"`
  712. Duration int64 `json:"duration"` //ms
  713. Feature string `json:"feature"`
  714. PoolID string `json:"pool_id"`
  715. Flavor string `json:"flavor"`
  716. ImageID string `json:"image_id"`
  717. WorkspaceID string `json:"workspace_id"`
  718. Volume VolumeReq `json:"volume"`
  719. }
  720. type CreateNotebookWithoutPoolParams struct {
  721. JobName string `json:"name"`
  722. Description string `json:"description"`
  723. Duration int64 `json:"duration"` //ms
  724. Feature string `json:"feature"`
  725. Flavor string `json:"flavor"`
  726. ImageID string `json:"image_id"`
  727. WorkspaceID string `json:"workspace_id"`
  728. Volume VolumeReq `json:"volume"`
  729. }
  730. type VolumeReq struct {
  731. Capacity int `json:"capacity"`
  732. Category string `json:"category"`
  733. Ownership string `json:"ownership"`
  734. Uri string `json:"uri"`
  735. }
  736. type CreateNotebookParams struct {
  737. JobName string `json:"name"`
  738. Description string `json:"description"`
  739. ProfileID string `json:"profile_id"`
  740. Flavor string `json:"flavor"`
  741. Spec Spec `json:"spec"`
  742. Workspace Workspace `json:"workspace"`
  743. Pool Pool `json:"pool"`
  744. }
  745. type Pool struct {
  746. ID string `json:"id"`
  747. Name string `json:"name"`
  748. Type string `json:"type"`
  749. }
  750. type Workspace struct {
  751. ID string `json:"id"`
  752. }
  753. type Spec struct {
  754. Storage Storage `json:"storage"`
  755. AutoStop AutoStop `json:"auto_stop"`
  756. }
  757. type AutoStop struct {
  758. Enable bool `json:"enable"`
  759. Duration int `json:"duration"`
  760. }
  761. type Storage struct {
  762. Type string `json:"type"`
  763. Location Location `json:"location"`
  764. }
  765. type Location struct {
  766. Path string `json:"path"`
  767. }
  768. type NotebookResult struct {
  769. ErrorCode string `json:"error_code"`
  770. ErrorMsg string `json:"error_msg"`
  771. }
  772. type CreateNotebookResult struct {
  773. ErrorCode string `json:"error_code"`
  774. ErrorMsg string `json:"error_msg"`
  775. ID string `json:"id"`
  776. Name string `json:"name"`
  777. Description string `json:"description"`
  778. Status string `json:"status"`
  779. CreationTimestamp string `json:"creation_timestamp"`
  780. LatestUpdateTimestamp string `json:"latest_update_timestamp"`
  781. Profile struct {
  782. ID string `json:"id"`
  783. Name string `json:"name"`
  784. Description string `json:"description"`
  785. DeType string `json:"de_type"`
  786. FlavorType string `json:"flavor_type"`
  787. } `json:"profile"`
  788. Flavor string `json:"flavor"`
  789. FlavorDetails struct {
  790. Name string `json:"name"`
  791. Status string `json:"status"`
  792. QueuingNum int `json:"queuing_num"`
  793. QueueLeftTime int `json:"queue_left_time"` //s
  794. Duration int `json:"duration"` //auto_stop_time s
  795. } `json:"flavor_details"`
  796. }
  797. type GetNotebookResult struct {
  798. ErrorCode string `json:"error_code"`
  799. ErrorMsg string `json:"error_msg"`
  800. ID string `json:"id"`
  801. Name string `json:"name"`
  802. Description string `json:"description"`
  803. Status string `json:"status"`
  804. CreationTimestamp string `json:"creation_timestamp"`
  805. CreateTime string
  806. LatestUpdateTimestamp string `json:"latest_update_timestamp"`
  807. LatestUpdateTime string
  808. Profile struct {
  809. ID string `json:"id"`
  810. Name string `json:"name"`
  811. Description string `json:"description"`
  812. DeType string `json:"de_type"`
  813. FlavorType string `json:"flavor_type"`
  814. } `json:"profile"`
  815. Flavor string `json:"flavor"`
  816. FlavorDetails struct {
  817. Name string `json:"name"`
  818. Status string `json:"status"`
  819. QueuingNum int `json:"queuing_num"`
  820. QueueLeftTime int `json:"queue_left_time"` //s
  821. Duration int `json:"duration"` //auto_stop_time s
  822. } `json:"flavor_details"`
  823. QueuingInfo struct {
  824. ID string `json:"id"`
  825. Name string `json:"name"`
  826. Flavor string `json:"flavor"`
  827. DeType string `json:"de_type"`
  828. Status string `json:"status"`
  829. BeginTimestamp int `json:"begin_timestamp"` //time of instance begin in queue
  830. BeginTime string
  831. RemainTime int `json:"remain_time"` //remain time of instance
  832. EndTimestamp int `json:"end_timestamp"` //
  833. EndTime string
  834. Rank int `json:"rank"` //rank of instance in queue
  835. } `json:"queuing_info"`
  836. Spec struct {
  837. Annotations struct {
  838. TargetDomain string `json:"target_domain"`
  839. Url string `json:"url"`
  840. } `json:"annotations"`
  841. } `json:"spec"`
  842. }
  843. type GetNotebook2Result struct {
  844. ErrorCode string `json:"error_code"`
  845. ErrorMsg string `json:"error_msg"`
  846. FailReason string `json:"fail_reason"`
  847. ID string `json:"id"`
  848. Name string `json:"name"`
  849. Description string `json:"description"`
  850. Status string `json:"status"`
  851. Url string `json:"url"` //实例访问的URL
  852. Token string `json:"token"` //notebook鉴权使用的token信息
  853. Flavor string `json:"flavor"`
  854. CreateTime string
  855. LatestUpdateTime string
  856. CreateAt int64 `json:"create_at"` //实例创建的时间,UTC毫秒
  857. UpdateAt int64 `json:"update_at"` //实例最后更新(不包括保活心跳)的时间,UTC毫秒
  858. Image struct {
  859. Name string `json:"name"`
  860. Status string `json:"status"`
  861. QueuingNum int `json:"queuing_num"`
  862. QueueLeftTime int `json:"queue_left_time"` //s
  863. Duration int `json:"duration"` //auto_stop_time s
  864. } `json:"image"`
  865. Lease struct {
  866. CreateTime int64 `json:"create_at"` //实例创建的时间,UTC毫秒
  867. Duration int64 `json:"duration"` //实例运行时长,以创建时间为起点计算,即“创建时间+duration > 当前时刻”时,系统会自动停止实例
  868. UpdateTime int64 `json:"update_at"` //实例最后更新(不包括保活心跳)的时间,UTC毫秒
  869. } `json:"lease"` //实例自动停止的倒计时信息
  870. VolumeRes struct {
  871. Capacity int `json:"capacity"`
  872. Category string `json:"category"`
  873. MountPath string `json:"mount_path"`
  874. Ownership string `json:"ownership"`
  875. Status string `json:"status"`
  876. } `json:"volume"`
  877. }
  878. type GetTokenParams struct {
  879. Auth Auth `json:"auth"`
  880. }
  881. type Auth struct {
  882. Identity Identity `json:"identity"`
  883. Scope Scope `json:"scope"`
  884. }
  885. type Scope struct {
  886. Project Project `json:"project"`
  887. }
  888. type Project struct {
  889. Name string `json:"name"`
  890. }
  891. type Identity struct {
  892. Methods []string `json:"methods"`
  893. Password Password `json:"password"`
  894. }
  895. type Password struct {
  896. User NotebookUser `json:"user"`
  897. }
  898. type NotebookUser struct {
  899. Name string `json:"name"`
  900. Password string `json:"password"`
  901. Domain Domain `json:"domain"`
  902. }
  903. type Domain struct {
  904. Name string `json:"name"`
  905. }
  906. const (
  907. ActionStart = "start"
  908. ActionStop = "stop"
  909. ActionRestart = "restart"
  910. ActionQueue = "queue"
  911. ActionDequeue = "dequeue"
  912. )
  913. type NotebookAction struct {
  914. Action string `json:"action"`
  915. }
  916. type NotebookActionResult struct {
  917. ErrorCode string `json:"error_code"`
  918. ErrorMsg string `json:"error_msg"`
  919. CurrentStatus string `json:"current_status"`
  920. PreviousState string `json:"previous_state"`
  921. Status string `json:"status"`
  922. }
  923. type NotebookGetJobTokenResult struct {
  924. ErrorCode string `json:"error_code"`
  925. ErrorMsg string `json:"error_msg"`
  926. Token string `json:"token"`
  927. }
  928. type NotebookDelResult struct {
  929. NotebookResult
  930. InstanceID string `json:"instance_id"`
  931. }
  932. type CreateUserImageTrainJobParams struct {
  933. JobName string `json:"job_name"`
  934. Description string `json:"job_desc"`
  935. Config UserImageConfig `json:"config"`
  936. WorkspaceID string `json:"workspace_id"`
  937. }
  938. type UserImageConfig struct {
  939. WorkServerNum int `json:"worker_server_num"`
  940. AppUrl string `json:"app_url"` //训练作业的代码目录
  941. BootFileUrl string `json:"boot_file_url"` //训练作业的代码启动文件,需要在代码目录下
  942. Parameter []Parameter `json:"parameter"`
  943. DataUrl string `json:"data_url"` //训练作业需要的数据集OBS路径URL
  944. TrainUrl string `json:"train_url"` //训练作业的输出文件OBS路径URL
  945. LogUrl string `json:"log_url"`
  946. UserImageUrl string `json:"user_image_url"`
  947. UserCommand string `json:"user_command"`
  948. CreateVersion bool `json:"create_version"`
  949. Flavor Flavor `json:"flavor"`
  950. PoolID string `json:"pool_id"`
  951. }
  952. type CreateTrainJobParams struct {
  953. JobName string `json:"job_name"`
  954. Description string `json:"job_desc"`
  955. Config Config `json:"config"`
  956. WorkspaceID string `json:"workspace_id"`
  957. }
  958. type Config struct {
  959. WorkServerNum int `json:"worker_server_num"`
  960. AppUrl string `json:"app_url"` //训练作业的代码目录
  961. BootFileUrl string `json:"boot_file_url"` //训练作业的代码启动文件,需要在代码目录下
  962. Parameter []Parameter `json:"parameter"`
  963. DataUrl string `json:"data_url"` //训练作业需要的数据集OBS路径URL
  964. EngineID int64 `json:"engine_id"`
  965. TrainUrl string `json:"train_url"` //训练作业的输出文件OBS路径URL
  966. LogUrl string `json:"log_url"`
  967. //UserImageUrl string `json:"user_image_url"`
  968. //UserCommand string `json:"user_command"`
  969. CreateVersion bool `json:"create_version"`
  970. Flavor Flavor `json:"flavor"`
  971. PoolID string `json:"pool_id"`
  972. }
  973. type CreateInferenceJobParams struct {
  974. JobName string `json:"job_name"`
  975. Description string `json:"job_desc"`
  976. InfConfig InfConfig `json:"config"`
  977. WorkspaceID string `json:"workspace_id"`
  978. }
  979. type CreateInfUserImageParams struct {
  980. JobName string `json:"job_name"`
  981. Description string `json:"job_desc"`
  982. Config InfUserImageConfig `json:"config"`
  983. WorkspaceID string `json:"workspace_id"`
  984. }
  985. type InfConfig struct {
  986. WorkServerNum int `json:"worker_server_num"`
  987. AppUrl string `json:"app_url"` //训练作业的代码目录
  988. BootFileUrl string `json:"boot_file_url"` //训练作业的代码启动文件,需要在代码目录下
  989. Parameter []Parameter `json:"parameter"`
  990. DataUrl string `json:"data_url"` //训练作业需要的数据集OBS路径URL
  991. EngineID int64 `json:"engine_id"`
  992. LogUrl string `json:"log_url"`
  993. CreateVersion bool `json:"create_version"`
  994. Flavor Flavor `json:"flavor"`
  995. PoolID string `json:"pool_id"`
  996. }
  997. type InfUserImageConfig struct {
  998. WorkServerNum int `json:"worker_server_num"`
  999. AppUrl string `json:"app_url"` //训练作业的代码目录
  1000. BootFileUrl string `json:"boot_file_url"` //训练作业的代码启动文件,需要在代码目录下
  1001. Parameter []Parameter `json:"parameter"`
  1002. DataUrl string `json:"data_url"` //训练作业需要的数据集OBS路径URL
  1003. EngineID int64 `json:"engine_id"`
  1004. LogUrl string `json:"log_url"`
  1005. CreateVersion bool `json:"create_version"`
  1006. Flavor Flavor `json:"flavor"`
  1007. PoolID string `json:"pool_id"`
  1008. UserImageUrl string `json:"user_image_url"`
  1009. UserCommand string `json:"user_command"`
  1010. }
  1011. type CreateTrainJobVersionParams struct {
  1012. Description string `json:"job_desc"`
  1013. Config TrainJobVersionConfig `json:"config"`
  1014. }
  1015. type CreateTrainJobVersionUserImageParams struct {
  1016. Description string `json:"job_desc"`
  1017. Config TrainJobVersionUserImageConfig `json:"config"`
  1018. }
  1019. type TrainJobVersionConfig struct {
  1020. WorkServerNum int `json:"worker_server_num"`
  1021. AppUrl string `json:"app_url"` //训练作业的代码目录
  1022. BootFileUrl string `json:"boot_file_url"` //训练作业的代码启动文件,需要在代码目录下
  1023. Parameter []Parameter `json:"parameter"`
  1024. DataUrl string `json:"data_url"` //训练作业需要的数据集OBS路径URL
  1025. EngineID int64 `json:"engine_id"`
  1026. TrainUrl string `json:"train_url"` //训练作业的输出文件OBS路径URL
  1027. LogUrl string `json:"log_url"`
  1028. Flavor Flavor `json:"flavor"`
  1029. PoolID string `json:"pool_id"`
  1030. PreVersionId int64 `json:"pre_version_id"`
  1031. }
  1032. type TrainJobVersionUserImageConfig struct {
  1033. WorkServerNum int `json:"worker_server_num"`
  1034. AppUrl string `json:"app_url"` //训练作业的代码目录
  1035. BootFileUrl string `json:"boot_file_url"` //训练作业的代码启动文件,需要在代码目录下
  1036. Parameter []Parameter `json:"parameter"`
  1037. DataUrl string `json:"data_url"` //训练作业需要的数据集OBS路径URL
  1038. TrainUrl string `json:"train_url"` //训练作业的输出文件OBS路径URL
  1039. LogUrl string `json:"log_url"`
  1040. Flavor Flavor `json:"flavor"`
  1041. PoolID string `json:"pool_id"`
  1042. PreVersionId int64 `json:"pre_version_id"`
  1043. UserImageUrl string `json:"user_image_url"`
  1044. UserCommand string `json:"user_command"`
  1045. }
  1046. type CreateConfigParams struct {
  1047. ConfigName string `json:"config_name"`
  1048. Description string `json:"config_desc"`
  1049. WorkServerNum int `json:"worker_server_num"`
  1050. AppUrl string `json:"app_url"` //训练作业的代码目录
  1051. BootFileUrl string `json:"boot_file_url"` //训练作业的代码启动文件,需要在代码目录下
  1052. Parameter []Parameter `json:"parameter"`
  1053. DataUrl string `json:"data_url"` //训练作业需要的数据集OBS路径URL
  1054. EngineID int64 `json:"engine_id"`
  1055. TrainUrl string `json:"train_url"` //训练作业的输出文件OBS路径URL
  1056. LogUrl string `json:"log_url"`
  1057. Flavor Flavor `json:"flavor"`
  1058. PoolID string `json:"pool_id"`
  1059. }
  1060. type Parameter struct {
  1061. Label string `json:"label"`
  1062. Value string `json:"value"`
  1063. }
  1064. type Parameters struct {
  1065. Parameter []Parameter `json:"parameter"`
  1066. }
  1067. type Datasurl struct {
  1068. DatasetUrl string `json:"dataset_url"`
  1069. DatasetName string `json:"dataset_name"`
  1070. }
  1071. type DatasetDownload struct {
  1072. DatasetName string `json:"dataset_name"`
  1073. DatasetDownloadLink string `json:"dataset_download_link"`
  1074. RepositoryLink string `json:"repository_link"`
  1075. IsDelete bool `json:"is_delete"`
  1076. }
  1077. type DataSource struct {
  1078. DatasetID string `json:"dataset_id"`
  1079. DatasetVersion string `json:"dataset_version"`
  1080. Type string `json:"type"`
  1081. DataUrl string `json:"data_url"`
  1082. }
  1083. type Volumes struct {
  1084. Nfs Nfs `json:"nfs"`
  1085. HostPath HostPath `json:"host_path"`
  1086. }
  1087. type Nfs struct {
  1088. ID string `json:"id"`
  1089. SourcePath string `json:"src_path"`
  1090. DestPath string `json:"dest_path"`
  1091. ReadOnly bool `json:"read_only"`
  1092. }
  1093. type HostPath struct {
  1094. SourcePath string `json:"src_path"`
  1095. DestPath string `json:"dest_path"`
  1096. ReadOnly bool `json:"read_only"`
  1097. }
  1098. type Flavor struct {
  1099. Code string `json:"code"`
  1100. }
  1101. type CreateTrainJobResult struct {
  1102. ErrorCode string `json:"error_code"`
  1103. ErrorMsg string `json:"error_msg"`
  1104. IsSuccess bool `json:"is_success"`
  1105. JobName string `json:"job_name"`
  1106. JobID int64 `json:"job_id"`
  1107. Status int `json:"status"`
  1108. CreateTime int64 `json:"create_time"`
  1109. VersionID int64 `json:"version_id"`
  1110. ResourceID string `json:"resource_id"`
  1111. VersionName string `json:"version_name"`
  1112. }
  1113. type CreateTrainJobConfigResult struct {
  1114. ErrorCode string `json:"error_code"`
  1115. ErrorMsg string `json:"error_msg"`
  1116. IsSuccess bool `json:"is_success"`
  1117. }
  1118. type GetResourceSpecsResult struct {
  1119. ErrorCode string `json:"error_code"`
  1120. ErrorMsg string `json:"error_msg"`
  1121. IsSuccess bool `json:"is_success"`
  1122. SpecTotalCount int `json:"spec_total_count"`
  1123. Specs []Specs `json:"specs"`
  1124. }
  1125. type Specs struct {
  1126. Core string `json:"core"`
  1127. Cpu string `json:"cpu"`
  1128. IsNoResource bool `json:"no_resource"`
  1129. GpuType string `json:"gpu_type"`
  1130. SpecID int64 `json:"spec_id"`
  1131. GpuNum int `json:"gpu_num"`
  1132. SpecCode string `json:"spec_code"`
  1133. Storage string `json:"storage"`
  1134. MaxNum int `json:"max_num"`
  1135. UnitNum int `json:"unit_num"`
  1136. InterfaceType int `json:"interface_type"`
  1137. }
  1138. type GetConfigListResult struct {
  1139. ErrorCode string `json:"error_code"`
  1140. ErrorMsg string `json:"error_msg"`
  1141. IsSuccess bool `json:"is_success"`
  1142. ConfigTotalCount int `json:"config_total_count"`
  1143. ParaConfigs []ParaConfig `json:"configs"`
  1144. }
  1145. type ParaConfig struct {
  1146. ConfigName string `json:"config_name"`
  1147. ConfigDesc string `json:"config_desc"`
  1148. CreateTime int64 `json:"create_time"`
  1149. EngineType int `json:"engine_type"`
  1150. EngineName string `json:"engine_name"`
  1151. EngineId int64 `json:"engine_id"`
  1152. EngineVersion string `json:"engine_version"`
  1153. UserImageUrl string `json:"user_image_url"`
  1154. UserCommand string `json:"user_command"`
  1155. Result GetConfigResult
  1156. }
  1157. type GetConfigResult struct {
  1158. ErrorCode string `json:"error_code"`
  1159. ErrorMsg string `json:"error_msg"`
  1160. IsSuccess bool `json:"is_success"`
  1161. ConfigName string `json:"config_name"`
  1162. Description string `json:"config_desc"`
  1163. WorkServerNum int `json:"worker_server_num"`
  1164. AppUrl string `json:"app_url"` //训练作业的代码目录
  1165. BootFileUrl string `json:"boot_file_url"` //训练作业的代码启动文件,需要在代码目录下
  1166. Parameter []Parameter `json:"parameter"`
  1167. DataUrl string `json:"data_url"` //训练作业需要的数据集OBS路径URL
  1168. EngineID int64 `json:"engine_id"`
  1169. TrainUrl string `json:"train_url"` //训练作业的输出文件OBS路径URL
  1170. LogUrl string `json:"log_url"`
  1171. Flavor Flavor `json:"flavor"`
  1172. PoolID string `json:"pool_id"`
  1173. }
  1174. type ErrorResult struct {
  1175. ErrorCode string `json:"error_code"`
  1176. ErrorMsg string `json:"error_message"`
  1177. IsSuccess bool `json:"is_success"`
  1178. }
  1179. type GetTrainJobResult struct {
  1180. IsSuccess bool `json:"is_success"`
  1181. JobName string `json:"job_name"`
  1182. JobID int64 `json:"job_id"`
  1183. Description string `json:"job_desc"`
  1184. IntStatus int `json:"status"`
  1185. Status string
  1186. LongCreateTime int64 `json:"create_time"`
  1187. CreateTime string
  1188. Duration int64 `json:"duration"` //训练作业的运行时间,单位为毫秒
  1189. TrainJobDuration string //训练作业的运行时间,格式为hh:mm:ss
  1190. VersionID int64 `json:"version_id"`
  1191. ResourceID string `json:"resource_id"`
  1192. VersionName string `json:"version_name"`
  1193. PreVersionID int64 `json:"pre_version_id"`
  1194. WorkServerNum int `json:"worker_server_num"`
  1195. AppUrl string `json:"app_url"` //训练作业的代码目录
  1196. BootFileUrl string `json:"boot_file_url"` //训练作业的代码启动文件,需要在代码目录下
  1197. Parameter []Parameter `json:"parameter"`
  1198. DataUrl string `json:"data_url"` //训练作业需要的数据集OBS路径URL
  1199. EngineID int64 `json:"engine_id"`
  1200. EngineName string `json:"engine_name"`
  1201. EngineVersion string `json:"engine_version"`
  1202. TrainUrl string `json:"train_url"` //训练作业的输出文件OBS路径URL
  1203. LogUrl string `json:"log_url"`
  1204. Flavor Flavor `json:"flavor"`
  1205. PoolID string `json:"pool_id"`
  1206. PoolName string `json:"pool_name"`
  1207. NasMountPath string `json:"nas_mount_path"`
  1208. NasShareAddr string `json:"nas_share_addr"`
  1209. DatasetName string
  1210. ModelMetricList string `json:"model_metric_list"` //列表里包含f1_score,recall,precision,accuracy,若有的话
  1211. StartTime int64 `json:"start_time"` //训练作业开始时间。
  1212. }
  1213. type GetTrainJobLogResult struct {
  1214. ErrorCode string `json:"error_code"`
  1215. ErrorMsg string `json:"error_msg"`
  1216. IsSuccess bool `json:"is_success"`
  1217. Content string `json:"content"`
  1218. Lines int `json:"lines"`
  1219. StartLine string `json:"start_line"`
  1220. EndLine string `json:"end_line"`
  1221. }
  1222. type GetTrainJobLogFileNamesResult struct {
  1223. ErrorCode string `json:"error_code"`
  1224. ErrorMsg string `json:"error_msg"`
  1225. IsSuccess bool `json:"is_success"`
  1226. LogFileList []string `json:"log_file_list"`
  1227. }
  1228. type TrainJobResult struct {
  1229. ErrorCode string `json:"error_code"`
  1230. ErrorMsg string `json:"error_msg"`
  1231. IsSuccess bool `json:"is_success"`
  1232. }
  1233. type LogFile struct {
  1234. Name string
  1235. }
  1236. type JobList struct {
  1237. JobName string `json:"job_name"`
  1238. JobID int64 `json:"job_id"`
  1239. VersionID int64 `json:"version_id"`
  1240. VersionCount int64 `json:"version_count"`
  1241. Description string `json:"job_desc"`
  1242. IntStatus int `json:"status"`
  1243. }
  1244. type GetTrainJobListResult struct {
  1245. ErrorResult
  1246. JobTotalCount int `json:"job_total_count"` //查询到的用户创建作业总数
  1247. JobCountLimit int `json:"job_count_limit"` //用户还可以创建训练作业的数量
  1248. Quotas int `json:"quotas"` //训练作业的运行数量上限
  1249. JobList []JobList `json:"jobs"`
  1250. }
  1251. type JobVersionList struct {
  1252. VersionName string `json:"version_name"`
  1253. VersionID int64 `json:"version_id"`
  1254. IntStatus int `json:"status"`
  1255. }
  1256. type GetTrainJobVersionListResult struct {
  1257. ErrorResult
  1258. JobID int64 `json:"job_id"`
  1259. JobName string `json:"job_name"`
  1260. JobDesc string `json:"job_desc"`
  1261. VersionCount int64 `json:"version_count"`
  1262. JobVersionList []JobVersionList `json:"versions"`
  1263. }
  1264. type NotebookList struct {
  1265. JobName string `json:"name"`
  1266. JobID string `json:"id"`
  1267. Status string `json:"status"`
  1268. }
  1269. type GetNotebookListResult struct {
  1270. TotalCount int64 `json:"total"` //总的记录数量
  1271. CurrentPage int `json:"current"` //当前页数
  1272. TotalPages int `json:"pages"` //总的页数
  1273. Size int `json:"size"` //每一页的数量
  1274. NotebookList []NotebookList `json:"data"`
  1275. }
  1276. //Grampus
  1277. type GrampusResult struct {
  1278. ErrorCode int `json:"errorCode"`
  1279. ErrorMsg string `json:"errorMsg"`
  1280. }
  1281. type GrampusJobInfo struct {
  1282. StartedAt int64 `json:"startedAt"`
  1283. RunSec int64 `json:"runSec"`
  1284. CompletedAt int64 `json:"completedAt"`
  1285. CreatedAt int64 `json:"createdAt"`
  1286. UpdatedAt int64 `json:"updatedAt"`
  1287. Desc string `json:"desc"`
  1288. JobID string `json:"id"`
  1289. Name string `json:"name"`
  1290. Status string `json:"status"`
  1291. UserID string `json:"userId"`
  1292. Tasks []GrampusTasks `json:"tasks"`
  1293. }
  1294. type Center struct {
  1295. ID string `json:"id"`
  1296. Name string `json:"name"`
  1297. }
  1298. type GrampusSpec struct {
  1299. CreatedAt int64 `json:"createdAt"`
  1300. UpdatedAt int64 `json:"updatedAt"`
  1301. ID string `json:"id"`
  1302. Name string `json:"name"`
  1303. ProcessorType string `json:"processorType"`
  1304. Centers []Center `json:"centers"`
  1305. SpecInfo SpecInfo `json:"specInfo"`
  1306. }
  1307. type GrampusAiCenter struct {
  1308. AccDevices []GrampusAccDevice `json:"accDevices"`
  1309. Id string `json:"id"`
  1310. Name string `json:"name"`
  1311. Resource []GrampusCenterResource `json:"resource"`
  1312. }
  1313. type GrampusAccDevice struct {
  1314. Kind string `json:"kind"` //加速卡类别, npu.huawei.com/NPU,nvidia.com/gpu,cambricon.com/mlu
  1315. Model string `json:"model"` //加速卡型号
  1316. }
  1317. type GrampusCenterResource struct {
  1318. Allocated string `json:"allocated"`
  1319. Capacity string `json:"capacity"`
  1320. Name string `json:"name"`
  1321. }
  1322. type SpecInfo struct {
  1323. AccDeviceKind string `json:"accDeviceKind"`
  1324. AccDeviceMemory string `json:"accDeviceMemory"`
  1325. AccDeviceModel string `json:"accDeviceModel"`
  1326. AccDeviceNum int `json:"accDeviceNum"`
  1327. CpuCoreNum int `json:"cpuCoreNum"`
  1328. MemorySize string `json:"memorySize"`
  1329. }
  1330. type GetGrampusResourceSpecsResult struct {
  1331. GrampusResult
  1332. Infos []GrampusSpec `json:"resourceSpecs"`
  1333. }
  1334. type GetGrampusAiCentersResult struct {
  1335. GrampusResult
  1336. Infos []GrampusAiCenter `json:"aiCenterInfos"`
  1337. TotalSize int `json:"totalSize"`
  1338. }
  1339. type GrampusImage struct {
  1340. CreatedAt int64 `json:"createdAt"`
  1341. UpdatedAt int64 `json:"updatedAt"`
  1342. ID string `json:"id"`
  1343. Name string `json:"name"`
  1344. ProcessorType string `json:"processorType"`
  1345. }
  1346. type GetGrampusImagesResult struct {
  1347. GrampusResult
  1348. TotalSize int `json:"totalSize"`
  1349. Infos []GrampusImage `json:"images"`
  1350. }
  1351. type CreateGrampusJobResponse struct {
  1352. GrampusResult
  1353. JobInfo GrampusJobInfo `json:"otJob"`
  1354. }
  1355. type GetGrampusJobResponse struct {
  1356. GrampusResult
  1357. JobInfo GrampusJobInfo `json:"otJob"`
  1358. }
  1359. type GrampusStopJobResponse struct {
  1360. GrampusResult
  1361. StoppedAt int64 `json:"stoppedAt"`
  1362. }
  1363. type GrampusTasks struct {
  1364. Command string `json:"command"`
  1365. Name string `json:"name"`
  1366. ImageId string `json:"imageId"`
  1367. ResourceSpecId string `json:"resourceSpecId"`
  1368. ImageUrl string `json:"imageUrl"`
  1369. CenterID []string `json:"centerID"`
  1370. CenterName []string `json:"centerName"`
  1371. ReplicaNum int `json:"replicaNum"`
  1372. Datasets []GrampusDataset `json:"datasets"`
  1373. Models []GrampusDataset `json:"models"`
  1374. Code GrampusDataset `json:"code"`
  1375. BootFile string `json:"bootFile"`
  1376. }
  1377. type GrampusDataset struct {
  1378. Name string `json:"name"`
  1379. Bucket string `json:"bucket"`
  1380. EndPoint string `json:"endPoint"`
  1381. ObjectKey string `json:"objectKey"`
  1382. }
  1383. type CreateGrampusJobRequest struct {
  1384. Name string `json:"name"`
  1385. Tasks []GrampusTasks `json:"tasks"`
  1386. }
  1387. type GetTrainJobMetricStatisticResult struct {
  1388. TrainJobResult
  1389. Interval int `json:"interval"` //查询的时间间隔,单位为分钟
  1390. MetricsInfo []Metrics `json:"metrics"` //监控详情
  1391. }
  1392. type Metrics struct {
  1393. Metric string `json:"metric"` //监控指标项
  1394. Value []string `json:"value"` //获取的监控值的序列,元素为String类型
  1395. }
  1396. func Cloudbrains(opts *CloudbrainsOptions) ([]*CloudbrainInfo, int64, error) {
  1397. sess := x.NewSession()
  1398. defer sess.Close()
  1399. var cond = builder.NewCond()
  1400. if opts.RepoID > 0 {
  1401. cond = cond.And(
  1402. builder.Eq{"cloudbrain.repo_id": opts.RepoID},
  1403. )
  1404. }
  1405. if opts.UserID > 0 {
  1406. cond = cond.And(
  1407. builder.Eq{"cloudbrain.user_id": opts.UserID},
  1408. )
  1409. }
  1410. if (opts.JobID) != "" {
  1411. cond = cond.And(
  1412. builder.Eq{"cloudbrain.job_id": opts.JobID},
  1413. )
  1414. }
  1415. if (opts.ComputeResource) != "" {
  1416. cond = cond.And(
  1417. builder.Eq{"cloudbrain.compute_resource": opts.ComputeResource},
  1418. )
  1419. }
  1420. if (opts.Type) >= 0 {
  1421. cond = cond.And(
  1422. builder.Eq{"cloudbrain.type": opts.Type},
  1423. )
  1424. }
  1425. if len(opts.JobTypes) > 0 {
  1426. if opts.JobTypeNot {
  1427. cond = cond.And(
  1428. builder.NotIn("cloudbrain.job_type", opts.JobTypes),
  1429. )
  1430. } else {
  1431. cond = cond.And(
  1432. builder.In("cloudbrain.job_type", opts.JobTypes),
  1433. )
  1434. }
  1435. }
  1436. if (opts.AiCenter) != "" {
  1437. if opts.AiCenter == AICenterOfCloudBrainOne {
  1438. cond = cond.And(
  1439. builder.Eq{"cloudbrain.type": TypeCloudBrainOne},
  1440. )
  1441. } else if opts.AiCenter == AICenterOfCloudBrainTwo {
  1442. cond = cond.And(
  1443. builder.Eq{"cloudbrain.type": TypeCloudBrainTwo},
  1444. )
  1445. } else if opts.AiCenter == AICenterOfChengdu {
  1446. cond = cond.And(
  1447. builder.Eq{"cloudbrain.type": TypeCDCenter},
  1448. )
  1449. } else {
  1450. cond = cond.And(
  1451. builder.Like{"cloudbrain.ai_center", opts.AiCenter},
  1452. )
  1453. }
  1454. }
  1455. if (opts.Cluster) != "" {
  1456. if opts.Cluster == "resource_cluster_openi" {
  1457. cond = cond.And(
  1458. builder.Or(builder.Eq{"cloudbrain.type": TypeCloudBrainOne}, builder.Eq{"cloudbrain.type": TypeCloudBrainTwo}, builder.Eq{"cloudbrain.type": TypeCDCenter}),
  1459. )
  1460. }
  1461. if opts.Cluster == "resource_cluster_c2net" {
  1462. cond = cond.And(
  1463. builder.Eq{"cloudbrain.type": TypeC2Net},
  1464. )
  1465. }
  1466. }
  1467. if (opts.IsLatestVersion) != "" {
  1468. cond = cond.And(builder.Or(builder.And(builder.Eq{"cloudbrain.is_latest_version": opts.IsLatestVersion}, builder.Eq{"cloudbrain.job_type": "TRAIN"}), builder.Neq{"cloudbrain.job_type": "TRAIN"}))
  1469. }
  1470. if len(opts.CloudbrainIDs) > 0 {
  1471. cond = cond.And(builder.In("cloudbrain.id", opts.CloudbrainIDs))
  1472. }
  1473. if len(opts.JobStatus) > 0 {
  1474. if opts.JobStatusNot {
  1475. cond = cond.And(
  1476. builder.NotIn("cloudbrain.status", opts.JobStatus),
  1477. )
  1478. } else {
  1479. cond = cond.And(
  1480. builder.In("cloudbrain.status", opts.JobStatus),
  1481. )
  1482. }
  1483. }
  1484. if len(opts.RepoIDList) > 0 {
  1485. cond = cond.And(
  1486. builder.In("cloudbrain.repo_id", opts.RepoIDList),
  1487. )
  1488. }
  1489. var count int64
  1490. var err error
  1491. condition := "cloudbrain.user_id = `user`.id"
  1492. if len(opts.Keyword) == 0 {
  1493. count, err = sess.Where(cond).Count(new(Cloudbrain))
  1494. } else {
  1495. lowerKeyWord := strings.ToLower(opts.Keyword)
  1496. cond = cond.And(builder.Or(builder.Like{"LOWER(cloudbrain.job_name)", lowerKeyWord}, builder.Like{"LOWER(cloudbrain.display_job_name)", lowerKeyWord}, builder.Like{"`user`.lower_name", lowerKeyWord}))
  1497. count, err = sess.Table(&Cloudbrain{}).Where(cond).
  1498. Join("left", "`user`", condition).Count(new(CloudbrainInfo))
  1499. }
  1500. if err != nil {
  1501. return nil, 0, fmt.Errorf("Count: %v", err)
  1502. }
  1503. if opts.Page >= 0 && opts.PageSize > 0 {
  1504. var start int
  1505. if opts.Page == 0 {
  1506. start = 0
  1507. } else {
  1508. start = (opts.Page - 1) * opts.PageSize
  1509. }
  1510. sess.Limit(opts.PageSize, start)
  1511. }
  1512. sess.OrderBy("cloudbrain.created_unix DESC")
  1513. cloudbrains := make([]*CloudbrainInfo, 0, setting.UI.IssuePagingNum)
  1514. if err := sess.Table(&Cloudbrain{}).Where(cond).
  1515. Join("left", "`user`", condition).
  1516. Find(&cloudbrains); err != nil {
  1517. return nil, 0, fmt.Errorf("Find: %v", err)
  1518. }
  1519. if opts.NeedRepoInfo {
  1520. var ids []int64
  1521. for _, task := range cloudbrains {
  1522. ids = append(ids, task.RepoID)
  1523. }
  1524. repositoryMap, err := GetRepositoriesMapByIDs(ids)
  1525. if err == nil {
  1526. for _, task := range cloudbrains {
  1527. task.Repo = repositoryMap[task.RepoID]
  1528. }
  1529. }
  1530. }
  1531. return cloudbrains, count, nil
  1532. }
  1533. func QueryModelTrainJobVersionList(jobId string) ([]*Cloudbrain, int, error) {
  1534. sess := x.NewSession()
  1535. defer sess.Close()
  1536. var cond = builder.NewCond()
  1537. cond = cond.And(
  1538. builder.Eq{"cloudbrain.job_id": jobId},
  1539. )
  1540. cond = cond.And(
  1541. builder.In("cloudbrain.Status", "COMPLETED", "SUCCEEDED"),
  1542. //builder.Eq{"cloudbrain.Status": "COMPLETED"},
  1543. )
  1544. sess.OrderBy("cloudbrain.created_unix DESC")
  1545. cloudbrains := make([]*Cloudbrain, 0)
  1546. if err := sess.Table(&Cloudbrain{}).Where(cond).
  1547. Find(&cloudbrains); err != nil {
  1548. return nil, 0, fmt.Errorf("Find: %v", err)
  1549. }
  1550. return cloudbrains, int(len(cloudbrains)), nil
  1551. }
  1552. func QueryModelTrainJobList(repoId int64) ([]*CloudbrainInfo, int, error) {
  1553. sess := x.NewSession()
  1554. defer sess.Close()
  1555. var cond = builder.NewCond()
  1556. cond = cond.And(
  1557. builder.Eq{"repo_id": repoId},
  1558. )
  1559. cond = cond.And(
  1560. builder.In("Status", "COMPLETED", "SUCCEEDED"),
  1561. )
  1562. cond = cond.And(
  1563. builder.Eq{"job_type": "TRAIN"},
  1564. )
  1565. // cond = cond.And(
  1566. // builder.In("type", 0, 1),
  1567. // )
  1568. cloudbrains := make([]*CloudbrainInfo, 0)
  1569. if err := sess.Select("job_id,display_job_name").Table(&Cloudbrain{}).Where(cond).OrderBy("created_unix DESC").
  1570. Find(&cloudbrains); err != nil {
  1571. return nil, 0, fmt.Errorf("Find: %v", err)
  1572. }
  1573. keys := make(map[string]string)
  1574. uniqueElements := make([]*CloudbrainInfo, 0)
  1575. for _, entry := range cloudbrains {
  1576. if _, value := keys[entry.JobID]; !value {
  1577. keys[entry.JobID] = entry.DisplayJobName
  1578. uniqueElements = append(uniqueElements, entry)
  1579. }
  1580. }
  1581. return uniqueElements, int(len(uniqueElements)), nil
  1582. }
  1583. func CloudbrainsVersionList(opts *CloudbrainsOptions) ([]*CloudbrainInfo, int, error) {
  1584. sess := x.NewSession()
  1585. defer sess.Close()
  1586. var cond = builder.NewCond()
  1587. if opts.RepoID > 0 {
  1588. cond = cond.And(
  1589. builder.Eq{"cloudbrain.repo_id": opts.RepoID},
  1590. )
  1591. }
  1592. if opts.UserID > 0 {
  1593. cond = cond.And(
  1594. builder.Eq{"cloudbrain.user_id": opts.UserID},
  1595. )
  1596. }
  1597. if (opts.Type) >= 0 {
  1598. cond = cond.And(
  1599. builder.Eq{"cloudbrain.type": opts.Type},
  1600. )
  1601. }
  1602. if (opts.JobID) != "" {
  1603. cond = cond.And(
  1604. builder.Eq{"cloudbrain.job_id": opts.JobID},
  1605. )
  1606. }
  1607. if len(opts.JobTypes) > 0 {
  1608. cond = cond.And(
  1609. builder.In("cloudbrain.job_type", opts.JobTypes),
  1610. )
  1611. }
  1612. if len(opts.CloudbrainIDs) > 0 {
  1613. cond = cond.And(builder.In("cloudbrain.id", opts.CloudbrainIDs))
  1614. }
  1615. count, err := sess.Where(cond).Count(new(Cloudbrain))
  1616. if err != nil {
  1617. return nil, 0, fmt.Errorf("Count: %v", err)
  1618. }
  1619. if opts.Page >= 0 && opts.PageSize > 0 {
  1620. var start int
  1621. if opts.Page == 0 {
  1622. start = 0
  1623. } else {
  1624. start = (opts.Page - 1) * opts.PageSize
  1625. }
  1626. sess.Limit(opts.PageSize, start)
  1627. }
  1628. sess.OrderBy("cloudbrain.created_unix DESC")
  1629. cloudbrains := make([]*CloudbrainInfo, 0, setting.UI.IssuePagingNum)
  1630. if err := sess.Table(&Cloudbrain{}).Where(cond).
  1631. Join("left", "`user`", "cloudbrain.user_id = `user`.id").
  1632. Find(&cloudbrains); err != nil {
  1633. return nil, 0, fmt.Errorf("Find: %v", err)
  1634. }
  1635. return cloudbrains, int(count), nil
  1636. }
  1637. func CreateCloudbrain(cloudbrain *Cloudbrain) (err error) {
  1638. session := x.NewSession()
  1639. defer session.Close()
  1640. err = session.Begin()
  1641. cloudbrain.TrainJobDuration = DURATION_STR_ZERO
  1642. if _, err = session.NoAutoTime().InsertOne(cloudbrain); err != nil {
  1643. session.Rollback()
  1644. return err
  1645. }
  1646. if cloudbrain.Spec != nil {
  1647. if _, err = session.Insert(NewCloudBrainSpec(cloudbrain.ID, *cloudbrain.Spec)); err != nil {
  1648. session.Rollback()
  1649. return err
  1650. }
  1651. }
  1652. session.Commit()
  1653. go IncreaseDatasetUseCount(cloudbrain.Uuid)
  1654. return nil
  1655. }
  1656. func getRepoCloudBrain(cb *Cloudbrain) (*Cloudbrain, error) {
  1657. has, err := x.Get(cb)
  1658. if err != nil {
  1659. return nil, err
  1660. } else if !has {
  1661. return nil, ErrJobNotExist{}
  1662. }
  1663. return cb, nil
  1664. }
  1665. func getRepoCloudBrainWithDeleted(cb *Cloudbrain) (*Cloudbrain, error) {
  1666. has, err := x.Unscoped().Get(cb)
  1667. if err != nil {
  1668. return nil, err
  1669. } else if !has {
  1670. return nil, ErrJobNotExist{}
  1671. }
  1672. return cb, nil
  1673. }
  1674. func GetRepoCloudBrainByJobID(repoID int64, jobID string) (*Cloudbrain, error) {
  1675. cb := &Cloudbrain{JobID: jobID, RepoID: repoID}
  1676. return getRepoCloudBrain(cb)
  1677. }
  1678. func GetCloudbrainByJobID(jobID string) (*Cloudbrain, error) {
  1679. cb := &Cloudbrain{JobID: jobID}
  1680. return getRepoCloudBrain(cb)
  1681. }
  1682. func GetCloudbrainByJobIDWithDeleted(jobID string) (*Cloudbrain, error) {
  1683. cb := &Cloudbrain{JobID: jobID}
  1684. return getRepoCloudBrainWithDeleted(cb)
  1685. }
  1686. func GetCloudbrainByID(id string) (*Cloudbrain, error) {
  1687. idInt64, _ := strconv.ParseInt(id, 10, 64)
  1688. cb := &Cloudbrain{ID: idInt64}
  1689. return getRepoCloudBrain(cb)
  1690. }
  1691. func IsCloudbrainExistByJobName(jobName string) (bool, error) {
  1692. return x.Unscoped().Exist(&Cloudbrain{
  1693. JobName: jobName,
  1694. })
  1695. }
  1696. func GetCloudbrainByIDWithDeleted(id string) (*Cloudbrain, error) {
  1697. idInt64, _ := strconv.ParseInt(id, 10, 64)
  1698. cb := &Cloudbrain{ID: idInt64}
  1699. return getRepoCloudBrainWithDeleted(cb)
  1700. }
  1701. func GetCloudbrainByJobIDAndVersionName(jobID string, versionName string) (*Cloudbrain, error) {
  1702. cb := &Cloudbrain{JobID: jobID, VersionName: versionName}
  1703. return getRepoCloudBrain(cb)
  1704. }
  1705. func GetCloudbrainByJobIDAndIsLatestVersion(jobID string, isLatestVersion string) (*Cloudbrain, error) {
  1706. cb := &Cloudbrain{JobID: jobID, IsLatestVersion: isLatestVersion}
  1707. return getRepoCloudBrain(cb)
  1708. }
  1709. func GetCloudbrainsNeededStopByUserID(userID int64) ([]*Cloudbrain, error) {
  1710. cloudBrains := make([]*Cloudbrain, 0)
  1711. err := x.Cols("job_id", "status", "type", "job_type", "version_id", "start_time").Where("user_id=? AND status !=?", userID, string(JobStopped)).Find(&cloudBrains)
  1712. return cloudBrains, err
  1713. }
  1714. func GetModelartsReDebugTaskByJobId(jobID string) ([]*Cloudbrain, error) {
  1715. sess := x.NewSession()
  1716. defer sess.Close()
  1717. var cond = builder.NewCond()
  1718. cond = cond.And(
  1719. builder.Eq{"cloudbrain.job_id": jobID},
  1720. )
  1721. sess.OrderBy("cloudbrain.created_unix ASC limit 1")
  1722. cloudbrains := make([]*Cloudbrain, 0, 10)
  1723. if err := sess.Table(&Cloudbrain{}).Unscoped().Where(cond).
  1724. Find(&cloudbrains); err != nil {
  1725. log.Info("find error.")
  1726. }
  1727. return cloudbrains, nil
  1728. }
  1729. func GetCloudbrainsNeededStopByRepoID(repoID int64) ([]*Cloudbrain, error) {
  1730. cloudBrains := make([]*Cloudbrain, 0)
  1731. err := x.Cols("job_id", "status", "type", "job_type", "version_id", "start_time").Where("repo_id=? AND status !=?", repoID, string(JobStopped)).Find(&cloudBrains)
  1732. return cloudBrains, err
  1733. }
  1734. func GetCloudbrainsNeededDeleteByRepoID(repoID int64) ([]*Cloudbrain, error) {
  1735. cloudBrains := make([]*Cloudbrain, 0)
  1736. err := x.Where("repo_id=?", repoID).Find(&cloudBrains)
  1737. return cloudBrains, err
  1738. }
  1739. func GetCloudbrainsByDisplayJobName(repoID int64, jobType string, displayJobName string) ([]*Cloudbrain, error) {
  1740. cloudBrains := make([]*Cloudbrain, 0)
  1741. err := x.Cols("job_id", "job_name", "repo_id", "user_id", "job_type", "display_job_name").Where("repo_id=? AND job_type =? AND lower(display_job_name) = lower(?)", repoID, jobType, displayJobName).Find(&cloudBrains)
  1742. return cloudBrains, err
  1743. }
  1744. func SetCloudbrainStatusByJobID(jobID string, status CloudbrainStatus) (err error) {
  1745. cb := &Cloudbrain{JobID: jobID, Status: string(status)}
  1746. _, err = x.Cols("status").Where("cloudbrain.job_id=?", jobID).Update(cb)
  1747. return
  1748. }
  1749. func SetTrainJobStatusByJobID(jobID string, status string, duration int64, trainjobduration string) (err error) {
  1750. cb := &Cloudbrain{JobID: jobID, Status: string(status), Duration: duration, TrainJobDuration: trainjobduration}
  1751. _, err = x.Cols("status", "duration", "train_job_duration").Where("cloudbrain.job_id=?", jobID).Update(cb)
  1752. return
  1753. }
  1754. func SetVersionCountAndLatestVersion(jobID string, versionName string, versionCount int, isLatestVersion string, totalVersionCount int) (err error) {
  1755. cb := &Cloudbrain{JobID: jobID, VersionName: versionName, VersionCount: versionCount, IsLatestVersion: isLatestVersion, TotalVersionCount: totalVersionCount}
  1756. _, err = x.Cols("version_Count", "is_latest_version", "total_version_count").Where("cloudbrain.job_id=? AND cloudbrain.version_name=?", jobID, versionName).Update(cb)
  1757. return
  1758. }
  1759. func UpdateJob(job *Cloudbrain) error {
  1760. return updateJob(x, job)
  1761. }
  1762. func UpdateJobDurationWithDeleted(job *Cloudbrain) error {
  1763. _, err := x.Exec("update cloudbrain set start_time=?, end_time=?,train_job_duration=?,duration=? where id=?", job.StartTime, job.EndTime, job.TrainJobDuration, job.Duration, job.ID)
  1764. return err
  1765. }
  1766. func updateJob(e Engine, job *Cloudbrain) error {
  1767. _, err := e.ID(job.ID).AllCols().Update(job)
  1768. return err
  1769. }
  1770. func UpdateTrainJobVersion(job *Cloudbrain) error {
  1771. return updateJobTrainVersion(x, job)
  1772. }
  1773. func updateJobTrainVersion(e Engine, job *Cloudbrain) error {
  1774. var sess *xorm.Session
  1775. sess = e.Where("job_id = ? AND version_name=?", job.JobID, job.VersionName)
  1776. _, err := sess.Cols("status", "train_job_duration", "duration", "start_time", "end_time", "created_unix", "ai_center").Update(job)
  1777. return err
  1778. }
  1779. func DeleteJob(job *Cloudbrain) error {
  1780. return deleteJob(x, job)
  1781. }
  1782. func deleteJob(e Engine, job *Cloudbrain) error {
  1783. _, err := e.ID(job.ID).Delete(job)
  1784. return err
  1785. }
  1786. func GetCloudbrainByName(jobName string) (*Cloudbrain, error) {
  1787. cb := &Cloudbrain{JobName: jobName}
  1788. return getRepoCloudBrain(cb)
  1789. }
  1790. func CanDelJob(isSigned bool, user *User, job *CloudbrainInfo) bool {
  1791. if !isSigned || (job.Status != string(JobStopped) && job.Status != string(JobFailed) && job.Status != string(ModelArtsStartFailed) && job.Status != string(ModelArtsCreateFailed)) {
  1792. return false
  1793. }
  1794. repo, err := GetRepositoryByID(job.RepoID)
  1795. if err != nil {
  1796. log.Error("GetRepositoryByID failed:%v", err.Error())
  1797. return false
  1798. }
  1799. permission, _ := GetUserRepoPermission(repo, user)
  1800. if err != nil {
  1801. log.Error("GetUserRepoPermission failed:%v", err.Error())
  1802. return false
  1803. }
  1804. if (user.ID == job.UserID && permission.AccessMode >= AccessModeWrite) || user.IsAdmin || permission.AccessMode >= AccessModeAdmin {
  1805. return true
  1806. }
  1807. return false
  1808. }
  1809. func GetCloudBrainUnStoppedJob() ([]*Cloudbrain, error) {
  1810. cloudbrains := make([]*Cloudbrain, 0, 10)
  1811. return cloudbrains, x.
  1812. NotIn("status",
  1813. JobStopped, JobSucceeded, JobFailed, ModelArtsCreateFailed, ModelArtsStartFailed, ModelArtsUnavailable, ModelArtsResizFailed, ModelArtsDeleted,
  1814. ModelArtsStopped, ModelArtsTrainJobCanceled, ModelArtsTrainJobCheckFailed, ModelArtsTrainJobCompleted, ModelArtsTrainJobDeleteFailed, ModelArtsTrainJobDeployServiceFailed,
  1815. ModelArtsTrainJobFailed, ModelArtsTrainJobImageFailed, ModelArtsTrainJobKilled, ModelArtsTrainJobLost, ModelArtsTrainJobSubmitFailed, ModelArtsTrainJobSubmitModelFailed).
  1816. Limit(100).
  1817. Find(&cloudbrains)
  1818. }
  1819. func GetCloudBrainOneStoppedNotDebugJobDaysAgo(days int, limit int) ([]*Cloudbrain, error) {
  1820. cloudbrains := make([]*Cloudbrain, 0, 10)
  1821. endTimeBefore := time.Now().Unix() - int64(days)*24*3600
  1822. missEndTimeBefore := endTimeBefore - 24*3600
  1823. return cloudbrains, x.Unscoped().Cols("id,job_name,job_id").
  1824. In("status",
  1825. JobStopped, JobSucceeded, JobFailed, ModelArtsCreateFailed, ModelArtsStartFailed, ModelArtsUnavailable, ModelArtsResizFailed, ModelArtsDeleted,
  1826. ModelArtsStopped, ModelArtsTrainJobCanceled, ModelArtsTrainJobCheckFailed, ModelArtsTrainJobCompleted, ModelArtsTrainJobDeleteFailed, ModelArtsTrainJobDeployServiceFailed,
  1827. ModelArtsTrainJobFailed, ModelArtsTrainJobImageFailed, ModelArtsTrainJobKilled, ModelArtsTrainJobLost, ModelArtsTrainJobSubmitFailed, ModelArtsTrainJobSubmitModelFailed).
  1828. Where("(((end_time is null or end_time=0) and updated_unix<? and updated_unix != 0 ) or (end_time<? and end_time != 0)) and cleared=false and type=0 and job_type != 'DEBUG'", missEndTimeBefore, endTimeBefore).
  1829. Limit(limit).
  1830. Find(&cloudbrains)
  1831. }
  1832. /**
  1833. 本方法考虑了再次调试的情况,多次调试取最后一次的任务的结束时间
  1834. */
  1835. func GetCloudBrainOneStoppedDebugJobDaysAgo(days int, limit int) ([]*Cloudbrain, error) {
  1836. cloudbrains := make([]*Cloudbrain, 0, 10)
  1837. endTimeBefore := time.Now().Unix() - int64(days)*24*3600
  1838. missEndTimeBefore := endTimeBefore - 24*3600
  1839. sql := `SELECT id,job_name,job_id from (SELECT DISTINCT ON (job_name)
  1840. id, job_name, job_id,status,end_time,updated_unix,cleared
  1841. FROM cloudbrain
  1842. where type=0 and job_type='DEBUG'
  1843. ORDER BY job_name, updated_unix DESC) a
  1844. where status in ('STOPPED','SUCCEEDED','FAILED') and (((end_time is null or end_time=0) and updated_unix<? and updated_unix != 0 ) or (end_time<? and end_time != 0)) and cleared=false`
  1845. return cloudbrains, x.Unscoped().SQL(sql, missEndTimeBefore, endTimeBefore).Limit(limit).Find(&cloudbrains)
  1846. }
  1847. func UpdateCloudBrainRecordsCleared(ids []int64) error {
  1848. pageSize := 150
  1849. n := len(ids) / pageSize
  1850. var err error
  1851. for i := 1; i <= n+1; i++ {
  1852. tempIds := getPageIds(ids, i, pageSize)
  1853. if len(tempIds) > 0 {
  1854. idsIn := ""
  1855. for i, id := range tempIds {
  1856. if i == 0 {
  1857. idsIn += strconv.FormatInt(id, 10)
  1858. } else {
  1859. idsIn += "," + strconv.FormatInt(id, 10)
  1860. }
  1861. }
  1862. _, errTemp := x.Unscoped().Exec("update cloudbrain set cleared=true where id in (" + idsIn + ")")
  1863. if errTemp != nil {
  1864. err = errTemp
  1865. }
  1866. }
  1867. }
  1868. return err
  1869. }
  1870. func getPageIds(ids []int64, page int, pagesize int) []int64 {
  1871. begin := (page - 1) * pagesize
  1872. end := (page) * pagesize
  1873. if begin > len(ids)-1 {
  1874. return []int64{}
  1875. }
  1876. if end > len(ids)-1 {
  1877. return ids[begin:]
  1878. } else {
  1879. return ids[begin:end]
  1880. }
  1881. }
  1882. func GetStoppedJobWithNoDurationJob() ([]*Cloudbrain, error) {
  1883. cloudbrains := make([]*Cloudbrain, 0)
  1884. return cloudbrains, x.
  1885. In("status", ModelArtsTrainJobCompleted, ModelArtsTrainJobFailed, ModelArtsTrainJobKilled, ModelArtsStopped, JobStopped, JobFailed, JobSucceeded).
  1886. Where("train_job_duration is null or train_job_duration = '' ").
  1887. Limit(100).
  1888. Find(&cloudbrains)
  1889. }
  1890. func GetStoppedJobWithNoStartTimeEndTime() ([]*Cloudbrain, error) {
  1891. cloudbrains := make([]*Cloudbrain, 0)
  1892. return cloudbrains, x.SQL("select * from cloudbrain where status in (?,?,?,?,?,?,?) and (start_time is null or end_time is null) limit 100", ModelArtsTrainJobCompleted, ModelArtsTrainJobFailed, ModelArtsTrainJobKilled, ModelArtsStopped, JobStopped, JobFailed, JobSucceeded).Find(&cloudbrains)
  1893. }
  1894. func GetC2NetWithAiCenterWrongJob() ([]*Cloudbrain, error) {
  1895. cloudbrains := make([]*Cloudbrain, 0)
  1896. return cloudbrains, x.
  1897. In("status", ModelArtsTrainJobCompleted, ModelArtsTrainJobFailed, ModelArtsTrainJobKilled, ModelArtsStopped, JobStopped, JobFailed, JobSucceeded).
  1898. Where("type = ?", TypeC2Net).
  1899. Find(&cloudbrains)
  1900. }
  1901. func GetModelSafetyTestTask() ([]*Cloudbrain, error) {
  1902. cloudbrains := make([]*Cloudbrain, 0)
  1903. sess := x.Where("job_type=?", string(JobTypeModelSafety))
  1904. err := sess.Find(&cloudbrains)
  1905. return cloudbrains, err
  1906. }
  1907. func GetCloudbrainRunCountByRepoID(repoID int64) (int, error) {
  1908. count, err := x.In("status", JobWaiting, JobRunning, ModelArtsCreateQueue, ModelArtsCreating, ModelArtsStarting,
  1909. ModelArtsReadyToStart, ModelArtsResizing, ModelArtsStartQueuing, ModelArtsRunning, ModelArtsDeleting, ModelArtsRestarting, ModelArtsTrainJobInit,
  1910. ModelArtsTrainJobImageCreating, ModelArtsTrainJobSubmitTrying, ModelArtsTrainJobWaiting, ModelArtsTrainJobRunning, ModelArtsStopping, ModelArtsResizing,
  1911. ModelArtsTrainJobScaling, ModelArtsTrainJobCheckInit, ModelArtsTrainJobCheckRunning, ModelArtsTrainJobKilling, ModelArtsTrainJobCheckRunningCompleted).And("repo_id = ?", repoID).Count(new(Cloudbrain))
  1912. return int(count), err
  1913. }
  1914. func GetModelSafetyCountByUserID(userID int64) (int, error) {
  1915. count, err := x.In("status", JobWaiting, JobRunning, ModelArtsTrainJobInit, ModelArtsTrainJobImageCreating, ModelArtsTrainJobSubmitTrying, ModelArtsTrainJobScaling, ModelArtsTrainJobCheckInit, ModelArtsTrainJobCheckRunning, ModelArtsTrainJobCheckRunningCompleted).And("job_type = ? and user_id = ?", string(JobTypeModelSafety), userID).Count(new(Cloudbrain))
  1916. return int(count), err
  1917. }
  1918. func GetWaitingCloudbrainCount(cloudbrainType int, computeResource string, jobTypes ...JobType) (int64, error) {
  1919. sess := x.Where("status=? and type=?", JobWaiting, cloudbrainType)
  1920. if len(jobTypes) > 0 {
  1921. sess.In("job_type", jobTypes)
  1922. }
  1923. if computeResource != "" {
  1924. sess.And("compute_resource=?", computeResource)
  1925. }
  1926. return sess.Count(new(Cloudbrain))
  1927. }
  1928. func GetNotFinalStatusTaskCount(userID int64, notFinalStatus []string, jobTypes []JobType, cloudbrainTypes []int, computeResource string) (int, error) {
  1929. count, err := x.In("status", notFinalStatus).
  1930. In("job_type", jobTypes).
  1931. In("type", cloudbrainTypes).
  1932. And("user_id = ? and compute_resource = ?", userID, computeResource).Count(new(Cloudbrain))
  1933. return int(count), err
  1934. }
  1935. func RestartCloudbrain(old *Cloudbrain, new *Cloudbrain) (err error) {
  1936. sess := x.NewSession()
  1937. defer sess.Close()
  1938. if err = sess.Begin(); err != nil {
  1939. return err
  1940. }
  1941. if _, err = sess.Delete(old); err != nil {
  1942. sess.Rollback()
  1943. return err
  1944. }
  1945. if _, err = sess.NoAutoTime().InsertOne(new); err != nil {
  1946. sess.Rollback()
  1947. return err
  1948. }
  1949. if new.Spec != nil {
  1950. if _, err = sess.Insert(NewCloudBrainSpec(new.ID, *new.Spec)); err != nil {
  1951. sess.Rollback()
  1952. return err
  1953. }
  1954. }
  1955. if err = sess.Commit(); err != nil {
  1956. return err
  1957. }
  1958. go IncreaseDatasetUseCount(new.Uuid)
  1959. return nil
  1960. }
  1961. func CloudbrainAll(opts *CloudbrainsOptions) ([]*CloudbrainInfo, int64, error) {
  1962. sess := x.NewSession()
  1963. defer sess.Close()
  1964. var cond = builder.NewCond()
  1965. if opts.RepoID > 0 {
  1966. cond = cond.And(
  1967. builder.Eq{"cloudbrain.repo_id": opts.RepoID},
  1968. )
  1969. }
  1970. if opts.UserID > 0 {
  1971. cond = cond.And(
  1972. builder.Eq{"cloudbrain.user_id": opts.UserID},
  1973. )
  1974. }
  1975. if (opts.JobID) != "" {
  1976. cond = cond.And(
  1977. builder.Eq{"cloudbrain.job_id": opts.JobID},
  1978. )
  1979. }
  1980. if (opts.ComputeResource) != "" {
  1981. cond = cond.And(
  1982. builder.Eq{"cloudbrain.compute_resource": opts.ComputeResource},
  1983. )
  1984. }
  1985. if (opts.Type) >= 0 {
  1986. cond = cond.And(
  1987. builder.Eq{"cloudbrain.type": opts.Type},
  1988. )
  1989. }
  1990. if len(opts.JobTypes) > 0 {
  1991. if opts.JobTypeNot {
  1992. cond = cond.And(
  1993. builder.NotIn("cloudbrain.job_type", opts.JobTypes),
  1994. )
  1995. } else {
  1996. cond = cond.And(
  1997. builder.In("cloudbrain.job_type", opts.JobTypes),
  1998. )
  1999. }
  2000. }
  2001. if (opts.AiCenter) != "" {
  2002. cond = cond.And(
  2003. builder.Like{"cloudbrain.ai_center", opts.AiCenter},
  2004. )
  2005. }
  2006. if (opts.NeedDeleteInfo) != "" {
  2007. if opts.NeedDeleteInfo == "yes" {
  2008. cond = cond.And(
  2009. builder.And(builder.NotNull{"cloudbrain.deleted_at"}),
  2010. )
  2011. }
  2012. if opts.NeedDeleteInfo == "no" {
  2013. cond = cond.And(
  2014. builder.And(builder.IsNull{"cloudbrain.deleted_at"}),
  2015. )
  2016. }
  2017. }
  2018. if (opts.IsLatestVersion) != "" {
  2019. cond = cond.And(builder.Or(builder.And(builder.Eq{"cloudbrain.is_latest_version": opts.IsLatestVersion},
  2020. builder.Eq{"cloudbrain.job_type": "TRAIN"}), builder.Neq{"cloudbrain.job_type": "TRAIN"}))
  2021. }
  2022. if len(opts.CloudbrainIDs) > 0 {
  2023. cond = cond.And(builder.In("cloudbrain.id", opts.CloudbrainIDs))
  2024. }
  2025. if len(opts.JobStatus) > 0 {
  2026. if opts.JobStatusNot {
  2027. cond = cond.And(
  2028. builder.NotIn("cloudbrain.status", opts.JobStatus),
  2029. )
  2030. } else {
  2031. cond = cond.And(
  2032. builder.In("cloudbrain.status", opts.JobStatus),
  2033. )
  2034. }
  2035. }
  2036. if len(opts.RepoIDList) > 0 {
  2037. cond = cond.And(
  2038. builder.In("cloudbrain.repo_id", opts.RepoIDList),
  2039. )
  2040. }
  2041. if opts.BeginTimeUnix > 0 && opts.EndTimeUnix > 0 {
  2042. cond = cond.And(
  2043. builder.And(builder.Gte{"cloudbrain.created_unix": opts.BeginTimeUnix}, builder.Lte{"cloudbrain.created_unix": opts.EndTimeUnix}),
  2044. )
  2045. }
  2046. if opts.WorkServerNumber > 0 {
  2047. if opts.WorkServerNumber == 1 {
  2048. cond = cond.And(builder.Or(
  2049. builder.Eq{"cloudbrain.work_server_number": 0},
  2050. builder.Eq{"cloudbrain.work_server_number": 1},
  2051. builder.IsNull{"cloudbrain.work_server_number"},
  2052. ))
  2053. } else {
  2054. cond = cond.And(
  2055. builder.Eq{"cloudbrain.work_server_number": opts.WorkServerNumber},
  2056. )
  2057. }
  2058. }
  2059. if opts.AccCardType != "" {
  2060. cond = cond.And(builder.Eq{"cloudbrain_spec.acc_card_type": opts.AccCardType})
  2061. }
  2062. if opts.AccCardsNum != "" {
  2063. cond = cond.And(builder.Eq{"cloudbrain_spec.acc_cards_num": opts.AccCardsNum})
  2064. }
  2065. var count int64
  2066. var err error
  2067. condition := "cloudbrain.user_id = `user`.id"
  2068. if len(opts.Keyword) == 0 {
  2069. count, err = sess.Table(&Cloudbrain{}).Unscoped().Where(cond).
  2070. Join("left", "`user`", condition).
  2071. Join("left", "cloudbrain_spec", "cloudbrain.id = cloudbrain_spec.cloudbrain_id").
  2072. Count(new(CloudbrainInfo))
  2073. } else {
  2074. lowerKeyWord := strings.ToLower(opts.Keyword)
  2075. cond = cond.And(builder.Or(builder.Like{"LOWER(cloudbrain.job_name)", lowerKeyWord},
  2076. builder.Like{"LOWER(cloudbrain.display_job_name)", lowerKeyWord}, builder.Like{"`user`.lower_name", lowerKeyWord}))
  2077. count, err = sess.Table(&Cloudbrain{}).Unscoped().Where(cond).
  2078. Join("left", "`user`", condition).
  2079. Join("left", "cloudbrain_spec", "cloudbrain.id = cloudbrain_spec.cloudbrain_id").
  2080. Count(new(CloudbrainInfo))
  2081. }
  2082. if err != nil {
  2083. return nil, 0, fmt.Errorf("Count: %v", err)
  2084. }
  2085. if opts.Page >= 0 && opts.PageSize > 0 {
  2086. var start int
  2087. if opts.Page == 0 {
  2088. start = 0
  2089. } else {
  2090. start = (opts.Page - 1) * opts.PageSize
  2091. }
  2092. sess.Limit(opts.PageSize, start)
  2093. }
  2094. sess.OrderBy("cloudbrain.created_unix DESC")
  2095. cloudbrains := make([]*CloudbrainInfo, 0, setting.UI.IssuePagingNum)
  2096. if err := sess.Table(&Cloudbrain{}).Unscoped().Where(cond).
  2097. Join("left", "`user`", condition).
  2098. Join("left", "cloudbrain_spec", "cloudbrain.id = cloudbrain_spec.cloudbrain_id").
  2099. Find(&cloudbrains); err != nil {
  2100. return nil, 0, fmt.Errorf("Find: %v", err)
  2101. }
  2102. if opts.NeedRepoInfo {
  2103. var ids []int64
  2104. for _, task := range cloudbrains {
  2105. ids = append(ids, task.RepoID)
  2106. }
  2107. repositoryMap, err := GetRepositoriesMapByIDs(ids)
  2108. if err == nil {
  2109. for _, task := range cloudbrains {
  2110. task.Repo = repositoryMap[task.RepoID]
  2111. }
  2112. }
  2113. }
  2114. return cloudbrains, count, nil
  2115. }
  2116. func CloudbrainAllStatic(opts *CloudbrainsOptions) ([]*CloudbrainInfo, int64, error) {
  2117. sess := x.NewSession()
  2118. defer sess.Close()
  2119. var cond = builder.NewCond()
  2120. if (opts.Type) >= 0 {
  2121. cond = cond.And(
  2122. builder.Eq{"cloudbrain.type": opts.Type},
  2123. )
  2124. }
  2125. if opts.BeginTimeUnix > 0 && opts.EndTimeUnix > 0 {
  2126. cond = cond.And(
  2127. builder.And(builder.Gte{"cloudbrain.created_unix": opts.BeginTimeUnix}, builder.Lte{"cloudbrain.created_unix": opts.EndTimeUnix}),
  2128. )
  2129. }
  2130. var count int64
  2131. var err error
  2132. count, err = sess.Unscoped().Where(cond).Count(new(Cloudbrain))
  2133. if err != nil {
  2134. return nil, 0, fmt.Errorf("Count: %v", err)
  2135. }
  2136. if opts.Page >= 0 && opts.PageSize > 0 {
  2137. var start int
  2138. if opts.Page == 0 {
  2139. start = 0
  2140. } else {
  2141. start = (opts.Page - 1) * opts.PageSize
  2142. }
  2143. sess.Limit(opts.PageSize, start)
  2144. }
  2145. // sess.OrderBy("cloudbrain.created_unix DESC")
  2146. cloudbrains := make([]*CloudbrainInfo, 0, setting.UI.IssuePagingNum)
  2147. if err := sess.Table(&Cloudbrain{}).Unscoped().Where(cond).
  2148. Find(&cloudbrains); err != nil {
  2149. return nil, 0, fmt.Errorf("Find: %v", err)
  2150. }
  2151. if opts.NeedRepoInfo {
  2152. var ids []int64
  2153. for _, task := range cloudbrains {
  2154. ids = append(ids, task.RepoID)
  2155. }
  2156. repositoryMap, err := GetRepositoriesMapByIDs(ids)
  2157. if err == nil {
  2158. for _, task := range cloudbrains {
  2159. task.Repo = repositoryMap[task.RepoID]
  2160. }
  2161. }
  2162. }
  2163. return cloudbrains, count, nil
  2164. }
  2165. func CloudbrainAllKanBan(opts *CloudbrainsOptions) ([]*CloudbrainInfo, int64, error) {
  2166. sess := x.NewSession()
  2167. defer sess.Close()
  2168. var cond = builder.NewCond()
  2169. if (opts.Type) >= 0 {
  2170. cond = cond.And(
  2171. builder.Eq{"cloudbrain.type": opts.Type},
  2172. )
  2173. }
  2174. if opts.BeginTimeUnix > 0 && opts.EndTimeUnix > 0 {
  2175. cond = cond.And(
  2176. builder.And(builder.Gte{"cloudbrain.created_unix": opts.BeginTimeUnix}, builder.Lte{"cloudbrain.created_unix": opts.EndTimeUnix}),
  2177. )
  2178. }
  2179. var count int64
  2180. var err error
  2181. count, err = sess.Unscoped().Where(cond).Count(new(Cloudbrain))
  2182. if err != nil {
  2183. return nil, 0, fmt.Errorf("Count: %v", err)
  2184. }
  2185. if opts.Page >= 0 && opts.PageSize > 0 {
  2186. var start int
  2187. if opts.Page == 0 {
  2188. start = 0
  2189. } else {
  2190. start = (opts.Page - 1) * opts.PageSize
  2191. }
  2192. sess.Limit(opts.PageSize, start)
  2193. }
  2194. // sess.OrderBy("cloudbrain.created_unix DESC")
  2195. cloudbrains := make([]*CloudbrainInfo, 0, setting.UI.IssuePagingNum)
  2196. if err := sess.Cols("id", "type", "work_server_number", "duration", "train_job_duration", "ai_center", "cluster").Table(&Cloudbrain{}).Unscoped().Where(cond).
  2197. Find(&cloudbrains); err != nil {
  2198. return nil, 0, fmt.Errorf("Find: %v", err)
  2199. }
  2200. if opts.NeedRepoInfo {
  2201. var ids []int64
  2202. for _, task := range cloudbrains {
  2203. ids = append(ids, task.RepoID)
  2204. }
  2205. repositoryMap, err := GetRepositoriesMapByIDs(ids)
  2206. if err == nil {
  2207. for _, task := range cloudbrains {
  2208. task.Repo = repositoryMap[task.RepoID]
  2209. }
  2210. }
  2211. }
  2212. return cloudbrains, count, nil
  2213. }
  2214. func GetStartedCloudbrainTaskByUpdatedUnix(startTime, endTime time.Time) ([]Cloudbrain, error) {
  2215. r := make([]Cloudbrain, 0)
  2216. err := x.Where("updated_unix >= ? and updated_unix <= ? and start_time > 0", startTime.Unix(), endTime.Unix()).Unscoped().Find(&r)
  2217. if err != nil {
  2218. return nil, err
  2219. }
  2220. return r, nil
  2221. }
  2222. func GetCloudbrainByIds(ids []int64) ([]*Cloudbrain, error) {
  2223. if len(ids) == 0 {
  2224. return nil, nil
  2225. }
  2226. cloudbrains := make([]*Cloudbrain, 0)
  2227. err := x.In("id", ids).Unscoped().Find(&cloudbrains)
  2228. if err != nil {
  2229. return nil, err
  2230. }
  2231. return cloudbrains, nil
  2232. }
  2233. type DatasetInfo struct {
  2234. DataLocalPath string
  2235. Name string
  2236. FullName string
  2237. }
  2238. func GetDatasetInfo(uuidStr string, grampusType ...string) (map[string]DatasetInfo, string, error) {
  2239. var datasetNames string
  2240. uuids := strings.Split(uuidStr, ";")
  2241. if len(uuids) > setting.MaxDatasetNum {
  2242. log.Error("the dataset count(%d) exceed the limit", len(uuids))
  2243. return nil, datasetNames, errors.New("the dataset count exceed the limit")
  2244. }
  2245. datasetInfos := make(map[string]DatasetInfo)
  2246. attachs, err := GetAttachmentsByUUIDs(uuids)
  2247. if err != nil {
  2248. log.Error("GetAttachmentsByUUIDs failed: %v", err)
  2249. return nil, datasetNames, err
  2250. }
  2251. for i, tmpUuid := range uuids {
  2252. var attach *Attachment
  2253. for _, tmpAttach := range attachs {
  2254. if tmpAttach.UUID == tmpUuid {
  2255. attach = tmpAttach
  2256. break
  2257. }
  2258. }
  2259. if attach == nil {
  2260. log.Error("GetAttachmentsByUUIDs failed: %v", err)
  2261. return nil, datasetNames, err
  2262. }
  2263. fileName := strings.TrimSuffix(strings.TrimSuffix(strings.TrimSuffix(attach.Name, ".zip"), ".tar.gz"), ".tgz")
  2264. for _, datasetInfo := range datasetInfos {
  2265. if fileName == datasetInfo.Name {
  2266. log.Error("the dataset name is same: %v", attach.Name)
  2267. return nil, datasetNames, errors.New("the dataset name is same")
  2268. }
  2269. }
  2270. var dataLocalPath string
  2271. if len(grampusType) > 0 {
  2272. if grampusType[0] == GPU {
  2273. dataLocalPath = setting.Attachment.Minio.BasePath + path.Join(attach.UUID[0:1], attach.UUID[1:2]) + "/" + attach.UUID
  2274. } else {
  2275. dataLocalPath = setting.BasePath + path.Join(attach.UUID[0:1], attach.UUID[1:2]) + "/" + attach.UUID + "/"
  2276. }
  2277. } else {
  2278. dataLocalPath = setting.Attachment.Minio.RealPath +
  2279. setting.Attachment.Minio.Bucket + "/" +
  2280. setting.Attachment.Minio.BasePath +
  2281. AttachmentRelativePath(attach.UUID) +
  2282. attach.UUID
  2283. }
  2284. datasetInfos[attach.UUID] = DatasetInfo{
  2285. DataLocalPath: dataLocalPath,
  2286. Name: fileName,
  2287. FullName: attach.Name,
  2288. }
  2289. if i == 0 {
  2290. datasetNames = attach.Name
  2291. } else {
  2292. datasetNames += ";" + attach.Name
  2293. }
  2294. }
  2295. return datasetInfos, datasetNames, nil
  2296. }
  2297. var (
  2298. SpecsMapInitFlag = false
  2299. CloudbrainDebugResourceSpecsMap map[int]*ResourceSpec
  2300. CloudbrainTrainResourceSpecsMap map[int]*ResourceSpec
  2301. CloudbrainInferenceResourceSpecsMap map[int]*ResourceSpec
  2302. CloudbrainBenchmarkResourceSpecsMap map[int]*ResourceSpec
  2303. CloudbrainSpecialResourceSpecsMap map[int]*ResourceSpec
  2304. GpuInfosMapInitFlag = false
  2305. CloudbrainDebugGpuInfosMap map[string]*GpuInfo
  2306. CloudbrainTrainGpuInfosMap map[string]*GpuInfo
  2307. CloudbrainInferenceGpuInfosMap map[string]*GpuInfo
  2308. CloudbrainBenchmarkGpuInfosMap map[string]*GpuInfo
  2309. CloudbrainSpecialGpuInfosMap map[string]*GpuInfo
  2310. )
  2311. func GetNewestJobsByAiCenter() ([]int64, error) {
  2312. ids := make([]int64, 0)
  2313. return ids, x.
  2314. Select("max(id) as id").
  2315. Where("type=? and ai_center!='' and ai_center is not null", TypeC2Net).
  2316. GroupBy("ai_center").
  2317. Table(Cloudbrain{}).
  2318. Find(&ids)
  2319. }
  2320. func GetNewestJobsByType() ([]int64, error) {
  2321. ids := make([]int64, 0)
  2322. return ids, x.
  2323. Select("max(id) as id").
  2324. In("type", TypeCloudBrainOne, TypeCloudBrainTwo).
  2325. GroupBy("type").
  2326. Table(Cloudbrain{}).
  2327. Find(&ids)
  2328. }
  2329. func GetCloudbrainByIDs(ids []int64) ([]*Cloudbrain, error) {
  2330. cloudbrains := make([]*Cloudbrain, 0)
  2331. return cloudbrains, x.
  2332. In("id", ids).
  2333. Find(&cloudbrains)
  2334. }
  2335. func GetCloudbrainWithDeletedByIDs(ids []int64) ([]*Cloudbrain, error) {
  2336. cloudbrains := make([]*Cloudbrain, 0)
  2337. return cloudbrains, x.
  2338. In("id", ids).Unscoped().Find(&cloudbrains)
  2339. }
  2340. func GetCloudbrainCountByJobName(jobName, jobType string, typeCloudbrain int) (int, error) {
  2341. count, err := x.Where("job_name = ? and job_type= ? and type = ?", jobName, jobType, typeCloudbrain).Count(new(Cloudbrain))
  2342. return int(count), err
  2343. }
  2344. func LoadSpecs(tasks []*Cloudbrain) error {
  2345. cloudbrainIds := make([]int64, len(tasks))
  2346. for i, v := range tasks {
  2347. cloudbrainIds[i] = v.ID
  2348. }
  2349. specs := make([]*CloudbrainSpec, 0)
  2350. err := x.In("cloudbrain_id", cloudbrainIds).Find(&specs)
  2351. if err != nil {
  2352. return err
  2353. }
  2354. specMap := make(map[int64]*CloudbrainSpec)
  2355. for _, v := range specs {
  2356. specMap[v.SpecId] = v
  2357. }
  2358. for _, v := range tasks {
  2359. if specMap[v.ID] != nil {
  2360. v.Spec = specMap[v.ID].ConvertToSpecification()
  2361. }
  2362. }
  2363. return nil
  2364. }
  2365. func LoadSpecs4CloudbrainInfo(tasks []*CloudbrainInfo) error {
  2366. cloudbrainIds := make([]int64, len(tasks))
  2367. for i, v := range tasks {
  2368. cloudbrainIds[i] = v.Cloudbrain.ID
  2369. }
  2370. specs := make([]*CloudbrainSpec, 0)
  2371. err := x.In("cloudbrain_id", cloudbrainIds).Find(&specs)
  2372. if err != nil {
  2373. return err
  2374. }
  2375. specMap := make(map[int64]*CloudbrainSpec)
  2376. for _, v := range specs {
  2377. specMap[v.CloudbrainID] = v
  2378. }
  2379. for _, v := range tasks {
  2380. if specMap[v.Cloudbrain.ID] != nil {
  2381. v.Cloudbrain.Spec = specMap[v.Cloudbrain.ID].ConvertToSpecification()
  2382. }
  2383. }
  2384. return nil
  2385. }