open-nomad/nomad/drainer_shims.go

44 lines
1.5 KiB
Go
Raw Normal View History

2018-02-27 00:28:10 +00:00
package nomad
import "github.com/hashicorp/nomad/nomad/structs"
// drainerShim implements the drainer.RaftApplier interface required by the
// NodeDrainer.
type drainerShim struct {
s *Server
}
2018-03-06 22:37:37 +00:00
func (d drainerShim) NodeDrainComplete(nodeID string) (uint64, error) {
2018-02-27 00:28:10 +00:00
args := &structs.NodeUpdateDrainRequest{
NodeID: nodeID,
Drain: false,
WriteRequest: structs.WriteRequest{Region: d.s.config.Region},
}
2018-03-06 22:37:37 +00:00
resp, index, err := d.s.raftApply(structs.NodeUpdateDrainRequestType, args)
return d.convertApplyErrors(resp, 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},
}
2018-03-06 22:37:37 +00:00
resp, index, err := d.s.raftApply(structs.AllocUpdateDesiredTransitionRequestType, args)
return d.convertApplyErrors(resp, index, err)
}
// convertApplyErrors parses the results of a raftApply and returns the index at
// which it was applied and any error that occurred. Raft Apply returns two
// separate errors, Raft library errors and user returned errors from the FSM.
// This helper, joins the errors by inspecting the applyResponse for an error.
2018-03-06 22:37:37 +00:00
func (d drainerShim) convertApplyErrors(applyResp interface{}, index uint64, err error) (uint64, error) {
if applyResp != nil {
if fsmErr, ok := applyResp.(error); ok && fsmErr != nil {
2018-03-06 22:37:37 +00:00
return index, fsmErr
}
}
2018-03-06 22:37:37 +00:00
return index, err
2018-02-27 00:28:10 +00:00
}