Browse Source

云脑任务运维列表

tags/v1.22.2.2^2
ychao_1983 3 years ago
parent
commit
80ec65ea46
3 changed files with 151 additions and 8 deletions
  1. +50
    -8
      models/cloudbrain.go
  2. +98
    -0
      routers/admin/cloudbrains.go
  3. +3
    -0
      routers/routes/routes.go

+ 50
- 8
models/cloudbrain.go View File

@@ -209,17 +209,20 @@ type GetImagesPayload struct {

type CloudbrainsOptions struct {
ListOptions
RepoID int64 // include all repos if empty
UserID int64
JobID string
SortType string
CloudbrainIDs []int64
// JobStatus CloudbrainStatus
RepoID int64 // include all repos if empty
UserID int64
JobID string
SortType string
CloudbrainIDs []int64
JobStatus []string
JobStatusNot bool
Keyword string
Type int
JobTypes []string
VersionName string
IsLatestVersion string
JobTypeNot bool
NeedRepoInfo bool
}

type TaskPod struct {
@@ -1015,7 +1018,32 @@ func Cloudbrains(opts *CloudbrainsOptions) ([]*CloudbrainInfo, int64, error) {
cond = cond.And(builder.In("cloudbrain.id", opts.CloudbrainIDs))
}

count, err := sess.Where(cond).Count(new(Cloudbrain))
if len(opts.JobStatus) > 0 {
if opts.JobStatusNot {
cond = cond.And(
builder.NotIn("cloudbrain.status", opts.JobStatus),
)
} else {
cond = cond.And(
builder.In("cloudbrain.status", opts.JobStatus),
)
}
}

var count int64
var err error
condition := "cloudbrain.user_id = `user`.id"
if len(opts.Keyword) == 0 {
count, err = sess.Where(cond).Count(new(Cloudbrain))
} else {
lowerKeyWord := strings.ToLower(opts.Keyword)

cond = cond.And(builder.Or(builder.Like{"LOWER(cloudbrain.job_name)", lowerKeyWord}), builder.Like{"`user`.lower_name", lowerKeyWord})
count, err = sess.Table(&Cloudbrain{}).Where(cond).
Join("left", "`user`", condition).Count(new(CloudbrainInfo))

}

if err != nil {
return nil, 0, fmt.Errorf("Count: %v", err)
}
@@ -1033,11 +1061,25 @@ func Cloudbrains(opts *CloudbrainsOptions) ([]*CloudbrainInfo, int64, error) {
sess.OrderBy("cloudbrain.created_unix DESC")
cloudbrains := make([]*CloudbrainInfo, 0, setting.UI.IssuePagingNum)
if err := sess.Table(&Cloudbrain{}).Where(cond).
Join("left", "`user`", "cloudbrain.user_id = `user`.id").
Join("left", "`user`", condition).
Find(&cloudbrains); err != nil {
return nil, 0, fmt.Errorf("Find: %v", err)
}

if opts.NeedRepoInfo {
var ids []int64
for _, task := range cloudbrains {
ids = append(ids, task.RepoID)
}
repositoryMap, err := GetRepositoriesMapByIDs(ids)
if err == nil {
for _, task := range cloudbrains {
task.Repo = repositoryMap[task.RepoID]
}
}

}

return cloudbrains, count, nil
}



+ 98
- 0
routers/admin/cloudbrains.go View File

@@ -0,0 +1,98 @@
package admin

import (
"strings"

"code.gitea.io/gitea/modules/modelarts"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
)

const (
tplCloudBrains base.TplName = "admin/cloudbrain/list"
)

func CloudBrains(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("admin.cloudBrains")
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminCloudBrains"] = true

listType := ctx.Query("listType")
jobType := ctx.Query("jobType")
jobStatus := ctx.Query("jobStatus")

ctx.Data["ListType"] = listType
ctx.Data["JobType"] = jobType
ctx.Data["JobStatus"] = jobStatus

page := ctx.QueryInt("page")
if page <= 0 {
page = 1
}
debugType := modelarts.DebugType
if listType == models.GPUResource {
debugType = models.TypeCloudBrainOne
} else if listType == models.NPUResource {
debugType = models.TypeCloudBrainTwo
}

var jobTypes []string
jobTypeNot := false
if jobType == string(models.JobTypeDebug) {
jobTypes = append(jobTypes, string(models.JobTypeSnn4imagenet), string(models.JobTypeBrainScore), string(models.JobTypeDebug))
} else if jobType != "all" && jobType != "" {
jobTypes = append(jobTypes, jobType)
}

var jobStatuses []string
jobStatusNot := false
if jobStatus == "other" {
jobStatusNot = true
jobStatuses = append(jobStatuses, string(models.ModelArtsTrainJobWaiting), string(models.ModelArtsTrainJobFailed), string(models.ModelArtsRunning), string(models.ModelArtsTrainJobCompleted),
string(models.ModelArtsStarting), string(models.ModelArtsRestarting), string(models.ModelArtsStartFailed),
string(models.ModelArtsStopping), string(models.ModelArtsStopped))
} else if jobStatus != "all" && jobStatus != "" {
jobStatuses = append(jobStatuses, jobStatus)
}

keyword := strings.Trim(ctx.Query("q"), " ")

ciTasks, count, err := models.Cloudbrains(&models.CloudbrainsOptions{
ListOptions: models.ListOptions{
Page: page,
PageSize: setting.UI.IssuePagingNum,
},
Keyword: keyword,
Type: debugType,
JobTypeNot: jobTypeNot,
JobStatusNot: jobStatusNot,
JobStatus: jobStatuses,
JobTypes: jobTypes,
NeedRepoInfo: true,
})
if err != nil {
ctx.ServerError("Get job failed:", err)
return
}

for i, task := range ciTasks {
ciTasks[i].CanDebug = true
ciTasks[i].CanDel = true
ciTasks[i].Cloudbrain.ComputeResource = task.ComputeResource
}

pager := context.NewPagination(int(count), setting.UI.IssuePagingNum, page, 5)
pager.SetDefaultParams(ctx)
pager.AddParam(ctx, "listType", "ListType")
ctx.Data["Page"] = pager
ctx.Data["PageIsCloudBrain"] = true
ctx.Data["Tasks"] = ciTasks
ctx.Data["CanCreate"] = true
ctx.Data["Keyword"] = keyword

ctx.HTML(200, tplCloudBrains)

}

+ 3
- 0
routers/routes/routes.go View File

@@ -507,6 +507,9 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("", admin.Datasets)
// m.Post("/delete", admin.DeleteDataset)
})
m.Group("/cloudbrains", func() {
m.Get("", admin.CloudBrains)
})

m.Group("/^:configType(hooks|system-hooks)$", func() {
m.Get("", admin.DefaultOrSystemWebhooks)


Loading…
Cancel
Save