| @@ -3,6 +3,7 @@ package models | |||
| import ( | |||
| "encoding/json" | |||
| "fmt" | |||
| "strconv" | |||
| "strings" | |||
| "time" | |||
| @@ -90,7 +91,6 @@ const ( | |||
| type Cloudbrain struct { | |||
| ID int64 `xorm:"pk autoincr"` | |||
| JobID string `xorm:"INDEX NOT NULL"` | |||
| CloudBrainJobID string | |||
| JobType string `xorm:"INDEX NOT NULL DEFAULT 'DEBUG'"` | |||
| JobName string `xorm:"INDEX NOT NULL"` | |||
| DisplayJobName string | |||
| @@ -1306,6 +1306,12 @@ func GetCloudbrainByJobID(jobID string) (*Cloudbrain, error) { | |||
| return getRepoCloudBrain(cb) | |||
| } | |||
| func GetCloudbrainByID(id string) (*Cloudbrain, error) { | |||
| idInt64, _ := strconv.ParseInt(id, 10, 64) | |||
| cb := &Cloudbrain{ID: idInt64} | |||
| return getRepoCloudBrain(cb) | |||
| } | |||
| func GetCloudbrainByJobIDAndVersionName(jobID string, versionName string) (*Cloudbrain, error) { | |||
| cb := &Cloudbrain{JobID: jobID, VersionName: versionName} | |||
| return getRepoCloudBrain(cb) | |||
| @@ -6,7 +6,6 @@ import ( | |||
| "strconv" | |||
| "code.gitea.io/gitea/modules/storage" | |||
| "code.gitea.io/gitea/modules/util" | |||
| "code.gitea.io/gitea/models" | |||
| "code.gitea.io/gitea/modules/context" | |||
| @@ -206,14 +205,12 @@ func GenerateTask(ctx *context.Context, displayJobName, jobName, image, command, | |||
| return errors.New(jobResult.Msg) | |||
| } | |||
| var cloudBrainJobID = jobResult.Payload["jobId"].(string) | |||
| jobID := util.ConvertCloudBrainIdToJobId(cloudBrainJobID) | |||
| var jobID = jobResult.Payload["jobId"].(string) | |||
| err = models.CreateCloudbrain(&models.Cloudbrain{ | |||
| Status: string(models.JobWaiting), | |||
| UserID: ctx.User.ID, | |||
| RepoID: ctx.Repo.Repository.ID, | |||
| JobID: jobID, | |||
| CloudBrainJobID: cloudBrainJobID, | |||
| JobName: jobName, | |||
| DisplayJobName: displayJobName, | |||
| SubTaskName: SubTaskName, | |||
| @@ -340,13 +337,12 @@ func RestartTask(ctx *context.Context, task *models.Cloudbrain, newJobID *string | |||
| return errors.New(jobResult.Msg) | |||
| } | |||
| var cloudBrainJobID = jobResult.Payload["jobId"].(string) | |||
| var jobID = jobResult.Payload["jobId"].(string) | |||
| newTask := &models.Cloudbrain{ | |||
| Status: string(models.JobWaiting), | |||
| UserID: task.UserID, | |||
| RepoID: task.RepoID, | |||
| JobID: task.JobID, | |||
| CloudBrainJobID: cloudBrainJobID, | |||
| JobID: jobID, | |||
| JobName: task.JobName, | |||
| DisplayJobName: task.DisplayJobName, | |||
| SubTaskName: task.SubTaskName, | |||
| @@ -119,12 +119,6 @@ func ConvertDisplayJobNameToJobName(DisplayName string) (JobName string) { | |||
| return JobName | |||
| } | |||
| func ConvertCloudBrainIdToJobId(CloudBrainJobID string) (JobID string) { | |||
| t := time.Now() | |||
| JobID = "jobid" + strings.ToLower(cutNameString(CloudBrainJobID, 15)) + "t" + t.Format("2006010215") + strconv.Itoa(int(rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(100000))) | |||
| return JobID | |||
| } | |||
| func cutNameString(str string, lens int) string { | |||
| if len(str) < lens { | |||
| return str | |||
| @@ -58,7 +58,7 @@ func GetCloudbrainTask(ctx *context.APIContext) { | |||
| ctx.Data["error"] = err.Error() | |||
| } | |||
| // jobResult, err := cloudbrain.GetJob(job.JobID) | |||
| jobResult, err := cloudbrain.GetJob(job.CloudBrainJobID) | |||
| jobResult, err := cloudbrain.GetJob(jobID) | |||
| if err != nil { | |||
| ctx.NotFound(err) | |||
| return | |||
| @@ -107,7 +107,7 @@ func CloudbrainGetLog(ctx *context.Context) { | |||
| } | |||
| var hits []models.Hits | |||
| result, err := cloudbrain.GetJobLog(job.CloudBrainJobID) | |||
| result, err := cloudbrain.GetJobLog(jobID) | |||
| if err != nil { | |||
| log.Error("GetJobLog failed: %v", err, ctx.Data["MsgID"]) | |||
| ctx.ServerError(err.Error(), err) | |||
| @@ -279,7 +279,7 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { | |||
| } | |||
| func CloudBrainRestart(ctx *context.Context) { | |||
| var jobID = ctx.Params(":jobid") | |||
| var ID = ctx.Params(":id") | |||
| var resultCode = "0" | |||
| var errorMsg = "" | |||
| var status = string(models.JobWaiting) | |||
| @@ -322,7 +322,7 @@ func CloudBrainRestart(ctx *context.Context) { | |||
| } | |||
| } | |||
| err = cloudbrain.RestartTask(ctx, task, &task.CloudBrainJobID) | |||
| err = cloudbrain.RestartTask(ctx, task, &task.JobID) | |||
| if err != nil { | |||
| log.Error("RestartTask failed:%v", err.Error(), ctx.Data["MsgID"]) | |||
| resultCode = "-1" | |||
| @@ -337,7 +337,7 @@ func CloudBrainRestart(ctx *context.Context) { | |||
| "result_code": resultCode, | |||
| "error_msg": errorMsg, | |||
| "status": status, | |||
| "job_id": jobID, | |||
| "id": ID, | |||
| }) | |||
| } | |||
| @@ -356,13 +356,13 @@ func CloudBrainShow(ctx *context.Context) { | |||
| func cloudBrainShow(ctx *context.Context, tpName base.TplName) { | |||
| ctx.Data["PageIsCloudBrain"] = true | |||
| var jobID = ctx.Params(":jobid") | |||
| var ID = ctx.Params(":id") | |||
| debugListType := ctx.Query("debugListType") | |||
| task, err := models.GetCloudbrainByJobID(jobID) | |||
| task, err := models.GetCloudbrainByID(ID) | |||
| if err != nil { | |||
| ctx.Data["error"] = err.Error() | |||
| } | |||
| result, err := cloudbrain.GetJob(task.CloudBrainJobID) | |||
| result, err := cloudbrain.GetJob(task.JobID) | |||
| if err != nil { | |||
| ctx.Data["error"] = err.Error() | |||
| } | |||
| @@ -437,13 +437,12 @@ func cloudBrainShow(ctx *context.Context, tpName base.TplName) { | |||
| } | |||
| func CloudBrainDebug(ctx *context.Context) { | |||
| // debugUrl := setting.DebugServerHost + "jpylab_" + ctx.Cloudbrain.JobID + "_" + ctx.Cloudbrain.SubTaskName | |||
| debugUrl := setting.DebugServerHost + "jpylab_" + ctx.Cloudbrain.CloudBrainJobID + "_" + ctx.Cloudbrain.SubTaskName | |||
| debugUrl := setting.DebugServerHost + "jpylab_" + ctx.Cloudbrain.JobID + "_" + ctx.Cloudbrain.SubTaskName | |||
| ctx.Redirect(debugUrl) | |||
| } | |||
| func CloudBrainCommitImage(ctx *context.Context, form auth.CommitImageCloudBrainForm) { | |||
| err := cloudbrain.CommitImage(ctx.Cloudbrain.CloudBrainJobID, models.CommitImageParams{ | |||
| err := cloudbrain.CommitImage(ctx.Cloudbrain.JobID, models.CommitImageParams{ | |||
| Ip: ctx.Cloudbrain.ContainerIp, | |||
| TaskContainerId: ctx.Cloudbrain.ContainerID, | |||
| ImageDescription: form.Description, | |||
| @@ -465,7 +464,7 @@ func CloudBrainCommitImage(ctx *context.Context, form auth.CommitImageCloudBrain | |||
| } | |||
| func CloudBrainStop(ctx *context.Context) { | |||
| var jobID = ctx.Params(":jobid") | |||
| var ID = ctx.Params(":id") | |||
| var resultCode = "0" | |||
| var errorMsg = "" | |||
| var status = "" | |||
| @@ -479,7 +478,7 @@ func CloudBrainStop(ctx *context.Context) { | |||
| break | |||
| } | |||
| err := cloudbrain.StopJob(task.CloudBrainJobID) | |||
| err := cloudbrain.StopJob(task.JobID) | |||
| if err != nil { | |||
| log.Error("StopJob(%s) failed:%v", task.JobName, err, ctx.Data["msgID"]) | |||
| resultCode = "-1" | |||
| @@ -504,7 +503,7 @@ func CloudBrainStop(ctx *context.Context) { | |||
| "result_code": resultCode, | |||
| "error_msg": errorMsg, | |||
| "status": status, | |||
| "job_id": jobID, | |||
| "id": ID, | |||
| }) | |||
| } | |||
| @@ -626,10 +625,10 @@ func deleteCloudbrainJob(ctx *context.Context) error { | |||
| func CloudBrainShowModels(ctx *context.Context) { | |||
| ctx.Data["PageIsCloudBrain"] = true | |||
| jobID := ctx.Params(":jobid") | |||
| ID := ctx.Params(":id") | |||
| parentDir := ctx.Query("parentDir") | |||
| dirArray := strings.Split(parentDir, "/") | |||
| task, err := models.GetCloudbrainByJobID(jobID) | |||
| task, err := models.GetCloudbrainByID(ID) | |||
| if err != nil { | |||
| log.Error("no such job!", ctx.Data["msgID"]) | |||
| ctx.ServerError("no such job:", err) | |||
| @@ -733,8 +732,8 @@ func GetRate(ctx *context.Context) { | |||
| return | |||
| } | |||
| var jobID = ctx.Params(":jobid") | |||
| job, err := models.GetCloudbrainByJobID(jobID) | |||
| var ID = ctx.Params(":id") | |||
| job, err := models.GetCloudbrainByID(ID) | |||
| if err != nil { | |||
| ctx.ServerError("GetCloudbrainByJobID failed", err) | |||
| return | |||
| @@ -939,7 +938,7 @@ func SyncCloudbrainStatus() { | |||
| for _, task := range cloudBrains { | |||
| if task.Type == models.TypeCloudBrainOne { | |||
| result, err := cloudbrain.GetJob(task.CloudBrainJobID) | |||
| result, err := cloudbrain.GetJob(task.JobID) | |||
| if err != nil { | |||
| log.Error("GetJob(%s) failed:%v", task.JobName, err) | |||
| continue | |||
| @@ -238,15 +238,15 @@ func NotebookShow(ctx *context.Context) { | |||
| ctx.Data["PageIsCloudBrain"] = true | |||
| debugListType := ctx.Query("debugListType") | |||
| var jobID = ctx.Params(":jobid") | |||
| task, err := models.GetCloudbrainByJobID(jobID) | |||
| var ID = ctx.Params(":id") | |||
| task, err := models.GetCloudbrainByID(ID) | |||
| if err != nil { | |||
| ctx.Data["error"] = err.Error() | |||
| ctx.RenderWithErr(err.Error(), tplModelArtsNotebookShow, nil) | |||
| return | |||
| } | |||
| result, err := modelarts.GetNotebook2(jobID) | |||
| result, err := modelarts.GetNotebook2(task.JobID) | |||
| if err != nil { | |||
| ctx.Data["error"] = err.Error() | |||
| ctx.RenderWithErr(err.Error(), tplModelArtsNotebookShow, nil) | |||
| @@ -278,7 +278,7 @@ func NotebookShow(ctx *context.Context) { | |||
| ctx.Data["datasetDownloadLink"] = datasetDownloadLink | |||
| ctx.Data["task"] = task | |||
| ctx.Data["jobID"] = jobID | |||
| ctx.Data["ID"] = ID | |||
| ctx.Data["jobName"] = task.JobName | |||
| ctx.Data["result"] = result | |||
| ctx.Data["debugListType"] = debugListType | |||
| @@ -313,9 +313,14 @@ func NotebookDebug(ctx *context.Context) { | |||
| } | |||
| func NotebookDebug2(ctx *context.Context) { | |||
| var jobID = ctx.Params(":jobid") | |||
| result, err := modelarts.GetNotebook2(jobID) | |||
| 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 | |||
| } | |||
| result, err := modelarts.GetNotebook2(task.JobID) | |||
| if err != nil { | |||
| ctx.RenderWithErr(err.Error(), tplModelArtsNotebookIndex, nil) | |||
| return | |||
| @@ -433,7 +438,6 @@ func NotebookManage(ctx *context.Context) { | |||
| } | |||
| func NotebookDel(ctx *context.Context) { | |||
| var jobID = ctx.Params(":jobid") | |||
| var listType = ctx.Query("debugListType") | |||
| task := ctx.Cloudbrain | |||
| @@ -443,7 +447,7 @@ func NotebookDel(ctx *context.Context) { | |||
| return | |||
| } | |||
| _, err := modelarts.DelNotebook2(jobID) | |||
| _, err := modelarts.DelNotebook2(task.JobID) | |||
| if err != nil { | |||
| log.Error("DelNotebook2(%s) failed:%v", task.JobName, err.Error()) | |||
| if strings.Contains(err.Error(), modelarts.NotebookNotFound) || strings.Contains(err.Error(), modelarts.NotebookNoPermission) { | |||
| @@ -990,7 +990,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
| }, context.RepoRef()) | |||
| m.Group("/cloudbrain", func() { | |||
| m.Group("/:jobid", func() { | |||
| m.Group("/:id", func() { | |||
| m.Get("", reqRepoCloudBrainReader, repo.CloudBrainShow) | |||
| m.Get("/debug", cloudbrain.AdminOrJobCreaterRight, repo.CloudBrainDebug) | |||
| m.Post("/commit_image", cloudbrain.AdminOrJobCreaterRight, bindIgnErr(auth.CommitImageCloudBrainForm{}), repo.CloudBrainCommitImage) | |||
| @@ -1006,7 +1006,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
| m.Group("/benchmark", func() { | |||
| m.Get("", reqRepoCloudBrainReader, repo.CloudBrainBenchmarkIndex) | |||
| m.Group("/:jobid", func() { | |||
| m.Group("/:id", func() { | |||
| m.Get("", reqRepoCloudBrainReader, repo.CloudBrainBenchMarkShow) | |||
| m.Post("/stop", cloudbrain.AdminOrOwnerOrJobCreaterRight, repo.CloudBrainStop) | |||
| m.Post("/del", cloudbrain.AdminOrOwnerOrJobCreaterRight, repo.BenchmarkDel) | |||
| @@ -1055,7 +1055,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
| m.Get("/create", reqRepoCloudBrainWriter, repo.NotebookNew) | |||
| m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateModelArtsNotebookForm{}), repo.NotebookCreate) | |||
| */ | |||
| m.Group("/:jobid", func() { | |||
| m.Group("/:id", func() { | |||
| m.Get("", reqRepoCloudBrainReader, repo.NotebookShow) | |||
| m.Get("/debug", cloudbrain.AdminOrJobCreaterRight, repo.NotebookDebug2) | |||
| m.Post("/:action", reqRepoCloudBrainWriter, repo.NotebookManage) | |||