diff --git a/api/internal/algo/pcmStrategy.go b/api/internal/algo/k8sStrategy.go similarity index 97% rename from api/internal/algo/pcmStrategy.go rename to api/internal/algo/k8sStrategy.go index d4396e61..71efefc7 100644 --- a/api/internal/algo/pcmStrategy.go +++ b/api/internal/algo/k8sStrategy.go @@ -6,13 +6,13 @@ import ( "math" ) -type pcmStrategy struct { +type k8sStrategy struct { ProviderList []*Provider Task *Task StrategyList []*Strategy } -func NewPcmStrategy(task *Task, providers ...*Provider) *pcmStrategy { +func NewK8sStrategy(task *Task, providers ...*Provider) *k8sStrategy { var providerList []*Provider var res [][]int @@ -43,10 +43,10 @@ func NewPcmStrategy(task *Task, providers ...*Provider) *pcmStrategy { strategyList = append(strategyList, strategy) } - return &pcmStrategy{ProviderList: providerList, Task: task, StrategyList: strategyList} + return &k8sStrategy{ProviderList: providerList, Task: task, StrategyList: strategyList} } -func (ps pcmStrategy) computeMaxScore() (*Task, error) { +func (ps k8sStrategy) computeMaxScore() (*Task, error) { maxStrategy := NewStrategy() var maxprofit float64 diff --git a/api/internal/pkg/scheduler/aiScheduler.go b/api/internal/pkg/scheduler/aiScheduler.go index bbd817f5..2b181662 100644 --- a/api/internal/pkg/scheduler/aiScheduler.go +++ b/api/internal/pkg/scheduler/aiScheduler.go @@ -1,6 +1,7 @@ package scheduler import ( + "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/algo" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types" "gitlink.org.cn/jcce-pcm/pcm-coordinator/model" "gitlink.org.cn/jcce-pcm/utils/tool" @@ -24,3 +25,7 @@ func (cs aiScheduler) getNewStructForDb(task *types.TaskInfo, participantIds []i tool.Convert(task.Metadata, &ai) return ai, nil } + +func (cs aiScheduler) pickOptimalStrategy(task *algo.Task, providers ...*algo.Provider) (*algo.Task, error) { + return nil, nil +} diff --git a/api/internal/pkg/scheduler/cloudScheduler.go b/api/internal/pkg/scheduler/cloudScheduler.go index 81477de2..4b2c208d 100644 --- a/api/internal/pkg/scheduler/cloudScheduler.go +++ b/api/internal/pkg/scheduler/cloudScheduler.go @@ -3,6 +3,7 @@ package scheduler import ( "bytes" "encoding/json" + "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/algo" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types" "gitlink.org.cn/jcce-pcm/pcm-coordinator/model" "io" @@ -19,6 +20,15 @@ func NewCloudScheduler() *cloudScheduler { return &cloudScheduler{} } +func (cs cloudScheduler) pickOptimalStrategy(task *algo.Task, providers ...*algo.Provider) (*algo.Task, error) { + strategy := algo.NewK8sStrategy(task, providers...) + taskResult, err := algo.ScheduleWithFullCollaboration(strategy, strategy.ProviderList) + if err != nil { + return nil, err + } + return taskResult, nil +} + func (cs cloudScheduler) getNewStructForDb(task *types.TaskInfo, participantIds []int64) (interface{}, error) { bytes, err := json.Marshal(task.Metadata) if err != nil { diff --git a/api/internal/pkg/scheduler/commonScheduler.go b/api/internal/pkg/scheduler/commonScheduler.go index 0da9022e..30126a34 100644 --- a/api/internal/pkg/scheduler/commonScheduler.go +++ b/api/internal/pkg/scheduler/commonScheduler.go @@ -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 { diff --git a/api/internal/pkg/scheduler/hpcScheduler.go b/api/internal/pkg/scheduler/hpcScheduler.go index c1dba3cd..15443e0d 100644 --- a/api/internal/pkg/scheduler/hpcScheduler.go +++ b/api/internal/pkg/scheduler/hpcScheduler.go @@ -1,6 +1,7 @@ package scheduler import ( + "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/algo" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types" "gitlink.org.cn/jcce-pcm/pcm-coordinator/model" "gitlink.org.cn/jcce-pcm/utils/tool" @@ -24,3 +25,7 @@ func (h hpcScheduler) getNewStructForDb(task *types.TaskInfo, participantIds []i tool.Convert(task.Metadata, &hpc) return hpc, nil } + +func (cs hpcScheduler) pickOptimalStrategy(task *algo.Task, providers ...*algo.Provider) (*algo.Task, error) { + return nil, nil +} diff --git a/api/internal/pkg/scheduler/scheduler.go b/api/internal/pkg/scheduler/scheduler.go index 4c953239..17ede9ec 100644 --- a/api/internal/pkg/scheduler/scheduler.go +++ b/api/internal/pkg/scheduler/scheduler.go @@ -47,11 +47,15 @@ func (s scheduler) MatchLabels(dbEngin *gorm.DB) { s.participantIds = micsSlice(ids, 1) } +func (s scheduler) AssignAndSchedule() { + +} + func (s scheduler) SaveToDb(dbEngin *gorm.DB) error { if len(s.participantIds) == 0 { return errors.New("participantIds 为空") } - structForDb, err := s.scheduleService().getNewStructForDb(s.task, s.participantIds) + structForDb, err := s.scheduleService.getNewStructForDb(s.task, s.participantIds) if err != nil { return err }