open-consul/agent/consul/autopilot.go

46 lines
1.2 KiB
Go
Raw Normal View History

package consul
import (
"context"
"fmt"
2017-12-12 00:38:52 +00:00
"github.com/hashicorp/consul/agent/consul/autopilot"
"github.com/hashicorp/consul/agent/metadata"
"github.com/hashicorp/raft"
"github.com/hashicorp/serf/serf"
)
2017-12-12 00:38:52 +00:00
// AutopilotDelegate is a Consul delegate for autopilot operations.
type AutopilotDelegate struct {
server *Server
}
2017-12-12 00:38:52 +00:00
func (d *AutopilotDelegate) FetchStats(ctx context.Context, servers []*metadata.Server) map[string]*autopilot.ServerStats {
return d.server.statsFetcher.Fetch(ctx, servers)
}
2017-12-12 00:38:52 +00:00
func (d *AutopilotDelegate) GetOrCreateAutopilotConfig() (*autopilot.Config, bool) {
return d.server.getOrCreateAutopilotConfig()
}
2017-12-12 00:38:52 +00:00
func (d *AutopilotDelegate) Raft() *raft.Raft {
return d.server.raft
}
2017-12-12 00:38:52 +00:00
func (d *AutopilotDelegate) Serf() *serf.Serf {
return d.server.serfLAN
}
2017-12-12 00:38:52 +00:00
func (d *AutopilotDelegate) NumPeers() (int, error) {
return d.server.numPeers()
}
2017-12-12 00:38:52 +00:00
func (d *AutopilotDelegate) PromoteNonVoters(conf *autopilot.Config, health autopilot.OperatorHealthReply) ([]raft.Server, error) {
future := d.server.raft.GetConfiguration()
if err := future.Error(); err != nil {
return nil, fmt.Errorf("failed to get raft configuration: %v", err)
}
2017-03-21 23:36:44 +00:00
2017-12-12 00:38:52 +00:00
return autopilot.PromoteStableServers(conf, health, future.Configuration().Servers), nil
2017-03-21 23:36:44 +00:00
}