|
|
|
@@ -25,7 +25,6 @@ import ( |
|
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/scheduler/schedulers/option" |
|
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/scheduler/service/collector" |
|
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/scheduler/strategy" |
|
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/scheduler/strategy/param" |
|
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/pkg/response" |
|
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants" |
|
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models" |
|
|
|
@@ -71,44 +70,45 @@ func (as *AiScheduler) PickOptimalStrategy() (strategy.Strategy, error) { |
|
|
|
return &strategy.SingleAssignment{Cluster: &strategy.AssignedCluster{ClusterId: as.option.ClusterIds[0], Replicas: 1}}, nil |
|
|
|
} |
|
|
|
|
|
|
|
resources, err := as.findClustersWithResources() |
|
|
|
/* resources, err := as.findClustersWithResources() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
if len(resources) == 0 { |
|
|
|
return nil, errors.New("no cluster has resources") |
|
|
|
} |
|
|
|
if err != nil { |
|
|
|
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 |
|
|
|
cluster.Replicas = 1 |
|
|
|
return &strategy.SingleAssignment{Cluster: &cluster}, nil |
|
|
|
} |
|
|
|
if len(resources) == 1 { |
|
|
|
var cluster strategy.AssignedCluster |
|
|
|
cluster.ClusterId = resources[0].ClusterId |
|
|
|
cluster.Replicas = 1 |
|
|
|
return &strategy.SingleAssignment{Cluster: &cluster}, nil |
|
|
|
} |
|
|
|
|
|
|
|
params := ¶m.Params{Resources: resources} |
|
|
|
params := ¶m.Params{Resources: resources}*/ |
|
|
|
|
|
|
|
switch as.option.StrategyName { |
|
|
|
case strategy.REPLICATION: |
|
|
|
var clusterIds []string |
|
|
|
for _, resource := range resources { |
|
|
|
/* for _, resource := range resources { |
|
|
|
clusterIds = append(clusterIds, resource.ClusterId) |
|
|
|
} |
|
|
|
}*/ |
|
|
|
strategy := strategy.NewReplicationStrategy(clusterIds, 1) |
|
|
|
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, as.option, 1) |
|
|
|
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, as.option, 1) |
|
|
|
return strategy, nil*/ |
|
|
|
case strategy.STATIC_WEIGHT: |
|
|
|
//todo resources should match cluster StaticWeightMap |
|
|
|
strategy := strategy.NewStaticWeightStrategy(as.option.ClusterToStaticWeight, as.option.Replica) |
|
|
|
return strategy, nil |
|
|
|
case strategy.RANDOM: |
|
|
|
|
|
|
|
strategy := strategy.NewRandomStrategy(as.option.ClusterIds, as.option.Replica) |
|
|
|
return strategy, nil |
|
|
|
} |
|
|
|
|
|
|
|
return nil, errors.New("no strategy has been chosen") |
|
|
|
|