| @@ -90,6 +90,7 @@ 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 | |||
| @@ -6,6 +6,7 @@ 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" | |||
| @@ -205,12 +206,14 @@ func GenerateTask(ctx *context.Context, displayJobName, jobName, image, command, | |||
| return errors.New(jobResult.Msg) | |||
| } | |||
| var jobID = jobResult.Payload["jobId"].(string) | |||
| var cloudBrainJobID = jobResult.Payload["jobId"].(string) | |||
| jobID := util.ConvertCloudBrainIdToJobId(cloudBrainJobID) | |||
| 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, | |||
| @@ -337,13 +340,15 @@ func RestartTask(ctx *context.Context, task *models.Cloudbrain, newJobID *string | |||
| return errors.New(jobResult.Msg) | |||
| } | |||
| var jobID = jobResult.Payload["jobId"].(string) | |||
| var cloudBrainJobID = jobResult.Payload["jobId"].(string) | |||
| newTask := &models.Cloudbrain{ | |||
| Status: string(models.JobWaiting), | |||
| UserID: task.UserID, | |||
| RepoID: task.RepoID, | |||
| JobID: jobID, | |||
| JobID: task.JobID, | |||
| CloudBrainJobID: cloudBrainJobID, | |||
| JobName: task.JobName, | |||
| DisplayJobName: task.DisplayJobName, | |||
| SubTaskName: task.SubTaskName, | |||
| JobType: task.JobType, | |||
| Type: task.Type, | |||
| @@ -360,7 +365,7 @@ func RestartTask(ctx *context.Context, task *models.Cloudbrain, newJobID *string | |||
| return err | |||
| } | |||
| *newJobID = jobID | |||
| *newJobID = task.JobID | |||
| return nil | |||
| } | |||
| @@ -115,10 +115,16 @@ func AddZero(t int64) (m string) { | |||
| func ConvertDisplayJobNameToJobName(DisplayName string) (JobName string) { | |||
| t := time.Now() | |||
| JobName = "openi" + strings.ToLower(cutNameString(DisplayName, 15)) + "t" + t.Format("2006010215") + strconv.Itoa(int(rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(100000))) | |||
| JobName = "jobname" + strings.ToLower(cutNameString(DisplayName, 15)) + "t" + t.Format("2006010215") + strconv.Itoa(int(rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(100000))) | |||
| 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 | |||
| @@ -881,7 +881,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
| }, reqAnyRepoReader()) | |||
| m.Group("/cloudbrain", func() { | |||
| m.Get("/:jobid", repo.GetCloudbrainTask) | |||
| m.Get("/:jobname/log", repo.CloudbrainGetLog) | |||
| m.Get("/:jobid/log", repo.CloudbrainGetLog) | |||
| }, reqRepoReader(models.UnitTypeCloudBrain)) | |||
| m.Group("/modelarts", func() { | |||
| m.Group("/notebook", func() { | |||
| @@ -57,7 +57,8 @@ func GetCloudbrainTask(ctx *context.APIContext) { | |||
| if err != nil { | |||
| ctx.Data["error"] = err.Error() | |||
| } | |||
| jobResult, err := cloudbrain.GetJob(job.JobID) | |||
| // jobResult, err := cloudbrain.GetJob(job.JobID) | |||
| jobResult, err := cloudbrain.GetJob(job.CloudBrainJobID) | |||
| if err != nil { | |||
| ctx.NotFound(err) | |||
| return | |||
| @@ -97,8 +98,8 @@ func GetCloudbrainTask(ctx *context.APIContext) { | |||
| } | |||
| func CloudbrainGetLog(ctx *context.Context) { | |||
| jobName := ctx.Params(":jobname") | |||
| job, err := models.GetCloudbrainByName(jobName) | |||
| jobID := ctx.Params(":jobid") | |||
| job, err := models.GetCloudbrainByJobID(jobID) | |||
| if err != nil { | |||
| log.Error("GetCloudbrainByJobName failed: %v", err, ctx.Data["MsgID"]) | |||
| ctx.ServerError(err.Error(), err) | |||
| @@ -106,7 +107,7 @@ func CloudbrainGetLog(ctx *context.Context) { | |||
| } | |||
| var hits []models.Hits | |||
| result, err := cloudbrain.GetJobLog(job.JobID) | |||
| result, err := cloudbrain.GetJobLog(job.CloudBrainJobID) | |||
| if err != nil { | |||
| log.Error("GetJobLog failed: %v", err, ctx.Data["MsgID"]) | |||
| ctx.ServerError(err.Error(), err) | |||
| @@ -145,7 +146,7 @@ func CloudbrainGetLog(ctx *context.Context) { | |||
| } | |||
| ctx.JSON(http.StatusOK, map[string]interface{}{ | |||
| "JobName": jobName, | |||
| "JobName": job.JobName, | |||
| "Content": content, | |||
| }) | |||
| @@ -322,7 +322,7 @@ func CloudBrainRestart(ctx *context.Context) { | |||
| } | |||
| } | |||
| err = cloudbrain.RestartTask(ctx, task, &jobID) | |||
| err = cloudbrain.RestartTask(ctx, task, &task.CloudBrainJobID) | |||
| if err != nil { | |||
| log.Error("RestartTask failed:%v", err.Error(), ctx.Data["MsgID"]) | |||
| resultCode = "-1" | |||
| @@ -356,13 +356,13 @@ func CloudBrainShow(ctx *context.Context) { | |||
| func cloudBrainShow(ctx *context.Context, tpName base.TplName) { | |||
| ctx.Data["PageIsCloudBrain"] = true | |||
| var jobName = ctx.Params(":jobname") | |||
| var jobID = ctx.Params(":jobid") | |||
| debugListType := ctx.Query("debugListType") | |||
| task, err := models.GetCloudbrainByName(jobName) | |||
| task, err := models.GetCloudbrainByJobID(jobID) | |||
| if err != nil { | |||
| ctx.Data["error"] = err.Error() | |||
| } | |||
| result, err := cloudbrain.GetJob(task.JobID) | |||
| result, err := cloudbrain.GetJob(task.CloudBrainJobID) | |||
| if err != nil { | |||
| ctx.Data["error"] = err.Error() | |||
| } | |||
| @@ -437,12 +437,13 @@ 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.JobID + "_" + ctx.Cloudbrain.SubTaskName | |||
| debugUrl := setting.DebugServerHost + "jpylab_" + ctx.Cloudbrain.CloudBrainJobID + "_" + ctx.Cloudbrain.SubTaskName | |||
| ctx.Redirect(debugUrl) | |||
| } | |||
| func CloudBrainCommitImage(ctx *context.Context, form auth.CommitImageCloudBrainForm) { | |||
| err := cloudbrain.CommitImage(ctx.Cloudbrain.JobID, models.CommitImageParams{ | |||
| err := cloudbrain.CommitImage(ctx.Cloudbrain.CloudBrainJobID, models.CommitImageParams{ | |||
| Ip: ctx.Cloudbrain.ContainerIp, | |||
| TaskContainerId: ctx.Cloudbrain.ContainerID, | |||
| ImageDescription: form.Description, | |||
| @@ -478,7 +479,7 @@ func CloudBrainStop(ctx *context.Context) { | |||
| break | |||
| } | |||
| err := cloudbrain.StopJob(jobID) | |||
| err := cloudbrain.StopJob(task.CloudBrainJobID) | |||
| if err != nil { | |||
| log.Error("StopJob(%s) failed:%v", task.JobName, err, ctx.Data["msgID"]) | |||
| resultCode = "-1" | |||
| @@ -938,7 +939,7 @@ func SyncCloudbrainStatus() { | |||
| for _, task := range cloudBrains { | |||
| if task.Type == models.TypeCloudBrainOne { | |||
| result, err := cloudbrain.GetJob(task.JobID) | |||
| result, err := cloudbrain.GetJob(task.CloudBrainJobID) | |||
| if err != nil { | |||
| log.Error("GetJob(%s) failed:%v", task.JobName, err) | |||
| continue | |||
| @@ -6,13 +6,14 @@ package routes | |||
| import ( | |||
| "bytes" | |||
| "code.gitea.io/gitea/routers/authentication" | |||
| "encoding/gob" | |||
| "net/http" | |||
| "path" | |||
| "text/template" | |||
| "time" | |||
| "code.gitea.io/gitea/routers/authentication" | |||
| "code.gitea.io/gitea/modules/cloudbrain" | |||
| "code.gitea.io/gitea/routers/operation" | |||
| @@ -989,10 +990,8 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
| }, context.RepoRef()) | |||
| m.Group("/cloudbrain", func() { | |||
| m.Group("/:jobname", func() { | |||
| m.Get("", reqRepoCloudBrainReader, repo.CloudBrainShow) | |||
| }) | |||
| m.Group("/:jobid", func() { | |||
| m.Get("", reqRepoCloudBrainReader, repo.CloudBrainShow) | |||
| m.Get("/debug", cloudbrain.AdminOrJobCreaterRight, repo.CloudBrainDebug) | |||
| m.Post("/commit_image", cloudbrain.AdminOrJobCreaterRight, bindIgnErr(auth.CommitImageCloudBrainForm{}), repo.CloudBrainCommitImage) | |||
| m.Post("/stop", cloudbrain.AdminOrOwnerOrJobCreaterRight, repo.CloudBrainStop) | |||
| @@ -1007,10 +1006,8 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
| m.Group("/benchmark", func() { | |||
| m.Get("", reqRepoCloudBrainReader, repo.CloudBrainBenchmarkIndex) | |||
| m.Group("/:jobname", func() { | |||
| m.Get("", reqRepoCloudBrainReader, repo.CloudBrainBenchMarkShow) | |||
| }) | |||
| m.Group("/:jobid", func() { | |||
| m.Get("", reqRepoCloudBrainReader, repo.CloudBrainBenchMarkShow) | |||
| m.Post("/stop", cloudbrain.AdminOrOwnerOrJobCreaterRight, repo.CloudBrainStop) | |||
| m.Post("/del", cloudbrain.AdminOrOwnerOrJobCreaterRight, repo.BenchmarkDel) | |||
| m.Get("/rate", reqRepoCloudBrainReader, repo.GetRate) | |||
| @@ -99,7 +99,7 @@ | |||
| <!-- 任务名 --> | |||
| <div class="three wide column padding0"> | |||
| <a class="title" href="{{$.Link}}/{{.JobName}}" title="{{.JobName}}" style="font-size: 14px;"> | |||
| <a class="title" href="{{$.Link}}/{{.JobID}}" title="{{.JobID}}" style="font-size: 14px;"> | |||
| <span class="fitted" style="width: 90%;vertical-align: middle;">{{.DisplayJobName}}</span> | |||
| </a> | |||
| </div> | |||
| @@ -287,7 +287,7 @@ | |||
| <div class="row"> | |||
| <!-- 任务名 --> | |||
| <div class="four wide column"> | |||
| <a class="title" href='{{if eq .ComputeResource "CPU/GPU"}}{{$.RepoLink}}/cloudbrain/{{.JobName}}{{else}}{{$.RepoLink}}/modelarts/notebook/{{.JobID}}{{end}}' title="{{.JobName}}" style="font-size: 14px;"> | |||
| <a class="title" href='{{if eq .ComputeResource "CPU/GPU"}}{{$.RepoLink}}/cloudbrain/{{.JobID}}{{else}}{{$.RepoLink}}/modelarts/notebook/{{.JobID}}{{end}}' title="{{.JobName}}" style="font-size: 14px;"> | |||
| <span class="fitted text_over" style="width: 90%;vertical-align: middle;">{{.DisplayJobName}}</span> | |||
| </a> | |||
| </div> | |||