| @@ -92,11 +92,11 @@ type Cloudbrain struct { | |||
| ID int64 `xorm:"pk autoincr"` | |||
| JobID string `xorm:"INDEX NOT NULL"` | |||
| JobType string `xorm:"INDEX NOT NULL DEFAULT 'DEBUG'"` | |||
| JobName string `xorm:"INDEX NOT NULL"` | |||
| JobName string | |||
| DisplayJobName string | |||
| Status string | |||
| UserID int64 | |||
| RepoID int64 | |||
| UserID int64 `xorm:"INDEX NOT NULL"` | |||
| RepoID int64 `xorm:"INDEX NOT NULL"` | |||
| SubTaskName string | |||
| ContainerID string | |||
| ContainerIp string | |||
| @@ -85,9 +85,38 @@ func isAdminOrJobCreater(ctx *context.Context, job *models.Cloudbrain, err error | |||
| func AdminOrOwnerOrJobCreaterRight(ctx *context.Context) { | |||
| var jobID = ctx.Params(":jobid") | |||
| var ID = ctx.Params(":id") | |||
| job, err := models.GetCloudbrainByID(ID) | |||
| if err != nil { | |||
| ctx.NotFound(ctx.Req.URL.RequestURI(), nil) | |||
| } | |||
| ctx.Cloudbrain = job | |||
| if !isAdminOrOwnerOrJobCreater(ctx, job, err) { | |||
| ctx.NotFound(ctx.Req.URL.RequestURI(), nil) | |||
| } | |||
| } | |||
| func AdminOrJobCreaterRight(ctx *context.Context) { | |||
| var ID = ctx.Params(":id") | |||
| job, err := models.GetCloudbrainByID(ID) | |||
| ctx.Cloudbrain = job | |||
| if !isAdminOrJobCreater(ctx, job, err) { | |||
| ctx.NotFound(ctx.Req.URL.RequestURI(), nil) | |||
| } | |||
| } | |||
| func AdminOrOwnerOrJobCreaterRightForTrain(ctx *context.Context) { | |||
| var jobID = ctx.Params(":jobid") | |||
| job, err := models.GetCloudbrainByJobID(jobID) | |||
| if err != nil { | |||
| ctx.NotFound(ctx.Req.URL.RequestURI(), nil) | |||
| } | |||
| ctx.Cloudbrain = job | |||
| if !isAdminOrOwnerOrJobCreater(ctx, job, err) { | |||
| @@ -96,10 +125,13 @@ func AdminOrOwnerOrJobCreaterRight(ctx *context.Context) { | |||
| } | |||
| func AdminOrJobCreaterRight(ctx *context.Context) { | |||
| func AdminOrJobCreaterRightForTrain(ctx *context.Context) { | |||
| var jobID = ctx.Params(":jobid") | |||
| job, err := models.GetCloudbrainByJobID(jobID) | |||
| if err != nil { | |||
| ctx.NotFound(ctx.Req.URL.RequestURI(), nil) | |||
| } | |||
| ctx.Cloudbrain = job | |||
| if !isAdminOrJobCreater(ctx, job, err) { | |||
| @@ -283,10 +283,7 @@ func CloudBrainRestart(ctx *context.Context) { | |||
| var resultCode = "0" | |||
| var errorMsg = "" | |||
| var status = string(models.JobWaiting) | |||
| task, err := models.GetCloudbrainByID(ID) | |||
| if err != nil { | |||
| ctx.Data["error"] = err.Error() | |||
| } | |||
| task := ctx.Cloudbrain | |||
| for { | |||
| if task.Status != string(models.JobStopped) && task.Status != string(models.JobSucceeded) && task.Status != string(models.JobFailed) { | |||
| log.Error("the job(%s) is not stopped", task.JobName, ctx.Data["MsgID"]) | |||
| @@ -439,12 +436,7 @@ func cloudBrainShow(ctx *context.Context, tpName base.TplName) { | |||
| } | |||
| func CloudBrainDebug(ctx *context.Context) { | |||
| var ID = ctx.Params(":id") | |||
| task, err := models.GetCloudbrainByID(ID) | |||
| if err != nil { | |||
| ctx.Data["error"] = err.Error() | |||
| } | |||
| task := ctx.Cloudbrain | |||
| debugUrl := setting.DebugServerHost + "jpylab_" + task.JobID + "_" + task.SubTaskName | |||
| ctx.Redirect(debugUrl) | |||
| } | |||
| @@ -477,12 +469,7 @@ func CloudBrainStop(ctx *context.Context) { | |||
| var errorMsg = "" | |||
| var status = "" | |||
| task, err := models.GetCloudbrainByID(ID) | |||
| if err != nil { | |||
| ctx.Data["error"] = err.Error() | |||
| } | |||
| // task := ctx.Cloudbrain | |||
| task := ctx.Cloudbrain | |||
| for { | |||
| if task.Status == string(models.JobStopped) || task.Status == string(models.JobFailed) || task.Status == string(models.JobSucceeded) { | |||
| log.Error("the job(%s) has been stopped", task.JobName, ctx.Data["msgID"]) | |||
| @@ -313,13 +313,7 @@ func NotebookDebug(ctx *context.Context) { | |||
| } | |||
| func NotebookDebug2(ctx *context.Context) { | |||
| var ID = ctx.Params(":id") | |||
| task, err := models.GetCloudbrainByID(ID) | |||
| if err != nil { | |||
| ctx.Data["error"] = err.Error() | |||
| ctx.RenderWithErr(err.Error(), tplModelArtsNotebookIndex, nil) | |||
| return | |||
| } | |||
| task := ctx.Cloudbrain | |||
| result, err := modelarts.GetNotebook2(task.JobID) | |||
| if err != nil { | |||
| ctx.RenderWithErr(err.Error(), tplModelArtsNotebookIndex, nil) | |||
| @@ -337,13 +331,7 @@ func NotebookManage(ctx *context.Context) { | |||
| var status = "" | |||
| for { | |||
| task, err := models.GetCloudbrainByID(ID) | |||
| if err != nil { | |||
| log.Error("GetCloudbrainByJobID failed:%v", err, ctx.Data["MsgID"]) | |||
| resultCode = "-1" | |||
| errorMsg = "system error" | |||
| break | |||
| } | |||
| task := ctx.Cloudbrain | |||
| if action == models.ActionStop { | |||
| if task.Status != string(models.ModelArtsRunning) { | |||
| @@ -2159,12 +2147,11 @@ func ResultDownload(ctx *context.Context) { | |||
| err error | |||
| ) | |||
| var jobID = ctx.Params(":jobid") | |||
| versionName := ctx.Query("version_name") | |||
| parentDir := ctx.Query("parent_dir") | |||
| fileName := ctx.Query("file_name") | |||
| log.Info("DownloadResult start.") | |||
| task, err := models.GetCloudbrainByJobID(jobID) | |||
| task := ctx.Cloudbrain | |||
| if err != nil { | |||
| ctx.Data["error"] = err.Error() | |||
| } | |||
| @@ -1069,11 +1069,11 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
| m.Get("", reqRepoCloudBrainReader, repo.TrainJobIndex) | |||
| m.Group("/:jobid", func() { | |||
| m.Get("", reqRepoCloudBrainReader, repo.TrainJobShow) | |||
| m.Post("/stop", cloudbrain.AdminOrOwnerOrJobCreaterRight, repo.TrainJobStop) | |||
| m.Post("/del", cloudbrain.AdminOrOwnerOrJobCreaterRight, repo.TrainJobDel) | |||
| m.Get("/model_download", cloudbrain.AdminOrJobCreaterRight, repo.ModelDownload) | |||
| m.Get("/create_version", reqWechatBind, cloudbrain.AdminOrJobCreaterRight, repo.TrainJobNewVersion) | |||
| m.Post("/create_version", reqWechatBind, cloudbrain.AdminOrJobCreaterRight, bindIgnErr(auth.CreateModelArtsTrainJobForm{}), repo.TrainJobCreateVersion) | |||
| m.Post("/stop", cloudbrain.AdminOrOwnerOrJobCreaterRightForTrain, repo.TrainJobStop) | |||
| m.Post("/del", cloudbrain.AdminOrOwnerOrJobCreaterRightForTrain, repo.TrainJobDel) | |||
| m.Get("/model_download", cloudbrain.AdminOrJobCreaterRightForTrain, repo.ModelDownload) | |||
| m.Get("/create_version", reqWechatBind, cloudbrain.AdminOrJobCreaterRightForTrain, repo.TrainJobNewVersion) | |||
| m.Post("/create_version", reqWechatBind, cloudbrain.AdminOrJobCreaterRightForTrain, bindIgnErr(auth.CreateModelArtsTrainJobForm{}), repo.TrainJobCreateVersion) | |||
| }) | |||
| m.Get("/create", reqWechatBind, reqRepoCloudBrainWriter, repo.TrainJobNew) | |||
| m.Post("/create", reqWechatBind, reqRepoCloudBrainWriter, bindIgnErr(auth.CreateModelArtsTrainJobForm{}), repo.TrainJobCreate) | |||
| @@ -1085,7 +1085,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
| m.Get("", reqRepoCloudBrainReader, repo.InferenceJobIndex) | |||
| m.Group("/:jobid", func() { | |||
| m.Get("", reqRepoCloudBrainReader, repo.InferenceJobShow) | |||
| m.Get("/result_download", cloudbrain.AdminOrJobCreaterRight, repo.ResultDownload) | |||
| m.Get("/result_download", cloudbrain.AdminOrJobCreaterRightForTrain, repo.ResultDownload) | |||
| m.Get("/downloadall", repo.DownloadMultiResultFile) | |||
| }) | |||
| m.Get("/create", reqWechatBind, reqRepoCloudBrainWriter, repo.InferenceJobNew) | |||