| @@ -48,6 +48,8 @@ var ( | |||||
| const BENCHMARK_TYPE_CODE = "repo.cloudbrain.benchmark.types" | const BENCHMARK_TYPE_CODE = "repo.cloudbrain.benchmark.types" | ||||
| var benchmarkTypesMap = make(map[string]*models.BenchmarkTypes, 0) | |||||
| var jobNamePattern = regexp.MustCompile(`^[a-z0-9][a-z0-9-_]{1,34}[a-z0-9-]$`) | var jobNamePattern = regexp.MustCompile(`^[a-z0-9][a-z0-9-_]{1,34}[a-z0-9-]$`) | ||||
| // MustEnableDataset check if repository enable internal cb | // MustEnableDataset check if repository enable internal cb | ||||
| @@ -133,12 +135,7 @@ func cloudBrainNewDataPrepare(ctx *context.Context) error { | |||||
| } | } | ||||
| ctx.Data["benchmark_categories"] = categories.Category | ctx.Data["benchmark_categories"] = categories.Category | ||||
| if benchmarkTypes == nil { | |||||
| if err := json.Unmarshal([]byte(i18n.Tr(ctx.Locale.Language(), BENCHMARK_TYPE_CODE)), &benchmarkTypes); err != nil { | |||||
| log.Error("json.Unmarshal BenchmarkTypes(%s) failed:%v", i18n.Tr(ctx.Locale.Language(), BENCHMARK_TYPE_CODE), err, ctx.Data["MsgID"]) | |||||
| } | |||||
| } | |||||
| ctx.Data["benchmark_types"] = benchmarkTypes.BenchmarkType | |||||
| ctx.Data["benchmark_types"] = GetBenchmarkTypes(ctx).BenchmarkType | |||||
| if gpuInfos == nil { | if gpuInfos == nil { | ||||
| json.Unmarshal([]byte(setting.GpuTypes), &gpuInfos) | json.Unmarshal([]byte(setting.GpuTypes), &gpuInfos) | ||||
| @@ -342,13 +339,6 @@ func CloudBrainRestart(ctx *context.Context) { | |||||
| } | } | ||||
| func CloudBrainBenchMarkShow(ctx *context.Context) { | func CloudBrainBenchMarkShow(ctx *context.Context) { | ||||
| if benchmarkTypes == nil { | |||||
| if err := json.Unmarshal([]byte(i18n.Tr(ctx.Locale.Language(), BENCHMARK_TYPE_CODE)), &benchmarkTypes); err != nil { | |||||
| log.Error("json.Unmarshal BenchmarkTypes(%s) failed:%v", i18n.Tr(ctx.Locale.Language(), BENCHMARK_TYPE_CODE), err, ctx.Data["MsgID"]) | |||||
| ctx.ServerError(err.Error(), err) | |||||
| return | |||||
| } | |||||
| } | |||||
| cloudBrainShow(ctx, tplCloudBrainBenchmarkShow) | cloudBrainShow(ctx, tplCloudBrainBenchmarkShow) | ||||
| } | } | ||||
| @@ -415,7 +405,7 @@ func cloudBrainShow(ctx *context.Context, tpName base.TplName) { | |||||
| duration = int64(task.UpdatedUnix) - int64(task.CreatedUnix) | duration = int64(task.UpdatedUnix) - int64(task.CreatedUnix) | ||||
| } | } | ||||
| if task.BenchmarkTypeID > 0 { | if task.BenchmarkTypeID > 0 { | ||||
| for _, benchmarkType := range benchmarkTypes.BenchmarkType { | |||||
| for _, benchmarkType := range GetBenchmarkTypes(ctx).BenchmarkType { | |||||
| if task.BenchmarkTypeID == benchmarkType.Id { | if task.BenchmarkTypeID == benchmarkType.Id { | ||||
| ctx.Data["BenchmarkTypeName"] = benchmarkType.First | ctx.Data["BenchmarkTypeName"] = benchmarkType.First | ||||
| for _, benchmarkChildType := range benchmarkType.Second { | for _, benchmarkChildType := range benchmarkType.Second { | ||||
| @@ -1062,13 +1052,6 @@ func CloudBrainBenchmarkIndex(ctx *context.Context) { | |||||
| return | return | ||||
| } | } | ||||
| if benchmarkTypes == nil { | |||||
| if err := json.Unmarshal([]byte(i18n.Tr(ctx.Locale.Language(), BENCHMARK_TYPE_CODE)), &benchmarkTypes); err != nil { | |||||
| ctx.ServerError("Get BenchmarkTypes faild:", err) | |||||
| return | |||||
| } | |||||
| } | |||||
| for i, task := range ciTasks { | for i, task := range ciTasks { | ||||
| ciTasks[i].CanDel = cloudbrain.CanDeleteJob(ctx, &task.Cloudbrain) | ciTasks[i].CanDel = cloudbrain.CanDeleteJob(ctx, &task.Cloudbrain) | ||||
| ciTasks[i].Cloudbrain.ComputeResource = task.ComputeResource | ciTasks[i].Cloudbrain.ComputeResource = task.ComputeResource | ||||
| @@ -1081,7 +1064,7 @@ func CloudBrainBenchmarkIndex(ctx *context.Context) { | |||||
| ciTasks[i].TrainJobDuration = util.AddZero(duration/3600000) + ":" + util.AddZero(duration%3600000/60000) + ":" + util.AddZero(duration%60000/1000) | ciTasks[i].TrainJobDuration = util.AddZero(duration/3600000) + ":" + util.AddZero(duration%3600000/60000) + ":" + util.AddZero(duration%60000/1000) | ||||
| ciTasks[i].BenchmarkTypeName = "" | ciTasks[i].BenchmarkTypeName = "" | ||||
| if task.BenchmarkTypeID > 0 { | if task.BenchmarkTypeID > 0 { | ||||
| for _, benchmarkType := range benchmarkTypes.BenchmarkType { | |||||
| for _, benchmarkType := range GetBenchmarkTypes(ctx).BenchmarkType { | |||||
| if task.BenchmarkTypeID == benchmarkType.Id { | if task.BenchmarkTypeID == benchmarkType.Id { | ||||
| ciTasks[i].BenchmarkTypeRankLink = benchmarkType.RankLink | ciTasks[i].BenchmarkTypeRankLink = benchmarkType.RankLink | ||||
| ciTasks[i].BenchmarkTypeName = benchmarkType.First | ciTasks[i].BenchmarkTypeName = benchmarkType.First | ||||
| @@ -1105,15 +1088,8 @@ func GetChildTypes(ctx *context.Context) { | |||||
| benchmarkTypeID := ctx.QueryInt("benchmark_type_id") | benchmarkTypeID := ctx.QueryInt("benchmark_type_id") | ||||
| re := make(map[string]interface{}) | re := make(map[string]interface{}) | ||||
| for { | for { | ||||
| if benchmarkTypes == nil { | |||||
| if err := json.Unmarshal([]byte(i18n.Tr(ctx.Locale.Language(), BENCHMARK_TYPE_CODE)), &benchmarkTypes); err != nil { | |||||
| log.Error("json.Unmarshal BenchmarkTypes(%s) failed:%v", i18n.Tr(ctx.Locale.Language(), BENCHMARK_TYPE_CODE), err, ctx.Data["MsgID"]) | |||||
| re["errMsg"] = "system error" | |||||
| break | |||||
| } | |||||
| } | |||||
| var isExist bool | var isExist bool | ||||
| for _, benchmarkType := range benchmarkTypes.BenchmarkType { | |||||
| for _, benchmarkType := range GetBenchmarkTypes(ctx).BenchmarkType { | |||||
| if benchmarkTypeID == benchmarkType.Id { | if benchmarkTypeID == benchmarkType.Id { | ||||
| isExist = true | isExist = true | ||||
| re["child_types"] = benchmarkType.Second | re["child_types"] = benchmarkType.Second | ||||
| @@ -1146,15 +1122,9 @@ func CloudBrainBenchmarkNew(ctx *context.Context) { | |||||
| func getBenchmarkAttachment(benchmarkTypeID, benchmarkChildTypeID int, ctx *context.Context) (*models.BenchmarkDataset, error) { | func getBenchmarkAttachment(benchmarkTypeID, benchmarkChildTypeID int, ctx *context.Context) (*models.BenchmarkDataset, error) { | ||||
| var childInfo *models.BenchmarkDataset | var childInfo *models.BenchmarkDataset | ||||
| if benchmarkTypes == nil { | |||||
| if err := json.Unmarshal([]byte(i18n.Tr(ctx.Locale.Language(), BENCHMARK_TYPE_CODE)), &benchmarkTypes); err != nil { | |||||
| log.Error("json.Unmarshal BenchmarkTypes(%s) failed:%v", i18n.Tr(ctx.Locale.Language(), BENCHMARK_TYPE_CODE), err) | |||||
| return childInfo, err | |||||
| } | |||||
| } | |||||
| var isExist bool | var isExist bool | ||||
| for _, benchmarkType := range benchmarkTypes.BenchmarkType { | |||||
| for _, benchmarkType := range GetBenchmarkTypes(ctx).BenchmarkType { | |||||
| if benchmarkType.Id == benchmarkTypeID { | if benchmarkType.Id == benchmarkTypeID { | ||||
| for _, childType := range benchmarkType.Second { | for _, childType := range benchmarkType.Second { | ||||
| if childType.Id == benchmarkChildTypeID { | if childType.Id == benchmarkChildTypeID { | ||||
| @@ -1398,3 +1368,17 @@ func BenchmarkDel(ctx *context.Context) { | |||||
| ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/cloudbrain/benchmark") | ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/cloudbrain/benchmark") | ||||
| } | } | ||||
| } | } | ||||
| func GetBenchmarkTypes(ctx *context.Context) *models.BenchmarkTypes { | |||||
| var lang = ctx.Locale.Language() | |||||
| if benchmarkTypesMap[lang] == nil { | |||||
| var val = i18n.Tr(lang, BENCHMARK_TYPE_CODE) | |||||
| var tempType *models.BenchmarkTypes | |||||
| if err := json.Unmarshal([]byte(val), &tempType); err != nil { | |||||
| log.Error("json.Unmarshal BenchmarkTypes(%s) failed:%v", val, err, ctx.Data["MsgID"]) | |||||
| return &models.BenchmarkTypes{} | |||||
| } | |||||
| benchmarkTypesMap[lang] = tempType | |||||
| } | |||||
| return benchmarkTypesMap[lang] | |||||
| } | |||||