调度结构修改3
Former-commit-id: 8242a201cd8b7a4a7e9fc7320288f8585907bb6a
This commit is contained in:
parent
3af1dabbf6
commit
b86bd44f0c
|
@ -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
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue