| @@ -7,6 +7,7 @@ package setting | |||
| import ( | |||
| "encoding/base64" | |||
| "encoding/json" | |||
| "fmt" | |||
| "io" | |||
| "io/ioutil" | |||
| @@ -64,7 +65,16 @@ const ( | |||
| ReCaptcha = "recaptcha" | |||
| ) | |||
| // settings | |||
| type C2NetSequenceInfo struct { | |||
| ID int `json:"id"` | |||
| Name string `json:"name"` | |||
| Content string `json:"content"` | |||
| } | |||
| type C2NetSqInfos struct { | |||
| C2NetSqInfo []*C2NetSequenceInfo `json:"sequence"` | |||
| } | |||
| var ( | |||
| // AppVer settings | |||
| AppVer string | |||
| @@ -531,13 +541,16 @@ var ( | |||
| //grampus config | |||
| Grampus = struct { | |||
| Env string | |||
| Host string | |||
| UserName string | |||
| Password string | |||
| SpecialPools string | |||
| Env string | |||
| Host string | |||
| UserName string | |||
| Password string | |||
| SpecialPools string | |||
| C2NetSequence string | |||
| }{} | |||
| C2NetInfos *C2NetSqInfos | |||
| //elk config | |||
| ElkUrl string | |||
| ElkUser string | |||
| @@ -1416,7 +1429,12 @@ func GetGrampusConfig() { | |||
| Grampus.UserName = sec.Key("USERNAME").MustString("") | |||
| Grampus.Password = sec.Key("PASSWORD").MustString("") | |||
| Grampus.SpecialPools = sec.Key("SPECIAL_POOL").MustString("") | |||
| Grampus.C2NetSequence = sec.Key("C2NET_SEQUENCE").MustString("{\"sequence\":[{\"id\":1,\"name\":\"cloudbrain_one\",\"content\":\"鹏城云脑一号\"},{\"id\":2,\"name\":\"cloudbrain_two\",\"content\":\"鹏城云脑二号\"},{\"id\":3,\"name\":\"beida\",\"content\":\"北大人工智能集群系统\"},{\"id\":4,\"name\":\"hefei\",\"content\":\"合肥类脑智能开放平台\"},{\"id\":5,\"name\":\"wuhan\",\"content\":\"武汉人工智能计算中心\"},{\"id\":6,\"name\":\"xian\",\"content\":\"西安未来人工智能计算中心\"},{\"id\":7,\"pclcci\":\"more\",\"content\":\"鹏城云计算所\"},{\"id\":8,\"name\":\"xuchang\",\"content\":\"中原人工智能计算中心\"},{\"id\":9,\"name\":\"chengdu\",\"content\":\"成都人工智能计算中心\"},{\"id\":10,\"name\":\"more\",\"content\":\"横琴先进智能计算中心\"},{\"id\":11,\"name\":\"more\",\"content\":\"国家超级计算济南中心\"}]}") | |||
| if Grampus.C2NetSequence != "" { | |||
| if err := json.Unmarshal([]byte(Grampus.C2NetSequence), &C2NetInfos); err != nil { | |||
| log.Error("Unmarshal(C2NetSequence) failed:%v", err) | |||
| } | |||
| } | |||
| } | |||
| func SetRadarMapConfig() { | |||
| @@ -1057,6 +1057,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
| }) | |||
| m.Get("/wechat/material", authentication.GetMaterial) | |||
| m.Get("/cloudbrain/get_newest_job", repo.GetNewestJobs) | |||
| m.Get("/cloudbrain/get_center_info", repo.GetAICenterInfo) | |||
| }, securityHeaders(), context.APIContexter(), sudo()) | |||
| } | |||
| @@ -6,6 +6,7 @@ | |||
| package repo | |||
| import ( | |||
| "code.gitea.io/gitea/modules/setting" | |||
| "encoding/json" | |||
| "net/http" | |||
| "sort" | |||
| @@ -238,24 +239,61 @@ func GetNewestJobs(ctx *context.APIContext) { | |||
| jobInfos := make([]JobInfo, 0) | |||
| for _, job := range jobs { | |||
| var id int | |||
| var content string | |||
| switch job.Type { | |||
| case models.TypeCloudBrainOne: | |||
| jobInfos = append(jobInfos, JobInfo{ | |||
| JobName: job.DisplayJobName, | |||
| AiCenterId: 0, | |||
| }) | |||
| id, content = getAICenterID("cloudbrain_one") | |||
| if content == "" { | |||
| log.Error("job(%s) has no match config info", job.DisplayJobName) | |||
| continue | |||
| } | |||
| case models.TypeCloudBrainTwo: | |||
| jobInfos = append(jobInfos, JobInfo{ | |||
| JobName: job.DisplayJobName, | |||
| AiCenterId: 1, | |||
| }) | |||
| id, content = getAICenterID("cloudbrain_two") | |||
| if content == "" { | |||
| log.Error("job(%s) has no match config info", job.DisplayJobName) | |||
| continue | |||
| } | |||
| case models.TypeC2Net: | |||
| jobInfos = append(jobInfos, JobInfo{ | |||
| JobName: job.DisplayJobName, | |||
| AiCenterId: 3, | |||
| }) | |||
| centerInfo := strings.Split(job.AiCenter, "+") | |||
| if len(centerInfo) != 2 { | |||
| log.Error("job(%s):ai_center(%s) is wrong", job.DisplayJobName, job.AiCenter) | |||
| continue | |||
| } | |||
| id, content = getAICenterID(centerInfo[0]) | |||
| if content == "" { | |||
| log.Error("job(%s) has no match config info", job.DisplayJobName) | |||
| continue | |||
| } | |||
| default: | |||
| log.Error("no match info") | |||
| continue | |||
| } | |||
| jobInfos = append(jobInfos, JobInfo{ | |||
| JobName: content, | |||
| AiCenterId: id, | |||
| }) | |||
| } | |||
| ctx.JSON(http.StatusOK, jobInfos) | |||
| } | |||
| func GetAICenterInfo(ctx *context.APIContext) { | |||
| if setting.C2NetInfos == nil { | |||
| log.Error("C2NET_SEQUENCE is incorrect") | |||
| return | |||
| } | |||
| ctx.JSON(http.StatusOK, setting.C2NetInfos.C2NetSqInfo) | |||
| } | |||
| func getAICenterID(name string) (int, string) { | |||
| for _, info := range setting.C2NetInfos.C2NetSqInfo { | |||
| if name == info.Name { | |||
| return info.ID, info.Content | |||
| } | |||
| } | |||
| return 0, "" | |||
| } | |||