// steps is the ordered sequence of workflow steps to orchestrate a service instance change func (p plan) steps() (steps []step.Step) { if p.newFeatures.NodeCount == 0 { for i := 0; i < p.clusterModel.NodeCount(); i++ { steps = append(steps, step.NewStepRemoveRandomNode(p.clusterModel, "", p.allCells, p.logger)) } return } // we know the leader must survive because the cluster isn't being deleted leaderID, _ := p.patroni.ClusterLeader(p.clusterModel.InstanceID()) addedNodes := false for i := 0; i < p.clusterGrowingBy(); i++ { steps = append(steps, step.NewStepAddNode(p.clusterModel, p.patroni, p.availableCells, p.logger)) addedNodes = true } replicasToBeReplaced, leaderToBeReplaced := p.nodesToBeReplaced(leaderID) for _ = range replicasToBeReplaced { steps = append(steps, step.NewStepAddNode(p.clusterModel, p.patroni, p.availableCells, p.logger)) addedNodes = true } if leaderToBeReplaced != nil { steps = append(steps, step.NewStepAddNode(p.clusterModel, p.patroni, p.availableCells, p.logger)) addedNodes = true } if addedNodes { steps = append(steps, step.NewWaitForAllMembers(p.clusterModel, p.patroni, p.logger)) } removedNodes := false for _, replica := range replicasToBeReplaced { steps = append(steps, step.NewStepRemoveNode(replica, p.clusterModel, p.allCells, p.logger)) removedNodes = true } for i := 0; i < p.clusterShrinkingBy(); i++ { steps = append(steps, step.NewStepRemoveRandomNode(p.clusterModel, leaderID, p.allCells, p.logger)) removedNodes = true } if removedNodes { steps = append(steps, step.NewWaitForAllMembers(p.clusterModel, p.patroni, p.logger)) } if leaderToBeReplaced != nil { steps = append(steps, step.NewStepFailoverFrom(p.clusterModel, leaderID, p.patroni, p.logger)) steps = append(steps, step.NewStepRemoveNode(leaderToBeReplaced, p.clusterModel, p.allCells, p.logger)) } steps = append(steps, step.NewWaitForLeader(p.clusterModel, p.patroni, p.logger)) return }
// steps is the ordered sequence of workflow steps to orchestrate a service instance change func (p plan) steps() (steps []step.Step) { addedNodes := false for i := 0; i < p.clusterGrowingBy(); i++ { steps = append(steps, step.NewStepAddNode(p.clusterModel, p.patroni, p.availableCells, p.logger)) addedNodes = true } nodesToBeReplaced := p.nodesToBeReplaced() for _ = range nodesToBeReplaced { steps = append(steps, step.NewStepAddNode(p.clusterModel, p.patroni, p.availableCells, p.logger)) addedNodes = true } if addedNodes { steps = append(steps, step.NewWaitForAllMembers(p.clusterModel, p.patroni, p.logger)) } removedNodes := false for _, replica := range p.replicas(nodesToBeReplaced) { steps = append(steps, step.NewStepRemoveNode(replica, p.clusterModel, p.allCells, p.logger)) removedNodes = true } if leader := p.leader(nodesToBeReplaced); leader != nil { steps = append(steps, step.NewStepRemoveLeader(leader, p.clusterModel, p.allCells, p.logger)) removedNodes = true } if removedNodes { steps = append(steps, step.NewWaitForAllMembers(p.clusterModel, p.patroni, p.logger)) } for i := 0; i < p.clusterShrinkingBy(); i++ { steps = append(steps, step.NewStepRemoveRandomNode(p.clusterModel, p.allCells, p.logger)) } if p.newFeatures.NodeCount > 0 { steps = append(steps, step.NewWaitForLeader(p.clusterModel, p.patroni, p.logger)) } return }