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.

grampus.go 18 kB

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
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
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
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
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
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
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
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
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
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. package repo
  2. import (
  3. "code.gitea.io/gitea/modules/auth"
  4. "code.gitea.io/gitea/modules/git"
  5. "code.gitea.io/gitea/modules/grampus"
  6. "code.gitea.io/gitea/modules/modelarts"
  7. "code.gitea.io/gitea/modules/timeutil"
  8. "code.gitea.io/gitea/modules/util"
  9. "encoding/json"
  10. "errors"
  11. "io/ioutil"
  12. "net/http"
  13. "os"
  14. "path"
  15. "strconv"
  16. "strings"
  17. "time"
  18. "code.gitea.io/gitea/models"
  19. "code.gitea.io/gitea/modules/base"
  20. "code.gitea.io/gitea/modules/cloudbrain"
  21. "code.gitea.io/gitea/modules/context"
  22. "code.gitea.io/gitea/modules/log"
  23. "code.gitea.io/gitea/modules/setting"
  24. )
  25. const (
  26. tplGrampusTrainJobShow base.TplName = "repo/grampus/trainjob/show"
  27. //GPU
  28. tplGrampusTrainJobGPUNew base.TplName = "repo/grampus/trainjob/gpu/new"
  29. //NPU
  30. tplGrampusTrainJobNPUNew base.TplName = "repo/grampus/trainjob/npu/new"
  31. )
  32. func GrampusTrainJobGPUNew(ctx *context.Context) {
  33. err := grampusGpuNewDataPrepare(ctx)
  34. if err != nil {
  35. ctx.ServerError("get new train-job info failed", err)
  36. return
  37. }
  38. ctx.HTML(http.StatusOK, tplGrampusTrainJobGPUNew)
  39. }
  40. func grampusGpuNewDataPrepare(ctx *context.Context) error {
  41. ctx.Data["PageIsCloudBrain"] = true
  42. t := time.Now()
  43. var displayJobName = jobNamePrefixValid(cutString(ctx.User.Name, 5)) + t.Format("2006010215") + strconv.Itoa(int(t.Unix()))[5:]
  44. ctx.Data["display_job_name"] = displayJobName
  45. //get valid images
  46. result, err := cloudbrain.GetImages()
  47. if err != nil {
  48. ctx.Data["error"] = err.Error()
  49. log.Error("cloudbrain.GetImages failed:", err.Error(), ctx.Data["MsgID"])
  50. }
  51. for i, payload := range result.Payload.ImageInfo {
  52. if strings.HasPrefix(result.Payload.ImageInfo[i].Place, "192.168") {
  53. result.Payload.ImageInfo[i].PlaceView = payload.Place[strings.Index(payload.Place, "/"):len(payload.Place)]
  54. } else {
  55. result.Payload.ImageInfo[i].PlaceView = payload.Place
  56. }
  57. }
  58. ctx.Data["images"] = result.Payload.ImageInfo
  59. resultPublic, err := cloudbrain.GetPublicImages()
  60. if err != nil {
  61. ctx.Data["error"] = err.Error()
  62. log.Error("cloudbrain.GetPublicImages failed:", err.Error(), ctx.Data["MsgID"])
  63. }
  64. for i, payload := range resultPublic.Payload.ImageInfo {
  65. if strings.HasPrefix(resultPublic.Payload.ImageInfo[i].Place, "192.168") {
  66. resultPublic.Payload.ImageInfo[i].PlaceView = payload.Place[strings.Index(payload.Place, "/"):len(payload.Place)]
  67. } else {
  68. resultPublic.Payload.ImageInfo[i].PlaceView = payload.Place
  69. }
  70. }
  71. ctx.Data["public_images"] = resultPublic.Payload.ImageInfo
  72. //get valid dataset
  73. attachs, err := models.GetAllUserAttachments(ctx.User.ID)
  74. if err != nil {
  75. log.Error("GetAllUserAttachments failed: %v", err, ctx.Data["MsgID"])
  76. return err
  77. }
  78. ctx.Data["attachments"] = attachs
  79. ctx.Data["command"] = cloudbrain.Command
  80. ctx.Data["code_path"] = cloudbrain.CodeMountPath
  81. ctx.Data["dataset_path"] = cloudbrain.DataSetMountPath
  82. ctx.Data["model_path"] = cloudbrain.ModelMountPath
  83. ctx.Data["benchmark_path"] = cloudbrain.BenchMarkMountPath
  84. ctx.Data["is_benchmark_enabled"] = setting.IsBenchmarkEnabled
  85. //get valid resource specs
  86. if categories == nil {
  87. json.Unmarshal([]byte(setting.BenchmarkCategory), &categories)
  88. }
  89. ctx.Data["benchmark_categories"] = categories.Category
  90. ctx.Data["benchmark_types"] = GetBenchmarkTypes(ctx).BenchmarkType
  91. if gpuInfos == nil {
  92. json.Unmarshal([]byte(setting.GpuTypes), &gpuInfos)
  93. }
  94. ctx.Data["gpu_types"] = gpuInfos.GpuInfo
  95. if trainGpuInfos == nil {
  96. json.Unmarshal([]byte(setting.TrainGpuTypes), &trainGpuInfos)
  97. }
  98. ctx.Data["train_gpu_types"] = trainGpuInfos.GpuInfo
  99. if benchmarkGpuInfos == nil {
  100. json.Unmarshal([]byte(setting.BenchmarkGpuTypes), &benchmarkGpuInfos)
  101. }
  102. ctx.Data["benchmark_gpu_types"] = benchmarkGpuInfos.GpuInfo
  103. if benchmarkResourceSpecs == nil {
  104. json.Unmarshal([]byte(setting.BenchmarkResourceSpecs), &benchmarkResourceSpecs)
  105. }
  106. ctx.Data["benchmark_resource_specs"] = benchmarkResourceSpecs.ResourceSpec
  107. if cloudbrain.ResourceSpecs == nil {
  108. json.Unmarshal([]byte(setting.ResourceSpecs), &cloudbrain.ResourceSpecs)
  109. }
  110. ctx.Data["resource_specs"] = cloudbrain.ResourceSpecs.ResourceSpec
  111. if cloudbrain.TrainResourceSpecs == nil {
  112. json.Unmarshal([]byte(setting.TrainResourceSpecs), &cloudbrain.TrainResourceSpecs)
  113. }
  114. ctx.Data["train_resource_specs"] = cloudbrain.TrainResourceSpecs.ResourceSpec
  115. branches, _, err := ctx.Repo.GitRepo.GetBranches(0, 0)
  116. if err != nil {
  117. log.Error("GetBranches error:", err)
  118. }
  119. ctx.Data["branches"] = branches
  120. ctx.Data["branchName"] = ctx.Repo.BranchName
  121. return nil
  122. }
  123. func GrampusTrainJobNPUNew(ctx *context.Context) {
  124. err := grampusTrainJobNpuNewDataPrepare(ctx)
  125. if err != nil {
  126. ctx.ServerError("get new train-job info failed", err)
  127. return
  128. }
  129. ctx.HTML(200, tplGrampusTrainJobNPUNew)
  130. }
  131. func grampusTrainJobNpuNewDataPrepare(ctx *context.Context) error {
  132. ctx.Data["PageIsCloudBrain"] = true
  133. t := time.Now()
  134. var displayJobName = cutString(ctx.User.Name, 5) + t.Format("2006010215") + strconv.Itoa(int(t.Unix()))[5:]
  135. ctx.Data["display_job_name"] = displayJobName
  136. //get valid dataset
  137. attachs, err := models.GetModelArtsTrainAttachments(ctx.User.ID)
  138. if err != nil {
  139. log.Error("GetModelArtsTrainAttachments failed:", err.Error())
  140. } else {
  141. ctx.Data["attachments"] = attachs
  142. }
  143. //get valid engines
  144. images, err := grampus.GetImages(grampus.ProcessorTypeNPU)
  145. if err != nil {
  146. log.Error("GetResourceSpecs failed:", err.Error())
  147. } else {
  148. ctx.Data["engine_versions"] = images.Infos
  149. }
  150. //get valid resource specs
  151. specs, err := grampus.GetResourceSpecs(grampus.ProcessorTypeNPU)
  152. if err != nil {
  153. log.Error("GetResourceSpecs failed:", err.Error())
  154. } else {
  155. ctx.Data["flavor_infos"] = specs.Infos
  156. }
  157. //get branches
  158. branches, _, err := ctx.Repo.GitRepo.GetBranches(0, 0)
  159. if err != nil {
  160. log.Error("GetBranches error:", err.Error())
  161. } else {
  162. ctx.Data["branches"] = branches
  163. }
  164. ctx.Data["branchName"] = ctx.Repo.BranchName
  165. return nil
  166. }
  167. func grampusParamCheckCreateTrainJob(form auth.CreateGrampusTrainJobForm) error {
  168. if !strings.HasSuffix(form.BootFile, ".py") {
  169. log.Error("the boot file(%s) must be a python file", form.BootFile)
  170. return errors.New("启动文件必须是python文件")
  171. }
  172. if form.BranchName == "" {
  173. log.Error("the branch must not be null!", form.BranchName)
  174. return errors.New("代码分支不能为空!")
  175. }
  176. return nil
  177. }
  178. func GrampusTrainJobNpuCreate(ctx *context.Context, form auth.CreateGrampusTrainJobForm) {
  179. VersionOutputPath := modelarts.GetOutputPathByCount(modelarts.TotalVersionCount)
  180. displayJobName := form.DisplayJobName
  181. jobName := util.ConvertDisplayJobNameToJobName(displayJobName)
  182. uuid := form.Attachment
  183. description := form.Description
  184. bootFile := form.BootFile
  185. params := form.Params
  186. repo := ctx.Repo.Repository
  187. codeLocalPath := setting.JobPath + jobName + modelarts.CodePath
  188. codeObsPath := "/" + setting.Bucket + modelarts.JobPath + jobName + modelarts.CodePath
  189. dataPath := "/" + setting.Bucket + "/" + setting.BasePath + path.Join(uuid[0:1], uuid[1:2]) + "/" + uuid + uuid + "/"
  190. branchName := form.BranchName
  191. isLatestVersion := modelarts.IsLatestVersion
  192. flavorName := form.FlavorName
  193. versionCount := modelarts.VersionCount
  194. engineName := form.EngineName
  195. //check count limit
  196. count, err := models.GetGrampusCountByUserID(ctx.User.ID, string(models.JobTypeTrain), models.NPUResource)
  197. if err != nil {
  198. log.Error("GetGrampusCountByUserID failed:%v", err, ctx.Data["MsgID"])
  199. grampusTrainJobNpuNewDataPrepare(ctx)
  200. ctx.RenderWithErr("system error", tplGrampusTrainJobNPUNew, &form)
  201. return
  202. } else {
  203. if count >= 1 {
  204. log.Error("the user already has running or waiting task", ctx.Data["MsgID"])
  205. grampusTrainJobNpuNewDataPrepare(ctx)
  206. ctx.RenderWithErr("you have already a running or waiting task, can not create more", tplGrampusTrainJobNPUNew, &form)
  207. return
  208. }
  209. }
  210. //check param
  211. if err := grampusParamCheckCreateTrainJob(form); err != nil {
  212. log.Error("paramCheckCreateTrainJob failed:(%v)", err)
  213. grampusTrainJobNpuNewDataPrepare(ctx)
  214. ctx.RenderWithErr(err.Error(), tplGrampusTrainJobNPUNew, &form)
  215. return
  216. }
  217. //check whether the task name in the project is duplicated
  218. tasks, err := models.GetCloudbrainsByDisplayJobName(repo.ID, string(models.JobTypeTrain), displayJobName)
  219. if err == nil {
  220. if len(tasks) != 0 {
  221. log.Error("the job name did already exist", ctx.Data["MsgID"])
  222. grampusTrainJobNpuNewDataPrepare(ctx)
  223. ctx.RenderWithErr("the job name did already exist", tplGrampusTrainJobNPUNew, &form)
  224. return
  225. }
  226. } else {
  227. if !models.IsErrJobNotExist(err) {
  228. log.Error("system error, %v", err, ctx.Data["MsgID"])
  229. grampusTrainJobNpuNewDataPrepare(ctx)
  230. ctx.RenderWithErr("system error", tplGrampusTrainJobNPUNew, &form)
  231. return
  232. }
  233. }
  234. //prepare code and out path
  235. _, err = ioutil.ReadDir(codeLocalPath)
  236. if err == nil {
  237. os.RemoveAll(codeLocalPath)
  238. }
  239. if err := downloadCode(repo, codeLocalPath, branchName); err != nil {
  240. log.Error("downloadCode failed, server timed out: %s (%v)", repo.FullName(), err)
  241. grampusTrainJobNpuNewDataPrepare(ctx)
  242. ctx.RenderWithErr("Create task failed, server timed out", tplGrampusTrainJobNPUNew, &form)
  243. return
  244. }
  245. //todo: upload code (send to file_server todo this work?)
  246. if err := obsMkdir(setting.CodePathPrefix + jobName + modelarts.OutputPath + VersionOutputPath + "/"); err != nil {
  247. log.Error("Failed to obsMkdir_output: %s (%v)", repo.FullName(), err)
  248. grampusTrainJobNpuNewDataPrepare(ctx)
  249. ctx.RenderWithErr("Failed to obsMkdir_output", tplGrampusTrainJobNPUNew, &form)
  250. return
  251. }
  252. if err := obsMkdir(setting.CodePathPrefix + jobName + modelarts.LogPath + VersionOutputPath + "/"); err != nil {
  253. log.Error("Failed to obsMkdir_log: %s (%v)", repo.FullName(), err)
  254. grampusTrainJobNpuNewDataPrepare(ctx)
  255. ctx.RenderWithErr("Failed to obsMkdir_log", tplGrampusTrainJobNPUNew, &form)
  256. return
  257. }
  258. if err := uploadCodeToObs(codeLocalPath, jobName, ""); err != nil {
  259. log.Error("Failed to uploadCodeToObs: %s (%v)", repo.FullName(), err)
  260. grampusTrainJobNpuNewDataPrepare(ctx)
  261. ctx.RenderWithErr("Failed to uploadCodeToObs", tplGrampusTrainJobNPUNew, &form)
  262. return
  263. }
  264. //prepare command
  265. //todo: download code, download dataset, unzip dataset, exec code, upload model
  266. command, err := generateCommand(grampus.ProcessorTypeNPU, codeObsPath, dataPath, params, "")
  267. var parameters models.Parameters
  268. param := make([]models.Parameter, 0)
  269. if len(params) != 0 {
  270. err := json.Unmarshal([]byte(params), &parameters)
  271. if err != nil {
  272. log.Error("Failed to Unmarshal params: %s (%v)", params, err)
  273. grampusTrainJobNpuNewDataPrepare(ctx)
  274. ctx.RenderWithErr("运行参数错误", tplGrampusTrainJobNPUNew, &form)
  275. return
  276. }
  277. for _, parameter := range parameters.Parameter {
  278. param = append(param, models.Parameter{
  279. Label: parameter.Label,
  280. Value: parameter.Value,
  281. })
  282. }
  283. }
  284. param = append(param, models.Parameter{
  285. Label: modelarts.DeviceTarget,
  286. Value: modelarts.Ascend,
  287. })
  288. gitRepo, _ := git.OpenRepository(repo.RepoPath())
  289. commitID, _ := gitRepo.GetBranchCommitID(branchName)
  290. req := &grampus.GenerateTrainJobReq{
  291. JobName: jobName,
  292. DisplayJobName: displayJobName,
  293. ComputeResource: models.NPUResource,
  294. Command: command,
  295. ResourceSpecId: form.FlavorID,
  296. ImageUrl: "",
  297. ImageId: form.ImageID,
  298. DataUrl: dataPath,
  299. Description: description,
  300. CodeObsPath: codeObsPath,
  301. BootFileUrl: codeObsPath + bootFile,
  302. BootFile: bootFile,
  303. WorkServerNumber: form.WorkServerNumber,
  304. Uuid: uuid,
  305. CommitID: commitID,
  306. IsLatestVersion: isLatestVersion,
  307. BranchName: branchName,
  308. Params: form.Params,
  309. FlavorName: flavorName,
  310. EngineName: engineName,
  311. VersionCount: versionCount,
  312. TotalVersionCount: modelarts.TotalVersionCount,
  313. }
  314. err = grampus.GenerateTrainJob(ctx, req)
  315. if err != nil {
  316. log.Error("GenerateTrainJob failed:%v", err.Error())
  317. grampusTrainJobNpuNewDataPrepare(ctx)
  318. ctx.RenderWithErr(err.Error(), tplGrampusTrainJobNPUNew, &form)
  319. return
  320. }
  321. ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/modelarts/train-job")
  322. }
  323. func GrampusStopJob(ctx *context.Context) {
  324. var ID = ctx.Params(":jobid")
  325. var resultCode = "0"
  326. var errorMsg = ""
  327. var status = ""
  328. task := ctx.Cloudbrain
  329. for {
  330. if task.Status == string(models.GrampusStatusStopped) || task.Status == string(models.GrampusStatusFailed) || task.Status == string(models.GrampusStatusSucceeded) {
  331. log.Error("the job(%s) has been stopped", task.JobName, ctx.Data["msgID"])
  332. resultCode = "-1"
  333. errorMsg = "system error"
  334. break
  335. }
  336. res, err := grampus.StopJob(task.JobID)
  337. if err != nil {
  338. log.Error("StopJob(%s) failed:%v", task.JobName, err, ctx.Data["msgID"])
  339. resultCode = strconv.Itoa(res.ErrorCode)
  340. errorMsg = res.ErrorMsg
  341. break
  342. }
  343. task.Status = string(models.GrampusStatusStopped)
  344. if task.EndTime == 0 {
  345. task.EndTime = timeutil.TimeStampNow()
  346. }
  347. task.ComputeAndSetDuration()
  348. err = models.UpdateJob(task)
  349. if err != nil {
  350. log.Error("UpdateJob(%s) failed:%v", task.JobName, err, ctx.Data["msgID"])
  351. resultCode = "-1"
  352. errorMsg = "system error"
  353. break
  354. }
  355. status = task.Status
  356. break
  357. }
  358. ctx.JSON(200, map[string]interface{}{
  359. "result_code": resultCode,
  360. "error_msg": errorMsg,
  361. "status": status,
  362. "id": ID,
  363. "StatusOK": 0,
  364. })
  365. }
  366. func GrampusTrainJobDel(ctx *context.Context) {
  367. var listType = ctx.Query("listType")
  368. if err := deleteGrampusJob(ctx); err != nil {
  369. log.Error("deleteGrampusJob failed: %v", err, ctx.Data["msgID"])
  370. ctx.ServerError(err.Error(), err)
  371. return
  372. }
  373. var isAdminPage = ctx.Query("isadminpage")
  374. var isHomePage = ctx.Query("ishomepage")
  375. if ctx.IsUserSiteAdmin() && isAdminPage == "true" {
  376. ctx.Redirect(setting.AppSubURL + "/admin" + "/cloudbrains")
  377. } else if isHomePage == "true" {
  378. ctx.Redirect(setting.AppSubURL + "/cloudbrains")
  379. } else {
  380. ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/modelarts/train-job?listType=" + listType)
  381. }
  382. }
  383. func deleteGrampusJob(ctx *context.Context) error {
  384. task := ctx.Cloudbrain
  385. if task.Status != string(models.GrampusStatusStopped) && task.Status != string(models.GrampusStatusSucceeded) && task.Status != string(models.GrampusStatusFailed) {
  386. log.Error("the job(%s) has not been stopped", task.JobName, ctx.Data["msgID"])
  387. return errors.New("the job has not been stopped")
  388. }
  389. err := models.DeleteJob(task)
  390. if err != nil {
  391. log.Error("DeleteJob failed: %v", err, ctx.Data["msgID"])
  392. return err
  393. }
  394. storageType := models.TypeCloudBrainOne
  395. if task.ComputeResource == models.NPUResource {
  396. storageType = models.TypeCloudBrainTwo
  397. }
  398. deleteJobStorage(task.JobName, storageType)
  399. return nil
  400. }
  401. func GrampusTrainJobShow(ctx *context.Context) {
  402. ctx.Data["PageIsCloudBrain"] = true
  403. var task *models.Cloudbrain
  404. task, err := models.GetCloudbrainByJobIDWithDeleted(ctx.Params(":jobid"))
  405. if err != nil {
  406. log.Error("GetCloudbrainByJobID failed:" + err.Error())
  407. ctx.ServerError("system error", err)
  408. return
  409. }
  410. attachment, err := models.GetAttachmentByUUID(task.Uuid)
  411. if err == nil {
  412. task.DatasetName = attachment.Name
  413. }
  414. if task.DeletedAt.IsZero() { //normal record
  415. result, err := grampus.GetJob(task.JobID)
  416. if err != nil {
  417. log.Error("GetJob failed:" + err.Error())
  418. ctx.ServerError("GetJob failed", err)
  419. return
  420. }
  421. if result != nil {
  422. task.Status = grampus.TransTrainJobStatus(result.JobInfo.Status)
  423. if task.Status != result.JobInfo.Status || result.JobInfo.Status == models.GrampusStatusRunning {
  424. task.Duration = result.JobInfo.RunSec
  425. task.TrainJobDuration = models.ConvertDurationToStr(task.Duration)
  426. if task.StartTime == 0 && result.JobInfo.StartedAt > 0 {
  427. task.StartTime = timeutil.TimeStamp(result.JobInfo.StartedAt)
  428. }
  429. if task.EndTime == 0 && models.IsTrainJobTerminal(task.Status) && task.StartTime > 0 {
  430. task.EndTime = task.StartTime.Add(task.Duration)
  431. }
  432. task.CorrectCreateUnix()
  433. err = models.UpdateJob(task)
  434. if err != nil {
  435. log.Error("UpdateJob failed:" + err.Error())
  436. }
  437. }
  438. }
  439. }
  440. if len(task.Parameters) > 0 {
  441. var parameters models.Parameters
  442. err := json.Unmarshal([]byte(task.Parameters), &parameters)
  443. if err != nil {
  444. log.Error("Failed to Unmarshal Parameters: %s (%v)", task.Parameters, err)
  445. ctx.ServerError("system error", err)
  446. return
  447. }
  448. if len(parameters.Parameter) > 0 {
  449. paramTemp := ""
  450. for _, Parameter := range parameters.Parameter {
  451. param := Parameter.Label + " = " + Parameter.Value + "; "
  452. paramTemp = paramTemp + param
  453. }
  454. task.Parameters = paramTemp[:len(paramTemp)-2]
  455. }
  456. }
  457. taskList := make([]*models.Cloudbrain, 0)
  458. taskList = append(taskList, task)
  459. ctx.Data["version_list_task"] = taskList
  460. ctx.HTML(http.StatusOK, tplGrampusTrainJobShow)
  461. }
  462. func GrampusGetLog(ctx *context.Context) {
  463. jobID := ctx.Params(":jobid")
  464. job, err := models.GetCloudbrainByJobID(jobID)
  465. if err != nil {
  466. log.Error("GetCloudbrainByJobID failed: %v", err, ctx.Data["MsgID"])
  467. ctx.ServerError(err.Error(), err)
  468. return
  469. }
  470. content, err := grampus.GetTrainJobLog(job.JobID)
  471. if err != nil {
  472. log.Error("GetJobLog failed: %v", err, ctx.Data["MsgID"])
  473. ctx.ServerError(err.Error(), err)
  474. return
  475. }
  476. ctx.JSON(http.StatusOK, map[string]interface{}{
  477. "JobName": job.JobName,
  478. "Content": content,
  479. })
  480. return
  481. }
  482. func generateCommand(processorType, codePath, dataPath, params, outputPath string) (string, error) {
  483. var command string
  484. //download code
  485. //download dataset
  486. //unzip dataset
  487. //exec code
  488. //upload models
  489. return command, nil
  490. }