From f16396c7464075e84b6ebab86a0db2c0d8af183e Mon Sep 17 00:00:00 2001 From: zhouqunjie Date: Wed, 29 Nov 2023 17:27:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 8710013a832280ba3418fe451ead53c47559430c --- api/desc/core/pcm-core.api | 1 + api/internal/mqs/ScheduleCloud.go | 4 ---- api/internal/types/types.go | 1 + api/pkg/response/TaskInfo.go | 1 + pkg/scheduler/scheduler.go | 33 ++----------------------------- 5 files changed, 5 insertions(+), 35 deletions(-) diff --git a/api/desc/core/pcm-core.api b/api/desc/core/pcm-core.api index 6d677523..ede17fc1 100644 --- a/api/desc/core/pcm-core.api +++ b/api/desc/core/pcm-core.api @@ -180,6 +180,7 @@ type ( Description string `yaml:"description"` tenantId int64 `yaml:"tenantId"` nsID string `yaml:"nsID"` + replicas int64 `yaml:"replicas"` tasks []TaskYaml `yaml:"tasks"` } TaskYaml { diff --git a/api/internal/mqs/ScheduleCloud.go b/api/internal/mqs/ScheduleCloud.go index a7237f7b..dc61924b 100644 --- a/api/internal/mqs/ScheduleCloud.go +++ b/api/internal/mqs/ScheduleCloud.go @@ -55,10 +55,6 @@ func (l *CloudMq) Consume(val string) error { //todo 屏蔽原调度算法,因为监控数据暂未上报,临时采用随机调度 schdl.TempAssign() - //err = schdl.AssignAndSchedule() - //if err != nil { - // return err - //} // 存储数据 err = schdl.SaveToDb() diff --git a/api/internal/types/types.go b/api/internal/types/types.go index 7cb9030b..2057a921 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -161,6 +161,7 @@ type ScheduleTaskByYamlReq struct { Description string `yaml:"description"` TenantId int64 `yaml:"tenantId"` NsID string `yaml:"nsID"` + Replicas int64 `yaml:"replicas"` Tasks []TaskYaml `yaml:"tasks"` } diff --git a/api/pkg/response/TaskInfo.go b/api/pkg/response/TaskInfo.go index 861db255..93ddf5fa 100644 --- a/api/pkg/response/TaskInfo.go +++ b/api/pkg/response/TaskInfo.go @@ -24,6 +24,7 @@ type TaskInfo struct { ParticipantId int64 `json:"participantId,optional"` //湘江预留字段 Clusters []string `json:"clusters,optional"` //云际平台传入集群名称列表 TenantId int64 `json:"tenantId"` + Replicas int64 `json:"replicas"` Metadata interface{} `json:"metadata"` } diff --git a/pkg/scheduler/scheduler.go b/pkg/scheduler/scheduler.go index 5e6c782d..2dc98adb 100644 --- a/pkg/scheduler/scheduler.go +++ b/pkg/scheduler/scheduler.go @@ -24,10 +24,8 @@ import ( tool "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils" "gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/client/participantservice" "gorm.io/gorm" - "math/rand" "strconv" "strings" - "time" ) type scheduler struct { @@ -105,37 +103,10 @@ func (s *scheduler) TempAssign() error { for _, resource := range resources { //如果是Deployment,需要对副本数做分发 if resource.(map[string]interface{})["kind"].(string) == "Deployment" || resource.(map[string]interface{})["kind"].(string) == "Replicaset" { - //replicas := int(resource.(map[string]interface{})["spec"].(map[string]interface{})["replicas"].(float64)) - - rand.Seed(time.Now().UnixNano()) - - //// 生成pID对应副本数 数组 - //arrReplica := make(map[int64]int, len(s.participantIds)) - //for i := 0; i < len(s.participantIds)-1; i++ { - // arrReplica[s.participantIds[i]] = rand.Intn(replicas) - // replicas -= arrReplica[s.participantIds[i]] // 更新剩余的和 - //} - //arrReplica[s.participantIds[len(s.participantIds)-1]] = replicas - // - ////将副本数依次写入新的yaml中并生成result数据 - //yamlArray := make(map[int64]string, len(s.participantIds)) - // - //for i := 0; i < len(s.participantIds)-1; i++ { - // //调整yaml - // yamlArray[s.participantIds[i]] = "sds" - //} - + resource.(map[string]interface{})["spec"].(map[string]interface{})["replicas"] = s.task.Replicas } - - s.result[s.participantIds[0]] = "" - } - - //var crd = s.task.Metadata - //for i := 0; i < len(s.task.Metadata); i++ { - // - //} - + s.task.Metadata = resources return nil }