|
|
@@ -42,6 +42,7 @@ var ( |
|
|
|
categories *models.Categories |
|
|
|
benchmarkTypes *models.BenchmarkTypes |
|
|
|
benchmarkGpuInfos *models.GpuInfos |
|
|
|
benchmarkResourceSpecs *models.ResourceSpecs |
|
|
|
) |
|
|
|
|
|
|
|
var jobNamePattern = regexp.MustCompile(`^[a-z0-9][a-z0-9-_]{1,34}[a-z0-9-]$`) |
|
|
@@ -146,6 +147,11 @@ func cloudBrainNewDataPrepare(ctx *context.Context) error { |
|
|
|
} |
|
|
|
ctx.Data["benchmark_gpu_types"] = benchmarkGpuInfos.GpuInfo |
|
|
|
|
|
|
|
if benchmarkResourceSpecs == nil { |
|
|
|
json.Unmarshal([]byte(setting.BenchmarkResourceSpecs), &benchmarkResourceSpecs) |
|
|
|
} |
|
|
|
ctx.Data["benchmark_resource_specs"] = benchmarkResourceSpecs.ResourceSpec |
|
|
|
|
|
|
|
if cloudbrain.ResourceSpecs == nil { |
|
|
|
json.Unmarshal([]byte(setting.ResourceSpecs), &cloudbrain.ResourceSpecs) |
|
|
|
} |
|
|
@@ -1116,6 +1122,32 @@ func getBenchmarkGpuQueue(gpuQueue string) (string, error) { |
|
|
|
return queue, nil |
|
|
|
} |
|
|
|
|
|
|
|
func getBenchmarkResourceSpec(resourceSpecID int) (int, error) { |
|
|
|
var id int |
|
|
|
if benchmarkResourceSpecs == nil { |
|
|
|
if err := json.Unmarshal([]byte(setting.BenchmarkResourceSpecs), &benchmarkResourceSpecs); err != nil { |
|
|
|
log.Error("json.Unmarshal BenchmarkResourceSpecs(%s) failed:%v", setting.BenchmarkResourceSpecs, err) |
|
|
|
return id, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var isExist bool |
|
|
|
for _, resourceSpec := range benchmarkResourceSpecs.ResourceSpec { |
|
|
|
if resourceSpecID == resourceSpec.Id { |
|
|
|
isExist = true |
|
|
|
id = resourceSpecID |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if !isExist { |
|
|
|
log.Error("no such resourceSpecID, %d", resourceSpecID) |
|
|
|
return id, errors.New("no such resourceSpec") |
|
|
|
} |
|
|
|
|
|
|
|
return id, nil |
|
|
|
} |
|
|
|
|
|
|
|
func CloudBrainBenchmarkCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { |
|
|
|
ctx.Data["PageIsCloudBrain"] = true |
|
|
|
jobName := form.JobName |
|
|
@@ -1148,6 +1180,14 @@ func CloudBrainBenchmarkCreate(ctx *context.Context, form auth.CreateCloudBrainF |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
_, err = getBenchmarkResourceSpec(resourceSpecId) |
|
|
|
if err != nil { |
|
|
|
log.Error("getBenchmarkResourceSpec failed:%v", err, ctx.Data["MsgID"]) |
|
|
|
cloudBrainNewDataPrepare(ctx) |
|
|
|
ctx.RenderWithErr("resource spec 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"]) |
|
|
@@ -1186,6 +1226,8 @@ func CloudBrainBenchmarkCreate(ctx *context.Context, form auth.CreateCloudBrainF |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
//todo: check the boot file(train.py&test.py) |
|
|
|
|
|
|
|
if err := uploadCodeToMinio(codePath+"/", jobName, cloudbrain.CodeMountPath+"/"); err != nil { |
|
|
|
log.Error("uploadCodeToMinio failed, %v", err, ctx.Data["MsgID"]) |
|
|
|
cloudBrainNewDataPrepare(ctx) |
|
|
|