|
|
|
@@ -5,6 +5,7 @@ import ( |
|
|
|
"encoding/json" |
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"github.com/unknwon/i18n" |
|
|
|
"io" |
|
|
|
"net/http" |
|
|
|
"os" |
|
|
|
@@ -45,6 +46,8 @@ var ( |
|
|
|
benchmarkResourceSpecs *models.ResourceSpecs |
|
|
|
) |
|
|
|
|
|
|
|
const BENCHMARK_TYPE_CODE = "repo.cloudbrain.benchmark.types" |
|
|
|
|
|
|
|
var jobNamePattern = regexp.MustCompile(`^[a-z0-9][a-z0-9-_]{1,34}[a-z0-9-]$`) |
|
|
|
|
|
|
|
// MustEnableDataset check if repository enable internal cb |
|
|
|
@@ -131,8 +134,8 @@ func cloudBrainNewDataPrepare(ctx *context.Context) error { |
|
|
|
ctx.Data["benchmark_categories"] = categories.Category |
|
|
|
|
|
|
|
if benchmarkTypes == nil { |
|
|
|
if err := json.Unmarshal([]byte(setting.BenchmarkTypes), &benchmarkTypes); err != nil { |
|
|
|
log.Error("json.Unmarshal BenchmarkTypes(%s) failed:%v", setting.BenchmarkTypes, err, ctx.Data["MsgID"]) |
|
|
|
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 |
|
|
|
@@ -340,8 +343,8 @@ func CloudBrainRestart(ctx *context.Context) { |
|
|
|
|
|
|
|
func CloudBrainBenchMarkShow(ctx *context.Context) { |
|
|
|
if benchmarkTypes == nil { |
|
|
|
if err := json.Unmarshal([]byte(setting.BenchmarkTypes), &benchmarkTypes); err != nil { |
|
|
|
log.Error("json.Unmarshal BenchmarkTypes(%s) failed:%v", setting.BenchmarkTypes, err, ctx.Data["MsgID"]) |
|
|
|
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 |
|
|
|
} |
|
|
|
@@ -1060,7 +1063,7 @@ func CloudBrainBenchmarkIndex(ctx *context.Context) { |
|
|
|
} |
|
|
|
|
|
|
|
if benchmarkTypes == nil { |
|
|
|
if err := json.Unmarshal([]byte(setting.BenchmarkTypes), &benchmarkTypes); err != nil { |
|
|
|
if err := json.Unmarshal([]byte(i18n.Tr(ctx.Locale.Language(), BENCHMARK_TYPE_CODE)), &benchmarkTypes); err != nil { |
|
|
|
ctx.ServerError("Get BenchmarkTypes faild:", err) |
|
|
|
return |
|
|
|
} |
|
|
|
@@ -1103,8 +1106,8 @@ func GetChildTypes(ctx *context.Context) { |
|
|
|
re := make(map[string]interface{}) |
|
|
|
for { |
|
|
|
if benchmarkTypes == nil { |
|
|
|
if err := json.Unmarshal([]byte(setting.BenchmarkTypes), &benchmarkTypes); err != nil { |
|
|
|
log.Error("json.Unmarshal BenchmarkTypes(%s) failed:%v", setting.BenchmarkTypes, err, ctx.Data["MsgID"]) |
|
|
|
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 |
|
|
|
} |
|
|
|
@@ -1141,11 +1144,11 @@ func CloudBrainBenchmarkNew(ctx *context.Context) { |
|
|
|
ctx.HTML(200, tplCloudBrainBenchmarkNew) |
|
|
|
} |
|
|
|
|
|
|
|
func getBenchmarkAttachment(benchmarkTypeID, benchmarkChildTypeID int) (*models.BenchmarkDataset, error) { |
|
|
|
func getBenchmarkAttachment(benchmarkTypeID, benchmarkChildTypeID int, ctx *context.Context) (*models.BenchmarkDataset, error) { |
|
|
|
var childInfo *models.BenchmarkDataset |
|
|
|
if benchmarkTypes == nil { |
|
|
|
if err := json.Unmarshal([]byte(setting.BenchmarkTypes), &benchmarkTypes); err != nil { |
|
|
|
log.Error("json.Unmarshal BenchmarkTypes(%s) failed:%v", setting.BenchmarkTypes, err) |
|
|
|
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 |
|
|
|
} |
|
|
|
} |
|
|
|
@@ -1265,7 +1268,7 @@ func CloudBrainBenchmarkCreate(ctx *context.Context, form auth.CreateCloudBrainF |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
childInfo, err := getBenchmarkAttachment(benchmarkTypeID, benchmarkChildTypeID) |
|
|
|
childInfo, err := getBenchmarkAttachment(benchmarkTypeID, benchmarkChildTypeID, ctx) |
|
|
|
if err != nil { |
|
|
|
log.Error("getBenchmarkAttachment failed:%v", err, ctx.Data["MsgID"]) |
|
|
|
cloudBrainNewDataPrepare(ctx) |
|
|
|
|