forked from JointCloud/pcm-coordinator
34 lines
720 B
Go
34 lines
720 B
Go
package strategy
|
|
|
|
import (
|
|
"errors"
|
|
)
|
|
|
|
type ReplicationStrategy struct {
|
|
replicas int32
|
|
clusterIds []string
|
|
}
|
|
|
|
func NewReplicationStrategy(clusterIds []string, replicas int32) *ReplicationStrategy {
|
|
return &ReplicationStrategy{clusterIds: clusterIds,
|
|
replicas: replicas,
|
|
}
|
|
}
|
|
|
|
func (r *ReplicationStrategy) Schedule() ([]*AssignedCluster, error) {
|
|
if r.replicas < 1 {
|
|
return nil, errors.New("replicas must be greater than 0")
|
|
}
|
|
|
|
if len(r.clusterIds) == 0 {
|
|
return nil, errors.New("clusterIds must be set")
|
|
}
|
|
|
|
var results []*AssignedCluster
|
|
for _, c := range r.clusterIds {
|
|
cluster := &AssignedCluster{ClusterId: c, Replicas: r.replicas}
|
|
results = append(results, cluster)
|
|
}
|
|
return results, nil
|
|
}
|