Browse Source

调度结构修改3

Former-commit-id: 8242a201cd
pull/9/head
tzwang 2 years ago
parent
commit
b86bd44f0c
6 changed files with 48 additions and 23 deletions
  1. +4
    -4
      api/internal/algo/k8sStrategy.go
  2. +5
    -0
      api/internal/pkg/scheduler/aiScheduler.go
  3. +10
    -0
      api/internal/pkg/scheduler/cloudScheduler.go
  4. +19
    -18
      api/internal/pkg/scheduler/commonScheduler.go
  5. +5
    -0
      api/internal/pkg/scheduler/hpcScheduler.go
  6. +5
    -1
      api/internal/pkg/scheduler/scheduler.go

api/internal/algo/pcmStrategy.go → api/internal/algo/k8sStrategy.go View File

@@ -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


+ 5
- 0
api/internal/pkg/scheduler/aiScheduler.go View File

@@ -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
}

+ 10
- 0
api/internal/pkg/scheduler/cloudScheduler.go View File

@@ -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 {


+ 19
- 18
api/internal/pkg/scheduler/commonScheduler.go View File

@@ -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 {


+ 5
- 0
api/internal/pkg/scheduler/hpcScheduler.go View File

@@ -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
}

+ 5
- 1
api/internal/pkg/scheduler/scheduler.go View File

@@ -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…
Cancel
Save