| @@ -170,6 +170,8 @@ type VmInfo struct { | |||||
| DeleteOnTermination bool `json:"delete_on_termination,omitempty"` | DeleteOnTermination bool `json:"delete_on_termination,omitempty"` | ||||
| Status string `json:"Status,omitempty"` | Status string `json:"Status,omitempty"` | ||||
| StartTime string `json:"startTime,omitempty"` | StartTime string `json:"startTime,omitempty"` | ||||
| platform string `json:"platform,omitempty"` | |||||
| VmName string `json:"vm_name,omitempty"` | |||||
| } | } | ||||
| type ResourceStats struct { | type ResourceStats struct { | ||||
| @@ -224,14 +224,8 @@ type ( | |||||
| ImageRef int64 `json:"imageRef,optional"` | ImageRef int64 `json:"imageRef,optional"` | ||||
| FlavorRef int64 `json:"flavorRef,optional"` | FlavorRef int64 `json:"flavorRef,optional"` | ||||
| Uuid int64 `json:"uuid,optional"` | Uuid int64 `json:"uuid,optional"` | ||||
| //Replicas int64 `json:"replicas,string"` | |||||
| Replicas int32 `json:"replicas,string"` | |||||
| VmName string `json:"vm_name,optional"` | 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 { | TaskVm { | ||||
| Image string `json:"image"` | Image string `json:"image"` | ||||
| @@ -52,11 +52,11 @@ func (l *CommitVmTaskLogic) CommitVmTask(req *types.CommitVmTaskReq) (resp *type | |||||
| }() | }() | ||||
| //TODO adapter | //TODO adapter | ||||
| adapterId, _ := strconv.ParseUint(req.AdapterIds[0], 10, 64) | 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 { | if err2 != nil { | ||||
| logx.Errorf("CommitGeneralTask() => sql execution error: %v", err) | logx.Errorf("CommitGeneralTask() => sql execution error: %v", err) | ||||
| } | |||||
| }*/ | |||||
| taskVm := models.TaskVm{} | taskVm := models.TaskVm{} | ||||
| //TODO 执行策略返回集群跟 Replica | //TODO 执行策略返回集群跟 Replica | ||||
| opt := &option.VmOption{} | opt := &option.VmOption{} | ||||
| @@ -115,9 +115,10 @@ func (l *CommitVmTaskLogic) CommitVmTask(req *types.CommitVmTaskReq) (resp *type | |||||
| logx.Error(err) | logx.Error(err) | ||||
| return nil, txVm.Error | 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.Name = req.VmName | ||||
| taskVm.Status = "Saved" | taskVm.Status = "Saved" | ||||
| taskVm.StartTime = time.Now().String() | taskVm.StartTime = time.Now().String() | ||||
| @@ -12,7 +12,7 @@ type VmOption struct { | |||||
| ClusterToStaticWeight map[string]int32 | ClusterToStaticWeight map[string]int32 | ||||
| CommitTime time.Time | CommitTime time.Time | ||||
| NsID string | NsID string | ||||
| Replicas int64 | |||||
| Replicas int32 | |||||
| MatchLabels map[string]string | MatchLabels map[string]string | ||||
| StaticWeightMap map[string]int32 | StaticWeightMap map[string]int32 | ||||
| CreateMulServer []CreateMulDomainServer | CreateMulServer []CreateMulDomainServer | ||||
| @@ -53,10 +53,6 @@ func (vm *VmScheduler) PickOptimalStrategy() (strategy.Strategy, error) { | |||||
| return nil, err | return nil, err | ||||
| }*/ | }*/ | ||||
| /* if len(resources) == 0 { | |||||
| return nil, errors.New("no cluster has resources") | |||||
| }*/ | |||||
| // | |||||
| //if len(resources) == 1 { | //if len(resources) == 1 { | ||||
| // var cluster strategy.AssignedCluster | // var cluster strategy.AssignedCluster | ||||
| // cluster.ClusterId = resources[0].ClusterId | // cluster.ClusterId = resources[0].ClusterId | ||||
| @@ -75,19 +71,18 @@ func (vm *VmScheduler) PickOptimalStrategy() (strategy.Strategy, error) { | |||||
| return strategy, nil | return strategy, nil | ||||
| case strategy.RESOURCES_PRICING: | case strategy.RESOURCES_PRICING: | ||||
| strategy := strategy.NewPricingStrategy(¶m.ResourcePricingParams{Params: params, Replicas: 1}) | 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*/ | return strategy, nil*/ | ||||
| /* case strategy.DYNAMIC_RESOURCES: | |||||
| strategy := strategy.NewDynamicResourcesStrategy(params.Resources, vm.option, 1) | |||||
| return strategy, nil*/ | |||||
| case strategy.STATIC_WEIGHT: | case strategy.STATIC_WEIGHT: | ||||
| //todo resources should match cluster StaticWeightMap | //todo resources should match cluster StaticWeightMap | ||||
| strategy := strategy.NewStaticWeightStrategy(vm.option.StaticWeightMap, 1) | strategy := strategy.NewStaticWeightStrategy(vm.option.StaticWeightMap, 1) | ||||
| return strategy, nil | 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") | return nil, errors.New("no strategy has been chosen") | ||||
| } | } | ||||
| @@ -202,6 +202,7 @@ type CommitVmTaskReq struct { | |||||
| ImageRef int64 `json:"imageRef,optional"` | ImageRef int64 `json:"imageRef,optional"` | ||||
| FlavorRef int64 `json:"flavorRef,optional"` | FlavorRef int64 `json:"flavorRef,optional"` | ||||
| Uuid int64 `json:"uuid,optional"` | Uuid int64 `json:"uuid,optional"` | ||||
| Replicas int32 `json:"replicas,string"` | |||||
| VmName string `json:"vm_name,optional"` | VmName string `json:"vm_name,optional"` | ||||
| } | } | ||||