skipper

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2015 License: GPL-2.0 Imports: 3 Imported by: 0

README

consul-skipper

GoDoc Build Status

consul-skipper is a library for a cluster leader election using Consul KV. This needs to be attached to the Consul Agent and then it runs leader election from there.

import "github.com/darkcrux/consul-skipper"

candidate := &skipper.Candidate{
    ConsulAddress:    "10.0.0.10:8500",
    ConsulDatacenter: "dc1",
    LeadershipKey:    "app/leader",
}
candidate.RunForElection()

Running for election runs asynchronously and will keep running as long as the main application is running. To check if the current attached agent is the current leader, use:

skipper.IsLeader()

It is also possible to force a leader to step down forcing a re-election.

skipper.Resign()

Documentation

Overview

consul-skipper is a library for a cluster leader election using Consul KV. This needs to be attached to the Consul Agent and then it runs leader election from there.

import "github.com/darkcrux/consul-skipper"

candidate := &skipper.Candidate{
	ConsulAddress:    "10.0.0.10:8500",
	ConsulDatacenter: "dc1",
	LeadershipKey:    "app/leader",
}
candidate.RunForElection()

Running for election runs asynchronously and will keep running as long as the main application is running. To check if the current attached agent is the current leader, use:

skipper.IsLeader()

It is also possible to force a leader to step down forcing a re-election.

skipper.Resign()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	ConsulAddress    string // The address of the consul agent. This defaults to 127.0.0.1:8500.
	ConsulDatacenter string // The datacenter to connect to. This defaults to the config used by the agent.
	LeadershipKey    string // The leadership key. This needs to be a proper Consul KV key. eg. app/leader
	// contains filtered or unexported fields
}

func (*Candidate) IsLeader

func (c *Candidate) IsLeader() bool

IsLeader returns true if the current agent is the leader.

func (*Candidate) Leader

func (c *Candidate) Leader() string

Leader returns the node of the current cluster leader. This returns an empty string if there is no leader.

func (*Candidate) Resign

func (c *Candidate) Resign()

Resign forces the current agent to step down as the leader forcing a re-election. Nothing happens if the agent is not the current leader.

func (*Candidate) RunForElection

func (c *Candidate) RunForElection()

RunForElection makes the candidate run for leadership against the other nodes in the cluster. This tries and acquire the lock of the given LeadershipKey and setting it's value with the current node. If the lock acquisition passes, then the node where the agent is running is now the new leader. A re-election will occur when there are changes in the LeadershipKey.

Jump to

Keyboard shortcuts

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