open-nomad/nomad/drainer_shims.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1.3 KiB
Go
Raw Normal View History

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
2018-02-27 00:28:10 +00:00
package nomad
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},
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
}
_, 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},
}
_, 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
}