Reviewed-on: https://openi.pcl.ac.cn/OpenI/aiforge/pulls/3242 Reviewed-by: ychao_1983 <ychao_1983@sina.com>tags/v1.22.11.2^2
| @@ -304,6 +304,17 @@ func ConvertDurationToStr(duration int64) string { | |||
| } | |||
| return util.AddZero(duration/3600) + ":" + util.AddZero(duration%3600/60) + ":" + util.AddZero(duration%60) | |||
| } | |||
| func ConvertStrToDuration(trainJobDuration string) int64 { | |||
| trainJobDurationList := strings.Split(trainJobDuration, ":") | |||
| if len(trainJobDurationList) == 3 { | |||
| i, _ := strconv.ParseInt(trainJobDurationList[0], 10, 64) | |||
| j, _ := strconv.ParseInt(trainJobDurationList[1], 10, 64) | |||
| k, _ := strconv.ParseInt(trainJobDurationList[2], 10, 64) | |||
| return i*3600 + j*60 + k | |||
| } else { | |||
| return 0 | |||
| } | |||
| } | |||
| func IsTrainJobTerminal(status string) bool { | |||
| return status == string(ModelArtsTrainJobCompleted) || status == string(ModelArtsTrainJobFailed) || status == string(ModelArtsTrainJobKilled) || status == GrampusStatusFailed || status == GrampusStatusStopped || status == GrampusStatusSucceeded | |||
| @@ -1596,9 +1607,23 @@ func Cloudbrains(opts *CloudbrainsOptions) ([]*CloudbrainInfo, int64, error) { | |||
| } | |||
| } | |||
| 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 == "resource_cluster_openi" { | |||
| @@ -1975,7 +2000,7 @@ func UpdateTrainJobVersion(job *Cloudbrain) error { | |||
| func updateJobTrainVersion(e Engine, job *Cloudbrain) error { | |||
| var sess *xorm.Session | |||
| sess = e.Where("job_id = ? AND version_name=?", job.JobID, job.VersionName) | |||
| _, err := sess.Cols("status", "train_job_duration", "duration", "start_time", "end_time", "created_unix").Update(job) | |||
| _, err := sess.Cols("status", "train_job_duration", "duration", "start_time", "end_time", "created_unix", "ai_center").Update(job) | |||
| return err | |||
| } | |||
| @@ -2040,7 +2065,7 @@ func GetStoppedJobWithNoStartTimeEndTime() ([]*Cloudbrain, error) { | |||
| func GetC2NetWithAiCenterWrongJob() ([]*Cloudbrain, error) { | |||
| cloudbrains := make([]*Cloudbrain, 0) | |||
| return cloudbrains, x. | |||
| In("status", ModelArtsTrainJobFailed, ModelArtsTrainJobKilled, ModelArtsStopped, JobStopped, JobFailed). | |||
| In("status", ModelArtsTrainJobCompleted, ModelArtsTrainJobFailed, ModelArtsTrainJobKilled, ModelArtsStopped, JobStopped, JobFailed, JobSucceeded). | |||
| Where("type = ?", TypeC2Net). | |||
| Find(&cloudbrains) | |||
| } | |||
| @@ -2299,10 +2324,23 @@ func CloudbrainAllStatic(opts *CloudbrainsOptions) ([]*CloudbrainInfo, int64, er | |||
| } | |||
| // sess.OrderBy("cloudbrain.created_unix DESC") | |||
| 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 { | |||
| return nil, 0, fmt.Errorf("Find: %v", err) | |||
| } | |||
| if opts.NeedRepoInfo { | |||
| var ids []int64 | |||
| for _, task := range cloudbrains { | |||
| ids = append(ids, task.RepoID) | |||
| } | |||
| repositoryMap, err := GetRepositoriesMapByIDs(ids) | |||
| if err == nil { | |||
| for _, task := range cloudbrains { | |||
| task.Repo = repositoryMap[task.RepoID] | |||
| } | |||
| } | |||
| } | |||
| return cloudbrains, count, nil | |||
| } | |||
| @@ -42,14 +42,14 @@ type TaskDetail struct { | |||
| type CloudbrainDurationStatistic struct { | |||
| ID int64 `xorm:"pk autoincr"` | |||
| Cluster string | |||
| AiCenterCode string | |||
| AiCenterCode string `xorm:"INDEX"` | |||
| AiCenterName string | |||
| ComputeResource string | |||
| AccCardType string | |||
| AccCardType string `xorm:"INDEX"` | |||
| DateTime string | |||
| DayTime string | |||
| HourTime int | |||
| DateTime timeutil.TimeStamp `xorm:"INDEX"` | |||
| DayTime string `xorm:"INDEX"` | |||
| HourTime int `xorm:"INDEX"` | |||
| CardsUseDuration int | |||
| CardsTotalDuration int | |||
| CardsTotalNum int | |||
| @@ -275,11 +275,15 @@ func GetCloudbrainByTime(beginTime int64, endTime int64) ([]*CloudbrainInfo, err | |||
| sess := x.NewSession() | |||
| defer sess.Close() | |||
| var cond = builder.NewCond() | |||
| cond = cond.And( | |||
| builder.And(builder.Gte{"cloudbrain.end_time": beginTime}, builder.Lte{"cloudbrain.end_time": endTime}), | |||
| sess.Exec("if ") | |||
| cond = cond.Or( | |||
| builder.And(builder.Gte{"cloudbrain.end_time": beginTime}, builder.Lte{"cloudbrain.start_time": beginTime}, builder.Gt{"cloudbrain.start_time": 0}), | |||
| ) | |||
| cond = cond.Or( | |||
| builder.Eq{"cloudbrain.status": string(JobRunning)}, | |||
| builder.And(builder.Gte{"cloudbrain.start_time": beginTime}, builder.Lte{"cloudbrain.start_time": endTime}, builder.Gt{"cloudbrain.start_time": 0}), | |||
| ) | |||
| cond = cond.Or( | |||
| builder.And(builder.Eq{"cloudbrain.status": string(JobRunning)}), | |||
| ) | |||
| sess.OrderBy("cloudbrain.created_unix ASC") | |||
| cloudbrains := make([]*CloudbrainInfo, 0, 10) | |||
| @@ -309,6 +313,20 @@ func InsertCloudbrainDurationStatistic(cloudbrainDurationStatistic *CloudbrainDu | |||
| return xStatistic.Insert(cloudbrainDurationStatistic) | |||
| } | |||
| func GetDurationStatisticByDate(date string, hour int, aiCenterCode string, accCardType string) (*CloudbrainDurationStatistic, error) { | |||
| cb := &CloudbrainDurationStatistic{DayTime: date, HourTime: hour, AiCenterCode: aiCenterCode, AccCardType: accCardType} | |||
| return getDurationStatistic(cb) | |||
| } | |||
| func getDurationStatistic(cb *CloudbrainDurationStatistic) (*CloudbrainDurationStatistic, error) { | |||
| has, err := x.Get(cb) | |||
| if err != nil { | |||
| return nil, err | |||
| } else if !has { | |||
| return nil, ErrJobNotExist{} | |||
| } | |||
| return cb, nil | |||
| } | |||
| func DeleteCloudbrainDurationStatisticHour(date string, hour int, aiCenterCode string, accCardType string) error { | |||
| sess := xStatistic.NewSession() | |||
| defer sess.Close() | |||
| @@ -332,7 +350,7 @@ func DeleteCloudbrainDurationStatisticHour(date string, hour int, aiCenterCode s | |||
| func GetCanUseCardInfo() ([]*ResourceQueue, error) { | |||
| sess := x.NewSession() | |||
| defer sess.Close() | |||
| sess.OrderBy("resource_queue.id ASC") | |||
| sess.OrderBy("resource_queue.cluster DESC, resource_queue.ai_center_code ASC") | |||
| ResourceQueues := make([]*ResourceQueue, 0, 10) | |||
| if err := sess.Table(&ResourceQueue{}).Find(&ResourceQueues); err != nil { | |||
| log.Info("find error.") | |||
| @@ -346,7 +364,7 @@ func GetCardDurationStatistics(opts *DurationStatisticOptions) ([]*CloudbrainDur | |||
| var cond = builder.NewCond() | |||
| if opts.BeginTime.Unix() > 0 && opts.EndTime.Unix() > 0 { | |||
| cond = cond.And( | |||
| builder.And(builder.Gte{"cloudbrain_duration_statistic.created_unix": opts.BeginTime.Unix()}, builder.Lte{"cloudbrain_duration_statistic.created_unix": opts.EndTime.Unix()}), | |||
| builder.And(builder.Gte{"cloudbrain_duration_statistic.date_time": opts.BeginTime.Unix()}, builder.Lt{"cloudbrain_duration_statistic.date_time": opts.EndTime.Unix()}), | |||
| ) | |||
| } | |||
| if opts.AiCenterCode != "" { | |||
| @@ -365,10 +383,31 @@ func GetCardDurationStatistics(opts *DurationStatisticOptions) ([]*CloudbrainDur | |||
| func GetDurationRecordBeginTime() ([]*CloudbrainDurationStatistic, error) { | |||
| sess := xStatistic.NewSession() | |||
| defer sess.Close() | |||
| sess.OrderBy("cloudbrain_duration_statistic.id ASC limit 1") | |||
| sess.OrderBy("cloudbrain_duration_statistic.date_time ASC limit 1") | |||
| CloudbrainDurationStatistics := make([]*CloudbrainDurationStatistic, 0) | |||
| if err := sess.Table(&CloudbrainDurationStatistic{}).Find(&CloudbrainDurationStatistics); err != nil { | |||
| log.Info("find error.") | |||
| } | |||
| return CloudbrainDurationStatistics, nil | |||
| } | |||
| func GetDurationRecordUpdateTime() ([]*CloudbrainDurationStatistic, error) { | |||
| sess := xStatistic.NewSession() | |||
| defer sess.Close() | |||
| sess.OrderBy("cloudbrain_duration_statistic.date_time DESC limit 1") | |||
| CloudbrainDurationStatistics := make([]*CloudbrainDurationStatistic, 0) | |||
| if err := sess.Table(&CloudbrainDurationStatistic{}).Find(&CloudbrainDurationStatistics); err != nil { | |||
| log.Info("find error.") | |||
| } | |||
| return CloudbrainDurationStatistics, nil | |||
| } | |||
| func DeleteCloudbrainDurationStatistic() error { | |||
| sess := xStatistic.NewSession() | |||
| defer sess.Close() | |||
| if _, err := sess.Exec("TRUNCATE TABLE cloudbrain_duration_statistic"); err != nil { | |||
| log.Info("TRUNCATE cloudbrain_duration_statistic error.") | |||
| return err | |||
| } | |||
| return nil | |||
| } | |||
| @@ -598,20 +598,23 @@ var ( | |||
| //grampus config | |||
| Grampus = struct { | |||
| Env string | |||
| Host string | |||
| UserName string | |||
| Password string | |||
| SpecialPools string | |||
| C2NetSequence string | |||
| SyncScriptProject string | |||
| LocalCenterID string | |||
| AiCenterInfo string | |||
| Env string | |||
| Host string | |||
| UserName string | |||
| Password string | |||
| SpecialPools string | |||
| C2NetSequence string | |||
| SyncScriptProject string | |||
| LocalCenterID string | |||
| AiCenterInfo string | |||
| AiCenterCodeAndNameInfo string | |||
| UsageRateBeginTime string | |||
| }{} | |||
| C2NetInfos *C2NetSqInfos | |||
| CenterInfos *AiCenterInfos | |||
| C2NetMapInfo map[string]*C2NetSequenceInfo | |||
| C2NetInfos *C2NetSqInfos | |||
| CenterInfos *AiCenterInfos | |||
| C2NetMapInfo map[string]*C2NetSequenceInfo | |||
| AiCenterCodeAndNameMapInfo map[string]*C2NetSequenceInfo | |||
| //elk config | |||
| ElkUrl string | |||
| @@ -1651,6 +1654,8 @@ func getGrampusConfig() { | |||
| 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\":\"鹏城云脑一号\",\"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 err := json.Unmarshal([]byte(Grampus.C2NetSequence), &C2NetInfos); err != nil { | |||
| log.Error("Unmarshal(C2NetSequence) failed:%v", err) | |||
| @@ -1660,6 +1665,15 @@ func getGrampusConfig() { | |||
| C2NetMapInfo[value.Name] = value | |||
| } | |||
| } | |||
| if Grampus.AiCenterCodeAndNameInfo != "" { | |||
| if err := json.Unmarshal([]byte(Grampus.AiCenterCodeAndNameInfo), &C2NetInfos); err != nil { | |||
| log.Error("Unmarshal(AiCenterCodeAndNameInfo) failed:%v", err) | |||
| } | |||
| AiCenterCodeAndNameMapInfo = make(map[string]*C2NetSequenceInfo) | |||
| for _, value := range C2NetInfos.C2NetSqInfo { | |||
| AiCenterCodeAndNameMapInfo[value.Name] = value | |||
| } | |||
| } | |||
| Grampus.SyncScriptProject = sec.Key("SYNC_SCRIPT_PROJECT").MustString("script_for_grampus") | |||
| Grampus.LocalCenterID = sec.Key("LOCAL_CENTER_ID").MustString("cloudbrain2") | |||
| Grampus.AiCenterInfo = sec.Key("AI_CENTER_INFO").MustString("") | |||
| @@ -17,6 +17,7 @@ import ( | |||
| "code.gitea.io/gitea/modules/context" | |||
| "code.gitea.io/gitea/modules/log" | |||
| "code.gitea.io/gitea/modules/setting" | |||
| cloudbrainService "code.gitea.io/gitea/services/cloudbrain" | |||
| ) | |||
| const ( | |||
| @@ -95,6 +96,8 @@ func CloudBrains(ctx *context.Context) { | |||
| models.LoadSpecs4CloudbrainInfo(ciTasks) | |||
| for i, task := range ciTasks { | |||
| ciTasks[i] = cloudbrainService.UpdateCloudbrainAiCenter(ciTasks[i]) | |||
| ciTasks[i].Cloudbrain.AiCenter = repo.GetAiCenterNameByCode(ciTasks[i].Cloudbrain.AiCenter, ctx.Language()) | |||
| ciTasks[i].CanDebug = true | |||
| ciTasks[i].CanDel = true | |||
| ciTasks[i].Cloudbrain.ComputeResource = task.ComputeResource | |||
| @@ -186,7 +189,8 @@ func DownloadCloudBrains(ctx *context.Context) { | |||
| } | |||
| models.LoadSpecs4CloudbrainInfo(pageRecords) | |||
| for _, record := range pageRecords { | |||
| record = cloudbrainService.UpdateCloudbrainAiCenter(record) | |||
| record.Cloudbrain.AiCenter = repo.GetAiCenterNameByCode(record.Cloudbrain.AiCenter, ctx.Language()) | |||
| for k, v := range allValues(row, record, ctx) { | |||
| f.SetCellValue(cloudBrain, k, v) | |||
| } | |||
| @@ -208,7 +212,7 @@ func allValues(row int, rs *models.CloudbrainInfo, ctx *context.Context) map[str | |||
| return map[string]string{getCellName("A", row): rs.DisplayJobName, getCellName("B", row): repo.GetCloudbrainCluster(rs.Cloudbrain, ctx), | |||
| getCellName("C", row): rs.JobType, getCellName("D", row): rs.Status, getCellName("E", row): time.Unix(int64(rs.Cloudbrain.CreatedUnix), 0).Format(CREATE_TIME_FORMAT), | |||
| getCellName("F", row): getDurationTime(rs), getCellName("G", row): rs.ComputeResource, | |||
| getCellName("H", row): repo.GetCloudbrainAiCenter(rs.Cloudbrain, ctx), getCellName("I", row): getCloudbrainCardType(rs), | |||
| getCellName("H", row): rs.Cloudbrain.AiCenter, getCellName("I", row): getCloudbrainCardType(rs), | |||
| getCellName("J", row): rs.Name, getCellName("K", row): getRepoPathName(rs), getCellName("L", row): rs.JobName, | |||
| } | |||
| } | |||
| @@ -631,6 +631,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
| m.Get("/overview_resource", repo.GetCloudbrainResourceOverview) | |||
| m.Get("/resource_usage_statistic", repo.GetDurationRateStatistic) | |||
| m.Get("/resource_usage_rate_detail", repo.GetCloudbrainResourceUsageDetail) | |||
| m.Get("/resource_queues", repo.GetResourceQueues) | |||
| m.Get("/apitest_for_statistic", repo.CloudbrainDurationStatisticForTest) | |||
| }) | |||
| }, operationReq) | |||
| @@ -12,6 +12,8 @@ import ( | |||
| "code.gitea.io/gitea/modules/context" | |||
| "code.gitea.io/gitea/modules/log" | |||
| "code.gitea.io/gitea/routers/repo" | |||
| cloudbrainService "code.gitea.io/gitea/services/cloudbrain" | |||
| "code.gitea.io/gitea/services/cloudbrain/resource" | |||
| "github.com/360EntSecGroup-Skylar/excelize/v2" | |||
| ) | |||
| @@ -121,8 +123,8 @@ func GetOverviewDuration(ctx *context.Context) { | |||
| recordBeginTime := recordCloudbrain[0].Cloudbrain.CreatedUnix | |||
| now := time.Now() | |||
| endTime := now | |||
| worker_server_num := 1 | |||
| cardNum := 1 | |||
| // worker_server_num := 1 | |||
| // cardNum := 1 | |||
| durationAllSum := int64(0) | |||
| cardDuSum := int64(0) | |||
| @@ -148,34 +150,40 @@ func GetOverviewDuration(ctx *context.Context) { | |||
| models.LoadSpecs4CloudbrainInfo(cloudbrains) | |||
| for _, cloudbrain := range cloudbrains { | |||
| if cloudbrain.Cloudbrain.WorkServerNumber >= 1 { | |||
| worker_server_num = cloudbrain.Cloudbrain.WorkServerNumber | |||
| } else { | |||
| worker_server_num = 1 | |||
| } | |||
| if cloudbrain.Cloudbrain.Spec == nil { | |||
| cardNum = 1 | |||
| } else { | |||
| cardNum = cloudbrain.Cloudbrain.Spec.AccCardsNum | |||
| } | |||
| duration := cloudbrain.Duration | |||
| durationSum := cloudbrain.Duration * int64(worker_server_num) * int64(cardNum) | |||
| cloudbrain = cloudbrainService.UpdateCloudbrainAiCenter(cloudbrain) | |||
| CardDurationString := repo.GetCloudbrainCardDuration(cloudbrain.Cloudbrain) | |||
| CardDuration := models.ConvertStrToDuration(CardDurationString) | |||
| // if cloudbrain.Cloudbrain.WorkServerNumber >= 1 { | |||
| // worker_server_num = cloudbrain.Cloudbrain.WorkServerNumber | |||
| // } else { | |||
| // worker_server_num = 1 | |||
| // } | |||
| // if cloudbrain.Cloudbrain.Spec == nil { | |||
| // cardNum = 1 | |||
| // } else { | |||
| // cardNum = cloudbrain.Cloudbrain.Spec.AccCardsNum | |||
| // } | |||
| // duration := cloudbrain.Duration | |||
| // duration := cloudbrain.Duration | |||
| duration := models.ConvertStrToDuration(cloudbrain.TrainJobDuration) | |||
| // CardDuration := cloudbrain.Duration * int64(worker_server_num) * int64(cardNum) | |||
| if cloudbrain.Cloudbrain.Type == models.TypeCloudBrainOne { | |||
| cloudBrainOneDuration += duration | |||
| cloudBrainOneCardDuSum += durationSum | |||
| cloudBrainOneCardDuSum += CardDuration | |||
| } else if cloudbrain.Cloudbrain.Type == models.TypeCloudBrainTwo { | |||
| cloudBrainTwoDuration += duration | |||
| cloudBrainTwoCardDuSum += durationSum | |||
| cloudBrainTwoCardDuSum += CardDuration | |||
| } else if cloudbrain.Cloudbrain.Type == models.TypeC2Net { | |||
| c2NetDuration += duration | |||
| c2NetCardDuSum += durationSum | |||
| c2NetCardDuSum += CardDuration | |||
| } else if cloudbrain.Cloudbrain.Type == models.TypeCDCenter { | |||
| cDCenterDuration += duration | |||
| cDNetCardDuSum += durationSum | |||
| cDNetCardDuSum += CardDuration | |||
| } | |||
| durationAllSum += duration | |||
| cardDuSum += durationSum | |||
| cardDuSum += CardDuration | |||
| } | |||
| ctx.JSON(http.StatusOK, map[string]interface{}{ | |||
| "cloudBrainOneCardDuSum": cloudBrainOneCardDuSum, | |||
| @@ -192,6 +200,28 @@ func GetOverviewDuration(ctx *context.Context) { | |||
| }) | |||
| } | |||
| func GetCloudbrainCardDuration(task models.Cloudbrain) string { | |||
| cardNum := int(0) | |||
| spec, err := resource.GetCloudbrainSpec(task.ID) | |||
| if err != nil { | |||
| log.Info("error:" + err.Error()) | |||
| return "" | |||
| } | |||
| if spec != nil { | |||
| cardNum = spec.AccCardsNum | |||
| } else { | |||
| cardNum = 1 | |||
| } | |||
| var workServerNumber int64 | |||
| if task.WorkServerNumber >= 1 { | |||
| workServerNumber = int64(task.WorkServerNumber) | |||
| } else { | |||
| workServerNumber = 1 | |||
| } | |||
| cardDuration := models.ConvertDurationToStr(workServerNumber * int64(cardNum) * task.Duration) | |||
| return cardDuration | |||
| } | |||
| func GetAllCloudbrainsTrend(ctx *context.Context) { | |||
| queryType := ctx.QueryTrim("type") | |||
| @@ -703,6 +733,30 @@ func GetCloudbrainsDetailData(ctx *context.Context) { | |||
| aiCenter := ctx.Query("aiCenter") | |||
| needDeleteInfo := ctx.Query("needDeleteInfo") | |||
| if cloudBrainType == models.TypeCloudBrainOne && aiCenter == models.AICenterOfCloudBrainOne { | |||
| aiCenter = "" | |||
| } | |||
| if cloudBrainType == models.TypeCloudBrainTwo && aiCenter == models.AICenterOfCloudBrainTwo { | |||
| aiCenter = "" | |||
| } | |||
| if cloudBrainType == models.TypeCDCenter && aiCenter == models.AICenterOfChengdu { | |||
| aiCenter = "" | |||
| } | |||
| if cloudBrainType == models.TypeCloudBrainAll { | |||
| if aiCenter == models.AICenterOfCloudBrainOne { | |||
| cloudBrainType = models.TypeCloudBrainOne | |||
| aiCenter = "" | |||
| } | |||
| if aiCenter == models.AICenterOfCloudBrainTwo { | |||
| cloudBrainType = models.TypeCloudBrainTwo | |||
| aiCenter = "" | |||
| } | |||
| if aiCenter == models.AICenterOfChengdu { | |||
| cloudBrainType = models.TypeCDCenter | |||
| aiCenter = "" | |||
| } | |||
| } | |||
| page := ctx.QueryInt("page") | |||
| pageSize := ctx.QueryInt("pagesize") | |||
| if page <= 0 { | |||
| @@ -732,7 +786,7 @@ func GetCloudbrainsDetailData(ctx *context.Context) { | |||
| keyword := strings.Trim(ctx.Query("q"), " ") | |||
| ciTasks, _, err := models.CloudbrainAll(&models.CloudbrainsOptions{ | |||
| ciTasks, count, err := models.CloudbrainAll(&models.CloudbrainsOptions{ | |||
| ListOptions: models.ListOptions{ | |||
| Page: page, | |||
| PageSize: pageSize, | |||
| @@ -747,8 +801,8 @@ func GetCloudbrainsDetailData(ctx *context.Context) { | |||
| NeedRepoInfo: true, | |||
| BeginTimeUnix: int64(recordBeginTime), | |||
| EndTimeUnix: endTime.Unix(), | |||
| // AiCenter: aiCenter, | |||
| NeedDeleteInfo: needDeleteInfo, | |||
| AiCenter: aiCenter, | |||
| NeedDeleteInfo: needDeleteInfo, | |||
| }) | |||
| if err != nil { | |||
| ctx.ServerError("Get job failed:", err) | |||
| @@ -758,45 +812,43 @@ func GetCloudbrainsDetailData(ctx *context.Context) { | |||
| nilTime := time.Time{} | |||
| tasks := []models.TaskDetail{} | |||
| 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) | |||
| 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 | |||
| taskDetail.AiCenter = repo.GetAiCenterNameByCode(task.Cloudbrain.AiCenter, ctx.Language()) | |||
| 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)) | |||
| pager := context.NewPagination(int(count), pageSize, page, getTotalPage(count, pageSize)) | |||
| pager.SetDefaultParams(ctx) | |||
| pager.AddParam(ctx, "listType", "ListType") | |||
| @@ -1176,6 +1228,12 @@ func getMonthCloudbrainInfo(beginTime time.Time, endTime time.Time) ([]DateCloud | |||
| } | |||
| func DownloadCloudBrainBoard(ctx *context.Context) { | |||
| recordCloudbrain, err := models.GetRecordBeginTime() | |||
| if err != nil { | |||
| log.Error("Can not get recordCloudbrain", err) | |||
| ctx.Error(http.StatusBadRequest, ctx.Tr("repo.record_begintime_get_err")) | |||
| return | |||
| } | |||
| page := 1 | |||
| @@ -1184,14 +1242,20 @@ func DownloadCloudBrainBoard(ctx *context.Context) { | |||
| var cloudBrain = ctx.Tr("repo.cloudbrain") | |||
| fileName := getCloudbrainFileName(cloudBrain) | |||
| recordBeginTime := recordCloudbrain[0].Cloudbrain.CreatedUnix | |||
| now := time.Now() | |||
| endTime := now | |||
| _, total, err := models.CloudbrainAll(&models.CloudbrainsOptions{ | |||
| ListOptions: models.ListOptions{ | |||
| Page: page, | |||
| PageSize: pageSize, | |||
| }, | |||
| Type: models.TypeCloudBrainAll, | |||
| NeedRepoInfo: false, | |||
| Type: models.TypeCloudBrainAll, | |||
| BeginTimeUnix: int64(recordBeginTime), | |||
| EndTimeUnix: endTime.Unix(), | |||
| }) | |||
| log.Info("totalcountisis:", total) | |||
| if err != nil { | |||
| log.Warn("Can not get cloud brain info", err) | |||
| @@ -1216,8 +1280,10 @@ func DownloadCloudBrainBoard(ctx *context.Context) { | |||
| Page: page, | |||
| PageSize: pageSize, | |||
| }, | |||
| Type: models.TypeCloudBrainAll, | |||
| NeedRepoInfo: true, | |||
| Type: models.TypeCloudBrainAll, | |||
| BeginTimeUnix: int64(recordBeginTime), | |||
| EndTimeUnix: endTime.Unix(), | |||
| NeedRepoInfo: true, | |||
| }) | |||
| if err != nil { | |||
| log.Warn("Can not get cloud brain info", err) | |||
| @@ -1225,7 +1291,8 @@ func DownloadCloudBrainBoard(ctx *context.Context) { | |||
| } | |||
| models.LoadSpecs4CloudbrainInfo(pageRecords) | |||
| for _, record := range pageRecords { | |||
| record = cloudbrainService.UpdateCloudbrainAiCenter(record) | |||
| record.Cloudbrain.AiCenter = repo.GetAiCenterNameByCode(record.Cloudbrain.AiCenter, ctx.Language()) | |||
| for k, v := range allCloudbrainValues(row, record, ctx) { | |||
| f.SetCellValue(cloudBrain, k, v) | |||
| } | |||
| @@ -1264,7 +1331,7 @@ func allCloudbrainValues(row int, rs *models.CloudbrainInfo, ctx *context.Contex | |||
| getCellName("G", row): rs.TrainJobDuration, getCellName("H", row): repo.GetCloudbrainCardDuration(rs.Cloudbrain), | |||
| getCellName("I", row): getBrainStartTime(rs), | |||
| getCellName("J", row): getBrainEndTime(rs), getCellName("K", row): rs.ComputeResource, getCellName("L", row): getCloudbrainCardType(rs), | |||
| getCellName("M", row): getWorkServerNum(rs), getCellName("N", row): repo.GetCloudbrainAiCenter(rs.Cloudbrain, ctx), | |||
| getCellName("M", row): getWorkServerNum(rs), getCellName("N", row): rs.Cloudbrain.AiCenter, | |||
| getCellName("O", row): getCloudbrainFlavorName(rs), getCellName("P", row): rs.Name, | |||
| getCellName("Q", row): getBrainRepo(rs), getCellName("R", row): rs.JobName, getCellName("S", row): getBrainDeleteTime(rs), | |||
| } | |||
| @@ -1417,7 +1484,7 @@ func GetCloudbrainResourceOverview(ctx *context.Context) { | |||
| log.Error("Can not get GetDurationRecordBeginTime", err) | |||
| return | |||
| } | |||
| recordBeginTime := recordCloudbrainDuration[0].CreatedUnix | |||
| recordBeginTime := recordCloudbrainDuration[0].DateTime | |||
| recordUpdateTime := time.Now().Unix() | |||
| resourceQueues, err := models.GetCanUseCardInfo() | |||
| if err != nil { | |||
| @@ -1428,11 +1495,12 @@ func GetCloudbrainResourceOverview(ctx *context.Context) { | |||
| C2NetResourceDetail := []models.ResourceDetail{} | |||
| for _, resourceQueue := range resourceQueues { | |||
| if resourceQueue.Cluster == models.OpenICluster { | |||
| aiCenterName := repo.GetAiCenterNameByCode(resourceQueue.AiCenterCode, ctx.Language()) | |||
| var resourceDetail models.ResourceDetail | |||
| resourceDetail.QueueCode = resourceQueue.QueueCode | |||
| resourceDetail.Cluster = resourceQueue.Cluster | |||
| resourceDetail.AiCenterCode = resourceQueue.AiCenterCode | |||
| resourceDetail.AiCenterName = resourceQueue.AiCenterName + "/" + resourceQueue.AiCenterCode | |||
| resourceDetail.AiCenterName = resourceQueue.AiCenterCode + "/" + aiCenterName | |||
| resourceDetail.ComputeResource = resourceQueue.ComputeResource | |||
| resourceDetail.AccCardType = resourceQueue.AccCardType + "(" + resourceQueue.ComputeResource + ")" | |||
| resourceDetail.CardsTotalNum = resourceQueue.CardsTotalNum | |||
| @@ -1440,11 +1508,12 @@ func GetCloudbrainResourceOverview(ctx *context.Context) { | |||
| OpenIResourceDetail = append(OpenIResourceDetail, resourceDetail) | |||
| } | |||
| if resourceQueue.Cluster == models.C2NetCluster { | |||
| aiCenterName := repo.GetAiCenterNameByCode(resourceQueue.AiCenterCode, ctx.Language()) | |||
| var resourceDetail models.ResourceDetail | |||
| resourceDetail.QueueCode = resourceQueue.QueueCode | |||
| resourceDetail.Cluster = resourceQueue.Cluster | |||
| resourceDetail.AiCenterCode = resourceQueue.AiCenterCode | |||
| resourceDetail.AiCenterName = resourceQueue.AiCenterName + "/" + resourceQueue.AiCenterCode | |||
| resourceDetail.AiCenterName = resourceQueue.AiCenterCode + "/" + aiCenterName | |||
| resourceDetail.ComputeResource = resourceQueue.ComputeResource | |||
| resourceDetail.AccCardType = resourceQueue.AccCardType + "(" + resourceQueue.ComputeResource + ")" | |||
| resourceDetail.CardsTotalNum = resourceQueue.CardsTotalNum | |||
| @@ -1554,7 +1623,7 @@ func getBeginAndEndTime(ctx *context.Context) (time.Time, time.Time) { | |||
| ctx.Error(http.StatusBadRequest, ctx.Tr("repo.record_begintime_get_err")) | |||
| return beginTime, endTime | |||
| } | |||
| brainRecordBeginTime := recordCloudbrainDuration[0].CreatedUnix.AsTime() | |||
| brainRecordBeginTime := recordCloudbrainDuration[0].DateTime.AsTime() | |||
| beginTime = brainRecordBeginTime | |||
| endTime = now | |||
| } else if queryType == "today" { | |||
| @@ -1596,7 +1665,7 @@ func getBeginAndEndTime(ctx *context.Context) (time.Time, time.Time) { | |||
| ctx.Error(http.StatusBadRequest, ctx.Tr("repo.record_begintime_get_err")) | |||
| return beginTime, endTime | |||
| } | |||
| brainRecordBeginTime := recordCloudbrainDuration[0].CreatedUnix.AsTime() | |||
| brainRecordBeginTime := recordCloudbrainDuration[0].DateTime.AsTime() | |||
| beginTime = brainRecordBeginTime | |||
| endTime = now | |||
| } else { | |||
| @@ -1627,7 +1696,7 @@ func getAiCenterUsageDuration(beginTime time.Time, endTime time.Time, cloudbrain | |||
| usageRate := float64(0) | |||
| for _, cloudbrainStatistic := range cloudbrainStatistics { | |||
| if int64(cloudbrainStatistic.CreatedUnix) >= beginTime.Unix() && int64(cloudbrainStatistic.CreatedUnix) < endTime.Unix() { | |||
| if int64(cloudbrainStatistic.DateTime) >= beginTime.Unix() && int64(cloudbrainStatistic.DateTime) < endTime.Unix() { | |||
| totalDuration += cloudbrainStatistic.CardsTotalDuration | |||
| usageDuration += cloudbrainStatistic.CardsUseDuration | |||
| } | |||
| @@ -1659,28 +1728,29 @@ func getDurationStatistic(beginTime time.Time, endTime time.Time) (models.Durati | |||
| return OpenIDurationRate, C2NetDurationRate, 0 | |||
| } | |||
| for _, cloudbrainStatistic := range cardDurationStatistics { | |||
| aiCenterName := cloudbrainStatistic.AiCenterCode + "/" + repo.GetAiCenterNameByCode(cloudbrainStatistic.AiCenterCode, "zh-CN") | |||
| if cloudbrainStatistic.Cluster == models.OpenICluster { | |||
| if _, ok := OpenITotalDuration[cloudbrainStatistic.AiCenterName]; !ok { | |||
| OpenITotalDuration[cloudbrainStatistic.AiCenterName] = cloudbrainStatistic.CardsTotalDuration | |||
| if _, ok := OpenITotalDuration[aiCenterName]; !ok { | |||
| OpenITotalDuration[aiCenterName] = cloudbrainStatistic.CardsTotalDuration | |||
| } else { | |||
| OpenITotalDuration[cloudbrainStatistic.AiCenterName] += cloudbrainStatistic.CardsTotalDuration | |||
| OpenITotalDuration[aiCenterName] += cloudbrainStatistic.CardsTotalDuration | |||
| } | |||
| if _, ok := OpenIUsageDuration[cloudbrainStatistic.AiCenterName]; !ok { | |||
| OpenIUsageDuration[cloudbrainStatistic.AiCenterName] = cloudbrainStatistic.CardsUseDuration | |||
| if _, ok := OpenIUsageDuration[aiCenterName]; !ok { | |||
| OpenIUsageDuration[aiCenterName] = cloudbrainStatistic.CardsUseDuration | |||
| } else { | |||
| OpenIUsageDuration[cloudbrainStatistic.AiCenterName] += cloudbrainStatistic.CardsUseDuration | |||
| OpenIUsageDuration[aiCenterName] += cloudbrainStatistic.CardsUseDuration | |||
| } | |||
| } | |||
| if cloudbrainStatistic.Cluster == models.C2NetCluster { | |||
| if _, ok := C2NetTotalDuration[cloudbrainStatistic.AiCenterName]; !ok { | |||
| C2NetTotalDuration[cloudbrainStatistic.AiCenterName] = cloudbrainStatistic.CardsTotalDuration | |||
| if _, ok := C2NetTotalDuration[aiCenterName]; !ok { | |||
| C2NetTotalDuration[aiCenterName] = cloudbrainStatistic.CardsTotalDuration | |||
| } else { | |||
| C2NetTotalDuration[cloudbrainStatistic.AiCenterName] += cloudbrainStatistic.CardsTotalDuration | |||
| C2NetTotalDuration[aiCenterName] += cloudbrainStatistic.CardsTotalDuration | |||
| } | |||
| if _, ok := C2NetUsageDuration[cloudbrainStatistic.AiCenterName]; !ok { | |||
| C2NetUsageDuration[cloudbrainStatistic.AiCenterName] = cloudbrainStatistic.CardsUseDuration | |||
| if _, ok := C2NetUsageDuration[aiCenterName]; !ok { | |||
| C2NetUsageDuration[aiCenterName] = cloudbrainStatistic.CardsUseDuration | |||
| } else { | |||
| C2NetUsageDuration[cloudbrainStatistic.AiCenterName] += cloudbrainStatistic.CardsUseDuration | |||
| C2NetUsageDuration[aiCenterName] += cloudbrainStatistic.CardsUseDuration | |||
| } | |||
| } | |||
| } | |||
| @@ -1690,16 +1760,17 @@ func getDurationStatistic(beginTime time.Time, endTime time.Time) (models.Durati | |||
| return OpenIDurationRate, C2NetDurationRate, 0 | |||
| } | |||
| for _, v := range ResourceAiCenterRes { | |||
| aiCenterName := v.AiCenterCode + "/" + repo.GetAiCenterNameByCode(v.AiCenterCode, "zh-CN") | |||
| if cutString(v.AiCenterCode, 4) == cutString(models.AICenterOfCloudBrainOne, 4) { | |||
| if _, ok := OpenIUsageDuration[v.AiCenterName]; !ok { | |||
| OpenIUsageDuration[v.AiCenterName] = 0 | |||
| if _, ok := OpenIUsageDuration[aiCenterName]; !ok { | |||
| OpenIUsageDuration[aiCenterName] = 0 | |||
| } | |||
| if _, ok := OpenITotalDuration[v.AiCenterName]; !ok { | |||
| OpenITotalDuration[v.AiCenterName] = 0 | |||
| if _, ok := OpenITotalDuration[aiCenterName]; !ok { | |||
| OpenITotalDuration[aiCenterName] = 0 | |||
| } | |||
| } else { | |||
| if _, ok := C2NetUsageDuration[v.AiCenterName]; !ok { | |||
| C2NetUsageDuration[v.AiCenterName] = 0 | |||
| if _, ok := C2NetUsageDuration[aiCenterName]; !ok { | |||
| C2NetUsageDuration[aiCenterName] = 0 | |||
| } | |||
| } | |||
| } | |||
| @@ -1716,7 +1787,7 @@ func getDurationStatistic(beginTime time.Time, endTime time.Time) (models.Durati | |||
| for _, v := range OpenITotalDuration { | |||
| totalCanUse += float64(v) | |||
| } | |||
| for _, v := range OpenIUsageRate { | |||
| for _, v := range OpenIUsageDuration { | |||
| totalUse += float64(v) | |||
| } | |||
| if totalCanUse == 0 || totalUse == 0 { | |||
| @@ -1724,6 +1795,7 @@ func getDurationStatistic(beginTime time.Time, endTime time.Time) (models.Durati | |||
| } else { | |||
| totalUsageRate = totalUse / totalCanUse | |||
| } | |||
| delete(C2NetUsageDuration, "/") | |||
| OpenIDurationRate.AiCenterTotalDurationStat = OpenITotalDuration | |||
| OpenIDurationRate.AiCenterUsageDurationStat = OpenIUsageDuration | |||
| @@ -1831,3 +1903,30 @@ func getHourCloudbrainDuration(beginTime time.Time, endTime time.Time, aiCenterC | |||
| hourTimeStatistic.HourTimeUsageRate = hourTimeUsageRate | |||
| return hourTimeStatistic, nil | |||
| } | |||
| func CloudbrainUpdateAiCenter(ctx *context.Context) { | |||
| repo.CloudbrainDurationStatisticHour() | |||
| ctx.JSON(http.StatusOK, map[string]interface{}{ | |||
| "message": 0, | |||
| }) | |||
| } | |||
| func GetResourceQueues(ctx *context.Context) { | |||
| resourceQueues, err := models.GetCanUseCardInfo() | |||
| if err != nil { | |||
| log.Info("GetCanUseCardInfo err: %v", err) | |||
| return | |||
| } | |||
| Resource := make([]*models.ResourceQueue, 0) | |||
| aiCenterCodeMap := make(map[string]string) | |||
| for _, resourceQueue := range resourceQueues { | |||
| if _, ok := aiCenterCodeMap[resourceQueue.AiCenterCode]; !ok { | |||
| resourceQueue.AiCenterName = repo.GetAiCenterNameByCode(resourceQueue.AiCenterCode, ctx.Language()) | |||
| aiCenterCodeMap[resourceQueue.AiCenterCode] = resourceQueue.AiCenterCode | |||
| Resource = append(Resource, resourceQueue) | |||
| } | |||
| } | |||
| ctx.JSON(http.StatusOK, map[string]interface{}{ | |||
| "resourceQueues": Resource, | |||
| }) | |||
| } | |||
| @@ -146,7 +146,6 @@ func GetModelArtsTrainJobVersion(ctx *context.APIContext) { | |||
| if len(result.JobInfo.Tasks) > 0 { | |||
| if len(result.JobInfo.Tasks[0].CenterID) > 0 && len(result.JobInfo.Tasks[0].CenterName) > 0 { | |||
| job.AiCenter = result.JobInfo.Tasks[0].CenterID[0] + "+" + result.JobInfo.Tasks[0].CenterName[0] | |||
| // aiCenterName = result.JobInfo.Tasks[0].CenterName[0] | |||
| aiCenterName = cloudbrainService.GetAiCenterShow(job.AiCenter, ctx.Context) | |||
| } | |||
| } | |||
| @@ -55,6 +55,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
| m.Post("/task/history_handle/duration", repo.HandleTaskWithNoDuration) | |||
| m.Post("/task/history_handle/aicenter", repo.HandleTaskWithAiCenter) | |||
| m.Post("/resources/specification/handle_historical_task", admin.RefreshHistorySpec) | |||
| m.Post("/duration_statisctic/history_handle", repo.CloudbrainUpdateHistoryData) | |||
| }, CheckInternalToken) | |||
| } | |||
| @@ -1,38 +1,87 @@ | |||
| package repo | |||
| import ( | |||
| "net/http" | |||
| "strings" | |||
| "time" | |||
| "code.gitea.io/gitea/models" | |||
| "code.gitea.io/gitea/modules/context" | |||
| "code.gitea.io/gitea/modules/log" | |||
| "code.gitea.io/gitea/modules/setting" | |||
| "code.gitea.io/gitea/modules/timeutil" | |||
| cloudbrainService "code.gitea.io/gitea/services/cloudbrain" | |||
| ) | |||
| func CloudbrainDurationStatisticHour() { | |||
| dateTime := time.Now().Format("2006-01-02 15:04:05") | |||
| dayTime := time.Now().Format("2006-01-02") | |||
| var statisticTime time.Time | |||
| var count int64 | |||
| recordBeginTime, _ := time.ParseInLocation("2006-01-02 15:04:05", setting.Grampus.UsageRateBeginTime, time.Local) | |||
| recordDurationUpdateTime, err := models.GetDurationRecordUpdateTime() | |||
| if err != nil { | |||
| log.Error("Can not get GetDurationRecordBeginTime", err) | |||
| return | |||
| } | |||
| if recordDurationUpdateTime == nil { | |||
| statisticTime = recordBeginTime | |||
| } else { | |||
| statisticTime = time.Unix(int64(recordDurationUpdateTime[0].DateTime), 0) | |||
| } | |||
| now := time.Now() | |||
| currentTime := time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), 0, 0, 0, now.Location()) | |||
| for statisticTime.Before(currentTime) || statisticTime.Equal(currentTime) { | |||
| countEach := summaryDurationStat(statisticTime) | |||
| count += countEach | |||
| statisticTime = statisticTime.Add(+1 * time.Hour) | |||
| } | |||
| log.Info("summaryDurationStat count: %v", count) | |||
| } | |||
| func UpdateDurationStatisticHistoryData() int64 { | |||
| var count int64 | |||
| recordBeginTime, _ := time.ParseInLocation("2006-01-02 15:04:05", setting.Grampus.UsageRateBeginTime, time.Local) | |||
| now := time.Now() | |||
| currentTime := time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), 0, 0, 0, now.Location()) | |||
| statisticTime := recordBeginTime.Add(+1 * time.Hour) | |||
| for statisticTime.Before(currentTime) || statisticTime.Equal(currentTime) { | |||
| countEach := summaryDurationStat(statisticTime) | |||
| count += countEach | |||
| statisticTime = statisticTime.Add(+1 * time.Hour) | |||
| } | |||
| return count | |||
| } | |||
| m, _ := time.ParseDuration("-1h") | |||
| beginTime := currentTime.Add(m).Unix() | |||
| endTime := currentTime.Unix() | |||
| hourTime := currentTime.Add(m).Hour() | |||
| //statisticTime是当前的时辰,比如当前是2019-01-01 12:01:01,那么statisticTime就是2019-01-01 12:00:00 | |||
| func summaryDurationStat(statisticTime time.Time) int64 { | |||
| var count int64 | |||
| dateTime := timeutil.TimeStamp(statisticTime.Add(-1 * time.Hour).Unix()) | |||
| beginTime := statisticTime.Add(-1 * time.Hour).Unix() | |||
| dayTime := statisticTime.Add(-1 * time.Hour).Format("2006-01-02") | |||
| hourTime := statisticTime.Add(-1 * time.Hour).Hour() | |||
| endTime := statisticTime.Unix() | |||
| ciTasks, err := models.GetCloudbrainByTime(beginTime, endTime) | |||
| if err != nil { | |||
| log.Info("GetCloudbrainByTime err: %v", err) | |||
| return | |||
| return 0 | |||
| } | |||
| specMap := make(map[string]*models.Specification) | |||
| cloudbrainMap := make(map[string]*models.Cloudbrain) | |||
| models.LoadSpecs4CloudbrainInfo(ciTasks) | |||
| for _, cloudbrain := range ciTasks { | |||
| if _, ok := specMap[cloudbrain.Cloudbrain.Spec.AiCenterCode+"/"+cloudbrain.Cloudbrain.Spec.AccCardType]; !ok { | |||
| if cloudbrain.Cloudbrain.Spec != nil { | |||
| specMap[cloudbrain.Cloudbrain.Spec.AiCenterCode+"/"+cloudbrain.Cloudbrain.Spec.AccCardType] = cloudbrain.Cloudbrain.Spec | |||
| if cloudbrain.Cloudbrain.StartTime == 0 { | |||
| cloudbrain.Cloudbrain.StartTime = cloudbrain.Cloudbrain.CreatedUnix | |||
| } | |||
| if cloudbrain.Cloudbrain.EndTime == 0 { | |||
| cloudbrain.Cloudbrain.EndTime = cloudbrain.Cloudbrain.UpdatedUnix | |||
| } | |||
| cloudbrain = cloudbrainService.UpdateCloudbrainAiCenter(cloudbrain) | |||
| if cloudbrain.Cloudbrain.Spec != nil { | |||
| if _, ok := cloudbrainMap[cloudbrain.Cloudbrain.AiCenter+"/"+cloudbrain.Cloudbrain.Spec.AccCardType]; !ok { | |||
| if cloudbrain.Cloudbrain.Spec != nil { | |||
| cloudbrainMap[cloudbrain.Cloudbrain.AiCenter+"/"+cloudbrain.Cloudbrain.Spec.AccCardType] = &cloudbrain.Cloudbrain | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -42,69 +91,96 @@ func CloudbrainDurationStatisticHour() { | |||
| resourceQueues, err := models.GetCanUseCardInfo() | |||
| if err != nil { | |||
| log.Info("GetCanUseCardInfo err: %v", err) | |||
| return | |||
| return 0 | |||
| } | |||
| cardsTotalDurationMap := make(map[string]int) | |||
| for _, resourceQueue := range resourceQueues { | |||
| cardsTotalDurationMap[resourceQueue.Cluster+"/"+resourceQueue.AiCenterName+"/"+resourceQueue.AiCenterCode+"/"+resourceQueue.AccCardType+"/"+resourceQueue.ComputeResource] = resourceQueue.CardsTotalNum * 1 * 60 * 60 | |||
| if _, ok := cardsTotalDurationMap[resourceQueue.Cluster+"/"+resourceQueue.AiCenterCode+"/"+resourceQueue.AccCardType]; !ok { | |||
| cardsTotalDurationMap[resourceQueue.Cluster+"/"+resourceQueue.AiCenterCode+"/"+resourceQueue.AccCardType] = resourceQueue.CardsTotalNum * 1 * 60 * 60 | |||
| } else { | |||
| cardsTotalDurationMap[resourceQueue.Cluster+"/"+resourceQueue.AiCenterCode+"/"+resourceQueue.AccCardType] += resourceQueue.CardsTotalNum * 1 * 60 * 60 | |||
| } | |||
| } | |||
| for centerCode, CardTypeInfo := range cloudBrainCenterCodeAndCardTypeInfo { | |||
| for cardType, cardDuration := range CardTypeInfo { | |||
| spec := specMap[centerCode+"/"+cardType] | |||
| if spec != nil { | |||
| if err := models.DeleteCloudbrainDurationStatisticHour(dayTime, hourTime, centerCode, cardType); err != nil { | |||
| log.Error("DeleteCloudbrainDurationStatisticHour failed: %v", err.Error()) | |||
| return | |||
| for centerCode, CardTypes := range cloudBrainCenterCodeAndCardTypeInfo { | |||
| for cardType, cardDuration := range CardTypes { | |||
| cloudbrainTable := cloudbrainMap[centerCode+"/"+cardType] | |||
| if cloudbrainTable != nil { | |||
| if _, err := models.GetDurationStatisticByDate(dayTime, hourTime, centerCode, cardType); err == nil { | |||
| if err := models.DeleteCloudbrainDurationStatisticHour(dayTime, hourTime, centerCode, cardType); err != nil { | |||
| log.Error("DeleteCloudbrainDurationStatisticHour failed: %v", err.Error()) | |||
| return 0 | |||
| } | |||
| } | |||
| if _, ok := cardsTotalDurationMap[spec.Cluster+"/"+spec.AiCenterName+"/"+centerCode+"/"+cardType+"/"+spec.ComputeResource]; !ok { | |||
| cardsTotalDurationMap[spec.Cluster+"/"+spec.AiCenterName+"/"+centerCode+"/"+cardType+"/"+spec.ComputeResource] = 0 | |||
| if _, ok := cardsTotalDurationMap[cloudbrainTable.Cluster+"/"+centerCode+"/"+cardType]; !ok { | |||
| cardsTotalDurationMap[cloudbrainTable.Cluster+"/"+centerCode+"/"+cardType] = 0 | |||
| } | |||
| cloudbrainDurationStat := models.CloudbrainDurationStatistic{ | |||
| DateTime: dateTime, | |||
| DayTime: dayTime, | |||
| HourTime: hourTime, | |||
| Cluster: spec.Cluster, | |||
| AiCenterName: spec.AiCenterName, | |||
| Cluster: cloudbrainTable.Cluster, | |||
| AiCenterName: GetAiCenterNameByCode(centerCode, "zh-CN"), | |||
| AiCenterCode: centerCode, | |||
| AccCardType: cardType, | |||
| ComputeResource: spec.ComputeResource, | |||
| CardsUseDuration: cardDuration, | |||
| CardsTotalDuration: cardsTotalDurationMap[spec.Cluster+"/"+spec.AiCenterName+"/"+centerCode+"/"+cardType+"/"+spec.ComputeResource], | |||
| CardsTotalDuration: cardsTotalDurationMap[cloudbrainTable.Cluster+"/"+centerCode+"/"+cardType], | |||
| CreatedUnix: timeutil.TimeStampNow(), | |||
| } | |||
| if _, err = models.InsertCloudbrainDurationStatistic(&cloudbrainDurationStat); err != nil { | |||
| log.Error("Insert cloudbrainDurationStat failed: %v", err.Error()) | |||
| } | |||
| delete(cardsTotalDurationMap, spec.Cluster+"/"+spec.AiCenterName+"/"+centerCode+"/"+cardType+"/"+spec.ComputeResource) | |||
| count++ | |||
| delete(cardsTotalDurationMap, cloudbrainTable.Cluster+"/"+centerCode+"/"+cardType) | |||
| } | |||
| } | |||
| } | |||
| for key, cardsTotalDuration := range cardsTotalDurationMap { | |||
| if err := models.DeleteCloudbrainDurationStatisticHour(dayTime, hourTime, strings.Split(key, "/")[2], strings.Split(key, "/")[3]); err != nil { | |||
| log.Error("DeleteCloudbrainDurationStatisticHour failed: %v", err.Error()) | |||
| return | |||
| if _, err := models.GetDurationStatisticByDate(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()) | |||
| return 0 | |||
| } | |||
| } | |||
| cloudbrainDurationStat := models.CloudbrainDurationStatistic{ | |||
| DateTime: dateTime, | |||
| DayTime: dayTime, | |||
| HourTime: hourTime, | |||
| Cluster: strings.Split(key, "/")[0], | |||
| AiCenterName: strings.Split(key, "/")[1], | |||
| AiCenterCode: strings.Split(key, "/")[2], | |||
| AccCardType: strings.Split(key, "/")[3], | |||
| ComputeResource: strings.Split(key, "/")[4], | |||
| AiCenterName: GetAiCenterNameByCode(strings.Split(key, "/")[1], "zh-CN"), | |||
| AiCenterCode: strings.Split(key, "/")[1], | |||
| AccCardType: strings.Split(key, "/")[2], | |||
| CardsUseDuration: 0, | |||
| CardsTotalDuration: cardsTotalDuration, | |||
| CardsTotalNum: cardsTotalDuration / 1 / 60 / 60, | |||
| CreatedUnix: timeutil.TimeStampNow(), | |||
| } | |||
| if _, err = models.InsertCloudbrainDurationStatistic(&cloudbrainDurationStat); err != nil { | |||
| log.Error("Insert cloudbrainDurationStat failed: %v", err.Error()) | |||
| } | |||
| count++ | |||
| } | |||
| log.Info("finish summary cloudbrainDurationStat") | |||
| return count | |||
| } | |||
| func GetAiCenterNameByCode(centerCode string, language string) string { | |||
| var aiCenterName string | |||
| aiCenterInfo := cloudbrainService.GetAiCenterInfoByCenterCode(centerCode) | |||
| if aiCenterInfo != nil { | |||
| if language == "zh-CN" { | |||
| aiCenterName = aiCenterInfo.Content | |||
| } else { | |||
| aiCenterName = aiCenterInfo.ContentEN | |||
| } | |||
| } else { | |||
| aiCenterName = centerCode | |||
| } | |||
| return aiCenterName | |||
| } | |||
| func getcloudBrainCenterCodeAndCardTypeInfo(ciTasks []*models.CloudbrainInfo, beginTime int64, endTime int64) map[string]map[string]int { | |||
| @@ -112,7 +188,7 @@ func getcloudBrainCenterCodeAndCardTypeInfo(ciTasks []*models.CloudbrainInfo, be | |||
| var AccCardsNum int | |||
| cloudBrainCenterCodeAndCardType := make(map[string]map[string]int) | |||
| for _, cloudbrain := range ciTasks { | |||
| cloudbrain = cloudbrainService.UpdateCloudbrainAiCenter(cloudbrain) | |||
| if cloudbrain.Cloudbrain.StartTime == 0 { | |||
| cloudbrain.Cloudbrain.StartTime = cloudbrain.Cloudbrain.CreatedUnix | |||
| } | |||
| @@ -129,41 +205,63 @@ func getcloudBrainCenterCodeAndCardTypeInfo(ciTasks []*models.CloudbrainInfo, be | |||
| } else { | |||
| AccCardsNum = cloudbrain.Cloudbrain.Spec.AccCardsNum | |||
| } | |||
| if _, ok := cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.Spec.AiCenterCode]; !ok { | |||
| cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.Spec.AiCenterCode] = make(map[string]int) | |||
| if _, ok := cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.AiCenter]; !ok { | |||
| cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.AiCenter] = make(map[string]int) | |||
| } | |||
| if cloudbrain.Cloudbrain.Status == string(models.ModelArtsRunning) { | |||
| if _, ok := cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.Spec.AiCenterCode][cloudbrain.Cloudbrain.Spec.AccCardType]; !ok { | |||
| if int64(cloudbrain.Cloudbrain.StartTime) < beginTime { | |||
| cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.Spec.AiCenterCode][cloudbrain.Cloudbrain.Spec.AccCardType] = AccCardsNum * WorkServerNumber * (int(endTime) - int(beginTime)) | |||
| if cloudbrain.Cloudbrain.Spec != nil { | |||
| if cloudbrain.Cloudbrain.Status == string(models.ModelArtsRunning) { | |||
| if _, ok := cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.AiCenter][cloudbrain.Cloudbrain.Spec.AccCardType]; !ok { | |||
| if int64(cloudbrain.Cloudbrain.StartTime) < beginTime { | |||
| cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.AiCenter][cloudbrain.Cloudbrain.Spec.AccCardType] = AccCardsNum * WorkServerNumber * (int(endTime) - int(beginTime)) | |||
| } else if beginTime <= int64(cloudbrain.Cloudbrain.StartTime) && int64(cloudbrain.Cloudbrain.StartTime) < endTime { | |||
| cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.AiCenter][cloudbrain.Cloudbrain.Spec.AccCardType] = AccCardsNum * WorkServerNumber * (int(endTime) - int(cloudbrain.Cloudbrain.StartTime)) | |||
| } else if int64(cloudbrain.Cloudbrain.StartTime) >= endTime { | |||
| cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.AiCenter][cloudbrain.Cloudbrain.Spec.AccCardType] = 0 | |||
| } | |||
| } else { | |||
| cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.Spec.AiCenterCode][cloudbrain.Cloudbrain.Spec.AccCardType] = AccCardsNum * WorkServerNumber * (int(endTime) - int(cloudbrain.Cloudbrain.StartTime)) | |||
| if int64(cloudbrain.Cloudbrain.StartTime) < beginTime { | |||
| cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.AiCenter][cloudbrain.Cloudbrain.Spec.AccCardType] += AccCardsNum * WorkServerNumber * (int(endTime) - int(beginTime)) | |||
| } else if beginTime <= int64(cloudbrain.Cloudbrain.StartTime) && int64(cloudbrain.Cloudbrain.StartTime) < endTime { | |||
| cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.AiCenter][cloudbrain.Cloudbrain.Spec.AccCardType] += AccCardsNum * WorkServerNumber * (int(endTime) - int(cloudbrain.Cloudbrain.StartTime)) | |||
| } else if int64(cloudbrain.Cloudbrain.StartTime) >= endTime { | |||
| cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.AiCenter][cloudbrain.Cloudbrain.Spec.AccCardType] += 0 | |||
| } | |||
| } | |||
| } else { | |||
| if int64(cloudbrain.Cloudbrain.StartTime) < beginTime { | |||
| cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.Spec.AiCenterCode][cloudbrain.Cloudbrain.Spec.AccCardType] += AccCardsNum * WorkServerNumber * (int(endTime) - int(beginTime)) | |||
| if _, ok := cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.AiCenter][cloudbrain.Cloudbrain.Spec.AccCardType]; !ok { | |||
| if int64(cloudbrain.Cloudbrain.StartTime) <= beginTime && int64(cloudbrain.Cloudbrain.EndTime) <= endTime { | |||
| cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.AiCenter][cloudbrain.Cloudbrain.Spec.AccCardType] = AccCardsNum * WorkServerNumber * (int(cloudbrain.Cloudbrain.EndTime) - int(beginTime)) | |||
| } else if int64(cloudbrain.Cloudbrain.StartTime) <= beginTime && int64(cloudbrain.Cloudbrain.EndTime) > endTime { | |||
| cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.AiCenter][cloudbrain.Cloudbrain.Spec.AccCardType] = AccCardsNum * WorkServerNumber * (int(endTime) - int(beginTime)) | |||
| } else if beginTime <= int64(cloudbrain.Cloudbrain.StartTime) && int64(cloudbrain.Cloudbrain.StartTime) <= endTime && int64(cloudbrain.Cloudbrain.EndTime) <= endTime { | |||
| cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.AiCenter][cloudbrain.Cloudbrain.Spec.AccCardType] = AccCardsNum * WorkServerNumber * (int(cloudbrain.Cloudbrain.EndTime) - int(cloudbrain.Cloudbrain.StartTime)) | |||
| } else if beginTime <= int64(cloudbrain.Cloudbrain.StartTime) && int64(cloudbrain.Cloudbrain.StartTime) <= endTime && int64(cloudbrain.Cloudbrain.EndTime) > endTime { | |||
| cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.AiCenter][cloudbrain.Cloudbrain.Spec.AccCardType] = AccCardsNum * WorkServerNumber * (int(endTime) - int(cloudbrain.Cloudbrain.StartTime)) | |||
| } | |||
| } else { | |||
| cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.Spec.AiCenterCode][cloudbrain.Cloudbrain.Spec.AccCardType] += AccCardsNum * WorkServerNumber * (int(endTime) - int(cloudbrain.Cloudbrain.StartTime)) | |||
| if int64(cloudbrain.Cloudbrain.StartTime) <= beginTime && int64(cloudbrain.Cloudbrain.EndTime) <= endTime { | |||
| cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.AiCenter][cloudbrain.Cloudbrain.Spec.AccCardType] += AccCardsNum * WorkServerNumber * (int(cloudbrain.Cloudbrain.EndTime) - int(beginTime)) | |||
| } else if int64(cloudbrain.Cloudbrain.StartTime) <= beginTime && int64(cloudbrain.Cloudbrain.EndTime) > endTime { | |||
| cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.AiCenter][cloudbrain.Cloudbrain.Spec.AccCardType] += AccCardsNum * WorkServerNumber * (int(endTime) - int(beginTime)) | |||
| } else if beginTime <= int64(cloudbrain.Cloudbrain.StartTime) && int64(cloudbrain.Cloudbrain.StartTime) <= endTime && int64(cloudbrain.Cloudbrain.EndTime) <= endTime { | |||
| cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.AiCenter][cloudbrain.Cloudbrain.Spec.AccCardType] += AccCardsNum * WorkServerNumber * (int(cloudbrain.Cloudbrain.EndTime) - int(cloudbrain.Cloudbrain.StartTime)) | |||
| } else if beginTime <= int64(cloudbrain.Cloudbrain.StartTime) && int64(cloudbrain.Cloudbrain.StartTime) <= endTime && int64(cloudbrain.Cloudbrain.EndTime) > endTime { | |||
| cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.AiCenter][cloudbrain.Cloudbrain.Spec.AccCardType] += AccCardsNum * WorkServerNumber * (int(endTime) - int(cloudbrain.Cloudbrain.StartTime)) | |||
| } | |||
| } | |||
| } | |||
| } else { | |||
| if _, ok := cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.Spec.AiCenterCode][cloudbrain.Cloudbrain.Spec.AccCardType]; !ok { | |||
| if int64(cloudbrain.Cloudbrain.StartTime) < beginTime { | |||
| cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.Spec.AiCenterCode][cloudbrain.Cloudbrain.Spec.AccCardType] = AccCardsNum * WorkServerNumber * (int(cloudbrain.Cloudbrain.EndTime) - int(beginTime)) | |||
| } else { | |||
| cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.Spec.AiCenterCode][cloudbrain.Cloudbrain.Spec.AccCardType] = AccCardsNum * WorkServerNumber * (int(cloudbrain.Cloudbrain.EndTime) - int(cloudbrain.Cloudbrain.StartTime)) | |||
| } | |||
| } else { | |||
| if int64(cloudbrain.Cloudbrain.StartTime) < beginTime { | |||
| cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.Spec.AiCenterCode][cloudbrain.Cloudbrain.Spec.AccCardType] += AccCardsNum * WorkServerNumber * (int(cloudbrain.Cloudbrain.EndTime) - int(beginTime)) | |||
| } else { | |||
| cloudBrainCenterCodeAndCardType[cloudbrain.Cloudbrain.Spec.AiCenterCode][cloudbrain.Cloudbrain.Spec.AccCardType] += AccCardsNum * WorkServerNumber * (int(cloudbrain.Cloudbrain.EndTime) - int(cloudbrain.Cloudbrain.StartTime)) | |||
| } | |||
| } | |||
| } | |||
| } | |||
| return cloudBrainCenterCodeAndCardType | |||
| } | |||
| func CloudbrainUpdateHistoryData(ctx *context.Context) { | |||
| err := models.DeleteCloudbrainDurationStatistic() | |||
| count := UpdateDurationStatisticHistoryData() | |||
| ctx.JSON(http.StatusOK, map[string]interface{}{ | |||
| "message": 0, | |||
| "count": count, | |||
| "err": err, | |||
| }) | |||
| } | |||
| @@ -1144,7 +1144,7 @@ func HandleTaskWithAiCenter(ctx *context.Context) { | |||
| log.Error("GetJob failed:" + err.Error()) | |||
| continue | |||
| } | |||
| if result != nil { | |||
| if len(result.JobInfo.Tasks) != 0 { | |||
| if len(result.JobInfo.Tasks[0].CenterID) == 1 && len(result.JobInfo.Tasks[0].CenterName) == 1 { | |||
| task.AiCenter = result.JobInfo.Tasks[0].CenterID[0] + "+" + result.JobInfo.Tasks[0].CenterName[0] | |||
| } | |||
| @@ -23,6 +23,8 @@ import ( | |||
| "code.gitea.io/gitea/modules/modelarts" | |||
| "code.gitea.io/gitea/modules/setting" | |||
| "code.gitea.io/gitea/modules/util" | |||
| "code.gitea.io/gitea/routers/repo" | |||
| cloudbrainService "code.gitea.io/gitea/services/cloudbrain" | |||
| issue_service "code.gitea.io/gitea/services/issue" | |||
| pull_service "code.gitea.io/gitea/services/pull" | |||
| @@ -837,6 +839,8 @@ func Cloudbrains(ctx *context.Context) { | |||
| } | |||
| models.LoadSpecs4CloudbrainInfo(ciTasks) | |||
| for i, _ := range ciTasks { | |||
| ciTasks[i] = cloudbrainService.UpdateCloudbrainAiCenter(ciTasks[i]) | |||
| ciTasks[i].Cloudbrain.AiCenter = repo.GetAiCenterNameByCode(ciTasks[i].Cloudbrain.AiCenter, ctx.Language()) | |||
| ciTasks[i].CanDebug = true | |||
| ciTasks[i].CanDel = true | |||
| ciTasks[i].Cloudbrain.ComputeResource = ciTasks[i].ComputeResource | |||
| @@ -1,27 +1,29 @@ | |||
| package cloudbrain | |||
| import ( | |||
| "strings" | |||
| "code.gitea.io/gitea/models" | |||
| "code.gitea.io/gitea/modules/context" | |||
| "code.gitea.io/gitea/modules/setting" | |||
| "strings" | |||
| ) | |||
| func GetAiCenterShow(aiCenter string,ctx *context.Context) string{ | |||
| func GetAiCenterShow(aiCenter string, ctx *context.Context) string { | |||
| aiCenterInfo := strings.Split(aiCenter, "+") | |||
| if len(aiCenterInfo) == 2{ | |||
| if setting.C2NetMapInfo!=nil { | |||
| if info,ok:=setting.C2NetMapInfo[aiCenterInfo[0]];ok { | |||
| if len(aiCenterInfo) == 2 { | |||
| if setting.C2NetMapInfo != nil { | |||
| if info, ok := setting.C2NetMapInfo[aiCenterInfo[0]]; ok { | |||
| if ctx.Language() == "zh-CN" { | |||
| return info.Content | |||
| } else { | |||
| return info.ContentEN | |||
| } | |||
| }else{ | |||
| } else { | |||
| return aiCenterInfo[1] | |||
| } | |||
| }else{ | |||
| } else { | |||
| return aiCenterInfo[1] | |||
| } | |||
| @@ -29,5 +31,42 @@ func GetAiCenterShow(aiCenter string,ctx *context.Context) string{ | |||
| return "" | |||
| } | |||
| func GetAiCenterInfoByCenterCode(aiCenterCode string) *setting.C2NetSequenceInfo { | |||
| if setting.AiCenterCodeAndNameMapInfo != nil { | |||
| if info, ok := setting.AiCenterCodeAndNameMapInfo[aiCenterCode]; ok { | |||
| return info | |||
| } else { | |||
| return nil | |||
| } | |||
| } else { | |||
| return nil | |||
| } | |||
| } | |||
| func getAiCenterCode(aiCenter string) string { | |||
| aiCenterInfo := strings.Split(aiCenter, "+") | |||
| return aiCenterInfo[0] | |||
| } | |||
| func UpdateCloudbrainAiCenter(cloudbrain *models.CloudbrainInfo) *models.CloudbrainInfo { | |||
| if cloudbrain.Cloudbrain.Type == models.TypeCloudBrainOne { | |||
| cloudbrain.Cloudbrain.AiCenter = models.AICenterOfCloudBrainOne | |||
| cloudbrain.Cloudbrain.Cluster = models.OpenICluster | |||
| } | |||
| if cloudbrain.Cloudbrain.Type == models.TypeCloudBrainTwo { | |||
| cloudbrain.Cloudbrain.AiCenter = models.AICenterOfCloudBrainTwo | |||
| cloudbrain.Cloudbrain.Cluster = models.OpenICluster | |||
| } | |||
| if cloudbrain.Cloudbrain.Type == models.TypeCDCenter { | |||
| cloudbrain.Cloudbrain.AiCenter = models.AICenterOfChengdu | |||
| cloudbrain.Cloudbrain.Cluster = models.OpenICluster | |||
| } | |||
| if cloudbrain.Cloudbrain.Type == models.TypeC2Net { | |||
| cloudbrain.Cloudbrain.AiCenter = getAiCenterCode(cloudbrain.Cloudbrain.AiCenter) | |||
| cloudbrain.Cloudbrain.Cluster = models.C2NetCluster | |||
| } | |||
| return cloudbrain | |||
| } | |||
| @@ -170,7 +170,7 @@ | |||
| </div> | |||
| <!-- 智算中心 --> | |||
| <div class="one wide column text center nowrap" style="width:8% !important;"> | |||
| <span style="font-size: 12px;" class="aicenter_{{.DisplayJobName}}_{{$JobID}}">{{if .AiCenter}}{{.AiCenter}}{{else}}--{{end}}</span> | |||
| <span style="font-size: 12px;" class="aicenter_{{.DisplayJobName}}_{{$JobID}}" title="{{if .AiCenter}}{{.AiCenter}}{{else}}--{{end}}">{{if .AiCenter}}{{.AiCenter}}{{else}}--{{end}}</span> | |||
| </div> | |||
| <!-- XPU类型 --> | |||
| <div class="one wide column text center nowrap" style="width:8% !important;"> | |||
| @@ -184,16 +184,16 @@ | |||
| spanEl.setAttribute('title', cardType); | |||
| spanEl.innerText = cardType; | |||
| var cluster = spec.Cluster || '--'; | |||
| var cluster = {{.Cluster}} || '--'; | |||
| var clusterName = document.querySelector('.cloudbrain_debug').dataset['cluster' + cluster[0] + cluster.toLocaleLowerCase().slice(1)] || '--'; | |||
| spanEl = document.querySelector('.cluster_{{.DisplayJobName}}_{{$JobID}}'); | |||
| spanEl.setAttribute('title', cluster); | |||
| spanEl.innerText = clusterName; | |||
| var aiCenter = spec.AiCenterName || '--'; | |||
| spanEl = document.querySelector('.aicenter_{{.DisplayJobName}}_{{$JobID}}'); | |||
| spanEl.setAttribute('title', aiCenter); | |||
| spanEl.innerText = aiCenter; | |||
| // var aiCenter = spec.AiCenterName || '--'; | |||
| // spanEl = document.querySelector('.aicenter_{{.DisplayJobName}}_{{$JobID}}'); | |||
| // spanEl.setAttribute('title', aiCenter); | |||
| // spanEl.innerText = aiCenter; | |||
| })(); | |||
| </script> | |||
| <!-- 创建者 --> | |||
| @@ -71,22 +71,20 @@ | |||
| document.addEventListener('DOMContentLoaded', function() { | |||
| $.ajax({ | |||
| type: "GET", | |||
| url: "/api/v1/cloudbrain/get_center_info", | |||
| url: "/api/v1/cloudbrainboard/cloudbrain/resource_queues", | |||
| dataType: "json", | |||
| data: {}, | |||
| success: function (res) { | |||
| var data = res || []; | |||
| var data = res.resourceQueues || []; | |||
| var aiCenterSelEl = $('#aiCenter-sel'); | |||
| var itemEl = aiCenterSelEl.find('.menu .item').eq(0); | |||
| var selectAiCenterCode = aiCenterSelEl.find('.default').attr('aicenter'); | |||
| var selectAiCenterName = ''; | |||
| var lang = document.querySelector('html').getAttribute('lang') || 'en-US'; | |||
| var except = ['', 'more']; | |||
| for (var i = 0, iLen = data.length; i < iLen; i++) { | |||
| var dataI = data[i]; | |||
| var aiCenterCode = dataI.name; | |||
| if (except.indexOf(aiCenterCode) >= 0) continue; | |||
| var aiCenterName = lang === 'en-US' ? dataI.content_en : dataI.content; | |||
| var aiCenterCode = dataI.AiCenterCode; | |||
| var aiCenterName = dataI.AiCenterName; | |||
| var itemClone = itemEl.clone(); | |||
| var oHref = itemClone.attr('href'); | |||
| var oId = itemClone.attr('id'); | |||
| @@ -85,22 +85,20 @@ | |||
| document.addEventListener('DOMContentLoaded', function() { | |||
| $.ajax({ | |||
| type: "GET", | |||
| url: "/api/v1/cloudbrain/get_center_info", | |||
| url: "/api/v1/cloudbrainboard/cloudbrain/resource_queues", | |||
| dataType: "json", | |||
| data: {}, | |||
| success: function (res) { | |||
| var data = res || []; | |||
| var data = res.resourceQueues || []; | |||
| var aiCenterSelEl = $('#aiCenter-sel'); | |||
| var itemEl = aiCenterSelEl.find('.menu .item').eq(0); | |||
| var selectAiCenterCode = aiCenterSelEl.find('.default').attr('aicenter'); | |||
| var selectAiCenterName = ''; | |||
| var lang = document.querySelector('html').getAttribute('lang') || 'en-US'; | |||
| var except = ['', 'more']; | |||
| for (var i = 0, iLen = data.length; i < iLen; i++) { | |||
| var dataI = data[i]; | |||
| var aiCenterCode = dataI.name; | |||
| if (except.indexOf(aiCenterCode) >= 0) continue; | |||
| var aiCenterName = lang === 'en-US' ? dataI.content_en : dataI.content; | |||
| var aiCenterCode = dataI.AiCenterCode; | |||
| var aiCenterName = dataI.AiCenterName; | |||
| var itemClone = itemEl.clone(); | |||
| var oHref = itemClone.attr('href'); | |||
| var oId = itemClone.attr('id'); | |||
| @@ -65,7 +65,7 @@ | |||
| </div> | |||
| </div> | |||
| </div> | |||
| {{range .Tasks}} | |||
| {{range .Tasks}} | |||
| {{if .Repo}} | |||
| <div class="ui grid stackable item"> | |||
| <div class="row"> | |||
| @@ -154,7 +154,7 @@ | |||
| <!-- 智算中心 --> | |||
| <div class="one wide column text center nowrap" style="width:8% !important;"> | |||
| <span style="font-size: 12px;" class="aicenter_{{.DisplayJobName}}_{{$JobID}}">{{if .AiCenter}}{{.AiCenter}}{{else}}--{{end}}</span> | |||
| <span style="font-size: 12px;" class="aicenter_{{.DisplayJobName}}_{{$JobID}}" title="{{if .AiCenter}}{{.AiCenter}}{{else}}--{{end}}">{{if .AiCenter}}{{.AiCenter}}{{else}}--{{end}}</span> | |||
| </div> | |||
| <!-- XPU类型 --> | |||
| <div class="one wide column text center nowrap" style="width:10% !important;"> | |||
| @@ -168,16 +168,16 @@ | |||
| spanEl.setAttribute('title', cardType); | |||
| spanEl.innerText = cardType; | |||
| var cluster = spec.Cluster || '--'; | |||
| var cluster = {{.Cluster}} || '--'; | |||
| var clusterName = document.querySelector('.cloudbrain_debug').dataset['cluster' + cluster[0] + cluster.toLocaleLowerCase().slice(1)] || '--'; | |||
| spanEl = document.querySelector('.cluster_{{.DisplayJobName}}_{{$JobID}}'); | |||
| spanEl.setAttribute('title', cluster); | |||
| spanEl.innerText = clusterName; | |||
| var aiCenter = spec.AiCenterName || '--'; | |||
| spanEl = document.querySelector('.aicenter_{{.DisplayJobName}}_{{$JobID}}'); | |||
| spanEl.setAttribute('title', aiCenter); | |||
| spanEl.innerText = aiCenter; | |||
| // var aiCenter = spec.AiCenterName || '--'; | |||
| // spanEl = document.querySelector('.aicenter_{{.DisplayJobName}}_{{$JobID}}'); | |||
| // spanEl.setAttribute('title', aiCenter); | |||
| // spanEl.innerText = aiCenter; | |||
| })(); | |||
| </script> | |||
| <!-- 项目 --> | |||