|
|
|
@@ -53,20 +53,140 @@ func GetAllCloudbrainsOverview(ctx *context.Context) { |
|
|
|
log.Error("Can not query todayCreatorCount.", err) |
|
|
|
return |
|
|
|
} |
|
|
|
cloudbrainTypeCount, err := models.GetCloudbrainTypeCount() |
|
|
|
log.Info("cloudbrainTypeCount:", cloudbrainTypeCount) |
|
|
|
if err != nil { |
|
|
|
log.Error("Can not query cloudbrainTypeCount.", err) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
cloudbrainTpyeDurationSum, err := models.GetCloudbrainTpyeDurationSum() |
|
|
|
log.Info("cloudbrainTpyeDurationSum:", cloudbrainTpyeDurationSum) |
|
|
|
if err != nil { |
|
|
|
log.Error("Can not query cloudbrainTpyeDurationSum.", err) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
todayCloudbrainCount, err := models.GetTodayCloudbrainCount(beginTime, endTime) |
|
|
|
log.Info("todayCloudbrainCount:", todayCloudbrainCount) |
|
|
|
if err != nil { |
|
|
|
log.Error("Can not query todayCloudbrainCount.", err) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
todayRunningCount, err := models.GetTodayRunningCount(beginTime, endTime) |
|
|
|
log.Info("todayRunningCount:", todayRunningCount) |
|
|
|
if err != nil { |
|
|
|
log.Error("Can not query todayRunningCount.", err) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
todayWaitingCount, err := models.GetTodayWaitingCount(beginTime, endTime) |
|
|
|
log.Info("todayWaittingCount:", todayWaitingCount) |
|
|
|
if err != nil { |
|
|
|
log.Error("Can not query todayWaitingCount.", err) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
todayCompletedCount := todayCloudbrainCount - todayRunningCount - todayWaitingCount |
|
|
|
log.Info("todayCompletedCount:", todayCompletedCount) |
|
|
|
|
|
|
|
creatorCount, err := models.GetCreatorCount() |
|
|
|
if err != nil { |
|
|
|
log.Error("Can not query creatorCount.", err) |
|
|
|
return |
|
|
|
} |
|
|
|
todayStatusResult := make(map[string]int) |
|
|
|
cloudBrainNum := make(map[int]int) |
|
|
|
cloudBrainOneDuration := int64(0) |
|
|
|
cloudBrainTwoDuration := int64(0) |
|
|
|
intelligentNetDuration := int64(0) |
|
|
|
todayNewJobCount := 0 |
|
|
|
// todayStatusResult := make(map[string]int) |
|
|
|
// cloudBrainNum := make(map[int]int) |
|
|
|
// cloudBrainOneDuration := int64(0) |
|
|
|
// cloudBrainTwoDuration := int64(0) |
|
|
|
// intelligentNetDuration := int64(0) |
|
|
|
// todayNewJobCount := 0 |
|
|
|
|
|
|
|
// if int64(cloudbrain.Cloudbrain.CreatedUnix) >= beginTime.Unix() && int64(cloudbrain.Cloudbrain.CreatedUnix) < endTime.Unix() { |
|
|
|
// todayNewJobCount += 1 |
|
|
|
// if _, ok := todayStatusResult[cloudbrain.Status]; !ok { |
|
|
|
// todayStatusResult[cloudbrain.Status] = 1 |
|
|
|
// } else { |
|
|
|
// todayStatusResult[cloudbrain.Status] += 1 |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
// if _, ok := cloudBrainNum[cloudbrain.Cloudbrain.Type]; !ok { |
|
|
|
// cloudBrainNum[cloudbrain.Cloudbrain.Type] = 1 |
|
|
|
// } else { |
|
|
|
// cloudBrainNum[cloudbrain.Cloudbrain.Type] += 1 |
|
|
|
// } |
|
|
|
|
|
|
|
// if cloudbrain.Cloudbrain.Type == models.TypeCloudBrainOne { |
|
|
|
// cloudBrainOneDuration = cloudBrainOneDuration + cloudbrain.Cloudbrain.Duration |
|
|
|
// } |
|
|
|
// if cloudbrain.Cloudbrain.Type == models.TypeCloudBrainTwo { |
|
|
|
// cloudBrainTwoDuration = cloudBrainTwoDuration + cloudbrain.Cloudbrain.Duration |
|
|
|
// } |
|
|
|
// if cloudbrain.Cloudbrain.Type == models.TypeC2Net { |
|
|
|
// intelligentNetDuration = intelligentNetDuration + cloudbrain.Cloudbrain.Duration |
|
|
|
// } |
|
|
|
|
|
|
|
// } |
|
|
|
// count = len(cloudbrains) |
|
|
|
// page += 1 |
|
|
|
// } |
|
|
|
|
|
|
|
// statusNameList := []string{string(models.ModelArtsTrainJobCompleted), string(models.JobFailed), string(models.ModelArtsTrainJobInit), |
|
|
|
// string(models.JobRunning), string(models.ModelArtsStartFailed), string(models.JobStopped), string(models.JobSucceeded), |
|
|
|
// string(models.JobWaiting), string(models.ModelArtsTrainJobKilled)} |
|
|
|
// for _, v := range statusNameList { |
|
|
|
// if _, ok := todayStatusResult[v]; !ok { |
|
|
|
// todayStatusResult[v] = 0 |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
// cloudBrainTypeList := []int{0, 1, 2} |
|
|
|
// for _, v := range cloudBrainTypeList { |
|
|
|
// if _, ok := cloudBrainNum[v]; !ok { |
|
|
|
// cloudBrainNum[v] = 0 |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
// todayRunningCount := todayStatusResult[string(models.JobRunning)] |
|
|
|
// todayCompletedCount := todayStatusResult[string(models.ModelArtsTrainJobCompleted)] + todayStatusResult[string(models.JobFailed)] + |
|
|
|
// todayStatusResult[string(models.ModelArtsStartFailed)] + todayStatusResult[string(models.JobStopped)] + todayStatusResult[string(models.JobSucceeded)] + todayStatusResult[string(models.ModelArtsTrainJobKilled)] |
|
|
|
// todayWaitingCount := todayStatusResult[string(models.ModelArtsTrainJobInit)] + todayStatusResult[string(models.JobWaiting)] |
|
|
|
|
|
|
|
ctx.JSON(http.StatusOK, map[string]interface{}{ |
|
|
|
"recordBeginTime": recordBeginTime, |
|
|
|
"updateTime": now.Unix(), |
|
|
|
// "cloudBrainNum": cloudBrainNum, |
|
|
|
// "cloudBrainOneDuration": cloudBrainOneDuration, |
|
|
|
// "cloudBrainTwoDuration": cloudBrainTwoDuration, |
|
|
|
// "intelligentNetDuration": intelligentNetDuration, |
|
|
|
"todayCreatorCount": todayCreatorCount, |
|
|
|
"creatorCount": creatorCount, |
|
|
|
"todayRunningCount": todayRunningCount, |
|
|
|
"todayCompletedCount": todayCompletedCount, |
|
|
|
"todayWaitingCount": todayWaitingCount, |
|
|
|
"todayNewJobCount": todayCloudbrainCount, |
|
|
|
"cloudbrainTypeCount": cloudbrainTypeCount, |
|
|
|
}) |
|
|
|
} |
|
|
|
func GetOverviewDuration(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 |
|
|
|
} |
|
|
|
recordBeginTime := recordCloudbrain[0].Cloudbrain.CreatedUnix |
|
|
|
now := time.Now() |
|
|
|
endTime := now |
|
|
|
page := 1 |
|
|
|
pagesize := 1000 |
|
|
|
count := pagesize |
|
|
|
worker_server_num := 1 |
|
|
|
cardNum := 1 |
|
|
|
durationSum := int64(0) |
|
|
|
durationSumAll := int64(0) |
|
|
|
for count == pagesize && count != 0 { |
|
|
|
cloudbrains, _, err := models.CloudbrainAllStatic(&models.CloudbrainsOptions{ |
|
|
|
ListOptions: models.ListOptions{ |
|
|
|
@@ -81,72 +201,30 @@ func GetAllCloudbrainsOverview(ctx *context.Context) { |
|
|
|
ctx.ServerError("Get cloudbrains failed:", err) |
|
|
|
return |
|
|
|
} |
|
|
|
models.LoadSpecs4CloudbrainInfo(cloudbrains) |
|
|
|
|
|
|
|
for _, cloudbrain := range cloudbrains { |
|
|
|
if int64(cloudbrain.Cloudbrain.CreatedUnix) >= beginTime.Unix() && int64(cloudbrain.Cloudbrain.CreatedUnix) < endTime.Unix() { |
|
|
|
todayNewJobCount += 1 |
|
|
|
if _, ok := todayStatusResult[cloudbrain.Status]; !ok { |
|
|
|
todayStatusResult[cloudbrain.Status] = 1 |
|
|
|
} else { |
|
|
|
todayStatusResult[cloudbrain.Status] += 1 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if _, ok := cloudBrainNum[cloudbrain.Cloudbrain.Type]; !ok { |
|
|
|
cloudBrainNum[cloudbrain.Cloudbrain.Type] = 1 |
|
|
|
duration := cloudbrain.Duration |
|
|
|
if cloudbrain.WorkServerNumber >= 1 { |
|
|
|
worker_server_num = cloudbrain.WorkServerNumber |
|
|
|
} else { |
|
|
|
cloudBrainNum[cloudbrain.Cloudbrain.Type] += 1 |
|
|
|
} |
|
|
|
|
|
|
|
if cloudbrain.Cloudbrain.Type == models.TypeCloudBrainOne { |
|
|
|
cloudBrainOneDuration = cloudBrainOneDuration + cloudbrain.Cloudbrain.Duration |
|
|
|
worker_server_num = 1 |
|
|
|
} |
|
|
|
if cloudbrain.Cloudbrain.Type == models.TypeCloudBrainTwo { |
|
|
|
cloudBrainTwoDuration = cloudBrainTwoDuration + cloudbrain.Cloudbrain.Duration |
|
|
|
} |
|
|
|
if cloudbrain.Cloudbrain.Type == models.TypeC2Net { |
|
|
|
intelligentNetDuration = intelligentNetDuration + cloudbrain.Cloudbrain.Duration |
|
|
|
if cloudbrain.Spec != nil { |
|
|
|
cardNum = cloudbrain.Spec.AccCardsNum |
|
|
|
} else { |
|
|
|
cardNum = 1 |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
count = len(cloudbrains) |
|
|
|
page += 1 |
|
|
|
} |
|
|
|
|
|
|
|
statusNameList := []string{string(models.ModelArtsTrainJobCompleted), string(models.JobFailed), string(models.ModelArtsTrainJobInit), |
|
|
|
string(models.JobRunning), string(models.ModelArtsStartFailed), string(models.JobStopped), string(models.JobSucceeded), |
|
|
|
string(models.JobWaiting), string(models.ModelArtsTrainJobKilled)} |
|
|
|
for _, v := range statusNameList { |
|
|
|
if _, ok := todayStatusResult[v]; !ok { |
|
|
|
todayStatusResult[v] = 0 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
cloudBrainTypeList := []int{0, 1, 2} |
|
|
|
for _, v := range cloudBrainTypeList { |
|
|
|
if _, ok := cloudBrainNum[v]; !ok { |
|
|
|
cloudBrainNum[v] = 0 |
|
|
|
durationSum = duration * int64(worker_server_num) * int64(cardNum) |
|
|
|
durationSumAll = durationSum + durationSumAll |
|
|
|
count = len(cloudbrains) |
|
|
|
page += 1 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
todayRunningCount := todayStatusResult[string(models.JobRunning)] |
|
|
|
todayCompletedCount := todayStatusResult[string(models.ModelArtsTrainJobCompleted)] + todayStatusResult[string(models.JobFailed)] + |
|
|
|
todayStatusResult[string(models.ModelArtsStartFailed)] + todayStatusResult[string(models.JobStopped)] + todayStatusResult[string(models.JobSucceeded)] + todayStatusResult[string(models.ModelArtsTrainJobKilled)] |
|
|
|
todayWaitingCount := todayStatusResult[string(models.ModelArtsTrainJobInit)] + todayStatusResult[string(models.JobWaiting)] |
|
|
|
|
|
|
|
log.Info("durationSumAll:", durationSumAll) |
|
|
|
ctx.JSON(http.StatusOK, map[string]interface{}{ |
|
|
|
"recordBeginTime": recordBeginTime, |
|
|
|
"updateTime": now.Unix(), |
|
|
|
"cloudBrainNum": cloudBrainNum, |
|
|
|
"cloudBrainOneDuration": cloudBrainOneDuration, |
|
|
|
"cloudBrainTwoDuration": cloudBrainTwoDuration, |
|
|
|
"intelligentNetDuration": intelligentNetDuration, |
|
|
|
"todayCreatorCount": todayCreatorCount, |
|
|
|
"creatorCount": creatorCount, |
|
|
|
"todayRunningCount": todayRunningCount, |
|
|
|
"todayCompletedCount": todayCompletedCount, |
|
|
|
"todayWaitingCount": todayWaitingCount, |
|
|
|
"todayNewJobCount": todayNewJobCount, |
|
|
|
"durationSum": durationSum, |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
@@ -605,64 +683,72 @@ func GetAllCloudbrainsPeriodDistribution(ctx *context.Context) { |
|
|
|
} |
|
|
|
|
|
|
|
func GetCloudbrainsStatusAnalysis(ctx *context.Context) { |
|
|
|
recordCloudbrain, err := models.GetRecordBeginTime() |
|
|
|
// 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 |
|
|
|
// } |
|
|
|
// recordBeginTime := recordCloudbrain[0].Cloudbrain.CreatedUnix |
|
|
|
// endTime := time.Now() |
|
|
|
// cloudBrainStatusResult := make(map[string]int) |
|
|
|
// cloudBrainStatusAnalysis := make(map[string]int) |
|
|
|
// totalCount := 0 |
|
|
|
|
|
|
|
// page := 1 |
|
|
|
// pagesize := 1000 |
|
|
|
// count := pagesize |
|
|
|
// for count == pagesize && count != 0 { |
|
|
|
// cloudbrains, _, err := models.CloudbrainAllStatic(&models.CloudbrainsOptions{ |
|
|
|
// ListOptions: models.ListOptions{ |
|
|
|
// Page: page, |
|
|
|
// PageSize: pagesize, |
|
|
|
// }, |
|
|
|
// Type: models.TypeCloudBrainAll, |
|
|
|
// BeginTimeUnix: int64(recordBeginTime), |
|
|
|
// EndTimeUnix: endTime.Unix(), |
|
|
|
// }) |
|
|
|
// if err != nil { |
|
|
|
// ctx.ServerError("Get cloudbrains failed:", err) |
|
|
|
// return |
|
|
|
// } |
|
|
|
// for _, cloudbrain := range cloudbrains { |
|
|
|
// if _, ok := cloudBrainStatusResult[cloudbrain.Status]; !ok { |
|
|
|
// cloudBrainStatusResult[cloudbrain.Status] = 1 |
|
|
|
// } else { |
|
|
|
// cloudBrainStatusResult[cloudbrain.Status] += 1 |
|
|
|
// } |
|
|
|
// } |
|
|
|
// count = len(cloudbrains) |
|
|
|
// totalCount = totalCount + count |
|
|
|
// page += 1 |
|
|
|
// } |
|
|
|
|
|
|
|
// var jobStatuses []string |
|
|
|
// jobStatuses = append(jobStatuses, string(models.ModelArtsTrainJobWaiting), string(models.ModelArtsTrainJobFailed), string(models.ModelArtsRunning), string(models.ModelArtsTrainJobCompleted), |
|
|
|
// string(models.ModelArtsStarting), string(models.ModelArtsRestarting), string(models.ModelArtsStartFailed), |
|
|
|
// string(models.ModelArtsStopping), string(models.ModelArtsStopped), string(models.JobSucceeded)) |
|
|
|
// jobStatusesCount := 0 |
|
|
|
// for _, v := range jobStatuses { |
|
|
|
// if _, ok := cloudBrainStatusResult[v]; !ok { |
|
|
|
// cloudBrainStatusAnalysis[v] = 0 |
|
|
|
// } else { |
|
|
|
// cloudBrainStatusAnalysis[v] = cloudBrainStatusResult[v] |
|
|
|
// } |
|
|
|
// jobStatusesCount = jobStatusesCount + cloudBrainStatusResult[v] |
|
|
|
// } |
|
|
|
// cloudBrainStatusAnalysis["OTHER"] = totalCount - jobStatusesCount |
|
|
|
|
|
|
|
cloudbrainStatusCount, err := models.GetCloudbrainStatusCount() |
|
|
|
log.Info("cloudbrainStatusCount:", cloudbrainStatusCount) |
|
|
|
if err != nil { |
|
|
|
log.Error("Can not get recordCloudbrain", err) |
|
|
|
ctx.Error(http.StatusBadRequest, ctx.Tr("repo.record_begintime_get_err")) |
|
|
|
log.Error("Can not query cloudbrainStatusCount.", err) |
|
|
|
return |
|
|
|
} |
|
|
|
recordBeginTime := recordCloudbrain[0].Cloudbrain.CreatedUnix |
|
|
|
endTime := time.Now() |
|
|
|
cloudBrainStatusResult := make(map[string]int) |
|
|
|
cloudBrainStatusAnalysis := make(map[string]int) |
|
|
|
totalCount := 0 |
|
|
|
|
|
|
|
page := 1 |
|
|
|
pagesize := 1000 |
|
|
|
count := pagesize |
|
|
|
for count == pagesize && count != 0 { |
|
|
|
cloudbrains, _, err := models.CloudbrainAllStatic(&models.CloudbrainsOptions{ |
|
|
|
ListOptions: models.ListOptions{ |
|
|
|
Page: page, |
|
|
|
PageSize: pagesize, |
|
|
|
}, |
|
|
|
Type: models.TypeCloudBrainAll, |
|
|
|
BeginTimeUnix: int64(recordBeginTime), |
|
|
|
EndTimeUnix: endTime.Unix(), |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
ctx.ServerError("Get cloudbrains failed:", err) |
|
|
|
return |
|
|
|
} |
|
|
|
for _, cloudbrain := range cloudbrains { |
|
|
|
if _, ok := cloudBrainStatusResult[cloudbrain.Status]; !ok { |
|
|
|
cloudBrainStatusResult[cloudbrain.Status] = 1 |
|
|
|
} else { |
|
|
|
cloudBrainStatusResult[cloudbrain.Status] += 1 |
|
|
|
} |
|
|
|
} |
|
|
|
count = len(cloudbrains) |
|
|
|
totalCount = totalCount + count |
|
|
|
page += 1 |
|
|
|
} |
|
|
|
|
|
|
|
var jobStatuses []string |
|
|
|
jobStatuses = append(jobStatuses, string(models.ModelArtsTrainJobWaiting), string(models.ModelArtsTrainJobFailed), string(models.ModelArtsRunning), string(models.ModelArtsTrainJobCompleted), |
|
|
|
string(models.ModelArtsStarting), string(models.ModelArtsRestarting), string(models.ModelArtsStartFailed), |
|
|
|
string(models.ModelArtsStopping), string(models.ModelArtsStopped), string(models.JobSucceeded)) |
|
|
|
jobStatusesCount := 0 |
|
|
|
for _, v := range jobStatuses { |
|
|
|
if _, ok := cloudBrainStatusResult[v]; !ok { |
|
|
|
cloudBrainStatusAnalysis[v] = 0 |
|
|
|
} else { |
|
|
|
cloudBrainStatusAnalysis[v] = cloudBrainStatusResult[v] |
|
|
|
} |
|
|
|
jobStatusesCount = jobStatusesCount + cloudBrainStatusResult[v] |
|
|
|
} |
|
|
|
cloudBrainStatusAnalysis["OTHER"] = totalCount - jobStatusesCount |
|
|
|
|
|
|
|
ctx.JSON(http.StatusOK, map[string]interface{}{ |
|
|
|
"cloudBrainStatusResult": cloudBrainStatusAnalysis, |
|
|
|
// "cloudBrainStatusResult": cloudBrainStatusAnalysis, |
|
|
|
"cloudbrainStatusCount": cloudbrainStatusCount, |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
|