调度结构修改3

Former-commit-id: 8242a201cd8b7a4a7e9fc7320288f8585907bb6a
This commit is contained in:
tzwang 2023-08-23 16:57:52 +08:00
parent 3af1dabbf6
commit b86bd44f0c
6 changed files with 48 additions and 23 deletions

View File

@ -6,13 +6,13 @@ import (
"math" "math"
) )
type pcmStrategy struct { type k8sStrategy struct {
ProviderList []*Provider ProviderList []*Provider
Task *Task Task *Task
StrategyList []*Strategy StrategyList []*Strategy
} }
func NewPcmStrategy(task *Task, providers ...*Provider) *pcmStrategy { func NewK8sStrategy(task *Task, providers ...*Provider) *k8sStrategy {
var providerList []*Provider var providerList []*Provider
var res [][]int var res [][]int
@ -43,10 +43,10 @@ func NewPcmStrategy(task *Task, providers ...*Provider) *pcmStrategy {
strategyList = append(strategyList, strategy) 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() maxStrategy := NewStrategy()
var maxprofit float64 var maxprofit float64

View File

@ -1,6 +1,7 @@
package scheduler package scheduler
import ( 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/api/internal/types"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/model" "gitlink.org.cn/jcce-pcm/pcm-coordinator/model"
"gitlink.org.cn/jcce-pcm/utils/tool" "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) tool.Convert(task.Metadata, &ai)
return ai, nil return ai, nil
} }
func (cs aiScheduler) pickOptimalStrategy(task *algo.Task, providers ...*algo.Provider) (*algo.Task, error) {
return nil, nil
}

View File

@ -3,6 +3,7 @@ package scheduler
import ( import (
"bytes" "bytes"
"encoding/json" "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/api/internal/types"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/model" "gitlink.org.cn/jcce-pcm/pcm-coordinator/model"
"io" "io"
@ -19,6 +20,15 @@ func NewCloudScheduler() *cloudScheduler {
return &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) { func (cs cloudScheduler) getNewStructForDb(task *types.TaskInfo, participantIds []int64) (interface{}, error) {
bytes, err := json.Marshal(task.Metadata) bytes, err := json.Marshal(task.Metadata)
if err != nil { if err != nil {

View File

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

View File

@ -1,6 +1,7 @@
package scheduler package scheduler
import ( 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/api/internal/types"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/model" "gitlink.org.cn/jcce-pcm/pcm-coordinator/model"
"gitlink.org.cn/jcce-pcm/utils/tool" "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) tool.Convert(task.Metadata, &hpc)
return hpc, nil return hpc, nil
} }
func (cs hpcScheduler) pickOptimalStrategy(task *algo.Task, providers ...*algo.Provider) (*algo.Task, error) {
return nil, nil
}

View File

@ -47,11 +47,15 @@ func (s scheduler) MatchLabels(dbEngin *gorm.DB) {
s.participantIds = micsSlice(ids, 1) s.participantIds = micsSlice(ids, 1)
} }
func (s scheduler) AssignAndSchedule() {
}
func (s scheduler) SaveToDb(dbEngin *gorm.DB) error { func (s scheduler) SaveToDb(dbEngin *gorm.DB) error {
if len(s.participantIds) == 0 { if len(s.participantIds) == 0 {
return errors.New("participantIds 为空") 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 { if err != nil {
return err return err
} }