|
|
@@ -1,6 +1,7 @@ |
|
|
|
package models |
|
|
|
|
|
|
|
import ( |
|
|
|
"code.gitea.io/gitea/modules/log" |
|
|
|
"code.gitea.io/gitea/modules/timeutil" |
|
|
|
"fmt" |
|
|
|
"strings" |
|
|
@@ -312,6 +313,12 @@ func (s *Specification) GetAvailableCenterIds(opts GetAvailableCenterIdOpts) []s |
|
|
|
//filter exclusive specs |
|
|
|
specs := FilterExclusiveSpecs(s.RelatedSpecs, opts.UserId) |
|
|
|
|
|
|
|
specs = HandleSpecialQueues(specs, opts.UserId, FindSpecsOptions{ |
|
|
|
JobType: opts.JobType, |
|
|
|
Cluster: s.Cluster, |
|
|
|
ComputeResource: s.ComputeResource, |
|
|
|
}) |
|
|
|
|
|
|
|
centerIds := make([]string, len(specs)) |
|
|
|
for i, v := range specs { |
|
|
|
centerIds[i] = v.AiCenterCode |
|
|
@@ -348,6 +355,80 @@ func FilterExclusiveSpecs(r []*Specification, userId int64) []*Specification { |
|
|
|
return specs |
|
|
|
} |
|
|
|
|
|
|
|
func GetSpecsInQueue(r []*Specification, queueIds []int64) []*Specification { |
|
|
|
specs := make([]*Specification, 0, len(r)) |
|
|
|
for i := 0; i < len(r); i++ { |
|
|
|
spec := r[i] |
|
|
|
for _, queueId := range queueIds { |
|
|
|
if spec.QueueId == queueId { |
|
|
|
specs = append(specs, spec) |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return specs |
|
|
|
} |
|
|
|
|
|
|
|
func GetSpecsNotInQueue(r []*Specification, queueIds []int64) []*Specification { |
|
|
|
specs := make([]*Specification, 0, len(r)) |
|
|
|
for i := 0; i < len(r); i++ { |
|
|
|
spec := r[i] |
|
|
|
flag := false |
|
|
|
for _, queueId := range queueIds { |
|
|
|
if spec.QueueId == queueId { |
|
|
|
flag = true |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
if !flag { |
|
|
|
specs = append(specs, spec) |
|
|
|
} |
|
|
|
} |
|
|
|
return specs |
|
|
|
} |
|
|
|
|
|
|
|
func HandleSpecialQueues(specs []*Specification, userId int64, opts FindSpecsOptions) []*Specification { |
|
|
|
if len(specs) == 0 { |
|
|
|
return specs |
|
|
|
} |
|
|
|
isUserInSpecialPool := IsUserInSpecialPool(userId) |
|
|
|
if isUserInSpecialPool { |
|
|
|
specs = handleSpecialUserSpecs(specs, userId, opts) |
|
|
|
} else { |
|
|
|
specs = handleNormalUserSpecs(specs, opts) |
|
|
|
} |
|
|
|
return specs |
|
|
|
} |
|
|
|
|
|
|
|
func handleSpecialUserSpecs(specs []*Specification, userId int64, opts FindSpecsOptions) []*Specification { |
|
|
|
specialQueues := GetSpecialQueueIds(opts) |
|
|
|
userOrgs, err := GetOrgsByUserID(userId, true) |
|
|
|
if err != nil { |
|
|
|
log.Error("handleSpecialUserSpecs GetOrgsByUserID error.%v", err) |
|
|
|
return []*Specification{} |
|
|
|
} |
|
|
|
userQueueIds := make([]int64, 0) |
|
|
|
for _, org := range userOrgs { |
|
|
|
for _, queue := range specialQueues { |
|
|
|
if strings.ToLower(org.Name) == strings.ToLower(queue.OrgName) { |
|
|
|
userQueueIds = append(userQueueIds, queue.QueueId) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
specs = GetSpecsInQueue(specs, userQueueIds) |
|
|
|
return specs |
|
|
|
} |
|
|
|
|
|
|
|
func handleNormalUserSpecs(specs []*Specification, opts FindSpecsOptions) []*Specification { |
|
|
|
queues := GetSpecialQueueIds(opts) |
|
|
|
queueIds := make([]int64, 0) |
|
|
|
for _, queue := range queues { |
|
|
|
queueIds = append(queueIds, queue.QueueId) |
|
|
|
} |
|
|
|
specs = GetSpecsNotInQueue(specs, queueIds) |
|
|
|
return specs |
|
|
|
} |
|
|
|
|
|
|
|
func DistinctSpecs(r []*Specification) []*Specification { |
|
|
|
specs := make([]*Specification, 0, len(r)) |
|
|
|
sourceSpecIdMap := make(map[string]string, 0) |
|
|
|