|
|
@@ -28,15 +28,17 @@ import ( |
|
|
|
) |
|
|
|
|
|
|
|
const ( |
|
|
|
tplCloudBrainIndex base.TplName = "repo/cloudbrain/index" |
|
|
|
tplCloudBrainNew base.TplName = "repo/cloudbrain/new" |
|
|
|
tplCloudBrainShow base.TplName = "repo/cloudbrain/show" |
|
|
|
tplCloudBrainShowModels base.TplName = "repo/cloudbrain/models/index" |
|
|
|
|
|
|
|
tplCloudBrainBenchmarkNew base.TplName = "repo/cloudbrain/benchmark/new" |
|
|
|
) |
|
|
|
|
|
|
|
var ( |
|
|
|
gpuInfos *models.GpuInfos |
|
|
|
categories *models.Categories |
|
|
|
benchmarkTypes *models.BenchmarkTypes |
|
|
|
) |
|
|
|
|
|
|
|
var jobNamePattern = regexp.MustCompile(`^[a-z0-9][a-z0-9-_]{1,34}[a-z0-9-]$`) |
|
|
@@ -124,6 +126,11 @@ func cloudBrainNewDataPrepare(ctx *context.Context) error { |
|
|
|
} |
|
|
|
ctx.Data["benchmark_categories"] = categories.Category |
|
|
|
|
|
|
|
if benchmarkTypes == nil { |
|
|
|
json.Unmarshal([]byte(setting.BenchmarkTypes), &benchmarkTypes) |
|
|
|
} |
|
|
|
ctx.Data["benchmark_types"] = benchmarkTypes.BenchmarkType |
|
|
|
|
|
|
|
if gpuInfos == nil { |
|
|
|
json.Unmarshal([]byte(setting.GpuTypes), &gpuInfos) |
|
|
|
} |
|
|
@@ -157,6 +164,7 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { |
|
|
|
image := form.Image |
|
|
|
uuid := form.Attachment |
|
|
|
jobType := form.JobType |
|
|
|
command := cloudbrain.Command |
|
|
|
gpuQueue := form.GpuType |
|
|
|
codePath := setting.JobPath + jobName + cloudbrain.CodeMountPath |
|
|
|
resourceSpecId := form.ResourceSpecId |
|
|
@@ -173,13 +181,6 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
var command string |
|
|
|
if jobType == string(models.JobTypeBenchmark) { |
|
|
|
command = cloudbrain.CommandBenchmark |
|
|
|
} else { |
|
|
|
command = cloudbrain.Command |
|
|
|
} |
|
|
|
|
|
|
|
count, err := models.GetCloudbrainCountByUserID(ctx.User.ID, jobType) |
|
|
|
if err != nil { |
|
|
|
log.Error("GetCloudbrainCountByUserID failed:%v", err, ctx.Data["MsgID"]) |
|
|
@@ -244,18 +245,14 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { |
|
|
|
err = cloudbrain.GenerateTask(ctx, jobName, image, command, uuid, storage.GetMinioPath(jobName, cloudbrain.CodeMountPath+"/"), |
|
|
|
storage.GetMinioPath(jobName, cloudbrain.ModelMountPath+"/"), |
|
|
|
storage.GetMinioPath(jobName, cloudbrain.BenchMarkMountPath+"/"), storage.GetMinioPath(jobName, cloudbrain.Snn4imagenetMountPath+"/"), |
|
|
|
storage.GetMinioPath(jobName, cloudbrain.BrainScoreMountPath+"/"), jobType, gpuQueue, resourceSpecId) |
|
|
|
storage.GetMinioPath(jobName, cloudbrain.BrainScoreMountPath+"/"), jobType, gpuQueue, "", resourceSpecId) |
|
|
|
if err != nil { |
|
|
|
cloudBrainNewDataPrepare(ctx) |
|
|
|
ctx.RenderWithErr(err.Error(), tplCloudBrainNew, &form) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if jobType == string(models.JobTypeBenchmark) { |
|
|
|
ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/debugjob?debugListType=all") |
|
|
|
} else { |
|
|
|
ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/debugjob?debugListType=all") |
|
|
|
} |
|
|
|
ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/debugjob?debugListType=all") |
|
|
|
} |
|
|
|
|
|
|
|
func CloudBrainRestart(ctx *context.Context) { |
|
|
@@ -934,3 +931,152 @@ func SyncCloudbrainStatus() { |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func CloudBrainBenchmarkIndex(ctx *context.Context) { |
|
|
|
MustEnableCloudbrain(ctx) |
|
|
|
repo := ctx.Repo.Repository |
|
|
|
page := ctx.QueryInt("page") |
|
|
|
if page <= 0 { |
|
|
|
page = 1 |
|
|
|
} |
|
|
|
|
|
|
|
ciTasks, count, err := models.Cloudbrains(&models.CloudbrainsOptions{ |
|
|
|
ListOptions: models.ListOptions{ |
|
|
|
Page: page, |
|
|
|
PageSize: setting.UI.IssuePagingNum, |
|
|
|
}, |
|
|
|
RepoID: repo.ID, |
|
|
|
Type: models.TypeCloudBrainOne, |
|
|
|
JobType: string(models.JobTypeBenchmark), |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
ctx.ServerError("Get debugjob faild:", err) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
for i, task := range ciTasks { |
|
|
|
ciTasks[i].CanDel = cloudbrain.CanDeleteJob(ctx, &task.Cloudbrain) |
|
|
|
ciTasks[i].Cloudbrain.ComputeResource = task.ComputeResource |
|
|
|
} |
|
|
|
|
|
|
|
pager := context.NewPagination(int(count), setting.UI.IssuePagingNum, page, 5) |
|
|
|
pager.AddParam(ctx, "debugListType", "ListType") |
|
|
|
ctx.Data["Page"] = pager |
|
|
|
ctx.Data["PageIsCloudBrain"] = true |
|
|
|
ctx.Data["Tasks"] = ciTasks |
|
|
|
ctx.Data["CanCreate"] = cloudbrain.CanCreateOrDebugJob(ctx) |
|
|
|
ctx.Data["RepoIsEmpty"] = repo.IsEmpty |
|
|
|
ctx.HTML(200, tplDebugJobIndex) |
|
|
|
} |
|
|
|
|
|
|
|
func CloudBrainBenchmarkNew(ctx *context.Context) { |
|
|
|
err := cloudBrainNewDataPrepare(ctx) |
|
|
|
if err != nil { |
|
|
|
ctx.ServerError("get new cloudbrain info failed", err) |
|
|
|
return |
|
|
|
} |
|
|
|
ctx.HTML(200, tplCloudBrainBenchmarkNew) |
|
|
|
} |
|
|
|
|
|
|
|
func CloudBrainBenchmarkCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { |
|
|
|
ctx.Data["PageIsCloudBrain"] = true |
|
|
|
jobName := form.JobName |
|
|
|
image := form.Image |
|
|
|
uuid := form.Attachment |
|
|
|
jobType := form.JobType |
|
|
|
gpuQueue := form.GpuType |
|
|
|
command := cloudbrain.CommandBenchmark |
|
|
|
codePath := setting.JobPath + jobName + cloudbrain.CodeMountPath |
|
|
|
resourceSpecId := form.ResourceSpecId |
|
|
|
benchmarkType := form.BenchmarkType |
|
|
|
|
|
|
|
if !jobNamePattern.MatchString(jobName) { |
|
|
|
ctx.RenderWithErr(ctx.Tr("repo.cloudbrain_jobname_err"), tplCloudBrainBenchmarkNew, &form) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if jobType != string(models.JobTypeBenchmark) { |
|
|
|
log.Error("jobtype error:", jobType, ctx.Data["MsgID"]) |
|
|
|
cloudBrainNewDataPrepare(ctx) |
|
|
|
ctx.RenderWithErr("jobtype error", tplCloudBrainBenchmarkNew, &form) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
count, err := models.GetCloudbrainCountByUserID(ctx.User.ID, jobType) |
|
|
|
if err != nil { |
|
|
|
log.Error("GetCloudbrainCountByUserID failed:%v", err, ctx.Data["MsgID"]) |
|
|
|
cloudBrainNewDataPrepare(ctx) |
|
|
|
ctx.RenderWithErr("system error", tplCloudBrainBenchmarkNew, &form) |
|
|
|
return |
|
|
|
} else { |
|
|
|
if count >= 1 { |
|
|
|
log.Error("the user already has running or waiting task", ctx.Data["MsgID"]) |
|
|
|
cloudBrainNewDataPrepare(ctx) |
|
|
|
ctx.RenderWithErr("you have already a running or waiting task, can not create more", tplCloudBrainBenchmarkNew, &form) |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
_, err = models.GetCloudbrainByName(jobName) |
|
|
|
if err == nil { |
|
|
|
log.Error("the job name did already exist", ctx.Data["MsgID"]) |
|
|
|
cloudBrainNewDataPrepare(ctx) |
|
|
|
ctx.RenderWithErr("the job name did already exist", tplCloudBrainBenchmarkNew, &form) |
|
|
|
return |
|
|
|
} else { |
|
|
|
if !models.IsErrJobNotExist(err) { |
|
|
|
log.Error("system error, %v", err, ctx.Data["MsgID"]) |
|
|
|
cloudBrainNewDataPrepare(ctx) |
|
|
|
ctx.RenderWithErr("system error", tplCloudBrainBenchmarkNew, &form) |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
repo := ctx.Repo.Repository |
|
|
|
if err := downloadCode(repo, codePath); err != nil { |
|
|
|
log.Error("system error, %v", err, ctx.Data["MsgID"]) |
|
|
|
cloudBrainNewDataPrepare(ctx) |
|
|
|
ctx.RenderWithErr("system error", tplCloudBrainBenchmarkNew, &form) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if err := uploadCodeToMinio(codePath+"/", jobName, cloudbrain.CodeMountPath+"/"); err != nil { |
|
|
|
log.Error("system error, %v", err, ctx.Data["MsgID"]) |
|
|
|
cloudBrainNewDataPrepare(ctx) |
|
|
|
ctx.RenderWithErr("system error", tplCloudBrainBenchmarkNew, &form) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
benchmarkPath := setting.JobPath + jobName + cloudbrain.BenchMarkMountPath |
|
|
|
var gpuType string |
|
|
|
for _, gpuInfo := range gpuInfos.GpuInfo { |
|
|
|
if gpuInfo.Queue == gpuQueue { |
|
|
|
gpuType = gpuInfo.Value |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if err := downloadRateCode(repo, jobName, setting.BenchmarkOwner, setting.BenchmarkName, benchmarkPath, form.BenchmarkCategory, gpuType); err != nil { |
|
|
|
log.Error("system error, %v", err, ctx.Data["MsgID"]) |
|
|
|
cloudBrainNewDataPrepare(ctx) |
|
|
|
ctx.RenderWithErr("system error", tplCloudBrainBenchmarkNew, &form) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if err := uploadCodeToMinio(benchmarkPath+"/", jobName, cloudbrain.BenchMarkMountPath+"/"); err != nil { |
|
|
|
log.Error("system error, %v", err, ctx.Data["MsgID"]) |
|
|
|
cloudBrainNewDataPrepare(ctx) |
|
|
|
ctx.RenderWithErr("system error", tplCloudBrainBenchmarkNew, &form) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
err = cloudbrain.GenerateTask(ctx, jobName, image, command, uuid, storage.GetMinioPath(jobName, cloudbrain.CodeMountPath+"/"), |
|
|
|
storage.GetMinioPath(jobName, cloudbrain.ModelMountPath+"/"), |
|
|
|
storage.GetMinioPath(jobName, cloudbrain.BenchMarkMountPath+"/"), storage.GetMinioPath(jobName, cloudbrain.Snn4imagenetMountPath+"/"), |
|
|
|
storage.GetMinioPath(jobName, cloudbrain.BrainScoreMountPath+"/"), jobType, gpuQueue, benchmarkType, resourceSpecId) |
|
|
|
if err != nil { |
|
|
|
cloudBrainNewDataPrepare(ctx) |
|
|
|
ctx.RenderWithErr(err.Error(), tplCloudBrainBenchmarkNew, &form) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/cloudbrain/benchmark") |
|
|
|
} |