diff --git a/models/cloudbrain_static.go b/models/cloudbrain_static.go index f4045dd69..45029e7e7 100644 --- a/models/cloudbrain_static.go +++ b/models/cloudbrain_static.go @@ -77,15 +77,6 @@ func GetJobFailedPeriodCount(beginTime time.Time, endTime time.Time) (int64, err return x.SQL(countSql).Count() } -// func GetWaitingCount(beginTime time.Time, endTime time.Time) (int64, error) { -// countSql := "SELECT distinct count(*) FROM " + -// "public.cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) + -// " and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) + -// " and status ='" + string(JobWaiting) + "'" - -// return x.SQL(countSql).Count() -// } - func GetDebugOnePeriodCount(beginTime time.Time, endTime time.Time) (int64, error) { countSql := "SELECT count(*) FROM " + "public.cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) + @@ -302,3 +293,24 @@ func CreateCloudbrainStatistic(cloudbrainStat *CloudbrainStatistic) (err error) } return nil } + +func GetJobWaitingCount() (int64, error) { + countSql := "SELECT count(*) FROM " + "public.cloudbrain where status ='" + string(JobWaiting) + "'" + return x.SQL(countSql).Count() +} +func GetJobStoppedCount() (int64, error) { + countSql := "SELECT count(*) FROM " + "public.cloudbrain where status ='" + string(JobStopped) + "'" + return x.SQL(countSql).Count() +} +func GetJobSucceededCount() (int64, error) { + countSql := "SELECT count(*) FROM " + "public.cloudbrain where status ='" + string(JobSucceeded) + "'" + return x.SQL(countSql).Count() +} +func GetJobFailedCount() (int64, error) { + countSql := "SELECT count(*) FROM " + "public.cloudbrain where status ='" + string(JobFailed) + "'" + return x.SQL(countSql).Count() +} +func GetJobRunningCount() (int64, error) { + countSql := "SELECT count(*) FROM " + "public.cloudbrain where status ='" + string(JobRunning) + "'" + return x.SQL(countSql).Count() +} diff --git a/routers/api/v1/repo/cloudbrain_dashboard.go b/routers/api/v1/repo/cloudbrain_dashboard.go index 44d7f7c95..95ffe7f1b 100644 --- a/routers/api/v1/repo/cloudbrain_dashboard.go +++ b/routers/api/v1/repo/cloudbrain_dashboard.go @@ -40,6 +40,14 @@ type CloudbrainsOverviewData struct { CreatorPeriodCount int64 `json:"creatorPeriodCount"` CreatorCount int64 `json:"creatorCount"` } + +type CloudbrainsStatusAnalysis struct { + JobWaitingCount int64 `json:"jobWaitingCount"` + JobRunningCount int64 `json:"jobRunningCount"` + JobStoppedCount int64 `json:"jobStoppedCount"` + JobSucceededCount int64 `json:"jobSucceededCount"` + JobFailedCount int64 `json:"jobFailedCount"` +} type TimeCloudbrainsNum struct { TimeCloudbrainNum []DateCloudbrainNum `json:"dateCloudbrainNum"` } @@ -370,7 +378,40 @@ func GetAllCloudbrainsPeriodDistribution(ctx *context.Context) { } func GetCloudbrainsStatusAnalysis(ctx *context.Context) { + jobWaitingCount, err := models.GetJobWaitingCount() + if err != nil { + log.Error("Can not query jobWaitingCount.", err) + return + } + jobRunningCount, err := models.GetJobRunningCount() + if err != nil { + log.Error("Can not query jobRunningCount.", err) + return + } + jobStoppedCount, err := models.GetJobStoppedCount() + if err != nil { + log.Error("Can not query jobStoppedCount.", err) + return + } + jobSucceededCount, err := models.GetJobSucceededCount() + if err != nil { + log.Error("Can not query jobSucceededCount.", err) + return + } + jobFailedCount, err := models.GetJobFailedCount() + if err != nil { + log.Error("Can not query jobFailedCount.", err) + return + } + cloudbrainsStatusAnalysis := CloudbrainsStatusAnalysis{ + JobWaitingCount: jobWaitingCount, + JobRunningCount: jobRunningCount, + JobStoppedCount: jobStoppedCount, + JobSucceededCount: jobSucceededCount, + JobFailedCount: jobFailedCount, + } + ctx.JSON(http.StatusOK, cloudbrainsStatusAnalysis) } func getCloudbrainCount(beginTime time.Time, endTime time.Time) (int64, int64, int64, int64, int64, int64, int64, int64, int64, error) {