From 47d0ae257b451d1716bacf810b11ff35e0270b94 Mon Sep 17 00:00:00 2001 From: tzwang Date: Thu, 24 Aug 2023 17:08:19 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E5=BA=A6=E7=BB=93=E6=9E=84=E4=BF=AE?= =?UTF-8?q?=E6=94=B95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 89372339e77858bc2b6c5443520402611f0c9bb2 --- api/internal/algo/provider.go | 4 ++-- api/internal/pkg/scheduler/scheduler.go | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/api/internal/algo/provider.go b/api/internal/algo/provider.go index 27cd8488..106d6464 100644 --- a/api/internal/algo/provider.go +++ b/api/internal/algo/provider.go @@ -3,7 +3,7 @@ package algo import "math" type Provider struct { - Pid int + Pid int64 CpuSum float64 MemSum float64 DiskSum float64 @@ -23,7 +23,7 @@ type Provider struct { ProfitPerTask map[int]float64 } -func NewProvider(Pid int, CpuSum float64, MemSum float64, DiskSum float64, CpuCost float64, MemCost float64, DiskCost float64) *Provider { +func NewProvider(Pid int64, CpuSum float64, MemSum float64, DiskSum float64, CpuCost float64, MemCost float64, DiskCost float64) *Provider { return &Provider{ Pid: Pid, CpuSum: CpuSum, diff --git a/api/internal/pkg/scheduler/scheduler.go b/api/internal/pkg/scheduler/scheduler.go index 4fd0fa2e..3ad7f568 100644 --- a/api/internal/pkg/scheduler/scheduler.go +++ b/api/internal/pkg/scheduler/scheduler.go @@ -48,6 +48,12 @@ func (s *scheduler) MatchLabels(dbEngin *gorm.DB) { } func (s *scheduler) AssignAndSchedule() error { + // 已指定 ParticipantId + if s.task.ParticipantId != 0 { + return nil + } + + //生成算法所需参数 task, providerList := s.genTaskAndProviders() strategy, err := s.scheduleService.pickOptimalStrategy(task, providerList...) @@ -57,6 +63,7 @@ func (s *scheduler) AssignAndSchedule() error { if strategy == nil { s.task.ParticipantId = s.participantIds[0] + return nil } return nil @@ -79,5 +86,10 @@ func (s *scheduler) SaveToDb(dbEngin *gorm.DB) error { } func (s *scheduler) genTaskAndProviders() (*algo.Task, []*algo.Provider) { + //var providerList []*algo.Provider + //for _, id := range s.participantIds { + // provider := algo.NewProvider(id, 100, 200, 200, 0.0, 0.0, 0.0) + // + //} return nil, nil }