leader

package
v0.0.0-...-a69e935 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2019 License: Apache-2.0 Imports: 16 Imported by: 92

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewID

func NewID(httpPort int, grpcPort int) string

NewID returns a ID for a server to implement leader.Nomination

func NewServiceInstance

func NewServiceInstance(endpoint Endpoint, additionalEndpoints map[string]Endpoint) string

NewServiceInstance creates a new instance for Aurora

Types

type Candidate

type Candidate interface {
	IsLeader() bool
	Start() error
	Stop() error
	Resign()
}

Candidate is an interface representing both a candidate campaigning to become a leader, and the observer that watches state changes in leadership to be notified about changes

func NewCandidate

func NewCandidate(
	cfg ElectionConfig,
	parent tally.Scope,
	role string,
	nomination Nomination) (Candidate, error)

NewCandidate creates new election object to control participation in leader election.

type Discovery

type Discovery interface {

	// Returns the app URL for a given Peloton role such as
	// peloton-jobmgr, peloton-resmgr or peloton-hostmgr etc.
	GetAppURL(role string) (*url.URL, error)
}

Discovery is the service discovery interface for Peloton clients

func NewStaticServiceDiscovery

func NewStaticServiceDiscovery(
	jobmgrURL *url.URL,
	resmgrURL *url.URL,
	hostmgrURL *url.URL) (Discovery, error)

NewStaticServiceDiscovery creates a staticDiscovery object

func NewZkServiceDiscovery

func NewZkServiceDiscovery(
	zkServers []string,
	zkRoot string) (Discovery, error)

NewZkServiceDiscovery creates a zkDiscovery object

type ElectionConfig

type ElectionConfig struct {
	// A comma separated list of ZK servers to use for leader election.
	ZKServers []string `yaml:"zk_servers"`

	// The root path in ZK to use for role leader election.
	// This will be something like /peloton/YOURCLUSTERHERE.
	Root string `yaml:"root"`
}

ElectionConfig is config related to leader election of this service.

type Endpoint

type Endpoint struct {
	Host string `json:"host"`
	Port int    `json:"port"`
}

Endpoint represents on instance for aurora leader/follower

func NewEndpoint

func NewEndpoint(port int) Endpoint

NewEndpoint creates a new endpoint

type ID

type ID struct {
	Hostname string `json:"hostname"`
	IP       string `json:"ip"`
	HTTPPort int    `json:"http"`
	GRPCPort int    `json:"grpc"`
	Version  string `json:"version"`
}

ID defines the json struct to be encoded in leader node TODO(rcharles) add Instance representing the instance number

type Nomination

type Nomination interface {
	// GainedLeadershipCallback is the callback when the current node
	// becomes the leader
	GainedLeadershipCallback() error

	// HasGainedLeadership returns true iff once GainedLeadershipCallback
	// completes
	HasGainedLeadership() bool

	// ShutDownCallback is the callback to shut down gracefully if
	// possible
	ShutDownCallback() error

	// LostLeadershipCallback is the callback when the leader lost
	// leadership
	LostLeadershipCallback() error

	// GetID returns the host:master_port of the node running for
	// leadership (i.e. the ID)
	GetID() string
}

Nomination represents the set of callbacks to handle leadership election

type Observer

type Observer interface {
	CurrentLeader() (string, error)
	Start() error
	Stop()
}

Observer is an interface that describes something that can observe an election for a given role, and can Start() observing, query the CurrentLeader(), and Stop() observing.

func NewObserver

func NewObserver(cfg ElectionConfig, scope tally.Scope, role string, newLeaderCallback func(string) error) (Observer, error)

NewObserver creates a new Observer that will watch and react to new leadership events for leaders in a given `role`, and will call newLeaderCallback whenever leadership changes

type ServiceInstance

type ServiceInstance struct {
	ServiceEndpoint     Endpoint            `json:"serviceEndpoint"`
	AdditionalEndpoints map[string]Endpoint `json:"additionalEndpoints"`
	Status              string              `json:"status"`
}

ServiceInstance represents znode for Peloton Bridge to mock Aurora leader

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL