2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2018-02-27 00:28:10 +00:00
|
|
|
package nomad
|
|
|
|
|
2019-05-21 19:45:00 +00:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
|
|
)
|
2018-02-27 00:28:10 +00:00
|
|
|
|
|
|
|
// drainerShim implements the drainer.RaftApplier interface required by the
|
|
|
|
// NodeDrainer.
|
|
|
|
type drainerShim struct {
|
|
|
|
s *Server
|
|
|
|
}
|
|
|
|
|
2018-05-11 00:22:06 +00:00
|
|
|
func (d drainerShim) NodesDrainComplete(nodes []string, event *structs.NodeEvent) (uint64, error) {
|
2018-03-09 22:15:21 +00:00
|
|
|
args := &structs.BatchNodeUpdateDrainRequest{
|
|
|
|
Updates: make(map[string]*structs.DrainUpdate, len(nodes)),
|
2018-05-11 00:22:06 +00:00
|
|
|
NodeEvents: make(map[string]*structs.NodeEvent, len(nodes)),
|
2018-02-27 00:28:10 +00:00
|
|
|
WriteRequest: structs.WriteRequest{Region: d.s.config.Region},
|
2019-05-21 19:45:00 +00:00
|
|
|
UpdatedAt: time.Now().Unix(),
|
2018-02-27 00:28:10 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 22:15:21 +00:00
|
|
|
update := &structs.DrainUpdate{}
|
|
|
|
for _, node := range nodes {
|
|
|
|
args.Updates[node] = update
|
2018-05-11 00:22:06 +00:00
|
|
|
if event != nil {
|
|
|
|
args.NodeEvents[node] = event
|
|
|
|
}
|
2018-03-09 22:15:21 +00:00
|
|
|
}
|
|
|
|
|
2023-03-02 18:51:09 +00:00
|
|
|
_, index, err := d.s.raftApply(structs.BatchNodeUpdateDrainRequestType, args)
|
|
|
|
return index, err
|
2018-02-27 00:28:10 +00:00
|
|
|
}
|
|
|
|
|
2018-03-06 22:37:37 +00:00
|
|
|
func (d drainerShim) AllocUpdateDesiredTransition(allocs map[string]*structs.DesiredTransition, evals []*structs.Evaluation) (uint64, error) {
|
2018-02-27 00:28:10 +00:00
|
|
|
args := &structs.AllocUpdateDesiredTransitionRequest{
|
|
|
|
Allocs: allocs,
|
|
|
|
Evals: evals,
|
|
|
|
WriteRequest: structs.WriteRequest{Region: d.s.config.Region},
|
|
|
|
}
|
2023-03-02 18:51:09 +00:00
|
|
|
_, index, err := d.s.raftApply(structs.AllocUpdateDesiredTransitionRequestType, args)
|
2018-03-06 22:37:37 +00:00
|
|
|
return index, err
|
2018-02-27 00:28:10 +00:00
|
|
|
}
|