| @@ -1589,9 +1589,23 @@ func Cloudbrains(opts *CloudbrainsOptions) ([]*CloudbrainInfo, int64, error) { | |||||
| } | } | ||||
| } | } | ||||
| if (opts.AiCenter) != "" { | if (opts.AiCenter) != "" { | ||||
| cond = cond.And( | |||||
| builder.Like{"cloudbrain.ai_center", opts.AiCenter}, | |||||
| ) | |||||
| if opts.AiCenter == AICenterOfCloudBrainOne { | |||||
| cond = cond.And( | |||||
| builder.Eq{"cloudbrain.type": TypeCloudBrainOne}, | |||||
| ) | |||||
| } else if opts.AiCenter == AICenterOfCloudBrainTwo { | |||||
| cond = cond.And( | |||||
| builder.Eq{"cloudbrain.type": TypeCloudBrainTwo}, | |||||
| ) | |||||
| } else if opts.AiCenter == AICenterOfChengdu { | |||||
| cond = cond.And( | |||||
| builder.Eq{"cloudbrain.type": TypeCDCenter}, | |||||
| ) | |||||
| } else { | |||||
| cond = cond.And( | |||||
| builder.Like{"cloudbrain.ai_center", opts.AiCenter}, | |||||
| ) | |||||
| } | |||||
| } | } | ||||
| if (opts.Cluster) != "" { | if (opts.Cluster) != "" { | ||||
| if opts.Cluster == "resource_cluster_openi" { | if opts.Cluster == "resource_cluster_openi" { | ||||
| @@ -2285,7 +2299,7 @@ func CloudbrainAllStatic(opts *CloudbrainsOptions) ([]*CloudbrainInfo, int64, er | |||||
| } | } | ||||
| // sess.OrderBy("cloudbrain.created_unix DESC") | // sess.OrderBy("cloudbrain.created_unix DESC") | ||||
| cloudbrains := make([]*CloudbrainInfo, 0, setting.UI.IssuePagingNum) | cloudbrains := make([]*CloudbrainInfo, 0, setting.UI.IssuePagingNum) | ||||
| if err := sess.Cols("status", "type", "job_type", "train_job_duration", "duration", "compute_resource", "created_unix", "start_time", "end_time", "work_server_number").Table(&Cloudbrain{}).Unscoped().Where(cond). | |||||
| if err := sess.Table(&Cloudbrain{}).Unscoped().Where(cond). | |||||
| Find(&cloudbrains); err != nil { | Find(&cloudbrains); err != nil { | ||||
| return nil, 0, fmt.Errorf("Find: %v", err) | return nil, 0, fmt.Errorf("Find: %v", err) | ||||
| } | } | ||||
| @@ -608,6 +608,7 @@ var ( | |||||
| LocalCenterID string | LocalCenterID string | ||||
| AiCenterInfo string | AiCenterInfo string | ||||
| AiCenterCodeAndNameInfo string | AiCenterCodeAndNameInfo string | ||||
| UsageRateBeginTime string | |||||
| }{} | }{} | ||||
| C2NetInfos *C2NetSqInfos | C2NetInfos *C2NetSqInfos | ||||
| @@ -1653,7 +1654,8 @@ func getGrampusConfig() { | |||||
| Grampus.Password = sec.Key("PASSWORD").MustString("") | Grampus.Password = sec.Key("PASSWORD").MustString("") | ||||
| Grampus.SpecialPools = sec.Key("SPECIAL_POOL").MustString("") | Grampus.SpecialPools = sec.Key("SPECIAL_POOL").MustString("") | ||||
| Grampus.C2NetSequence = sec.Key("C2NET_SEQUENCE").MustString("{\"sequence\":[{\"id\":1,\"name\":\"cloudbrain_one\",\"content\":\"鹏城云脑一号\",\"content_en\":\"Pencheng Cloudbrain Ⅰ\"},{\"id\":2,\"name\":\"cloudbrain_two\",\"content\":\"鹏城云脑二号\",\"content_en\":\"Pencheng Cloudbrain Ⅱ\"},{\"id\":3,\"name\":\"beida\",\"content\":\"北大人工智能集群系统\",\"content_en\":\"Peking University AI Center\"},{\"id\":4,\"name\":\"hefei\",\"content\":\"合肥类脑智能开放平台\",\"content_en\":\"Hefei AI Center\"},{\"id\":5,\"name\":\"wuhan\",\"content\":\"武汉人工智能计算中心\",\"content_en\":\"Wuhan AI Center\"},{\"id\":6,\"name\":\"xian\",\"content\":\"西安未来人工智能计算中心\",\"content_en\":\"Xi'an AI Center\"},{\"id\":7,\"pclcci\":\"more\",\"content\":\"鹏城云计算所\",\"content_en\":\"Pengcheng Cloud Computing Institute\"},{\"id\":8,\"name\":\"xuchang\",\"content\":\"中原人工智能计算中心\",\"content_en\":\"Zhongyuan AI Center\"},{\"id\":9,\"name\":\"chengdu\",\"content\":\"成都人工智能计算中心\",\"content_en\":\"Chengdu AI Center\"},{\"id\":10,\"name\":\"more\",\"content\":\"横琴先进智能计算中心\",\"content_en\":\"Hengqin AI Center\"},{\"id\":11,\"name\":\"more\",\"content\":\"国家超级计算济南中心\",\"content_en\":\"HPC & AI Center\"}]}") | Grampus.C2NetSequence = sec.Key("C2NET_SEQUENCE").MustString("{\"sequence\":[{\"id\":1,\"name\":\"cloudbrain_one\",\"content\":\"鹏城云脑一号\",\"content_en\":\"Pencheng Cloudbrain Ⅰ\"},{\"id\":2,\"name\":\"cloudbrain_two\",\"content\":\"鹏城云脑二号\",\"content_en\":\"Pencheng Cloudbrain Ⅱ\"},{\"id\":3,\"name\":\"beida\",\"content\":\"北大人工智能集群系统\",\"content_en\":\"Peking University AI Center\"},{\"id\":4,\"name\":\"hefei\",\"content\":\"合肥类脑智能开放平台\",\"content_en\":\"Hefei AI Center\"},{\"id\":5,\"name\":\"wuhan\",\"content\":\"武汉人工智能计算中心\",\"content_en\":\"Wuhan AI Center\"},{\"id\":6,\"name\":\"xian\",\"content\":\"西安未来人工智能计算中心\",\"content_en\":\"Xi'an AI Center\"},{\"id\":7,\"pclcci\":\"more\",\"content\":\"鹏城云计算所\",\"content_en\":\"Pengcheng Cloud Computing Institute\"},{\"id\":8,\"name\":\"xuchang\",\"content\":\"中原人工智能计算中心\",\"content_en\":\"Zhongyuan AI Center\"},{\"id\":9,\"name\":\"chengdu\",\"content\":\"成都人工智能计算中心\",\"content_en\":\"Chengdu AI Center\"},{\"id\":10,\"name\":\"more\",\"content\":\"横琴先进智能计算中心\",\"content_en\":\"Hengqin AI Center\"},{\"id\":11,\"name\":\"more\",\"content\":\"国家超级计算济南中心\",\"content_en\":\"HPC & AI Center\"}]}") | ||||
| Grampus.AiCenterCodeAndNameInfo = sec.Key("AiCenterCodeAndName").MustString("{\"sequence\":[{\"id\":1,\"name\":\"cloudbrain_one\",\"content\":\"鹏城云脑一号\",\"content_en\":\"Pencheng Cloudbrain Ⅰ\"},{\"id\":2,\"name\":\"cloudbrain_two\",\"content\":\"鹏城云脑二号\",\"content_en\":\"Pencheng Cloudbrain Ⅱ\"},{\"id\":3,\"name\":\"beida\",\"content\":\"北大人工智能集群系统\",\"content_en\":\"Peking University AI Center\"},{\"id\":4,\"name\":\"hefei\",\"content\":\"合肥类脑智能开放平台\",\"content_en\":\"Hefei AI Center\"},{\"id\":5,\"name\":\"wuhan\",\"content\":\"武汉人工智能计算中心\",\"content_en\":\"Wuhan AI Center\"},{\"id\":6,\"name\":\"xian\",\"content\":\"西安未来人工智能计算中心\",\"content_en\":\"Xi'an AI Center\"},{\"id\":7,\"pclcci\":\"more\",\"content\":\"鹏城云计算所\",\"content_en\":\"Pengcheng Cloud Computing Institute\"},{\"id\":8,\"name\":\"xuchang\",\"content\":\"中原人工智能计算中心\",\"content_en\":\"Zhongyuan AI Center\"},{\"id\":9,\"name\":\"chengdu\",\"content\":\"成都人工智能计算中心\",\"content_en\":\"Chengdu AI Center\"},{\"id\":10,\"name\":\"more\",\"content\":\"横琴先进智能计算中心\",\"content_en\":\"Hengqin AI Center\"},{\"id\":11,\"name\":\"more\",\"content\":\"国家超级计算济南中心\",\"content_en\":\"HPC & AI Center\"}]}") | |||||
| Grampus.AiCenterCodeAndNameInfo = sec.Key("AI_CENTER_CODE_AND_NAME").MustString("{\"sequence\":[{\"id\":1,\"name\":\"cloudbrain_one\",\"content\":\"鹏城云脑一号\",\"content_en\":\"Pencheng Cloudbrain Ⅰ\"},{\"id\":2,\"name\":\"cloudbrain_two\",\"content\":\"鹏城云脑二号\",\"content_en\":\"Pencheng Cloudbrain Ⅱ\"},{\"id\":3,\"name\":\"beida\",\"content\":\"北大人工智能集群系统\",\"content_en\":\"Peking University AI Center\"},{\"id\":4,\"name\":\"hefei\",\"content\":\"合肥类脑智能开放平台\",\"content_en\":\"Hefei AI Center\"},{\"id\":5,\"name\":\"wuhan\",\"content\":\"武汉人工智能计算中心\",\"content_en\":\"Wuhan AI Center\"},{\"id\":6,\"name\":\"xian\",\"content\":\"西安未来人工智能计算中心\",\"content_en\":\"Xi'an AI Center\"},{\"id\":7,\"pclcci\":\"more\",\"content\":\"鹏城云计算所\",\"content_en\":\"Pengcheng Cloud Computing Institute\"},{\"id\":8,\"name\":\"xuchang\",\"content\":\"中原人工智能计算中心\",\"content_en\":\"Zhongyuan AI Center\"},{\"id\":9,\"name\":\"chengdu\",\"content\":\"成都人工智能计算中心\",\"content_en\":\"Chengdu AI Center\"},{\"id\":10,\"name\":\"more\",\"content\":\"横琴先进智能计算中心\",\"content_en\":\"Hengqin AI Center\"},{\"id\":11,\"name\":\"more\",\"content\":\"国家超级计算济南中心\",\"content_en\":\"HPC & AI Center\"}]}") | |||||
| Grampus.UsageRateBeginTime = sec.Key("USAGE_RATE_BEGIN_TIME").MustString("2021-01-01 00:00:00") | |||||
| if Grampus.C2NetSequence != "" { | if Grampus.C2NetSequence != "" { | ||||
| if err := json.Unmarshal([]byte(Grampus.C2NetSequence), &C2NetInfos); err != nil { | if err := json.Unmarshal([]byte(Grampus.C2NetSequence), &C2NetInfos); err != nil { | ||||
| log.Error("Unmarshal(C2NetSequence) failed:%v", err) | log.Error("Unmarshal(C2NetSequence) failed:%v", err) | ||||
| @@ -97,6 +97,7 @@ func CloudBrains(ctx *context.Context) { | |||||
| for i, task := range ciTasks { | for i, task := range ciTasks { | ||||
| ciTasks[i] = cloudbrainService.UpdateCloudbrainAiCenter(ciTasks[i]) | ciTasks[i] = cloudbrainService.UpdateCloudbrainAiCenter(ciTasks[i]) | ||||
| ciTasks[i].Cloudbrain.AiCenter = repo.GetAiCenterNameByCode(ciTasks[i].Cloudbrain.AiCenter) | |||||
| ciTasks[i].CanDebug = true | ciTasks[i].CanDebug = true | ||||
| ciTasks[i].CanDel = true | ciTasks[i].CanDel = true | ||||
| ciTasks[i].Cloudbrain.ComputeResource = task.ComputeResource | ciTasks[i].Cloudbrain.ComputeResource = task.ComputeResource | ||||
| @@ -603,10 +603,8 @@ func RegisterRoutes(m *macaron.Macaron) { | |||||
| m.Get("/overview_resource", repo.GetCloudbrainResourceOverview) | m.Get("/overview_resource", repo.GetCloudbrainResourceOverview) | ||||
| m.Get("/resource_usage_statistic", repo.GetDurationRateStatistic) | m.Get("/resource_usage_statistic", repo.GetDurationRateStatistic) | ||||
| m.Get("/resource_usage_rate_detail", repo.GetCloudbrainResourceUsageDetail) | m.Get("/resource_usage_rate_detail", repo.GetCloudbrainResourceUsageDetail) | ||||
| m.Get("/resource_queues", repo.GetResourceQueues) | m.Get("/resource_queues", repo.GetResourceQueues) | ||||
| m.Get("/apitest_for_statistic", repo.CloudbrainDurationStatisticForTest) | m.Get("/apitest_for_statistic", repo.CloudbrainDurationStatisticForTest) | ||||
| m.Get("/apipost_for_cloudbrain_data", repo.CloudbrainUpdateHistoryData) | |||||
| }) | }) | ||||
| }, operationReq) | }, operationReq) | ||||
| @@ -12,6 +12,7 @@ import ( | |||||
| "code.gitea.io/gitea/modules/context" | "code.gitea.io/gitea/modules/context" | ||||
| "code.gitea.io/gitea/modules/log" | "code.gitea.io/gitea/modules/log" | ||||
| "code.gitea.io/gitea/routers/repo" | "code.gitea.io/gitea/routers/repo" | ||||
| cloudbrainService "code.gitea.io/gitea/services/cloudbrain" | |||||
| "github.com/360EntSecGroup-Skylar/excelize/v2" | "github.com/360EntSecGroup-Skylar/excelize/v2" | ||||
| ) | ) | ||||
| @@ -747,8 +748,8 @@ func GetCloudbrainsDetailData(ctx *context.Context) { | |||||
| NeedRepoInfo: true, | NeedRepoInfo: true, | ||||
| BeginTimeUnix: int64(recordBeginTime), | BeginTimeUnix: int64(recordBeginTime), | ||||
| EndTimeUnix: endTime.Unix(), | EndTimeUnix: endTime.Unix(), | ||||
| // AiCenter: aiCenter, | |||||
| NeedDeleteInfo: needDeleteInfo, | |||||
| AiCenter: aiCenter, | |||||
| NeedDeleteInfo: needDeleteInfo, | |||||
| }) | }) | ||||
| if err != nil { | if err != nil { | ||||
| ctx.ServerError("Get job failed:", err) | ctx.ServerError("Get job failed:", err) | ||||
| @@ -758,43 +759,42 @@ func GetCloudbrainsDetailData(ctx *context.Context) { | |||||
| nilTime := time.Time{} | nilTime := time.Time{} | ||||
| tasks := []models.TaskDetail{} | tasks := []models.TaskDetail{} | ||||
| for i, task := range ciTasks { | for i, task := range ciTasks { | ||||
| if aiCenter == "" || aiCenter == task.Cloudbrain.Spec.AiCenterCode { | |||||
| ciTasks[i].Cloudbrain.ComputeResource = task.ComputeResource | |||||
| var taskDetail models.TaskDetail | |||||
| taskDetail.ID = ciTasks[i].Cloudbrain.ID | |||||
| taskDetail.JobID = ciTasks[i].Cloudbrain.JobID | |||||
| taskDetail.JobName = ciTasks[i].JobName | |||||
| taskDetail.DisplayJobName = ciTasks[i].DisplayJobName | |||||
| taskDetail.Status = ciTasks[i].Status | |||||
| taskDetail.JobType = ciTasks[i].JobType | |||||
| taskDetail.CreatedUnix = ciTasks[i].Cloudbrain.CreatedUnix | |||||
| taskDetail.RunTime = ciTasks[i].Cloudbrain.TrainJobDuration | |||||
| taskDetail.StartTime = ciTasks[i].StartTime | |||||
| taskDetail.EndTime = ciTasks[i].EndTime | |||||
| taskDetail.ComputeResource = ciTasks[i].ComputeResource | |||||
| taskDetail.Type = ciTasks[i].Cloudbrain.Type | |||||
| taskDetail.UserName = ciTasks[i].User.Name | |||||
| taskDetail.RepoID = ciTasks[i].RepoID | |||||
| if ciTasks[i].Repo != nil { | |||||
| taskDetail.RepoName = ciTasks[i].Repo.OwnerName + "/" + ciTasks[i].Repo.Name | |||||
| taskDetail.RepoAlias = ciTasks[i].Repo.OwnerName + "/" + ciTasks[i].Repo.Alias | |||||
| } | |||||
| if ciTasks[i].Cloudbrain.WorkServerNumber >= 1 { | |||||
| taskDetail.WorkServerNum = int64(ciTasks[i].Cloudbrain.WorkServerNumber) | |||||
| } else { | |||||
| taskDetail.WorkServerNum = 1 | |||||
| } | |||||
| taskDetail.CardDuration = repo.GetCloudbrainCardDuration(ciTasks[i].Cloudbrain) | |||||
| taskDetail.WaitTime = repo.GetCloudbrainWaitTime(ciTasks[i].Cloudbrain) | |||||
| task = cloudbrainService.UpdateCloudbrainAiCenter(task) | |||||
| task.Cloudbrain.AiCenter = repo.GetAiCenterNameByCode(task.Cloudbrain.AiCenter) | |||||
| var taskDetail models.TaskDetail | |||||
| taskDetail.ID = ciTasks[i].Cloudbrain.ID | |||||
| taskDetail.JobID = ciTasks[i].Cloudbrain.JobID | |||||
| taskDetail.JobName = ciTasks[i].JobName | |||||
| taskDetail.DisplayJobName = ciTasks[i].DisplayJobName | |||||
| taskDetail.Status = ciTasks[i].Status | |||||
| taskDetail.JobType = ciTasks[i].JobType | |||||
| taskDetail.CreatedUnix = ciTasks[i].Cloudbrain.CreatedUnix | |||||
| taskDetail.RunTime = ciTasks[i].Cloudbrain.TrainJobDuration | |||||
| taskDetail.StartTime = ciTasks[i].StartTime | |||||
| taskDetail.EndTime = ciTasks[i].EndTime | |||||
| taskDetail.ComputeResource = ciTasks[i].ComputeResource | |||||
| taskDetail.Type = ciTasks[i].Cloudbrain.Type | |||||
| taskDetail.UserName = ciTasks[i].User.Name | |||||
| taskDetail.RepoID = ciTasks[i].RepoID | |||||
| if ciTasks[i].Repo != nil { | |||||
| taskDetail.RepoName = ciTasks[i].Repo.OwnerName + "/" + ciTasks[i].Repo.Name | |||||
| taskDetail.RepoAlias = ciTasks[i].Repo.OwnerName + "/" + ciTasks[i].Repo.Alias | |||||
| } | |||||
| if ciTasks[i].Cloudbrain.WorkServerNumber >= 1 { | |||||
| taskDetail.WorkServerNum = int64(ciTasks[i].Cloudbrain.WorkServerNumber) | |||||
| } else { | |||||
| taskDetail.WorkServerNum = 1 | |||||
| } | |||||
| taskDetail.CardDuration = repo.GetCloudbrainCardDuration(ciTasks[i].Cloudbrain) | |||||
| taskDetail.WaitTime = repo.GetCloudbrainWaitTime(ciTasks[i].Cloudbrain) | |||||
| if ciTasks[i].Cloudbrain.DeletedAt != nilTime || ciTasks[i].Repo == nil { | |||||
| taskDetail.IsDelete = true | |||||
| } else { | |||||
| taskDetail.IsDelete = false | |||||
| } | |||||
| taskDetail.Spec = ciTasks[i].Spec | |||||
| tasks = append(tasks, taskDetail) | |||||
| if ciTasks[i].Cloudbrain.DeletedAt != nilTime || ciTasks[i].Repo == nil { | |||||
| taskDetail.IsDelete = true | |||||
| } else { | |||||
| taskDetail.IsDelete = false | |||||
| } | } | ||||
| taskDetail.Spec = ciTasks[i].Spec | |||||
| tasks = append(tasks, taskDetail) | |||||
| } | } | ||||
| count := int64(len(tasks)) | count := int64(len(tasks)) | ||||
| pager := context.NewPagination(int(count), pageSize, page, getTotalPage(count, pageSize)) | pager := context.NewPagination(int(count), pageSize, page, getTotalPage(count, pageSize)) | ||||
| @@ -1843,13 +1843,6 @@ func CloudbrainUpdateAiCenter(ctx *context.Context) { | |||||
| }) | }) | ||||
| } | } | ||||
| func CloudbrainUpdateHistoryData(ctx *context.Context) { | |||||
| repo.UpdateDurationStatisticHistoryData() | |||||
| ctx.JSON(http.StatusOK, map[string]interface{}{ | |||||
| "message": 0, | |||||
| }) | |||||
| } | |||||
| func GetResourceQueues(ctx *context.Context) { | func GetResourceQueues(ctx *context.Context) { | ||||
| resourceQueues, err := models.GetCanUseCardInfo() | resourceQueues, err := models.GetCanUseCardInfo() | ||||
| if err != nil { | if err != nil { | ||||
| @@ -6,9 +6,10 @@ | |||||
| package private | package private | ||||
| import ( | import ( | ||||
| "code.gitea.io/gitea/routers/admin" | |||||
| "strings" | "strings" | ||||
| "code.gitea.io/gitea/routers/admin" | |||||
| "code.gitea.io/gitea/routers/repo" | "code.gitea.io/gitea/routers/repo" | ||||
| "code.gitea.io/gitea/modules/log" | "code.gitea.io/gitea/modules/log" | ||||
| @@ -53,6 +54,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||||
| m.Post("/tool/update_repo_visit/:date", UpdateRepoVisit) | m.Post("/tool/update_repo_visit/:date", UpdateRepoVisit) | ||||
| m.Post("/task/history_handle/duration", repo.HandleTaskWithNoDuration) | m.Post("/task/history_handle/duration", repo.HandleTaskWithNoDuration) | ||||
| m.Post("/resources/specification/handle_historical_task", admin.RefreshHistorySpec) | m.Post("/resources/specification/handle_historical_task", admin.RefreshHistorySpec) | ||||
| m.Post("/duration_statisctic/history_handle", repo.CloudbrainUpdateHistoryData) | |||||
| }, CheckInternalToken) | }, CheckInternalToken) | ||||
| } | } | ||||
| @@ -2,7 +2,6 @@ package repo | |||||
| import ( | import ( | ||||
| "bufio" | "bufio" | ||||
| "code.gitea.io/gitea/modules/urfs_client/urchin" | |||||
| "encoding/json" | "encoding/json" | ||||
| "errors" | "errors" | ||||
| "fmt" | "fmt" | ||||
| @@ -16,6 +15,8 @@ import ( | |||||
| "time" | "time" | ||||
| "unicode/utf8" | "unicode/utf8" | ||||
| "code.gitea.io/gitea/modules/urfs_client/urchin" | |||||
| "code.gitea.io/gitea/modules/dataset" | "code.gitea.io/gitea/modules/dataset" | ||||
| "code.gitea.io/gitea/services/cloudbrain/cloudbrainTask" | "code.gitea.io/gitea/services/cloudbrain/cloudbrainTask" | ||||
| @@ -1,11 +1,14 @@ | |||||
| package repo | package repo | ||||
| import ( | import ( | ||||
| "net/http" | |||||
| "strings" | "strings" | ||||
| "time" | "time" | ||||
| "code.gitea.io/gitea/models" | "code.gitea.io/gitea/models" | ||||
| "code.gitea.io/gitea/modules/context" | |||||
| "code.gitea.io/gitea/modules/log" | "code.gitea.io/gitea/modules/log" | ||||
| "code.gitea.io/gitea/modules/setting" | |||||
| "code.gitea.io/gitea/modules/timeutil" | "code.gitea.io/gitea/modules/timeutil" | ||||
| cloudbrainService "code.gitea.io/gitea/services/cloudbrain" | cloudbrainService "code.gitea.io/gitea/services/cloudbrain" | ||||
| ) | ) | ||||
| @@ -16,18 +19,22 @@ func CloudbrainDurationStatisticHour() { | |||||
| summaryDurationStat(currentTime) | summaryDurationStat(currentTime) | ||||
| } | } | ||||
| func UpdateDurationStatisticHistoryData() { | |||||
| func UpdateDurationStatisticHistoryData() int64 { | |||||
| var count int64 | |||||
| recordBeginTime, _ := time.ParseInLocation("2006-01-02 15:04:05", setting.Grampus.UsageRateBeginTime, time.Local) | |||||
| now := time.Now() | now := time.Now() | ||||
| currentTime := time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), 0, 0, 0, now.Location()) | currentTime := time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), 0, 0, 0, now.Location()) | ||||
| stamp := time.Date(2022, 10, 1, 0, 0, 0, 0, now.Location()) | |||||
| statisticTime := stamp.Add(+1 * time.Hour) | |||||
| statisticTime := recordBeginTime.Add(+1 * time.Hour) | |||||
| for statisticTime.Before(currentTime) || statisticTime.Equal(currentTime) { | for statisticTime.Before(currentTime) || statisticTime.Equal(currentTime) { | ||||
| summaryDurationStat(statisticTime) | |||||
| countEach := summaryDurationStat(statisticTime) | |||||
| count += countEach | |||||
| statisticTime = statisticTime.Add(+1 * time.Hour) | statisticTime = statisticTime.Add(+1 * time.Hour) | ||||
| } | } | ||||
| return count | |||||
| } | } | ||||
| func summaryDurationStat(statisticTime time.Time) { | |||||
| func summaryDurationStat(statisticTime time.Time) int64 { | |||||
| var count int64 | |||||
| dateTime := timeutil.TimeStamp(statisticTime.Unix()) | dateTime := timeutil.TimeStamp(statisticTime.Unix()) | ||||
| dayTime := statisticTime.Format("2006-01-02") | dayTime := statisticTime.Format("2006-01-02") | ||||
| @@ -38,7 +45,7 @@ func summaryDurationStat(statisticTime time.Time) { | |||||
| ciTasks, err := models.GetCloudbrainByTime(beginTime, endTime) | ciTasks, err := models.GetCloudbrainByTime(beginTime, endTime) | ||||
| if err != nil { | if err != nil { | ||||
| log.Info("GetCloudbrainByTime err: %v", err) | log.Info("GetCloudbrainByTime err: %v", err) | ||||
| return | |||||
| return 0 | |||||
| } | } | ||||
| cloudbrainMap := make(map[string]*models.Cloudbrain) | cloudbrainMap := make(map[string]*models.Cloudbrain) | ||||
| models.LoadSpecs4CloudbrainInfo(ciTasks) | models.LoadSpecs4CloudbrainInfo(ciTasks) | ||||
| @@ -56,7 +63,7 @@ func summaryDurationStat(statisticTime time.Time) { | |||||
| resourceQueues, err := models.GetCanUseCardInfo() | resourceQueues, err := models.GetCanUseCardInfo() | ||||
| if err != nil { | if err != nil { | ||||
| log.Info("GetCanUseCardInfo err: %v", err) | log.Info("GetCanUseCardInfo err: %v", err) | ||||
| return | |||||
| return 0 | |||||
| } | } | ||||
| cardsTotalDurationMap := make(map[string]int) | cardsTotalDurationMap := make(map[string]int) | ||||
| for _, resourceQueue := range resourceQueues { | for _, resourceQueue := range resourceQueues { | ||||
| @@ -69,7 +76,7 @@ func summaryDurationStat(statisticTime time.Time) { | |||||
| if cloudbrainTable != nil { | if cloudbrainTable != nil { | ||||
| if err := models.DeleteCloudbrainDurationStatisticHour(dayTime, hourTime, centerCode, cardType); err != nil { | if err := models.DeleteCloudbrainDurationStatisticHour(dayTime, hourTime, centerCode, cardType); err != nil { | ||||
| log.Error("DeleteCloudbrainDurationStatisticHour failed: %v", err.Error()) | log.Error("DeleteCloudbrainDurationStatisticHour failed: %v", err.Error()) | ||||
| return | |||||
| return 0 | |||||
| } | } | ||||
| if _, ok := cardsTotalDurationMap[cloudbrainTable.Cluster+"/"+centerCode+"/"+cardType+"/"+cloudbrainTable.ComputeResource]; !ok { | if _, ok := cardsTotalDurationMap[cloudbrainTable.Cluster+"/"+centerCode+"/"+cardType+"/"+cloudbrainTable.ComputeResource]; !ok { | ||||
| cardsTotalDurationMap[cloudbrainTable.Cluster+"/"+centerCode+"/"+cardType+"/"+cloudbrainTable.ComputeResource] = 0 | cardsTotalDurationMap[cloudbrainTable.Cluster+"/"+centerCode+"/"+cardType+"/"+cloudbrainTable.ComputeResource] = 0 | ||||
| @@ -90,6 +97,7 @@ func summaryDurationStat(statisticTime time.Time) { | |||||
| if _, err = models.InsertCloudbrainDurationStatistic(&cloudbrainDurationStat); err != nil { | if _, err = models.InsertCloudbrainDurationStatistic(&cloudbrainDurationStat); err != nil { | ||||
| log.Error("Insert cloudbrainDurationStat failed: %v", err.Error()) | log.Error("Insert cloudbrainDurationStat failed: %v", err.Error()) | ||||
| } | } | ||||
| count++ | |||||
| delete(cardsTotalDurationMap, cloudbrainTable.Cluster+"/"+centerCode+"/"+cardType+"/"+cloudbrainTable.ComputeResource) | delete(cardsTotalDurationMap, cloudbrainTable.Cluster+"/"+centerCode+"/"+cardType+"/"+cloudbrainTable.ComputeResource) | ||||
| } | } | ||||
| } | } | ||||
| @@ -98,7 +106,7 @@ func summaryDurationStat(statisticTime time.Time) { | |||||
| for key, cardsTotalDuration := range cardsTotalDurationMap { | for key, cardsTotalDuration := range cardsTotalDurationMap { | ||||
| if err := models.DeleteCloudbrainDurationStatisticHour(dayTime, hourTime, strings.Split(key, "/")[1], strings.Split(key, "/")[2]); err != nil { | if err := models.DeleteCloudbrainDurationStatisticHour(dayTime, hourTime, strings.Split(key, "/")[1], strings.Split(key, "/")[2]); err != nil { | ||||
| log.Error("DeleteCloudbrainDurationStatisticHour failed: %v", err.Error()) | log.Error("DeleteCloudbrainDurationStatisticHour failed: %v", err.Error()) | ||||
| return | |||||
| return 0 | |||||
| } | } | ||||
| cloudbrainDurationStat := models.CloudbrainDurationStatistic{ | cloudbrainDurationStat := models.CloudbrainDurationStatistic{ | ||||
| DateTime: dateTime, | DateTime: dateTime, | ||||
| @@ -117,9 +125,11 @@ func summaryDurationStat(statisticTime time.Time) { | |||||
| if _, err = models.InsertCloudbrainDurationStatistic(&cloudbrainDurationStat); err != nil { | if _, err = models.InsertCloudbrainDurationStatistic(&cloudbrainDurationStat); err != nil { | ||||
| log.Error("Insert cloudbrainDurationStat failed: %v", err.Error()) | log.Error("Insert cloudbrainDurationStat failed: %v", err.Error()) | ||||
| } | } | ||||
| count++ | |||||
| } | } | ||||
| log.Info("finish summary cloudbrainDurationStat") | log.Info("finish summary cloudbrainDurationStat") | ||||
| return count | |||||
| } | } | ||||
| func GetAiCenterNameByCode(centerCode string) string { | func GetAiCenterNameByCode(centerCode string) string { | ||||
| @@ -131,7 +141,6 @@ func GetAiCenterNameByCode(centerCode string) string { | |||||
| aiCenterName = centerCode | aiCenterName = centerCode | ||||
| } | } | ||||
| return aiCenterName | return aiCenterName | ||||
| } | } | ||||
| func getcloudBrainCenterCodeAndCardTypeInfo(ciTasks []*models.CloudbrainInfo, beginTime int64, endTime int64) map[string]map[string]int { | func getcloudBrainCenterCodeAndCardTypeInfo(ciTasks []*models.CloudbrainInfo, beginTime int64, endTime int64) map[string]map[string]int { | ||||
| @@ -205,3 +214,11 @@ func getcloudBrainCenterCodeAndCardTypeInfo(ciTasks []*models.CloudbrainInfo, be | |||||
| return cloudBrainCenterCodeAndCardType | return cloudBrainCenterCodeAndCardType | ||||
| } | } | ||||
| func CloudbrainUpdateHistoryData(ctx *context.Context) { | |||||
| count := UpdateDurationStatisticHistoryData() | |||||
| ctx.JSON(http.StatusOK, map[string]interface{}{ | |||||
| "message": 0, | |||||
| "count": count, | |||||
| }) | |||||
| } | |||||
| @@ -1,7 +1,6 @@ | |||||
| package repo | package repo | ||||
| import ( | import ( | ||||
| "code.gitea.io/gitea/modules/urfs_client/urchin" | |||||
| "encoding/json" | "encoding/json" | ||||
| "errors" | "errors" | ||||
| "fmt" | "fmt" | ||||
| @@ -13,6 +12,8 @@ import ( | |||||
| "strings" | "strings" | ||||
| "time" | "time" | ||||
| "code.gitea.io/gitea/modules/urfs_client/urchin" | |||||
| "code.gitea.io/gitea/services/cloudbrain/cloudbrainTask" | "code.gitea.io/gitea/services/cloudbrain/cloudbrainTask" | ||||
| "code.gitea.io/gitea/modules/dataset" | "code.gitea.io/gitea/modules/dataset" | ||||
| @@ -23,6 +23,7 @@ import ( | |||||
| "code.gitea.io/gitea/modules/modelarts" | "code.gitea.io/gitea/modules/modelarts" | ||||
| "code.gitea.io/gitea/modules/setting" | "code.gitea.io/gitea/modules/setting" | ||||
| "code.gitea.io/gitea/modules/util" | "code.gitea.io/gitea/modules/util" | ||||
| "code.gitea.io/gitea/routers/repo" | |||||
| cloudbrainService "code.gitea.io/gitea/services/cloudbrain" | cloudbrainService "code.gitea.io/gitea/services/cloudbrain" | ||||
| issue_service "code.gitea.io/gitea/services/issue" | issue_service "code.gitea.io/gitea/services/issue" | ||||
| pull_service "code.gitea.io/gitea/services/pull" | pull_service "code.gitea.io/gitea/services/pull" | ||||
| @@ -839,6 +840,7 @@ func Cloudbrains(ctx *context.Context) { | |||||
| models.LoadSpecs4CloudbrainInfo(ciTasks) | models.LoadSpecs4CloudbrainInfo(ciTasks) | ||||
| for i, _ := range ciTasks { | for i, _ := range ciTasks { | ||||
| ciTasks[i] = cloudbrainService.UpdateCloudbrainAiCenter(ciTasks[i]) | ciTasks[i] = cloudbrainService.UpdateCloudbrainAiCenter(ciTasks[i]) | ||||
| ciTasks[i].Cloudbrain.AiCenter = repo.GetAiCenterNameByCode(ciTasks[i].Cloudbrain.AiCenter) | |||||
| ciTasks[i].CanDebug = true | ciTasks[i].CanDebug = true | ||||
| ciTasks[i].CanDel = true | ciTasks[i].CanDel = true | ||||
| ciTasks[i].Cloudbrain.ComputeResource = ciTasks[i].ComputeResource | ciTasks[i].Cloudbrain.ComputeResource = ciTasks[i].ComputeResource | ||||
| @@ -63,7 +63,7 @@ func UpdateCloudbrainAiCenter(cloudbrain *models.CloudbrainInfo) *models.Cloudbr | |||||
| cloudbrain.Cloudbrain.AiCenter = models.AICenterOfChengdu | cloudbrain.Cloudbrain.AiCenter = models.AICenterOfChengdu | ||||
| cloudbrain.Cloudbrain.Cluster = models.OpenICluster | cloudbrain.Cloudbrain.Cluster = models.OpenICluster | ||||
| } | } | ||||
| if cloudbrain.Cloudbrain.Type == models.TypeC2Net && cloudbrain.Cloudbrain.AiCenter != "" { | |||||
| if cloudbrain.Cloudbrain.Type == models.TypeC2Net { | |||||
| cloudbrain.Cloudbrain.AiCenter = getAiCenterCode(cloudbrain.Cloudbrain.AiCenter) | cloudbrain.Cloudbrain.AiCenter = getAiCenterCode(cloudbrain.Cloudbrain.AiCenter) | ||||
| cloudbrain.Cloudbrain.Cluster = models.C2NetCluster | cloudbrain.Cloudbrain.Cluster = models.C2NetCluster | ||||
| } | } | ||||