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