|
- package strategy
-
- import (
- "errors"
- "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/scheduler/entity"
- "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/scheduler/strategy/param"
- )
-
- type ReplicationStrategy struct {
- replicas int32
- participants []*entity.Participant
- }
-
- func NewReplicationStrategy(params *param.ReplicationParams) *ReplicationStrategy {
- return &ReplicationStrategy{replicas: params.GetReplicas(),
- participants: params.GetParticipants(),
- }
- }
-
- func (ps *ReplicationStrategy) Schedule() ([]*AssignedCluster, error) {
- if ps.replicas < 1 {
- return nil, errors.New("replicas must be greater than 0")
- }
-
- if ps.participants == nil {
- return nil, errors.New("participantId must be set")
- }
-
- var results []*AssignedCluster
- for _, p := range ps.participants {
- cluster := &AssignedCluster{ParticipantId: p.Participant_id, Name: p.Name, Replicas: ps.replicas}
- results = append(results, cluster)
- }
- return results, nil
- }
|