|
|
|
@@ -41,6 +41,7 @@ var ( |
|
|
|
gpuInfos *models.GpuInfos |
|
|
|
categories *models.Categories |
|
|
|
benchmarkTypes *models.BenchmarkTypes |
|
|
|
benchmarkGpuInfos *models.GpuInfos |
|
|
|
) |
|
|
|
|
|
|
|
var jobNamePattern = regexp.MustCompile(`^[a-z0-9][a-z0-9-_]{1,34}[a-z0-9-]$`) |
|
|
|
@@ -140,6 +141,11 @@ func cloudBrainNewDataPrepare(ctx *context.Context) error { |
|
|
|
} |
|
|
|
ctx.Data["gpu_types"] = gpuInfos.GpuInfo |
|
|
|
|
|
|
|
if benchmarkGpuInfos == nil { |
|
|
|
json.Unmarshal([]byte(setting.BenchmarkGpuTypes), &benchmarkGpuInfos) |
|
|
|
} |
|
|
|
ctx.Data["benchmark_gpu_types"] = benchmarkGpuInfos.GpuInfo |
|
|
|
|
|
|
|
if cloudbrain.ResourceSpecs == nil { |
|
|
|
json.Unmarshal([]byte(setting.ResourceSpecs), &cloudbrain.ResourceSpecs) |
|
|
|
} |
|
|
|
@@ -1084,6 +1090,32 @@ func getBenchmarkAttachment(benchmarkTypeID, benchmarkChildTypeID int) (string, |
|
|
|
return uuid, nil |
|
|
|
} |
|
|
|
|
|
|
|
func getBenchmarkGpuQueue(gpuQueue string) (string, error) { |
|
|
|
queue := "" |
|
|
|
if benchmarkGpuInfos == nil { |
|
|
|
if err := json.Unmarshal([]byte(setting.BenchmarkGpuTypes), &benchmarkGpuInfos); err != nil { |
|
|
|
log.Error("json.Unmarshal BenchmarkGpuTypes(%s) failed:%v", setting.BenchmarkGpuTypes, err) |
|
|
|
return queue, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var isExist bool |
|
|
|
for _, gpuInfo := range benchmarkGpuInfos.GpuInfo { |
|
|
|
if gpuQueue == gpuInfo.Queue { |
|
|
|
isExist = true |
|
|
|
queue = gpuQueue |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if !isExist { |
|
|
|
log.Error("no such gpuQueue, %s", gpuQueue) |
|
|
|
return queue, errors.New("no such gpuQueue") |
|
|
|
} |
|
|
|
|
|
|
|
return queue, nil |
|
|
|
} |
|
|
|
|
|
|
|
func CloudBrainBenchmarkCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { |
|
|
|
ctx.Data["PageIsCloudBrain"] = true |
|
|
|
jobName := form.JobName |
|
|
|
@@ -1108,6 +1140,14 @@ func CloudBrainBenchmarkCreate(ctx *context.Context, form auth.CreateCloudBrainF |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
_, err = getBenchmarkGpuQueue(gpuQueue) |
|
|
|
if err != nil { |
|
|
|
log.Error("getBenchmarkGpuQueue failed:%v", err, ctx.Data["MsgID"]) |
|
|
|
cloudBrainNewDataPrepare(ctx) |
|
|
|
ctx.RenderWithErr("gpu queue error", tplCloudBrainBenchmarkNew, &form) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
count, err := models.GetCloudbrainCountByUserID(ctx.User.ID, string(models.JobTypeBenchmark)) |
|
|
|
if err != nil { |
|
|
|
log.Error("GetCloudbrainCountByUserID failed:%v", err, ctx.Data["MsgID"]) |
|
|
|
@@ -1131,7 +1171,7 @@ func CloudBrainBenchmarkCreate(ctx *context.Context, form auth.CreateCloudBrainF |
|
|
|
return |
|
|
|
} else { |
|
|
|
if !models.IsErrJobNotExist(err) { |
|
|
|
log.Error("system error, %v", err, ctx.Data["MsgID"]) |
|
|
|
log.Error("GetCloudbrainByName failed, %v", err, ctx.Data["MsgID"]) |
|
|
|
cloudBrainNewDataPrepare(ctx) |
|
|
|
ctx.RenderWithErr("system error", tplCloudBrainBenchmarkNew, &form) |
|
|
|
return |
|
|
|
@@ -1140,14 +1180,14 @@ func CloudBrainBenchmarkCreate(ctx *context.Context, form auth.CreateCloudBrainF |
|
|
|
repo := ctx.Repo.Repository |
|
|
|
os.RemoveAll(codePath) |
|
|
|
if err := downloadCode(repo, codePath); err != nil { |
|
|
|
log.Error("system error, %v", err, ctx.Data["MsgID"]) |
|
|
|
log.Error("downloadCode failed, %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"]) |
|
|
|
log.Error("uploadCodeToMinio failed, %v", err, ctx.Data["MsgID"]) |
|
|
|
cloudBrainNewDataPrepare(ctx) |
|
|
|
ctx.RenderWithErr("system error", tplCloudBrainBenchmarkNew, &form) |
|
|
|
return |
|
|
|
@@ -1162,14 +1202,14 @@ func CloudBrainBenchmarkCreate(ctx *context.Context, form auth.CreateCloudBrainF |
|
|
|
} |
|
|
|
|
|
|
|
if err := downloadRateCode(repo, jobName, setting.BenchmarkOwner, setting.BenchmarkName, benchmarkPath, form.BenchmarkCategory, gpuType); err != nil { |
|
|
|
log.Error("system error, %v", err, ctx.Data["MsgID"]) |
|
|
|
log.Error("downloadRateCode failed, %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"]) |
|
|
|
log.Error("uploadCodeToMinio failed, %v", err, ctx.Data["MsgID"]) |
|
|
|
//cloudBrainNewDataPrepare(ctx) |
|
|
|
//ctx.RenderWithErr("system error", tplCloudBrainBenchmarkNew, &form) |
|
|
|
//return |
|
|
|
|