|
|
|
@@ -1,33 +1,34 @@ |
|
|
|
package scheduler |
|
|
|
|
|
|
|
import ( |
|
|
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/algo" |
|
|
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types" |
|
|
|
"gorm.io/gorm" |
|
|
|
"math/rand" |
|
|
|
"time" |
|
|
|
) |
|
|
|
|
|
|
|
type scheduleService interface { |
|
|
|
getNewStructForDb(task *types.TaskInfo, participantIds []int64) (interface{}, error) |
|
|
|
pickOptimalStrategy(task *algo.Task, providers ...*algo.Provider) (*algo.Task, error) |
|
|
|
} |
|
|
|
|
|
|
|
func MatchLabels(dbEngin *gorm.DB, task *types.TaskInfo) ([]int64, error) { |
|
|
|
var ids []int64 |
|
|
|
count := 0 |
|
|
|
for key := range task.MatchLabels { |
|
|
|
var participantId []int64 |
|
|
|
dbEngin.Raw("select participant_id from sc_participant_label_info where `key` = ? and value = ?", key, task.MatchLabels[key]).Scan(&participantId) |
|
|
|
if count == 0 { |
|
|
|
ids = participantId |
|
|
|
} |
|
|
|
if len(participantId) == 0 || len(ids) == 0 { |
|
|
|
return nil, nil |
|
|
|
} |
|
|
|
ids = intersect(ids, participantId) |
|
|
|
count++ |
|
|
|
} |
|
|
|
return micsSlice(ids, 1), nil |
|
|
|
} |
|
|
|
//func MatchLabels(dbEngin *gorm.DB, task *types.TaskInfo) ([]int64, error) { |
|
|
|
// var ids []int64 |
|
|
|
// count := 0 |
|
|
|
// for key := range task.MatchLabels { |
|
|
|
// var participantId []int64 |
|
|
|
// dbEngin.Raw("select participant_id from sc_participant_label_info where `key` = ? and value = ?", key, task.MatchLabels[key]).Scan(&participantId) |
|
|
|
// if count == 0 { |
|
|
|
// ids = participantId |
|
|
|
// } |
|
|
|
// if len(participantId) == 0 || len(ids) == 0 { |
|
|
|
// return nil, nil |
|
|
|
// } |
|
|
|
// ids = intersect(ids, participantId) |
|
|
|
// count++ |
|
|
|
// } |
|
|
|
// return micsSlice(ids, 1), nil |
|
|
|
//} |
|
|
|
|
|
|
|
// 求交集 |
|
|
|
func intersect(slice1, slice2 []int64) []int64 { |
|
|
|
|