From 68c4469969fa88e51103144e27aca3777256f2c9 Mon Sep 17 00:00:00 2001 From: qiwang <1364512070@qq.com> Date: Wed, 15 May 2024 10:56:54 +0800 Subject: [PATCH] fix: update vmInfo Former-commit-id: 99cbee2f2c7c00e628cf97c9f4622c8c1bbea29a --- api/client/types.go | 2 ++ api/desc/core/pcm-core.api | 8 +------- api/internal/logic/core/commitvmtasklogic.go | 13 +++++++------ .../scheduler/schedulers/option/vmOption.go | 2 +- .../scheduler/schedulers/vmScheduler.go | 17 ++++++----------- api/internal/types/types.go | 1 + 6 files changed, 18 insertions(+), 25 deletions(-) diff --git a/api/client/types.go b/api/client/types.go index 32e22c1b..ff74a4cd 100644 --- a/api/client/types.go +++ b/api/client/types.go @@ -170,6 +170,8 @@ type VmInfo struct { DeleteOnTermination bool `json:"delete_on_termination,omitempty"` Status string `json:"Status,omitempty"` StartTime string `json:"startTime,omitempty"` + platform string `json:"platform,omitempty"` + VmName string `json:"vm_name,omitempty"` } type ResourceStats struct { diff --git a/api/desc/core/pcm-core.api b/api/desc/core/pcm-core.api index 9d9a5a20..57042231 100644 --- a/api/desc/core/pcm-core.api +++ b/api/desc/core/pcm-core.api @@ -224,14 +224,8 @@ type ( ImageRef int64 `json:"imageRef,optional"` FlavorRef int64 `json:"flavorRef,optional"` Uuid int64 `json:"uuid,optional"` - //Replicas int64 `json:"replicas,string"` + Replicas int32 `json:"replicas,string"` VmName string `json:"vm_name,optional"` - // Replicas int64 `json:"replicas,optional"` - // MatchLabels map[string]string `json:"matchLabels,optional"` - // ClusterType string `json:"clusterType,optional"` - // //Virtual Machine Section - //CreateMulServer []CreateMulDomainServer `json:"createMulServer,optional"` - //VmOption *VmOption `json:"vmOption,optional"` } TaskVm { Image string `json:"image"` diff --git a/api/internal/logic/core/commitvmtasklogic.go b/api/internal/logic/core/commitvmtasklogic.go index f339580a..84375e9a 100644 --- a/api/internal/logic/core/commitvmtasklogic.go +++ b/api/internal/logic/core/commitvmtasklogic.go @@ -52,11 +52,11 @@ func (l *CommitVmTaskLogic) CommitVmTask(req *types.CommitVmTaskReq) (resp *type }() //TODO adapter adapterId, _ := strconv.ParseUint(req.AdapterIds[0], 10, 64) - var clusters []*models.VmModel - err2 := l.svcCtx.DbEngin.Raw("SELECT * FROM `t_cluster` where adapter_id in ? and id in ?", req.AdapterIds, req.ClusterIds).Scan(&clusters).Error + /*var clusters []*models.VmModel + err2 := l.svcCtx.DbEngin.Raw("SELECT * FROM `t_cluster` where adapter_id in ? and id in ?", adapterId, req.ClusterIds).Scan(&clusters).Error if err2 != nil { logx.Errorf("CommitGeneralTask() => sql execution error: %v", err) - } + }*/ taskVm := models.TaskVm{} //TODO 执行策略返回集群跟 Replica opt := &option.VmOption{} @@ -115,9 +115,10 @@ func (l *CommitVmTaskLogic) CommitVmTask(req *types.CommitVmTaskReq) (resp *type logx.Error(err) return nil, txVm.Error } - if err2 != nil { - logx.Errorf("CommitGeneralTask() => sql execution error: %v", err) - } + /* if err2 != nil { + logx.Errorf("CommitGeneralTask() => sql execution error: %v", err) + //return errors.Errorf("the cluster does not match the drive resources. Check the data"), nil + }*/ taskVm.Name = req.VmName taskVm.Status = "Saved" taskVm.StartTime = time.Now().String() diff --git a/api/internal/scheduler/schedulers/option/vmOption.go b/api/internal/scheduler/schedulers/option/vmOption.go index 54006a83..94735bef 100644 --- a/api/internal/scheduler/schedulers/option/vmOption.go +++ b/api/internal/scheduler/schedulers/option/vmOption.go @@ -12,7 +12,7 @@ type VmOption struct { ClusterToStaticWeight map[string]int32 CommitTime time.Time NsID string - Replicas int64 + Replicas int32 MatchLabels map[string]string StaticWeightMap map[string]int32 CreateMulServer []CreateMulDomainServer diff --git a/api/internal/scheduler/schedulers/vmScheduler.go b/api/internal/scheduler/schedulers/vmScheduler.go index d4c3de4e..3d8e4750 100644 --- a/api/internal/scheduler/schedulers/vmScheduler.go +++ b/api/internal/scheduler/schedulers/vmScheduler.go @@ -53,10 +53,6 @@ func (vm *VmScheduler) PickOptimalStrategy() (strategy.Strategy, error) { return nil, err }*/ - /* if len(resources) == 0 { - return nil, errors.New("no cluster has resources") - }*/ - // //if len(resources) == 1 { // var cluster strategy.AssignedCluster // cluster.ClusterId = resources[0].ClusterId @@ -75,19 +71,18 @@ func (vm *VmScheduler) PickOptimalStrategy() (strategy.Strategy, error) { return strategy, nil case strategy.RESOURCES_PRICING: strategy := strategy.NewPricingStrategy(¶m.ResourcePricingParams{Params: params, Replicas: 1}) - return strategy, nil - case strategy.DYNAMIC_RESOURCES: - strategy := strategy.NewDynamicResourcesStrategy(params.Resources, vm.option, 1) return strategy, nil*/ + /* case strategy.DYNAMIC_RESOURCES: + strategy := strategy.NewDynamicResourcesStrategy(params.Resources, vm.option, 1) + return strategy, nil*/ case strategy.STATIC_WEIGHT: //todo resources should match cluster StaticWeightMap strategy := strategy.NewStaticWeightStrategy(vm.option.StaticWeightMap, 1) return strategy, nil + case strategy.RANDOM: + strategy := strategy.NewRandomStrategy(vm.option.ClusterIds, vm.option.Replicas) + return strategy, nil } - - /*strategy := strategy.NewPricingStrategy(¶m.ResourcePricingParams{}) - return strategy, nil*/ - return nil, errors.New("no strategy has been chosen") } diff --git a/api/internal/types/types.go b/api/internal/types/types.go index fed98b44..dc8a3da8 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -202,6 +202,7 @@ type CommitVmTaskReq struct { ImageRef int64 `json:"imageRef,optional"` FlavorRef int64 `json:"flavorRef,optional"` Uuid int64 `json:"uuid,optional"` + Replicas int32 `json:"replicas,string"` VmName string `json:"vm_name,optional"` }